rdv: add route, twig for listing and creating calendar items

This commit is contained in:
nobohan 2021-07-16 11:58:30 +02:00
parent 75caf3fa14
commit b01eba2533
11 changed files with 540 additions and 292 deletions

View File

@ -36,7 +36,9 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Role\Role; use Symfony\Component\Security\Core\Role\Role;
use Chill\CalendarBundle\Entity\Calendar; use Chill\CalendarBundle\Entity\Calendar;
use Chill\CalendarBundle\Form\CalendarType; use Chill\CalendarBundle\Form\CalendarType;
use Chill\MainBundle\Entity\User;
use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Routing\Annotation\Route;
/** /**
* Class CalendarController * Class CalendarController
@ -67,381 +69,374 @@ class CalendarController extends AbstractController
/** /**
* Lists all Calendar entities. * Lists all Calendar entities.
* @Route("/{_locale}/calendar/", name="chill_calendar_calendar")
*/ */
public function listAction(Request $request): Response public function listAction(Request $request): Response
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$view = null; $view = null;
[$person, $accompanyingPeriod] = $this->getEntity($request); [$user, $accompanyingPeriod] = $this->getEntity($request);
if ($person instanceof Person) { if ($user instanceof User) {
$reachableScopes = $this->authorizationHelper
->getReachableCircles($this->getUser(), new Role('CHILL_Calendar_SEE'),
$person->getCenter());
$activities = $em->getRepository(Calendar::class) // $calendar = $em->getRepository(Calendar::class)
->findByPersonImplied($person, $reachableScopes) // ->findByUser($user)
; // ;
$event = new PrivacyEvent($person, array( // $view = 'ChillCalendarBundle:Calendar:listByUser.html.twig';
'element_class' => Calendar::class,
'action' => 'list'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
$view = 'ChillCalendarBundle:Calendar:listPerson.html.twig';
} elseif ($accompanyingPeriod instanceof AccompanyingPeriod) { } elseif ($accompanyingPeriod instanceof AccompanyingPeriod) {
$activities = $em->getRepository('ChillCalendarBundle:Calendar')->findBy( $calendarItems = $em->getRepository(Calendar::class)->findBy(
['accompanyingPeriod' => $accompanyingPeriod], ['accompanyingPeriod' => $accompanyingPeriod]
['date' => 'DESC'],
); );
$view = 'ChillCalendarBundle:Calendar:listAccompanyingCourse.html.twig'; $view = 'ChillCalendarBundle:Calendar:listByAccompanyingCourse.html.twig';
} }
return $this->render($view, array( return $this->render($view, array(
'activities' => $activities, 'calendarItems' => $calendarItems,
'person' => $person, 'user' => $user,
'accompanyingCourse' => $accompanyingPeriod, 'accompanyingCourse' => $accompanyingPeriod,
)); ));
} }
public function selectTypeAction(Request $request): Response // public function selectTypeAction(Request $request): Response
{ // {
$em = $this->getDoctrine()->getManager(); // $em = $this->getDoctrine()->getManager();
$view = null; // $view = null;
[$person, $accompanyingPeriod] = $this->getEntity($request); // [$person, $accompanyingPeriod] = $this->getEntity($request);
if ($accompanyingPeriod instanceof AccompanyingPeriod) { // if ($accompanyingPeriod instanceof AccompanyingPeriod) {
$view = 'ChillCalendarBundle:Calendar:selectTypeAccompanyingCourse.html.twig'; // $view = 'ChillCalendarBundle:Calendar:selectTypeAccompanyingCourse.html.twig';
} elseif ($person instanceof Person) { // } elseif ($person instanceof Person) {
$view = 'ChillCalendarBundle:Calendar:selectTypePerson.html.twig'; // $view = 'ChillCalendarBundle:Calendar:selectTypePerson.html.twig';
} // }
$data = []; // $data = [];
$activityTypeCategories = $em->getRepository(\Chill\CalendarBundle\Entity\ActivityTypeCategory::class) // $activityTypeCategories = $em->getRepository(\Chill\CalendarBundle\Entity\ActivityTypeCategory::class)
->findBy(['active' => true], ['ordering' => 'ASC']); // ->findBy(['active' => true], ['ordering' => 'ASC']);
foreach ($activityTypeCategories as $activityTypeCategory) { // foreach ($activityTypeCategories as $activityTypeCategory) {
$activityTypes = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) // $activityTypes = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class)
->findBy(['active' => true, 'category' => $activityTypeCategory], ['ordering' => 'ASC']); // ->findBy(['active' => true, 'category' => $activityTypeCategory], ['ordering' => 'ASC']);
$data[] = [ // $data[] = [
'activityTypeCategory' => $activityTypeCategory, // 'activityTypeCategory' => $activityTypeCategory,
'activityTypes' => $activityTypes, // 'activityTypes' => $activityTypes,
]; // ];
} // }
if ($view === null) { // if ($view === null) {
throw $this->createNotFoundException('Template not found'); // throw $this->createNotFoundException('Template not found');
} // }
return $this->render($view, [ // return $this->render($view, [
'person' => $person, // 'person' => $person,
'accompanyingCourse' => $accompanyingPeriod, // 'accompanyingCourse' => $accompanyingPeriod,
'data' => $data, // 'data' => $data,
]); // ]);
} // }
/**
* Create a new calendar item
* @Route("/{_locale}/calendar/new", name="chill_calendar_calendar_new")
*/
public function newAction(Request $request): Response public function newAction(Request $request): Response
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
[$person, $accompanyingPeriod] = $this->getEntity($request); [$user, $accompanyingPeriod] = $this->getEntity($request);
if ($accompanyingPeriod instanceof AccompanyingPeriod) { if ($accompanyingPeriod instanceof AccompanyingPeriod) {
$view = 'ChillCalendarBundle:Calendar:newAccompanyingCourse.html.twig'; $view = 'ChillCalendarBundle:Calendar:newAccompanyingCourse.html.twig';
} elseif ($person instanceof Person) { }
$view = 'ChillCalendarBundle:Calendar:newPerson.html.twig'; // elseif ($user instanceof User) {
} // $view = 'ChillCalendarBundle:Calendar:newUser.html.twig';
// }
$activityType_id = $request->get('activityType_id', 0); // $activityType_id = $request->get('activityType_id', 0);
$activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) // $activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class)
->find($activityType_id); // ->find($activityType_id);
if (!$activityType instanceof \Chill\ActivityBundle\Entity\ActivityType || // if (!$activityType instanceof \Chill\ActivityBundle\Entity\ActivityType ||
!$activityType->isActive()) { // !$activityType->isActive()) {
$params = $this->buildParamsToUrl($person, $accompanyingPeriod); // $params = $this->buildParamsToUrl($user, $accompanyingPeriod);
return $this->redirectToRoute('chill_activity_activity_select_type', $params); // return $this->redirectToRoute('chill_activity_activity_select_type', $params);
} // }
$entity = new Calendar(); $entity = new Calendar();
$entity->setUser($this->getUser()); $entity->setUser($this->getUser());
if ($person instanceof Person) { // if ($user instanceof User) {
$entity->setPerson($person); // $entity->setPerson($user);
} // }
if ($accompanyingPeriod instanceof AccompanyingPeriod) { if ($accompanyingPeriod instanceof AccompanyingPeriod) {
$entity->setAccompanyingPeriod($accompanyingPeriod); $entity->setAccompanyingPeriod($accompanyingPeriod);
} }
$entity->setType($activityType); // $entity->setType($activityType);
$entity->setDate(new \DateTime('now')); // $entity->setDate(new \DateTime('now'));
// TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période // $form = $this->createForm(ActivityType::class, $entity, [
// $this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity); // 'center' => $entity->getCenter(),
// 'role' => new Role('CHILL_ACTIVITY_CREATE'),
// 'activityType' => $entity->getType(),
// 'accompanyingPeriod' => $accompanyingPeriod,
// ])->handleRequest($request);
$form = $this->createForm(ActivityType::class, $entity, [ // if ($form->isSubmitted() && $form->isValid()) {
'center' => $entity->getCenter(), // $em->persist($entity);
'role' => new Role('CHILL_ACTIVITY_CREATE'), // $em->flush();
'activityType' => $entity->getType(),
'accompanyingPeriod' => $accompanyingPeriod,
])->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { // $this->addFlash('success', $this->get('translator')->trans('Success : activity created!'));
$em->persist($entity);
$em->flush();
$this->addFlash('success', $this->get('translator')->trans('Success : activity created!')); // $params = $this->buildParamsToUrl($person, $accompanyingPeriod);
// $params['id'] = $entity->getId();
$params = $this->buildParamsToUrl($person, $accompanyingPeriod); // return $this->redirectToRoute('chill_activity_activity_show', $params);
$params['id'] = $entity->getId(); // }
return $this->redirectToRoute('chill_activity_activity_show', $params); // if ($view === null) {
} // throw $this->createNotFoundException('Template not found');
// }
if ($view === null) { // $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
throw $this->createNotFoundException('Template not found');
}
$activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
return $this->render($view, [ return $this->render($view, [
'person' => $person, 'user' => $user,
'accompanyingCourse' => $accompanyingPeriod, 'accompanyingCourse' => $accompanyingPeriod,
'entity' => $entity, 'entity' => $entity,
'form' => $form->createView(), // 'form' => $form->createView(),
'activity_json' => $activity_array //'activity_json' => $calendar_array
]); ]);
} }
public function showAction(Request $request, $id): Response // public function showAction(Request $request, $id): Response
{ // {
$em = $this->getDoctrine()->getManager(); // $em = $this->getDoctrine()->getManager();
[$person, $accompanyingPeriod] = $this->getEntity($request); // [$person, $accompanyingPeriod] = $this->getEntity($request);
if ($accompanyingPeriod instanceof AccompanyingPeriod) { // if ($accompanyingPeriod instanceof AccompanyingPeriod) {
$view = 'ChillCalendarBundle:Calendar:showAccompanyingCourse.html.twig'; // $view = 'ChillCalendarBundle:Calendar:showAccompanyingCourse.html.twig';
} elseif ($person instanceof Person) { // } elseif ($person instanceof Person) {
$view = 'ChillCalendarBundle:Calendar:showPerson.html.twig'; // $view = 'ChillCalendarBundle:Calendar:showPerson.html.twig';
} // }
$entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); // $entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
if (!$entity) { // if (!$entity) {
throw $this->createNotFoundException('Unable to find Calendar entity.'); // throw $this->createNotFoundException('Unable to find Calendar entity.');
} // }
if (null !== $accompanyingPeriod) { // if (null !== $accompanyingPeriod) {
$entity->personsAssociated = $entity->getPersonsAssociated(); // $entity->personsAssociated = $entity->getPersonsAssociated();
$entity->personsNotAssociated = $entity->getPersonsNotAssociated(); // $entity->personsNotAssociated = $entity->getPersonsNotAssociated();
} // }
// TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période // // TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période
// $this->denyAccessUnlessGranted('CHILL_ACTIVITY_SEE', $entity); // // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_SEE', $entity);
$deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod); // $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod);
// TODO // // TODO
/* // /*
$event = new PrivacyEvent($person, array( // $event = new PrivacyEvent($person, array(
'element_class' => Activity::class, // 'element_class' => Activity::class,
'element_id' => $entity->getId(), // 'element_id' => $entity->getId(),
'action' => 'show' // 'action' => 'show'
)); // ));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); // $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
*/ // */
if ($view === null) { // if ($view === null) {
throw $this->createNotFoundException('Template not found'); // throw $this->createNotFoundException('Template not found');
} // }
return $this->render($view, array( // return $this->render($view, array(
'person' => $person, // 'person' => $person,
'accompanyingCourse' => $accompanyingPeriod, // 'accompanyingCourse' => $accompanyingPeriod,
'entity' => $entity, // 'entity' => $entity,
'delete_form' => $deleteForm->createView(), // 'delete_form' => $deleteForm->createView(),
)); // ));
} // }
/** // /**
* Displays a form to edit an existing Activity entity. // * Displays a form to edit an existing Activity entity.
* // *
*/ // */
public function editAction($id, Request $request): Response // public function editAction($id, Request $request): Response
{ // {
$em = $this->getDoctrine()->getManager(); // $em = $this->getDoctrine()->getManager();
[$person, $accompanyingPeriod] = $this->getEntity($request); // [$person, $accompanyingPeriod] = $this->getEntity($request);
if ($accompanyingPeriod instanceof AccompanyingPeriod) { // if ($accompanyingPeriod instanceof AccompanyingPeriod) {
$view = 'ChillCalendarBundle:Calendar:editAccompanyingCourse.html.twig'; // $view = 'ChillCalendarBundle:Calendar:editAccompanyingCourse.html.twig';
} elseif ($person instanceof Person) { // } elseif ($person instanceof Person) {
$view = 'ChillCalendarBundle:Calendar:editPerson.html.twig'; // $view = 'ChillCalendarBundle:Calendar:editPerson.html.twig';
} // }
$entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); // $entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
if (!$entity) { // if (!$entity) {
throw $this->createNotFoundException('Unable to find Calendar entity.'); // throw $this->createNotFoundException('Unable to find Calendar entity.');
} // }
// TODO // // TODO
// $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity); // // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity);
$form = $this->createForm(CalendarType::class, $entity, [ // $form = $this->createForm(CalendarType::class, $entity, [
'center' => $entity->getCenter(), // 'center' => $entity->getCenter(),
'role' => new Role('CHILL_ACTIVITY_UPDATE'), // 'role' => new Role('CHILL_ACTIVITY_UPDATE'),
'activityType' => $entity->getType(), // 'activityType' => $entity->getType(),
'accompanyingPeriod' => $accompanyingPeriod, // 'accompanyingPeriod' => $accompanyingPeriod,
])->handleRequest($request); // ])->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { // if ($form->isSubmitted() && $form->isValid()) {
$em->persist($entity); // $em->persist($entity);
$em->flush(); // $em->flush();
$this->addFlash('success', $this->get('translator')->trans('Success : activity updated!')); // $this->addFlash('success', $this->get('translator')->trans('Success : activity updated!'));
$params = $this->buildParamsToUrl($person, $accompanyingPeriod); // $params = $this->buildParamsToUrl($person, $accompanyingPeriod);
$params['id'] = $id; // $params['id'] = $id;
return $this->redirectToRoute('chill_activity_activity_show', $params); // return $this->redirectToRoute('chill_activity_activity_show', $params);
} // }
$deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod); // $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod);
/* // /*
* TODO // * TODO
$event = new PrivacyEvent($person, array( // $event = new PrivacyEvent($person, array(
'element_class' => Calendar::class, // 'element_class' => Calendar::class,
'element_id' => $entity->getId(), // 'element_id' => $entity->getId(),
'action' => 'edit' // 'action' => 'edit'
)); // ));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); // $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
*/ // */
if ($view === null) { // if ($view === null) {
throw $this->createNotFoundException('Template not found'); // throw $this->createNotFoundException('Template not found');
} // }
$activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); // $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
return $this->render($view, array( // return $this->render($view, array(
'entity' => $entity, // 'entity' => $entity,
'edit_form' => $form->createView(), // 'edit_form' => $form->createView(),
'delete_form' => $deleteForm->createView(), // 'delete_form' => $deleteForm->createView(),
'person' => $person, // 'person' => $person,
'accompanyingCourse' => $accompanyingPeriod, // 'accompanyingCourse' => $accompanyingPeriod,
'activity_json' => $activity_array // 'activity_json' => $activity_array
)); // ));
} // }
/** // /**
* Deletes a Calendar entity. // * Deletes a Calendar entity.
* // *
*/ // */
public function deleteAction(Request $request, $id) // public function deleteAction(Request $request, $id)
{ // {
$em = $this->getDoctrine()->getManager(); // $em = $this->getDoctrine()->getManager();
[$person, $accompanyingPeriod] = $this->getEntity($request); // [$person, $accompanyingPeriod] = $this->getEntity($request);
if ($accompanyingPeriod instanceof AccompanyingPeriod) { // if ($accompanyingPeriod instanceof AccompanyingPeriod) {
$view = 'ChillCalendarBundle:Calendar:confirm_deleteAccompanyingCourse.html.twig'; // $view = 'ChillCalendarBundle:Calendar:confirm_deleteAccompanyingCourse.html.twig';
} elseif ($person instanceof Person) { // } elseif ($person instanceof Person) {
$view = 'ChillCalendarBundle:Calendar:confirm_deletePerson.html.twig'; // $view = 'ChillCalendarBundle:Calendar:confirm_deletePerson.html.twig';
} // }
/* @var $activity Calendar */ // /* @var $activity Calendar */
$activity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); // $activity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
if (!$activity) { // if (!$activity) {
throw $this->createNotFoundException('Unable to find Calendar entity.'); // throw $this->createNotFoundException('Unable to find Calendar entity.');
} // }
// TODO // // TODO
// $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity); // // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity);
$form = $this->createDeleteForm($id, $person, $accompanyingPeriod); // $form = $this->createDeleteForm($id, $person, $accompanyingPeriod);
if ($request->getMethod() === Request::METHOD_DELETE) { // if ($request->getMethod() === Request::METHOD_DELETE) {
$form->handleRequest($request); // $form->handleRequest($request);
if ($form->isValid()) { // if ($form->isValid()) {
$this->logger->notice("An activity has been removed", array( // $this->logger->notice("An activity has been removed", array(
'by_user' => $this->getUser()->getUsername(), // 'by_user' => $this->getUser()->getUsername(),
'activity_id' => $activity->getId(), // 'activity_id' => $activity->getId(),
'person_id' => $activity->getPerson() ? $activity->getPerson()->getId() : null, // 'person_id' => $activity->getPerson() ? $activity->getPerson()->getId() : null,
'comment' => $activity->getComment()->getComment(), // 'comment' => $activity->getComment()->getComment(),
'scope_id' => $activity->getScope() ? $activity->getScope()->getId() : null, // 'scope_id' => $activity->getScope() ? $activity->getScope()->getId() : null,
'reasons_ids' => $activity->getReasons() // 'reasons_ids' => $activity->getReasons()
->map(function ($ar) { return $ar->getId(); }) // ->map(function ($ar) { return $ar->getId(); })
->toArray(), // ->toArray(),
'type_id' => $activity->getType()->getId(), // 'type_id' => $activity->getType()->getId(),
'duration' => $activity->getDurationTime() ? $activity->getDurationTime()->format('U') : null, // 'duration' => $activity->getDurationTime() ? $activity->getDurationTime()->format('U') : null,
'date' => $activity->getDate()->format('Y-m-d'), // 'date' => $activity->getDate()->format('Y-m-d'),
'attendee' => $activity->getAttendee() // 'attendee' => $activity->getAttendee()
)); // ));
$em->remove($activity); // $em->remove($activity);
$em->flush(); // $em->flush();
$this->addFlash('success', $this->get('translator') // $this->addFlash('success', $this->get('translator')
->trans("The activity has been successfully removed.")); // ->trans("The activity has been successfully removed."));
$params = $this->buildParamsToUrl($person, $accompanyingPeriod); // $params = $this->buildParamsToUrl($person, $accompanyingPeriod);
return $this->redirectToRoute('chill_activity_activity_list', $params); // return $this->redirectToRoute('chill_activity_activity_list', $params);
} // }
} // }
if ($view === null) { // if ($view === null) {
throw $this->createNotFoundException('Template not found'); // throw $this->createNotFoundException('Template not found');
} // }
return $this->render($view, array( // return $this->render($view, array(
'activity' => $activity, // 'activity' => $activity,
'delete_form' => $form->createView(), // 'delete_form' => $form->createView(),
'person' => $person, // 'person' => $person,
'accompanyingCourse' => $accompanyingPeriod, // 'accompanyingCourse' => $accompanyingPeriod,
)); // ));
} // }
/** // /**
* Creates a form to delete a Calendar entity by id. // * Creates a form to delete a Calendar entity by id.
*/ // */
private function createDeleteForm(int $id, ?Person $person, ?AccompanyingPeriod $accompanyingPeriod): Form // private function createDeleteForm(int $id, ?Person $person, ?AccompanyingPeriod $accompanyingPeriod): Form
{ // {
$params = $this->buildParamsToUrl($person, $accompanyingPeriod); // $params = $this->buildParamsToUrl($person, $accompanyingPeriod);
$params['id'] = $id; // $params['id'] = $id;
return $this->createFormBuilder() // return $this->createFormBuilder()
->setAction($this->generateUrl('chill_activity_activity_delete', $params)) // ->setAction($this->generateUrl('chill_activity_activity_delete', $params))
->setMethod('DELETE') // ->setMethod('DELETE')
->add('submit', SubmitType::class, array('label' => 'Delete')) // ->add('submit', SubmitType::class, array('label' => 'Delete'))
->getForm() // ->getForm()
; // ;
} // }
private function getEntity(Request $request): array private function getEntity(Request $request): array
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$person = $accompanyingPeriod = null; $user = $accompanyingPeriod = null;
if ($request->query->has('person_id')) { if ($request->query->has('user_id')) {
$person_id = $request->get('person_id'); $user_id = $request->get('user_id');
$person = $em->getRepository(Person::class)->find($person_id); $user = $em->getRepository(User::class)->find($user_id);
if ($person === null) { if ($user === null) {
throw $this->createNotFoundException('Person not found'); throw $this->createNotFoundException('User not found');
} }
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $user);
} elseif ($request->query->has('accompanying_period_id')) { } elseif ($request->query->has('accompanying_period_id')) {
$accompanying_period_id = $request->get('accompanying_period_id'); $accompanying_period_id = $request->get('accompanying_period_id');
$accompanyingPeriod = $em->getRepository(AccompanyingPeriod::class)->find($accompanying_period_id); $accompanyingPeriod = $em->getRepository(AccompanyingPeriod::class)->find($accompanying_period_id);
@ -457,24 +452,24 @@ class CalendarController extends AbstractController
} }
return [ return [
$person, $accompanyingPeriod $user, $accompanyingPeriod
]; ];
} }
private function buildParamsToUrl( // private function buildParamsToUrl(
?Person $person, // ?Person $person,
?AccompanyingPeriod $accompanyingPeriod // ?AccompanyingPeriod $accompanyingPeriod
): array { // ): array {
$params = []; // $params = [];
if ($person) { // if ($person) {
$params['person_id'] = $person->getId(); // $params['person_id'] = $person->getId();
} // }
if ($accompanyingPeriod) { // if ($accompanyingPeriod) {
$params['accompanying_period_id'] = $accompanyingPeriod->getId(); // $params['accompanying_period_id'] = $accompanyingPeriod->getId();
} // }
return $params; // return $params;
} // }
} }

