mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
Form & save into DB
This commit is contained in:
parent
82d8556f24
commit
4d8afd53ad
@ -121,80 +121,6 @@ class ActivityController extends AbstractController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new Activity entity.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function createAction($person_id, Request $request)
|
|
||||||
{
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
|
||||||
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
|
|
||||||
|
|
||||||
if ($person === NULL) {
|
|
||||||
throw $this->createNotFoundException('person not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
|
||||||
|
|
||||||
$entity = new Activity();
|
|
||||||
$entity->setPerson($person);
|
|
||||||
$form = $this->createCreateForm($entity);
|
|
||||||
$form->handleRequest($request);
|
|
||||||
|
|
||||||
if ($form->isValid()) {
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity,
|
|
||||||
'creation of this activity not allowed');
|
|
||||||
|
|
||||||
$em->persist($entity);
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
$this->get('session')
|
|
||||||
->getFlashBag()
|
|
||||||
->add('success',
|
|
||||||
$this->get('translator')
|
|
||||||
->trans('Success : activity created!')
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->redirect(
|
|
||||||
$this->generateUrl('chill_activity_activity_show',
|
|
||||||
array('id' => $entity->getId(), 'person_id' => $person_id)));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->get('session')
|
|
||||||
->getFlashBag()->add('danger',
|
|
||||||
$this->get('translator')
|
|
||||||
->trans('The form is not valid. The activity has not been created !')
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->render('ChillActivityBundle:Activity:new.html.twig', array(
|
|
||||||
'entity' => $entity,
|
|
||||||
'form' => $form->createView(),
|
|
||||||
'person' => $person
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a form to create a Activity entity.
|
|
||||||
*
|
|
||||||
* @param Activity $entity The entity
|
|
||||||
*
|
|
||||||
* @return \Symfony\Component\Form\Form The form
|
|
||||||
*/
|
|
||||||
private function createCreateForm(Activity $entity): FormInterface
|
|
||||||
{
|
|
||||||
return $this->createForm(ActivityType::class, $entity, [
|
|
||||||
'action' => $this->generateUrl('chill_activity_activity_create', [
|
|
||||||
'person_id' => $entity->getPerson()->getId(),
|
|
||||||
]),
|
|
||||||
'method' => 'POST',
|
|
||||||
'center' => $entity->getCenter(),
|
|
||||||
'role' => new Role('CHILL_ACTIVITY_CREATE'),
|
|
||||||
'activityType' => $entity->getType(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a form to create a new Activity entity.
|
* Displays a form to create a new Activity entity.
|
||||||
*
|
*
|
||||||
@ -229,7 +155,23 @@ class ActivityController extends AbstractController
|
|||||||
|
|
||||||
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity);
|
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity);
|
||||||
|
|
||||||
$form = $this->createCreateForm($entity);
|
$form = $this->createForm(ActivityType::class, $entity, [
|
||||||
|
'center' => $entity->getCenter(),
|
||||||
|
'role' => new Role('CHILL_ACTIVITY_CREATE'),
|
||||||
|
'activityType' => $entity->getType(),
|
||||||
|
])->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
$em->persist($entity);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
$this->addFlash('success', $this->get('translator')->trans('Success : activity created!'));
|
||||||
|
|
||||||
|
return $this->redirectToRoute('chill_activity_activity_show', [
|
||||||
|
'id' => $entity->getId(),
|
||||||
|
'person_id' => $person_id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render('ChillActivityBundle:Activity:new.html.twig', array(
|
return $this->render('ChillActivityBundle:Activity:new.html.twig', array(
|
||||||
'person' => $person,
|
'person' => $person,
|
||||||
@ -238,6 +180,42 @@ class ActivityController extends AbstractController
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Activity entity.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function createAction($person_id, Request $request)
|
||||||
|
{
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
|
||||||
|
|
||||||
|
if ($person === NULL) {
|
||||||
|
throw $this->createNotFoundException('person not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||||
|
|
||||||
|
$entity = new Activity();
|
||||||
|
$entity->setPerson($person);
|
||||||
|
$form = $this->createCreateForm($entity);
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$this->get('session')
|
||||||
|
->getFlashBag()->add('danger',
|
||||||
|
$this->get('translator')
|
||||||
|
->trans('The form is not valid. The activity has not been created !')
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->render('ChillActivityBundle:Activity:new.html.twig', array(
|
||||||
|
'entity' => $entity,
|
||||||
|
'form' => $form->createView(),
|
||||||
|
'person' => $person
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and displays a Activity entity.
|
* Finds and displays a Activity entity.
|
||||||
*
|
*
|
||||||
|
@ -69,9 +69,9 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
private \DateTime $date;
|
private \DateTime $date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="time")
|
* @ORM\Column(type="time", nullable=true)
|
||||||
*/
|
*/
|
||||||
private \DateTime $durationTime;
|
private ?\DateTime $durationTime = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="time", nullable=true)
|
* @ORM\Column(type="time", nullable=true)
|
||||||
@ -81,7 +81,7 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityPresence")
|
* @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityPresence")
|
||||||
*/
|
*/
|
||||||
private ActivityPresence $attendee;
|
private ?ActivityPresence $attendee = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity="Chill\ActivityBundle\Entity\ActivityReason")
|
* @ORM\ManyToMany(targetEntity="Chill\ActivityBundle\Entity\ActivityReason")
|
||||||
@ -148,17 +148,11 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
$this->users = new ArrayCollection();
|
$this->users = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get id
|
|
||||||
*/
|
|
||||||
public function getId(): int
|
public function getId(): int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set user
|
|
||||||
*/
|
|
||||||
public function setUser(User $user): self
|
public function setUser(User $user): self
|
||||||
{
|
{
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
@ -166,17 +160,11 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get user
|
|
||||||
*/
|
|
||||||
public function getUser(): User
|
public function getUser(): User
|
||||||
{
|
{
|
||||||
return $this->user;
|
return $this->user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set date
|
|
||||||
*/
|
|
||||||
public function setDate(\DateTime $date): self
|
public function setDate(\DateTime $date): self
|
||||||
{
|
{
|
||||||
$this->date = $date;
|
$this->date = $date;
|
||||||
@ -184,28 +172,19 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get date
|
|
||||||
*/
|
|
||||||
public function getDate(): \DateTime
|
public function getDate(): \DateTime
|
||||||
{
|
{
|
||||||
return $this->date;
|
return $this->date;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setDurationTime(?\DateTime $durationTime): self
|
||||||
* Set durationTime
|
|
||||||
*/
|
|
||||||
public function setDurationTime(\DateTime $durationTime): self
|
|
||||||
{
|
{
|
||||||
$this->durationTime = $durationTime;
|
$this->durationTime = $durationTime;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getDurationTime(): ?\DateTime
|
||||||
* Get durationTime
|
|
||||||
*/
|
|
||||||
public function getDurationTime(): \DateTime
|
|
||||||
{
|
{
|
||||||
return $this->durationTime;
|
return $this->durationTime;
|
||||||
}
|
}
|
||||||
@ -229,17 +208,14 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAttendee(): ActivityPresence
|
public function getAttendee(): ?ActivityPresence
|
||||||
{
|
{
|
||||||
return $this->attendee;
|
return $this->attendee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a reason
|
|
||||||
*/
|
|
||||||
public function addReason(ActivityReason $reason): self
|
public function addReason(ActivityReason $reason): self
|
||||||
{
|
{
|
||||||
$this->reasons[] = $reason;
|
$this->reasons->add($reason);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -249,17 +225,18 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
$this->reasons->removeElement($reason);
|
$this->reasons->removeElement($reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get reasons
|
|
||||||
*/
|
|
||||||
public function getReasons(): Collection
|
public function getReasons(): Collection
|
||||||
{
|
{
|
||||||
return $this->reasons;
|
return $this->reasons;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setReasons(?ArrayCollection $reasons): self
|
||||||
* Set type
|
{
|
||||||
*/
|
$this->reasons = $reasons;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setType(ActivityType $type): self
|
public function setType(ActivityType $type): self
|
||||||
{
|
{
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
@ -267,17 +244,11 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get type
|
|
||||||
*/
|
|
||||||
public function getType(): ActivityType
|
public function getType(): ActivityType
|
||||||
{
|
{
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set scope
|
|
||||||
*/
|
|
||||||
public function setScope(Scope $scope): self
|
public function setScope(Scope $scope): self
|
||||||
{
|
{
|
||||||
$this->scope = $scope;
|
$this->scope = $scope;
|
||||||
@ -285,17 +256,11 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get scope
|
|
||||||
*/
|
|
||||||
public function getScope(): ?Scope
|
public function getScope(): ?Scope
|
||||||
{
|
{
|
||||||
return $this->scope;
|
return $this->scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set person
|
|
||||||
*/
|
|
||||||
public function setPerson(Person $person): self
|
public function setPerson(Person $person): self
|
||||||
{
|
{
|
||||||
$this->person = $person;
|
$this->person = $person;
|
||||||
@ -303,9 +268,6 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get person
|
|
||||||
*/
|
|
||||||
public function getPerson(): Person
|
public function getPerson(): Person
|
||||||
{
|
{
|
||||||
return $this->person;
|
return $this->person;
|
||||||
@ -453,9 +415,9 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
|||||||
return $this->sentReceived;
|
return $this->sentReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSentReceived(string $sentReceived): self
|
public function setSentReceived(?string $sentReceived): self
|
||||||
{
|
{
|
||||||
$this->sentReceived = $sentReceived;
|
$this->sentReceived = (string) $sentReceived;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -134,6 +134,7 @@ class ActivityType extends AbstractType
|
|||||||
'label' => $activityType->getLabel('reasons'),
|
'label' => $activityType->getLabel('reasons'),
|
||||||
'required' => $activityType->isRequired('reasons'),
|
'required' => $activityType->isRequired('reasons'),
|
||||||
'class' => ActivityReason::class,
|
'class' => ActivityReason::class,
|
||||||
|
'multiple' => true,
|
||||||
'choice_label' => function (ActivityReason $activityReason) {
|
'choice_label' => function (ActivityReason $activityReason) {
|
||||||
return $this->translatableStringHelper->localize($activityReason->getName());
|
return $this->translatableStringHelper->localize($activityReason->getName());
|
||||||
},
|
},
|
||||||
@ -172,6 +173,7 @@ class ActivityType extends AbstractType
|
|||||||
'label' => $activityType->getLabel('thirdParties'),
|
'label' => $activityType->getLabel('thirdParties'),
|
||||||
'required' => $activityType->isRequired('thirdParties'),
|
'required' => $activityType->isRequired('thirdParties'),
|
||||||
'class' => ThirdParty::class,
|
'class' => ThirdParty::class,
|
||||||
|
'multiple' => true,
|
||||||
'choice_label' => function (ThirdParty $thirdParty) {
|
'choice_label' => function (ThirdParty $thirdParty) {
|
||||||
return $thirdParty->getName();
|
return $thirdParty->getName();
|
||||||
},
|
},
|
||||||
@ -189,6 +191,7 @@ class ActivityType extends AbstractType
|
|||||||
'label' => $activityType->getLabel('users'),
|
'label' => $activityType->getLabel('users'),
|
||||||
'required' => $activityType->isRequired('users'),
|
'required' => $activityType->isRequired('users'),
|
||||||
'class' => User::class,
|
'class' => User::class,
|
||||||
|
'multiple' => true,
|
||||||
'choice_label' => function (User $user) {
|
'choice_label' => function (User $user) {
|
||||||
return $user->getUsername();
|
return $user->getUsername();
|
||||||
},
|
},
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
<h2 class="chill-red">{{ "Activity creation"|trans }}</h2>
|
<h2 class="chill-red">{{ "Activity creation"|trans }}</h2>
|
||||||
|
|
||||||
{{ form_start(form) }}
|
{{ form_start(form) }}
|
||||||
|
{{ form_errors(form) }}
|
||||||
|
|
||||||
{{ form_row(form.user) }}
|
{{ form_row(form.user) }}
|
||||||
{{ form_row(form.scope) }}
|
{{ form_row(form.scope) }}
|
||||||
|
@ -13,6 +13,7 @@ chill_activity_activity_select_type:
|
|||||||
chill_activity_activity_new:
|
chill_activity_activity_new:
|
||||||
path: /{_locale}/person/{person_id}/activity/new
|
path: /{_locale}/person/{person_id}/activity/new
|
||||||
controller: Chill\ActivityBundle\Controller\ActivityController::newAction
|
controller: Chill\ActivityBundle\Controller\ActivityController::newAction
|
||||||
|
methods: [POST, GET]
|
||||||
|
|
||||||
chill_activity_activity_create:
|
chill_activity_activity_create:
|
||||||
path: /{_locale}/person/{person_id}/activity/create
|
path: /{_locale}/person/{person_id}/activity/create
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\Activity;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20210506071150 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription() : string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema) : void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE activity ALTER durationtime DROP NOT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema) : void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE activity ALTER durationTime SET NOT NULL');
|
||||||
|
}
|
||||||
|
}
|
@ -31,13 +31,13 @@ final class ChillMarkdownRenderExtension extends AbstractExtension
|
|||||||
* @var Parsedown
|
* @var Parsedown
|
||||||
*/
|
*/
|
||||||
protected $parsedown;
|
protected $parsedown;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->parsedown = new Parsedown();
|
$this->parsedown = new Parsedown();
|
||||||
$this->parsedown->setSafeMode(true);
|
$this->parsedown->setSafeMode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilters(): array
|
public function getFilters(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -46,9 +46,9 @@ final class ChillMarkdownRenderExtension extends AbstractExtension
|
|||||||
])
|
])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderMarkdownToHtml(string $var): string
|
public function renderMarkdownToHtml(?string $var): string
|
||||||
{
|
{
|
||||||
return $this->parsedown->parse($var);
|
return $this->parsedown->parse((string) $var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user