From f35cb679b7b7c80f7e79f37be93586d379cc02fe Mon Sep 17 00:00:00 2001 From: Jean-Francois Monfort Date: Thu, 11 Mar 2021 14:27:46 +0100 Subject: [PATCH] Add CommentEmbeddable to Activity : remoke remark field (Ref #21) --- Controller/ActivityController.php | 28 ++-- DataFixtures/ORM/LoadActivity.php | 52 +++---- Entity/Activity.php | 29 ---- Form/ActivityType.php | 4 - Resources/views/Activity/edit.html.twig | 3 +- Resources/views/Activity/list.html.twig | 16 +- Resources/views/Activity/new.html.twig | 1 - Resources/views/Activity/show.html.twig | 2 - .../activity_person_context.html.twig | 17 +-- Tests/Controller/ActivityControllerTest.php | 142 +++++++++--------- Tests/Form/ActivityTypeTest.php | 82 +++++----- migrations/Version20210304154629.php | 36 +++++ migrations/Version20210311114250.php | 32 ++++ translations/messages.fr.yml | 6 +- 14 files changed, 240 insertions(+), 210 deletions(-) create mode 100644 migrations/Version20210304154629.php create mode 100644 migrations/Version20210311114250.php diff --git a/Controller/ActivityController.php b/Controller/ActivityController.php index 60b029de3..3b5517a70 100644 --- a/Controller/ActivityController.php +++ b/Controller/ActivityController.php @@ -41,22 +41,22 @@ use Chill\ActivityBundle\Form\ActivityType; */ class ActivityController extends AbstractController { - + /** * @var EventDispatcherInterface */ protected $eventDispatcher; - + /** * @var AuthorizationHelper */ protected $authorizationHelper; - + /** * @var LoggerInterface */ protected $logger; - + /** * ActivityController constructor. * @@ -72,7 +72,7 @@ class ActivityController extends AbstractController $this->authorizationHelper = $authorizationHelper; $this->logger = $logger; } - + /** * Lists all Activity entities. * @@ -97,13 +97,13 @@ class ActivityController extends AbstractController array('person' => $person, 'scope' => $reachableScopes), array('date' => 'DESC') ); - + $event = new PrivacyEvent($person, array( 'element_class' => Activity::class, 'action' => 'list' )); $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); - + return $this->render('ChillActivityBundle:Activity:list.html.twig', array( 'activities' => $activities, 'person' => $person @@ -241,14 +241,14 @@ class ActivityController extends AbstractController $this->denyAccessUnlessGranted('CHILL_ACTIVITY_SEE', $entity); $deleteForm = $this->createDeleteForm($id, $person); - + $event = new PrivacyEvent($person, array( 'element_class' => Activity::class, 'element_id' => $entity->getId(), 'action' => 'show' )); $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); - + return $this->render('ChillActivityBundle:Activity:show.html.twig', array( 'person' => $person, 'entity' => $entity, @@ -281,7 +281,7 @@ class ActivityController extends AbstractController $editForm = $this->createEditForm($entity); $deleteForm = $this->createDeleteForm($id, $person); - + $event = new PrivacyEvent($person, array( 'element_class' => Activity::class, 'element_id' => $entity->getId(), @@ -339,7 +339,7 @@ class ActivityController extends AbstractController $deleteForm = $this->createDeleteForm($id, $person); $editForm = $this->createEditForm($entity); $editForm->handleRequest($request); - + $event = new PrivacyEvent($person, array( 'element_class' => Activity::class, 'element_id' => $entity->getId(), @@ -356,7 +356,7 @@ class ActivityController extends AbstractController $this->get('translator') ->trans('Success : activity updated!') ); - + return $this->redirect($this->generateUrl('chill_activity_activity_show', array('id' => $id, 'person_id' => $person_id))); } @@ -400,12 +400,12 @@ class ActivityController extends AbstractController $form->handleRequest($request); if ($form->isValid()) { - + $this->logger->notice("An activity has been removed", array( 'by_user' => $this->getUser()->getUsername(), 'activity_id' => $activity->getId(), 'person_id' => $activity->getPerson()->getId(), - 'remark' => $activity->getRemark(), + 'comment' => $activity->getComment()->getComment(), 'scope_id' => $activity->getScope()->getId(), 'reasons_ids' => $activity->getReasons() ->map(function ($ar) { return $ar->getId(); }) diff --git a/DataFixtures/ORM/LoadActivity.php b/DataFixtures/ORM/LoadActivity.php index ab5f864ea..dd24cfcd2 100644 --- a/DataFixtures/ORM/LoadActivity.php +++ b/DataFixtures/ORM/LoadActivity.php @@ -2,20 +2,20 @@ /* * Chill is a software for social workers - * - * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, + * + * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, * , - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ @@ -41,25 +41,25 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface; class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface { use \Symfony\Component\DependencyInjection\ContainerAwareTrait; - + /** - * @var \Faker\Generator + * @var \Faker\Generator */ private $faker; - + public function __construct() { $this->faker = FakerFactory::create('fr_FR'); - } - + } + public function getOrder() { return 16400; } - + /** * Return a random scope - * + * * @return \Chill\MainBundle\Entity\Scope */ private function getRandomScope() @@ -67,10 +67,10 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C $scopeRef = LoadScopes::$references[array_rand(LoadScopes::$references)]; return $this->getReference($scopeRef); } - + /** * Return a random activityType - * + * * @return \Chill\ActivityBundle\Entity\ActivityType */ private function getRandomActivityType() @@ -78,27 +78,27 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C $typeRef = LoadActivityType::$references[array_rand(LoadActivityType::$references)]; return $this->getReference($typeRef); } - + /** * Return a random activityReason - * + * * @return \Chill\ActivityBundle\Entity\ActivityReason */ private function getRandomActivityReason(array $excludingIds) { $reasonRef = LoadActivityReason::$references[array_rand(LoadActivityReason::$references)]; - + if (in_array($this->getReference($reasonRef)->getId(), $excludingIds)) { // we have a reason which should be excluded. Find another... return $this->getRandomActivityReason($excludingIds); } - + return $this->getReference($reasonRef); } - + /** * Return a random user - * + * * @return \Chill\MainBundle\Entity\User */ private function getRandomUser() @@ -106,7 +106,7 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C $userRef = array_rand(LoadUsers::$refs); return $this->getReference($userRef); } - + public function newRandomActivity($person) { $activity = (new Activity()) @@ -117,24 +117,24 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C ->setType($this->getRandomActivityType()) ->setScope($this->getRandomScope()) ->setAttendee($this->faker->boolean()) - ->setRemark('A remark'); - + ; + $usedId = array(); for ($i = 0; $i < rand(0, 4); $i++) { $reason = $this->getRandomActivityReason($usedId); $usedId[] = $reason->getId(); $activity->addReason($reason); } - + return $activity; } - + public function load(ObjectManager $manager) { $persons = $this->container->get('doctrine.orm.entity_manager') ->getRepository('ChillPersonBundle:Person') ->findAll(); - + foreach($persons as $person) { $activityNbr = rand(0,3); for($i = 0; $i < $activityNbr; $i ++) { diff --git a/Entity/Activity.php b/Entity/Activity.php index dfb28301a..e96db03db 100644 --- a/Entity/Activity.php +++ b/Entity/Activity.php @@ -75,12 +75,6 @@ class Activity implements HasCenterInterface, HasScopeInterface */ private $durationTime; - /** - * @var string - * @ORM\Column(type="text") - */ - private $remark; - /** * @var boolean * @ORM\Column(type="boolean") @@ -204,29 +198,6 @@ class Activity implements HasCenterInterface, HasScopeInterface return $this->durationTime; } - /** - * Set remark - * - * @param string $remark - * @return Activity - */ - public function setRemark($remark) - { - $this->remark = $remark; - - return $this; - } - - /** - * Get remark - * - * @return string - */ - public function getRemark() - { - return $this->remark; - } - /** * Set attendee * diff --git a/Form/ActivityType.php b/Form/ActivityType.php index e2d660f3f..ad0e55aa7 100644 --- a/Form/ActivityType.php +++ b/Form/ActivityType.php @@ -93,10 +93,6 @@ class ActivityType extends AbstractType 'required' => true )) ->add('durationTime', ChoiceType::class, $durationTimeOptions) - ->add('remark', TextareaType::class, array( - 'required' => false, - 'empty_data' => '' - )) ->add('attendee', ChoiceType::class, array( 'expanded' => true, 'required' => false, diff --git a/Resources/views/Activity/edit.html.twig b/Resources/views/Activity/edit.html.twig index 5a70d3f81..7a69a8eee 100644 --- a/Resources/views/Activity/edit.html.twig +++ b/Resources/views/Activity/edit.html.twig @@ -32,10 +32,9 @@ {{ form_row(edit_form.date) }} {{ form_row(edit_form.durationTime) }} {{ form_row(edit_form.type) }} - {{ form_row(edit_form.remark) }} {{ form_row(edit_form.attendee) }} {{ form_row(edit_form.reasons) }} - {{ form_row(form.comment) }} + {{ form_row(edit_form.comment) }} {{ form_widget(edit_form) }}