View File

@ -23,26 +23,28 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf
$configuration = new Configuration(); $configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs); $config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services/fixtures.yaml'); $loader->load('services.yml');
$loader->load('services/controller.yml');
$loader->load('services/fixtures.yml');
} }
public function prepend(ContainerBuilder $container) public function prepend(ContainerBuilder $container)
{ {
// $this->preprendRoutes($container); $this->preprendRoutes($container);
} }
// protected function preprendRoutes(ContainerBuilder $container) protected function preprendRoutes(ContainerBuilder $container)
// { {
// $container->prependExtensionConfig('chill_main', array( $container->prependExtensionConfig('chill_main', array(
// 'routing' => array( 'routing' => array(
// 'resources' => array( 'resources' => array(
// '@ChillCalendarBundle/config/routes.yaml' '@ChillCalendarBundle/Resources/config/routing.yml'
// ) )
// ) )
// )); ));
// } }
} }

View File

@ -2,7 +2,7 @@
namespace Chill\CalendarBundle\Repository; namespace Chill\CalendarBundle\Repository;
use CalendarBundle\Entity\Calendar; use Chill\CalendarBundle\Entity\Calendar;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;

View File

@ -0,0 +1,3 @@
chill_calendar_controllers:
resource: '../../Controller/'
type: annotation

