diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index 3b5517a70..58d7e68ea 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -22,6 +22,7 @@ namespace Chill\ActivityBundle\Controller; +use Chill\ActivityBundle\Form\ActivitySelectTypeType; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\PersonBundle\Privacy\PrivacyEvent; use Psr\Log\LoggerInterface; @@ -29,9 +30,9 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Role\Role; use Chill\ActivityBundle\Entity\Activity; -use Chill\PersonBundle\Entity\Person; use Chill\ActivityBundle\Form\ActivityType; /** @@ -41,27 +42,18 @@ use Chill\ActivityBundle\Form\ActivityType; */ class ActivityController extends AbstractController { + protected EventDispatcherInterface $eventDispatcher; - /** - * @var EventDispatcherInterface - */ - protected $eventDispatcher; + protected AuthorizationHelper $authorizationHelper; - /** - * @var AuthorizationHelper - */ - protected $authorizationHelper; - - /** - * @var LoggerInterface - */ - protected $logger; + protected LoggerInterface $logger; /** * ActivityController constructor. * * @param EventDispatcherInterface $eventDispatcher * @param AuthorizationHelper $authorizationHelper + * @param \Psr\Log\LoggerInterface $logger */ public function __construct( EventDispatcherInterface $eventDispatcher, @@ -89,7 +81,7 @@ class ActivityController extends AbstractController $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); $reachableScopes = $this->authorizationHelper - ->getReachableScopes($this->getUser(), new Role('CHILL_ACTIVITY_SEE'), + ->getReachableCircles($this->getUser(), new Role('CHILL_ACTIVITY_SEE'), $person->getCenter()); $activities = $em->getRepository('ChillActivityBundle:Activity') @@ -109,6 +101,35 @@ class ActivityController extends AbstractController 'person' => $person )); } + + public function selectTypeAction(int $person_id, Request $request): Response + { + $em = $this->getDoctrine()->getManager(); + $person = $em->getRepository('ChillPersonBundle:Person')->find($person_id); + + if ($person === NULL) { + throw $this->createNotFoundException('Person not found'); + } + + $form = $this->createForm(ActivitySelectTypeType::class); + + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $activityType = $form->get('type')->getData(); + if ($activityType instanceof \Chill\ActivityBundle\Entity\ActivityType) { + return $this->redirectToRoute('chill_activity_activity_new', [ + 'person_id' => $person->getId(), + 'activityType_id' => $activityType->getId(), + ]); + } + } + + return $this->render('ChillActivityBundle:Activity:selectType.html.twig', [ + 'form' => $form->createView(), + 'person' => $person + ]); + } + /** * Creates a new Activity entity. * @@ -126,7 +147,7 @@ class ActivityController extends AbstractController $entity = new Activity(); $entity->setPerson($person); - $form = $this->createCreateForm($entity, $person); + $form = $this->createCreateForm($entity); $form->handleRequest($request); if ($form->isValid()) { @@ -190,7 +211,7 @@ class ActivityController extends AbstractController * Displays a form to create a new Activity entity. * */ - public function newAction($person_id) + public function newAction($person_id, Request $request) { $em = $this->getDoctrine()->getManager(); $person = $em->getRepository('ChillPersonBundle:Person')->find($person_id); @@ -199,16 +220,27 @@ class ActivityController extends AbstractController throw $this->createNotFoundException('Person not found'); } + $activityType_id = $request->get('activityType_id', 0); + $activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) + ->find($activityType_id); + + if (!$activityType instanceof \Chill\ActivityBundle\Entity\ActivityType) { + return $this->redirectToRoute('chill_activity_activity_select_type', [ + 'person_id' => $person->getId(), + ]); + } + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); $entity = new Activity(); - $entity->setUser($this->get('security.token_storage')->getToken()->getUser()); + $entity->setUser($this->getUser()); $entity->setPerson($person); + $entity->setType($activityType); $entity->setDate(new \DateTime('now')); $this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity); - $form = $this->createCreateForm($entity, $person); + $form = $this->createCreateForm($entity); return $this->render('ChillActivityBundle:Activity:new.html.twig', array( 'person' => $person, diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php index ca492fbf4..7dc2fbaa9 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php @@ -235,6 +235,7 @@ class ActivityType */ public function getName(?string $locale = null) { + // TODO if ($locale) { if (isset($this->name[$locale])) { return $this->name[$locale]; diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php b/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php index eaf347cb4..82d96b93e 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php @@ -72,22 +72,9 @@ class ActivityTypeCategory * * @return array | string */ - public function getName(?string $locale = null) + public function getName(): array { - if ($locale) { - if (isset($this->name[$locale])) { - return $this->name[$locale]; - } else { - foreach ($this->name as $name) { - if (!empty($name)) { - return $name; - } - } - } - return ''; - } else { - return $this->name; - } + return $this->name; } /** diff --git a/src/Bundle/ChillActivityBundle/Form/ActivitySelectTypeType.php b/src/Bundle/ChillActivityBundle/Form/ActivitySelectTypeType.php new file mode 100644 index 000000000..c637e5bcc --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Form/ActivitySelectTypeType.php @@ -0,0 +1,19 @@ +add('type', TranslatableActivityType::class, array( + 'placeholder' => 'Choose a type', + 'active_only' => true, + 'mapped' => false, + )); + } +} diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityType.php b/src/Bundle/ChillActivityBundle/Form/ActivityType.php index ad0e55aa7..eb63b6beb 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityType.php @@ -15,7 +15,6 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTra use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; -use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Chill\ActivityBundle\Form\Type\TranslatableActivityType; use Chill\ActivityBundle\Form\Type\TranslatableActivityReason; use Chill\MainBundle\Form\Type\UserPickerType; @@ -24,7 +23,6 @@ use Chill\MainBundle\Form\Type\ChillDateType; class ActivityType extends AbstractType { - /** * the user running this form * @@ -36,7 +34,7 @@ class ActivityType extends AbstractType * * @var AuthorizationHelper */ - protected $authorizationHelper; + protected AuthorizationHelper $authorizationHelper; /** * @@ -113,10 +111,6 @@ class ActivityType extends AbstractType 'multiple' => true, 'required' => false, )) - ->add('type', TranslatableActivityType::class, array( - 'placeholder' => 'Choose a type', - 'active_only' => true - )) ->add('comment', CommentType::class, [ 'required' => false, ]) diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig index e069bfce3..24c659a56 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig @@ -21,7 +21,7 @@ {% block title 'Activity creation' |trans %} {% block personcontent %} -

{{ "Activity creation"|trans }}

+

{{ "Activity creation"|trans }}

{{ form_start(form) }} @@ -32,14 +32,13 @@ {{ form_row(form.date) }} {{ form_row(form.durationTime) }} - {{ form_row(form.type) }} {{ form_row(form.attendee) }} {{ form_row(form.reasons) }} {{ form_row(form.comment) }} -
- -
+
+ +
{{ form_end(form) }} {% endblock %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/selectType.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/selectType.html.twig new file mode 100644 index 000000000..e6ab83482 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/selectType.html.twig @@ -0,0 +1,19 @@ +{% extends "@ChillPerson/layout.html.twig" %} + +{% set activeRouteKey = 'chill_activity_activity_new' %} + +{% block title 'Activity creation'|trans %} + +{% block personcontent %} +

{{ "Activity creation"|trans }}

+ + {{ form_start(form) }} + + {{ form_row(form.type) }} + +
+ +
+ + {{ form_end(form) }} +{% endblock %} diff --git a/src/Bundle/ChillActivityBundle/config/routes/activity.yaml b/src/Bundle/ChillActivityBundle/config/routes/activity.yaml index a320bb2ac..342ccf7d3 100644 --- a/src/Bundle/ChillActivityBundle/config/routes/activity.yaml +++ b/src/Bundle/ChillActivityBundle/config/routes/activity.yaml @@ -6,6 +6,10 @@ chill_activity_activity_show: path: /{_locale}/person/{person_id}/activity/{id}/show controller: Chill\ActivityBundle\Controller\ActivityController::showAction +chill_activity_activity_select_type: + path: /{_locale}/person/{person_id}/activity/select-type + controller: Chill\ActivityBundle\Controller\ActivityController::selectTypeAction + chill_activity_activity_new: path: /{_locale}/person/{person_id}/activity/new controller: Chill\ActivityBundle\Controller\ActivityController::newAction