View File

@ -0,0 +1,8 @@
---
services:
Chill\CalendarBundle\Repository\:
autowire: true
resource: '../../Repository/'
tags:
- { name: 'doctrine.repository_service' }

View File

@ -0,0 +1,5 @@
services:
Chill\CalendarBundle\Controller\:
autowire: true
resource: '../../../Controller'
tags: ['controller.service_arguments']

View File

@ -0,0 +1,189 @@
{% set user_id = null %}
{% if user %}
{% set user_id = user.id %}
{% endif %}
{% set accompanying_course_id = null %}
{% if accompanyingCourse %}
{% set accompanying_course_id = accompanyingCourse.id %}
{% endif %}
<h2>{{ 'Calendar list' |trans }}</h2>
{% if calendarItems|length == 0 %}
<p class="chill-no-data-statement">
{{ "There is no calendar items."|trans }}
<a href="{{ path('chill_calendar_calendar_new', {'user_id': user_id, 'accompanying_period_id': accompanying_course_id}) }}" class="btn btn-create button-small"></a>
</p>
{% else %}
<div class="flex-table list-records context-{{ context }}">
{% for calendar in calendarItems %}
{% set t = calendar.type %}
<div class="item-bloc">
<div class="item-row main">
<div class="item-col">
{% if calendar.date %}
<h3>{{ calendar.date|format_date('long') }}</h3>
{% endif %}
<div class="duration">
{% if t.durationTimeVisible > 0 %}
<p>
<i class="fa fa-fw fa-hourglass-end"></i>
{{ calendar.durationTime|date('H:i') }}
</p>
{% endif %}
{% if calendar.travelTime and t.travelTimeVisible %}
<p>
<i class="fa fa-fw fa-car"></i>
{{ calendar.travelTime|date('H:i') }}
</p>
{% endif %}
</div>
{% if context == 'user' and calendar.accompanyingPeriod is not empty %}
<div class="accompanyingPeriodLink" style="margin-top: 1rem">
<a
href="{{ chill_path_add_return_path(
"chill_user_accompanying_course_index",
{ 'accompanying_period_id': calendar.accompanyingPeriod.id }
) }}"
>
<i class="fa fa-random"></i>
{{ calendar.accompanyingPeriod.id }}
</a>
</div>
{% endif %}
</div>
<div class="item-col">
<ul class="list-content">
{% if calendar.user and t.userVisible %}
<li>
<b>{{ 'by'|trans }}{{ calendar.user.usernameCanonical }}</b>
</li>
{% endif %}
<li>
<b>{{ calendar.type.name | localize_translatable_string }}</b>
{% if calendar.attendee is not null and t.attendeeVisible %}
{% if calendar.attendee %}
{{ '→ ' ~ 'present'|trans|capitalize }}
{% else %}
{{ '→ ' ~ 'not present'|trans|capitalize }}
{% endif %}
{% endif %}
</li>
<li>
<b>{{ 'location'|trans ~ ': ' }}</b>
Domicile de l'usager
{#
{% if calendar.location %}{{ calendar.location }}{% endif %}
#}
</li>
{%- if t.reasonsVisible -%}
<li>
{%- if calendar.reasons is empty -%}
<span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span>
{%- else -%}
{% for r in calendar.reasons %}
{{ r|chill_entity_render_box }}
{% endfor %}
{%- endif -%}
</li>
{% endif %}
{%- if t.socialIssuesVisible %}
<li class="social-issues">
{%- if calendar.socialIssues is empty -%}
<span class="chill-no-data-statement">{{ 'No social issues associated'|trans }}</span>
{%- else -%}
{% for r in calendar.socialIssues %}
{{ r|chill_entity_render_box }}
{% endfor %}
{%- endif -%}
</li>
{% endif %}
{%- if t.socialActionsVisible -%}
<li class="social-actions">
{%- if calendar.socialActions is empty -%}
<span class="chill-no-data-statement">{{ 'No social actions associated'|trans }}</span>
{%- else -%}
{% for r in calendar.socialActions %}
<span class="badge bg-primary">{{ r.title|localize_translatable_string }}</span>
{% endfor %}
{%- endif -%}
</li>
{% endif %}
</ul>
<ul class="record_actions">
<li>
<a href="{{ path('chill_calendar_calendar_show', { 'id': calendar.id, 'user_id': user_id, 'accompanying_period_id': accompanying_course_id }) }}" class="btn btn-show "></a>
</li>
{# TOOD
{% if is_granted('CHILL_ACTIVITY_UPDATE', calendar) %}
#}
<li>
<a href="{{ path('chill_calendar_calendar_edit', { 'id': calendar.id, 'user_id': user_id, 'accompanying_period_id': accompanying_course_id }) }}" class="btn btn-update "></a>
</li>
{# TOOD
{% endif %}
{% if is_granted('CHILL_ACTIVITY_DELETE', calendar) %}
#}
<li>
<a href="{{ path('chill_calendar_calendar_delete', { 'id': calendar.id, 'user_id' : user_id, 'accompanying_period_id': accompanying_course_id } ) }}" class="btn btn-delete "></a>
</li>
{#
{% endif %}
#}
</ul>
</div>
</div>
{%
if calendar.comment.comment is not empty
or calendar.users|length > 0
or calendar.thirdParties|length > 0
or calendar.users|length > 0
%}
<div class="item-row details">
<div class="item-col">
{% include 'ChillCalendarBundle:Calendar:concernedGroups.html.twig' with {'context': context, 'with_display': 'row', 'entity': calendar } %}
</div>
{% if calendar.comment.comment is not empty %}
<div class="item-col comment">
{{ calendar.comment|chill_entity_render_box( { 'limit_lines': 3, 'metadata': false } ) }}
</div>
{% endif %}
</div>
{% endif %}
</div>
{% endfor %}
</div>
{% endif %}
{% if context != 'user' %}
{# TODO set this condition in configuration #}
<ul class="record_actions">
<li>
<a href="{{ path('chill_calendar_calendar_new', {'user_id': user_id, 'accompanying_period_id': accompanying_course_id}) }}" class="btn btn-create">
{{ 'Add a new calendar' | trans }}
</a>
</li>
</ul>
{% endif %}

View File

@ -0,0 +1,9 @@
{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %}
{% set activeRouteKey = 'chill_calendar_calendar_list' %}
{% block title %}{{ 'Calendar list' |trans }}{% endblock title %}
{% block content %}
{% include 'ChillCalendarBundle:Calendar:list.html.twig' with {'context': 'accompanyingCourse'} %}
{% endblock %}

View File

@ -0,0 +1,37 @@
{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %}
{% set activeRouteKey = 'chill_calendar_calendar_new' %}
{% block title 'Calendar creation' |trans %}
{% block content %}
<div class="calendar-new">
<div class="row justify-content-center">
<div class="col-md-10 col-xxl">
<div id="calendar"></div> {# <=== vue component #}
{% include 'ChillCalendarBundle:Calendar:new.html.twig' with {'context': 'accompanyingCourse'} %}
</div>
</div>
</div>
{% endblock %}
{% block js %}
{{ parent() }}
{{ encore_entry_script_tags('async_upload') }}
<script type="text/javascript">
window.addEventListener('DOMContentLoaded', function (e) {
chill.displayAlertWhenLeavingUnsubmittedForm('form[name="{{ form.vars.form.vars.name }}"]',
'{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}');
});
window.calendar = {{ calendar_json|json_encode|raw }};
</script>
{{ encore_entry_script_tags('vue_calendar') }}
{% endblock %}
{% block css %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('build/async_upload.css') }}"/>
{{ encore_entry_link_tags('vue_calendar') }}
{% endblock %}