From 0cb6a7c0ad7b7d3a04736b4923d38a55ed675d57 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Sun, 23 Apr 2023 20:14:45 +0200 Subject: [PATCH 1/6] OpeningHourController. Add templates. Add button on admin page --- .../Version20230423173822_opening_hour.php | 35 ++++ app/Resources/views/admin/index.html.twig | 15 +- .../views/admin/openinghour/_form.html.twig | 29 +++ .../views/admin/openinghour/edit.html.twig | 28 +++ .../views/admin/openinghour/list.html.twig | 43 +++++ .../views/admin/openinghour/new.html.twig | 21 +++ .../_partial/period_position_card.html.twig | 2 +- .../Controller/OpeningHourController.php | 141 ++++++++++++++ src/AppBundle/Entity/OpeningHour.php | 177 ++++++++++++++++++ src/AppBundle/Form/OpeningHourType.php | 52 +++++ .../Repository/OpeningHourRepository.php | 13 ++ 11 files changed, 550 insertions(+), 6 deletions(-) create mode 100644 app/DoctrineMigrations/Version20230423173822_opening_hour.php create mode 100644 app/Resources/views/admin/openinghour/_form.html.twig create mode 100644 app/Resources/views/admin/openinghour/edit.html.twig create mode 100644 app/Resources/views/admin/openinghour/list.html.twig create mode 100644 app/Resources/views/admin/openinghour/new.html.twig create mode 100644 src/AppBundle/Controller/OpeningHourController.php create mode 100644 src/AppBundle/Entity/OpeningHour.php create mode 100644 src/AppBundle/Form/OpeningHourType.php create mode 100644 src/AppBundle/Repository/OpeningHourRepository.php diff --git a/app/DoctrineMigrations/Version20230423173822_opening_hour.php b/app/DoctrineMigrations/Version20230423173822_opening_hour.php new file mode 100644 index 000000000..4fff0c93e --- /dev/null +++ b/app/DoctrineMigrations/Version20230423173822_opening_hour.php @@ -0,0 +1,35 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('CREATE TABLE opening_hour (id INT AUTO_INCREMENT NOT NULL, day_of_week SMALLINT NOT NULL, start TIME NOT NULL, end TIME NOT NULL, created_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('DROP TABLE opening_hour'); + } +} diff --git a/app/Resources/views/admin/index.html.twig b/app/Resources/views/admin/index.html.twig index 0536a6fe4..ac45724af 100644 --- a/app/Resources/views/admin/index.html.twig +++ b/app/Resources/views/admin/index.html.twig @@ -69,6 +69,16 @@ {% endif %} + {% if is_granted("ROLE_ADMIN") %} +
settings Informations
+ + scheduleHoraires d'ouvertures + + + publicRéseaux sociaux + + {% endif %} + {% if is_granted("ROLE_PROCESS_MANAGER") %}
content_paste Contenus
@@ -91,11 +101,6 @@ mailModèles d'emails - {% if is_granted("ROLE_ADMIN") %} - - publicRéseaux sociaux - - {% endif %} {% endif %} {% if is_granted("ROLE_FINANCE_MANAGER") %} diff --git a/app/Resources/views/admin/openinghour/_form.html.twig b/app/Resources/views/admin/openinghour/_form.html.twig new file mode 100644 index 000000000..5f5722691 --- /dev/null +++ b/app/Resources/views/admin/openinghour/_form.html.twig @@ -0,0 +1,29 @@ +
+
+
+ {{ form_errors(form.dayOfWeek) }} +
+
+ {{ form_widget(form.dayOfWeek) }} + {{ form_label(form.dayOfWeek) }} +
+
+
+
+ {{ form_errors(form.start) }} +
+
+ {{ form_widget(form.start) }} + {{ form_label(form.start) }} +
+
+
+
+ {{ form_errors(form.end) }} +
+
+ {{ form_widget(form.end) }} + {{ form_label(form.end) }} +
+
+
diff --git a/app/Resources/views/admin/openinghour/edit.html.twig b/app/Resources/views/admin/openinghour/edit.html.twig new file mode 100644 index 000000000..1fb2d710d --- /dev/null +++ b/app/Resources/views/admin/openinghour/edit.html.twig @@ -0,0 +1,28 @@ +{% extends 'layout.html.twig' %} + +{% block title %}Editer l'horaire d'ouverture - {{ site_name }}{% endblock %} + +{% block breadcrumbs %} +homechevron_right +build Administrationchevron_right +public Liste des horaires d'ouvertureschevron_right +edit Editer +{% endblock %} + +{% block content %} +

Editer l'horaire d'ouverture

+ + {{ form_start(form) }} + {% include "/admin/openinghour/_form.html.twig" with { form: form } %} +
+ +
+ {{ form_end(form) }} + + {{ form_start(delete_form) }} + {{ form_widget(delete_form) }} +
+ +
+ {{ form_end(delete_form) }} +{% endblock %} diff --git a/app/Resources/views/admin/openinghour/list.html.twig b/app/Resources/views/admin/openinghour/list.html.twig new file mode 100644 index 000000000..9e5e420eb --- /dev/null +++ b/app/Resources/views/admin/openinghour/list.html.twig @@ -0,0 +1,43 @@ +{% extends 'layout.html.twig' %} + +{% block title %}Liste des horaires d'ouvertures - {{ site_name }}{% endblock %} + +{% block breadcrumbs %} +homechevron_right +build Administrationchevron_right +public Liste des horaires d'ouvertures +{% endblock %} + +{% block content %} +

Liste des horaires d'ouvertures ({{ openingHours | length }})

+ + + + + + + + + + + + {% for openingHour in openingHours %} + + + + + + + {% endfor %} + +
Jour d'ouvertureHeure de débutHeure de finActions
{{ openingHour.dayOfWeekString }}{{ openingHour.start | date('H:i') }}{{ openingHour.end | date('H:i') }} + + editediter + +
+ +
+ + addAjouter une horaire d'ouverture + +{% endblock %} diff --git a/app/Resources/views/admin/openinghour/new.html.twig b/app/Resources/views/admin/openinghour/new.html.twig new file mode 100644 index 000000000..a9fd05eb5 --- /dev/null +++ b/app/Resources/views/admin/openinghour/new.html.twig @@ -0,0 +1,21 @@ +{% extends 'layout.html.twig' %} + +{% block title %}Ajouter une horaire d'ouverture - {{ site_name }}{% endblock %} + +{% block breadcrumbs %} +homechevron_right +build Administrationchevron_right +public Liste des horaires d'ouverturechevron_right +add Ajouter +{% endblock %} + +{% block content %} +

Nouvelle horaire d'ouverture

+ + {{ form_start(form) }} + {% include "/admin/openinghour/_form.html.twig" with { form: form } %} +
+ +
+ {{ form_end(form) }} +{% endblock %} diff --git a/app/Resources/views/user/_partial/period_position_card.html.twig b/app/Resources/views/user/_partial/period_position_card.html.twig index 3970fdb23..48ead61bf 100644 --- a/app/Resources/views/user/_partial/period_position_card.html.twig +++ b/app/Resources/views/user/_partial/period_position_card.html.twig @@ -1,7 +1,7 @@
- {{ period_position.period.getDayOfWeekString() }} de {{ period_position.period.start | date('H:i') }} à {{ period_position.period.end | date('H:i') }} + {{ period_position.period.dayOfWeekString }} de {{ period_position.period.start | date('H:i') }} à {{ period_position.period.end | date('H:i') }}
(Semaine {{ period_position.weekCycle }})
diff --git a/src/AppBundle/Controller/OpeningHourController.php b/src/AppBundle/Controller/OpeningHourController.php new file mode 100644 index 000000000..c56a413ec --- /dev/null +++ b/src/AppBundle/Controller/OpeningHourController.php @@ -0,0 +1,141 @@ +getDoctrine()->getManager(); + $openingHours = $em->getRepository('AppBundle:OpeningHour')->findAll(); + + return $this->render('admin/openinghour/list.html.twig', array( + 'openingHours' => $openingHours + )); + } + + /** + * Add new opening hour. + * + * @Route("/new", name="admin_openinghour_new", methods={"GET","POST"}) + * @Security("has_role('ROLE_ADMIN')") + */ + public function newAction(Request $request) + { + $session = new Session(); + $em = $this->getDoctrine()->getManager(); + + $openingHour = new OpeningHour(); + + $form = $this->createForm(OpeningHourType::class, $openingHour); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $time = $form->get('start')->getData(); + $openingHour->setStart(new \DateTime($time)); + $time = $form->get('end')->getData(); + $openingHour->setEnd(new \DateTime($time)); + + $em->persist($openingHour); + $em->flush(); + + $session->getFlashBag()->add('success', "L'horaire a bien été crée !"); + return $this->redirectToRoute('admin_openinghour_list'); + } + + return $this->render('admin/openinghour/new.html.twig', array( + 'form' => $form->createView() + )); + } + + /** + * Edit opening hour. + * + * @Route("/edit/{id}", name="admin_openinghour_edit", methods={"GET","POST"}) + * @Security("has_role('ROLE_ADMIN')") + */ + public function editAction(Request $request, OpeningHour $openingHour) + { + $session = new Session(); + + $form = $this->createForm(OpeningHourType::class, $openingHour); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($openingHour); + $em->flush(); + + $session->getFlashBag()->add('success', "L'horaire a bien été éditée !"); + return $this->redirectToRoute('admin_openinghour_list'); + } + + return $this->render('admin/openinghour/edit.html.twig', array( + 'form' => $form->createView(), + 'delete_form' => $this->getDeleteForm($openingHour)->createView() + )); + } + + /** + * Delete opening hour. + * + * @Route("/{id}", name="admin_openinghour_delete", methods={"DELETE"}) + * @Security("has_role('ROLE_ADMIN')") + */ + public function removeAction(Request $request, OpeningHour $openingHour) + { + $session = new Session(); + + $form = $this->getDeleteForm($openingHour); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->remove($openingHour); + $em->flush(); + + $session->getFlashBag()->add('success', "L'horaire a bien été supprimée !"); + return $this->redirectToRoute('admin_openinghour_list'); + } + + return $this->redirectToRoute('admin_openinghour_list'); + } + + /** + * @param OpeningHour $openingHour + * @return \Symfony\Component\Form\FormInterface + */ + protected function getDeleteForm(OpeningHour $openingHour) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('admin_openinghour_delete', array('id' => $openingHour->getId()))) + ->setMethod('DELETE') + ->getForm(); + } +} diff --git a/src/AppBundle/Entity/OpeningHour.php b/src/AppBundle/Entity/OpeningHour.php new file mode 100644 index 000000000..b6dea92aa --- /dev/null +++ b/src/AppBundle/Entity/OpeningHour.php @@ -0,0 +1,177 @@ +createdAt = new \DateTime(); + } + + /** + * Get id. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Set dayOfWeek + * + * @param integer $dayOfWeek + * + * @return Period + */ + public function setDayOfWeek($dayOfWeek) + { + $this->dayOfWeek = $dayOfWeek; + + return $this; + } + + /** + * Get dayOfWeek + * + * @return int + */ + public function getDayOfWeek() + { + return $this->dayOfWeek; + } + + /** + * Get dayOfWeekString + * + * @return int + */ + public function getDayOfWeekString() + { + setlocale(LC_TIME, 'fr_FR.UTF8'); + return strftime("%A", strtotime("Monday + {$this->dayOfWeek} days")); + } + + /** + * Set start + * + * @param \DateTime $start + * + * @return Period + */ + public function setStart($start) + { + $this->start = $start; + + return $this; + } + + /** + * Get start + * + * @return \DateTime + */ + public function getStart() + { + return $this->start; + } + + /** + * Set end + * + * @param \DateTime $end + * + * @return Period + */ + public function setEnd($end) + { + $this->end = $end; + + return $this; + } + + /** + * Get end + * + * @return \DateTime + */ + public function getEnd() + { + return $this->end; + } + + /** + * Set createdAt. + * + * @param \DateTime $createdAt + * + * @return SocialNetwork + */ + public function setCreatedAt($createdAt) + { + $this->createdAt = $createdAt; + + return $this; + } + + /** + * Get createdAt. + * + * @return \DateTime + */ + public function getCreatedAt() + { + return $this->createdAt; + } +} diff --git a/src/AppBundle/Form/OpeningHourType.php b/src/AppBundle/Form/OpeningHourType.php new file mode 100644 index 000000000..2c3f73cf4 --- /dev/null +++ b/src/AppBundle/Form/OpeningHourType.php @@ -0,0 +1,52 @@ +add('dayOfWeek', ChoiceType::class, array('label' => 'Jour de la semaine', 'choices' => array( + "Lundi" => 0, + "Mardi" => 1, + "Mercredi" => 2, + "Jeudi" => 3, + "Vendredi" => 4, + "Samedi" => 5, + "Dimanche" => 6, + ))) + ->add('start', TextType::class, array('label' => 'Heure de début', 'attr' => array('class' => 'timepicker'))) + ->add('end', TextType::class, array('label' => 'Heure de fin', 'attr' => array('class' => 'timepicker'))); + } + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => OpeningHour::class + )); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'appbundle_opening_hour'; + } +} diff --git a/src/AppBundle/Repository/OpeningHourRepository.php b/src/AppBundle/Repository/OpeningHourRepository.php new file mode 100644 index 000000000..67edc9b4d --- /dev/null +++ b/src/AppBundle/Repository/OpeningHourRepository.php @@ -0,0 +1,13 @@ + Date: Sun, 23 Apr 2023 20:31:08 +0200 Subject: [PATCH 2/6] Assert start < end. Order list by day & time --- .../views/admin/openinghour/_form.html.twig | 3 +++ .../views/admin/openinghour/list.html.twig | 2 +- .../views/admin/openinghour/new.html.twig | 2 +- .../views/admin/service/new.html.twig | 2 +- .../views/admin/socialnetwork/_form.html.twig | 3 +++ .../views/admin/socialnetwork/new.html.twig | 2 +- .../Controller/CommissionController.php | 2 +- .../Controller/OpeningHourController.php | 17 ++++++++----- src/AppBundle/Controller/PeriodController.php | 25 ++++++++++--------- .../Controller/SocialNetworkController.php | 2 +- src/AppBundle/Entity/OpeningHour.php | 9 +++++++ src/AppBundle/Entity/Period.php | 10 +++++++- .../Repository/OpeningHourRepository.php | 4 +++ 13 files changed, 58 insertions(+), 25 deletions(-) diff --git a/app/Resources/views/admin/openinghour/_form.html.twig b/app/Resources/views/admin/openinghour/_form.html.twig index 5f5722691..2e233fadd 100644 --- a/app/Resources/views/admin/openinghour/_form.html.twig +++ b/app/Resources/views/admin/openinghour/_form.html.twig @@ -1,3 +1,6 @@ +
+ {{ form_errors(form) }} +
diff --git a/app/Resources/views/admin/openinghour/list.html.twig b/app/Resources/views/admin/openinghour/list.html.twig index 9e5e420eb..651132d0c 100644 --- a/app/Resources/views/admin/openinghour/list.html.twig +++ b/app/Resources/views/admin/openinghour/list.html.twig @@ -23,7 +23,7 @@ {% for openingHour in openingHours %} - {{ openingHour.dayOfWeekString }} + {{ openingHour.dayOfWeekString | capitalize }} {{ openingHour.start | date('H:i') }} {{ openingHour.end | date('H:i') }} diff --git a/app/Resources/views/admin/openinghour/new.html.twig b/app/Resources/views/admin/openinghour/new.html.twig index a9fd05eb5..f6e5f9f31 100644 --- a/app/Resources/views/admin/openinghour/new.html.twig +++ b/app/Resources/views/admin/openinghour/new.html.twig @@ -13,7 +13,7 @@

Nouvelle horaire d'ouverture

{{ form_start(form) }} - {% include "/admin/openinghour/_form.html.twig" with { form: form } %} + {% include "/admin/openinghour/_form.html.twig" with { form: form } %}
diff --git a/app/Resources/views/admin/service/new.html.twig b/app/Resources/views/admin/service/new.html.twig index c1e6ff79f..0b7a0ba9a 100644 --- a/app/Resources/views/admin/service/new.html.twig +++ b/app/Resources/views/admin/service/new.html.twig @@ -13,7 +13,7 @@

Nouveau service

{{ form_start(form) }} - {% include "/admin/service/_form.html.twig" with { form: form } %} + {% include "/admin/service/_form.html.twig" with { form: form } %}
diff --git a/app/Resources/views/admin/socialnetwork/_form.html.twig b/app/Resources/views/admin/socialnetwork/_form.html.twig index 1ef8bf0f9..f0328b47e 100644 --- a/app/Resources/views/admin/socialnetwork/_form.html.twig +++ b/app/Resources/views/admin/socialnetwork/_form.html.twig @@ -1,3 +1,6 @@ +
+ {{ form_errors(form) }} +
diff --git a/app/Resources/views/admin/socialnetwork/new.html.twig b/app/Resources/views/admin/socialnetwork/new.html.twig index 8375a9806..31d7c6cd8 100644 --- a/app/Resources/views/admin/socialnetwork/new.html.twig +++ b/app/Resources/views/admin/socialnetwork/new.html.twig @@ -13,7 +13,7 @@

Nouveau réseau social

{{ form_start(form) }} - {% include "/admin/socialnetwork/_form.html.twig" with { form: form } %} + {% include "/admin/socialnetwork/_form.html.twig" with { form: form } %}
diff --git a/src/AppBundle/Controller/CommissionController.php b/src/AppBundle/Controller/CommissionController.php index ee4db4a98..757c50ef8 100644 --- a/src/AppBundle/Controller/CommissionController.php +++ b/src/AppBundle/Controller/CommissionController.php @@ -229,7 +229,7 @@ public function removeBeneficiaryAction(Request $request,Commission $commission) * @Route("/{id}", name="commission_delete", methods={"DELETE"}) * @Security("has_role('ROLE_SUPER_ADMIN')") */ - public function removeAction(Request $request,Commission $commission) + public function deleteAction(Request $request,Commission $commission) { $session = new Session(); $form = $this->getDeleteForm($commission); diff --git a/src/AppBundle/Controller/OpeningHourController.php b/src/AppBundle/Controller/OpeningHourController.php index c56a413ec..99b841054 100644 --- a/src/AppBundle/Controller/OpeningHourController.php +++ b/src/AppBundle/Controller/OpeningHourController.php @@ -57,10 +57,10 @@ public function newAction(Request $request) $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $time = $form->get('start')->getData(); - $openingHour->setStart(new \DateTime($time)); - $time = $form->get('end')->getData(); - $openingHour->setEnd(new \DateTime($time)); + $start = $form->get('start')->getData(); + $openingHour->setStart(new \DateTime($start)); + $end = $form->get('end')->getData(); + $openingHour->setEnd(new \DateTime($end)); $em->persist($openingHour); $em->flush(); @@ -83,12 +83,17 @@ public function newAction(Request $request) public function editAction(Request $request, OpeningHour $openingHour) { $session = new Session(); + $em = $this->getDoctrine()->getManager(); $form = $this->createForm(OpeningHourType::class, $openingHour); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $start = $form->get('start')->getData(); + $openingHour->setStart(new \DateTime($start)); + $end = $form->get('end')->getData(); + $openingHour->setEnd(new \DateTime($end)); + $em->persist($openingHour); $em->flush(); @@ -108,7 +113,7 @@ public function editAction(Request $request, OpeningHour $openingHour) * @Route("/{id}", name="admin_openinghour_delete", methods={"DELETE"}) * @Security("has_role('ROLE_ADMIN')") */ - public function removeAction(Request $request, OpeningHour $openingHour) + public function deleteAction(Request $request, OpeningHour $openingHour) { $session = new Session(); diff --git a/src/AppBundle/Controller/PeriodController.php b/src/AppBundle/Controller/PeriodController.php index 25eab4338..900957551 100644 --- a/src/AppBundle/Controller/PeriodController.php +++ b/src/AppBundle/Controller/PeriodController.php @@ -218,9 +218,9 @@ public function adminIndexAction(Request $request, EntityManagerInterface $em): public function newAction(Request $request) { $session = new Session(); - $period = new Period(); - $em = $this->getDoctrine()->getManager(); + + $period = new Period(); $job = $em->getRepository(Job::class)->findOneBy(array()); if (!$job) { @@ -232,14 +232,14 @@ public function newAction(Request $request) $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - - $time = $form->get('start')->getData(); - $period->setStart(new \DateTime($time)); - $time = $form->get('end')->getData(); - $period->setEnd(new \DateTime($time)); + $start = $form->get('start')->getData(); + $period->setStart(new \DateTime($start)); + $end = $form->get('end')->getData(); + $period->setEnd(new \DateTime($end)); $em->persist($period); $em->flush(); + $session->getFlashBag()->add('success', 'Le nouveau créneau type a bien été créé !'); return $this->redirectToRoute('period_edit',array('id'=>$period->getId())); } @@ -256,19 +256,20 @@ public function newAction(Request $request) public function editPeriodAction(Request $request, Period $period) { $session = new Session(); + $em = $this->getDoctrine()->getManager(); $form = $this->createForm(PeriodType::class, $period); $form->handleRequest($request); - $em = $this->getDoctrine()->getManager(); if ($form->isSubmitted() && $form->isValid()) { - $time = $form->get('start')->getData(); - $period->setStart(new \DateTime($time)); - $time = $form->get('end')->getData(); - $period->setEnd(new \DateTime($time)); + $start = $form->get('start')->getData(); + $period->setStart(new \DateTime($start)); + $end = $form->get('end')->getData(); + $period->setEnd(new \DateTime($end)); $em->persist($period); $em->flush(); + $session->getFlashBag()->add('success', 'Le créneau type a bien été édité !'); return $this->redirectToRoute('period'); } diff --git a/src/AppBundle/Controller/SocialNetworkController.php b/src/AppBundle/Controller/SocialNetworkController.php index ad0cd957d..81f27aef0 100644 --- a/src/AppBundle/Controller/SocialNetworkController.php +++ b/src/AppBundle/Controller/SocialNetworkController.php @@ -103,7 +103,7 @@ public function editAction(Request $request, SocialNetwork $socialNetwork) * @Route("/{id}", name="admin_socialnetwork_delete", methods={"DELETE"}) * @Security("has_role('ROLE_SUPER_ADMIN')") */ - public function removeAction(Request $request, SocialNetwork $socialNetwork) + public function deleteAction(Request $request, SocialNetwork $socialNetwork) { $session = new Session(); diff --git a/src/AppBundle/Entity/OpeningHour.php b/src/AppBundle/Entity/OpeningHour.php index b6dea92aa..0c6fec0a0 100644 --- a/src/AppBundle/Entity/OpeningHour.php +++ b/src/AppBundle/Entity/OpeningHour.php @@ -3,6 +3,7 @@ namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; /** * OpeningHour @@ -151,6 +152,14 @@ public function getEnd() return $this->end; } + /** + * @Assert\IsTrue(message="L'heure de début doit être avant celle de fin") + */ + public function isStartBeforeEnd() + { + return $this->start < $this->end; + } + /** * Set createdAt. * diff --git a/src/AppBundle/Entity/Period.php b/src/AppBundle/Entity/Period.php index 219b3d3fc..8f420bd9f 100644 --- a/src/AppBundle/Entity/Period.php +++ b/src/AppBundle/Entity/Period.php @@ -3,7 +3,7 @@ namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; -use Doctrine\ORM\Mapping\OrderBy; +use Symfony\Component\Validator\Constraints as Assert; /** * Period @@ -173,6 +173,14 @@ public function getEnd() return $this->end; } + /** + * @Assert\IsTrue(message="L'heure de début doit être avant celle de fin") + */ + public function isStartBeforeEnd() + { + return $this->start < $this->end; + } + /** * Set job * diff --git a/src/AppBundle/Repository/OpeningHourRepository.php b/src/AppBundle/Repository/OpeningHourRepository.php index 67edc9b4d..02472e795 100644 --- a/src/AppBundle/Repository/OpeningHourRepository.php +++ b/src/AppBundle/Repository/OpeningHourRepository.php @@ -10,4 +10,8 @@ */ class OpeningHourRepository extends \Doctrine\ORM\EntityRepository { + public function findAll() + { + return $this->findBy(array(), array('dayOfWeek' => 'ASC', 'start' => 'ASC')); + } } From ffced4ff8a43e91c0242bd124722746fed1b7b5c Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Sun, 23 Apr 2023 23:04:54 +0200 Subject: [PATCH 3/6] Fix edit action --- .../views/admin/openinghour/edit.html.twig | 26 ++++----- .../views/admin/openinghour/list.html.twig | 58 +++++++++---------- .../views/admin/openinghour/new.html.twig | 14 ++--- .../Controller/OpeningHourController.php | 5 ++ src/AppBundle/Controller/PeriodController.php | 8 ++- 5 files changed, 59 insertions(+), 52 deletions(-) diff --git a/app/Resources/views/admin/openinghour/edit.html.twig b/app/Resources/views/admin/openinghour/edit.html.twig index 1fb2d710d..427bbe4b1 100644 --- a/app/Resources/views/admin/openinghour/edit.html.twig +++ b/app/Resources/views/admin/openinghour/edit.html.twig @@ -10,19 +10,19 @@ {% endblock %} {% block content %} -

Editer l'horaire d'ouverture

+

Editer l'horaire d'ouverture

- {{ form_start(form) }} - {% include "/admin/openinghour/_form.html.twig" with { form: form } %} -
- -
- {{ form_end(form) }} +{{ form_start(form) }} +{% include "/admin/openinghour/_form.html.twig" with { form: form } %} +
+ +
+{{ form_end(form) }} - {{ form_start(delete_form) }} - {{ form_widget(delete_form) }} -
- -
- {{ form_end(delete_form) }} +{{ form_start(delete_form) }} +{{ form_widget(delete_form) }} +
+ +
+{{ form_end(delete_form) }} {% endblock %} diff --git a/app/Resources/views/admin/openinghour/list.html.twig b/app/Resources/views/admin/openinghour/list.html.twig index 651132d0c..1681d4469 100644 --- a/app/Resources/views/admin/openinghour/list.html.twig +++ b/app/Resources/views/admin/openinghour/list.html.twig @@ -9,35 +9,35 @@ {% endblock %} {% block content %} -

Liste des horaires d'ouvertures ({{ openingHours | length }})

+

Liste des horaires d'ouvertures ({{ openingHours | length }})

- - - - - - - - - - - {% for openingHour in openingHours %} - - - - - - - {% endfor %} - -
Jour d'ouvertureHeure de débutHeure de finActions
{{ openingHour.dayOfWeekString | capitalize }}{{ openingHour.start | date('H:i') }}{{ openingHour.end | date('H:i') }} - - editediter - -
+ + + + + + + + + + + {% for openingHour in openingHours %} + + + + + + + {% endfor %} + +
Jour d'ouvertureHeure de débutHeure de finActions
{{ openingHour.dayOfWeekString | capitalize }}{{ openingHour.start | date('H:i') }}{{ openingHour.end | date('H:i') }} + + editediter + +
-
- - addAjouter une horaire d'ouverture - +
+ + addAjouter une horaire d'ouverture + {% endblock %} diff --git a/app/Resources/views/admin/openinghour/new.html.twig b/app/Resources/views/admin/openinghour/new.html.twig index f6e5f9f31..41ac12b4a 100644 --- a/app/Resources/views/admin/openinghour/new.html.twig +++ b/app/Resources/views/admin/openinghour/new.html.twig @@ -10,12 +10,12 @@ {% endblock %} {% block content %} -

Nouvelle horaire d'ouverture

+

Nouvelle horaire d'ouverture

- {{ form_start(form) }} - {% include "/admin/openinghour/_form.html.twig" with { form: form } %} -
- -
- {{ form_end(form) }} +{{ form_start(form) }} +{% include "/admin/openinghour/_form.html.twig" with { form: form } %} +
+ +
+{{ form_end(form) }} {% endblock %} diff --git a/src/AppBundle/Controller/OpeningHourController.php b/src/AppBundle/Controller/OpeningHourController.php index 99b841054..9b9e9e7a8 100644 --- a/src/AppBundle/Controller/OpeningHourController.php +++ b/src/AppBundle/Controller/OpeningHourController.php @@ -88,6 +88,11 @@ public function editAction(Request $request, OpeningHour $openingHour) $form = $this->createForm(OpeningHourType::class, $openingHour); $form->handleRequest($request); + if ($request->isMethod('GET')) { + $form->get('start')->setData($openingHour->getStart()->format('H:i')); + $form->get('end')->setData($openingHour->getEnd()->format('H:i')); + } + if ($form->isSubmitted() && $form->isValid()) { $start = $form->get('start')->getData(); $openingHour->setStart(new \DateTime($start)); diff --git a/src/AppBundle/Controller/PeriodController.php b/src/AppBundle/Controller/PeriodController.php index 900957551..f7140f6a5 100644 --- a/src/AppBundle/Controller/PeriodController.php +++ b/src/AppBundle/Controller/PeriodController.php @@ -261,6 +261,11 @@ public function editPeriodAction(Request $request, Period $period) $form = $this->createForm(PeriodType::class, $period); $form->handleRequest($request); + if ($request->isMethod('GET')) { + $form->get('start')->setData($period->getStart()->format('H:i')); + $form->get('end')->setData($period->getEnd()->format('H:i')); + } + if ($form->isSubmitted() && $form->isValid()) { $start = $form->get('start')->getData(); $period->setStart(new \DateTime($start)); @@ -276,9 +281,6 @@ public function editPeriodAction(Request $request, Period $period) $beneficiaries = $em->getRepository(Beneficiary::class)->findAllActive(); - $form->get('start')->setData($period->getStart()->format('H:i')); - $form->get('end')->setData($period->getEnd()->format('H:i')); - $periodDeleteForm = $this->createPeriodDeleteForm($period); $positionAddForm = $this->createPeriodPositionAddForm($period); From 4c8210129fa2421db697587b61a974d892d3b71f Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Sun, 23 Apr 2023 23:08:40 +0200 Subject: [PATCH 4/6] rename to Horaires d'ouverture --- app/Resources/views/admin/index.html.twig | 2 +- app/Resources/views/admin/openinghour/edit.html.twig | 2 +- app/Resources/views/admin/openinghour/list.html.twig | 6 +++--- app/Resources/views/admin/openinghour/new.html.twig | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Resources/views/admin/index.html.twig b/app/Resources/views/admin/index.html.twig index ac45724af..7b1be9177 100644 --- a/app/Resources/views/admin/index.html.twig +++ b/app/Resources/views/admin/index.html.twig @@ -72,7 +72,7 @@ {% if is_granted("ROLE_ADMIN") %}
settings Informations
- scheduleHoraires d'ouvertures + scheduleHoraires d'ouverture publicRéseaux sociaux diff --git a/app/Resources/views/admin/openinghour/edit.html.twig b/app/Resources/views/admin/openinghour/edit.html.twig index 427bbe4b1..6c6d3317c 100644 --- a/app/Resources/views/admin/openinghour/edit.html.twig +++ b/app/Resources/views/admin/openinghour/edit.html.twig @@ -5,7 +5,7 @@ {% block breadcrumbs %} homechevron_right build Administrationchevron_right -public Liste des horaires d'ouvertureschevron_right +schedule Horaires d'ouverturechevron_right edit Editer {% endblock %} diff --git a/app/Resources/views/admin/openinghour/list.html.twig b/app/Resources/views/admin/openinghour/list.html.twig index 1681d4469..d23c0c53a 100644 --- a/app/Resources/views/admin/openinghour/list.html.twig +++ b/app/Resources/views/admin/openinghour/list.html.twig @@ -1,15 +1,15 @@ {% extends 'layout.html.twig' %} -{% block title %}Liste des horaires d'ouvertures - {{ site_name }}{% endblock %} +{% block title %}Horaires d'ouverture - {{ site_name }}{% endblock %} {% block breadcrumbs %} homechevron_right build Administrationchevron_right -public Liste des horaires d'ouvertures +schedule Horaires d'ouverture {% endblock %} {% block content %} -

Liste des horaires d'ouvertures ({{ openingHours | length }})

+

Horaires d'ouverture ({{ openingHours | length }})

diff --git a/app/Resources/views/admin/openinghour/new.html.twig b/app/Resources/views/admin/openinghour/new.html.twig index 41ac12b4a..d3ad6156c 100644 --- a/app/Resources/views/admin/openinghour/new.html.twig +++ b/app/Resources/views/admin/openinghour/new.html.twig @@ -5,7 +5,7 @@ {% block breadcrumbs %} homechevron_rightbuild Administrationchevron_right -public Liste des horaires d'ouverturechevron_right +schedule Horaires d'ouverturechevron_rightadd Ajouter {% endblock %} From 32f73723b25d6d202c542bc11df898a45537a570 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Wed, 26 Apr 2023 15:36:14 +0200 Subject: [PATCH 5/6] Rename listAction to indexAction --- app/Resources/views/admin/index.html.twig | 2 +- .../{_form.html.twig => _partial/form.html.twig} | 0 .../views/admin/openinghour/edit.html.twig | 4 ++-- .../{list.html.twig => index.html.twig} | 0 .../views/admin/openinghour/new.html.twig | 4 ++-- src/AppBundle/Controller/OpeningHourController.php | 14 +++++++------- 6 files changed, 12 insertions(+), 12 deletions(-) rename app/Resources/views/admin/openinghour/{_form.html.twig => _partial/form.html.twig} (100%) rename app/Resources/views/admin/openinghour/{list.html.twig => index.html.twig} (100%) diff --git a/app/Resources/views/admin/index.html.twig b/app/Resources/views/admin/index.html.twig index 7b1be9177..1d1dc6e5e 100644 --- a/app/Resources/views/admin/index.html.twig +++ b/app/Resources/views/admin/index.html.twig @@ -71,7 +71,7 @@ {% if is_granted("ROLE_ADMIN") %}
settings Informations
- + scheduleHoraires d'ouverture diff --git a/app/Resources/views/admin/openinghour/_form.html.twig b/app/Resources/views/admin/openinghour/_partial/form.html.twig similarity index 100% rename from app/Resources/views/admin/openinghour/_form.html.twig rename to app/Resources/views/admin/openinghour/_partial/form.html.twig diff --git a/app/Resources/views/admin/openinghour/edit.html.twig b/app/Resources/views/admin/openinghour/edit.html.twig index 6c6d3317c..fba237f20 100644 --- a/app/Resources/views/admin/openinghour/edit.html.twig +++ b/app/Resources/views/admin/openinghour/edit.html.twig @@ -5,7 +5,7 @@ {% block breadcrumbs %} homechevron_right build Administrationchevron_right -schedule Horaires d'ouverturechevron_right +schedule Horaires d'ouverturechevron_right edit Editer {% endblock %} @@ -13,7 +13,7 @@

Editer l'horaire d'ouverture

{{ form_start(form) }} -{% include "/admin/openinghour/_form.html.twig" with { form: form } %} +{% include "/admin/openinghour/_partial/form.html.twig" with { form: form } %}
diff --git a/app/Resources/views/admin/openinghour/list.html.twig b/app/Resources/views/admin/openinghour/index.html.twig similarity index 100% rename from app/Resources/views/admin/openinghour/list.html.twig rename to app/Resources/views/admin/openinghour/index.html.twig diff --git a/app/Resources/views/admin/openinghour/new.html.twig b/app/Resources/views/admin/openinghour/new.html.twig index d3ad6156c..8c182da36 100644 --- a/app/Resources/views/admin/openinghour/new.html.twig +++ b/app/Resources/views/admin/openinghour/new.html.twig @@ -5,7 +5,7 @@ {% block breadcrumbs %} homechevron_right build Administrationchevron_right -schedule Horaires d'ouverturechevron_right +schedule Horaires d'ouverturechevron_right add Ajouter {% endblock %} @@ -13,7 +13,7 @@

Nouvelle horaire d'ouverture

{{ form_start(form) }} -{% include "/admin/openinghour/_form.html.twig" with { form: form } %} +{% include "/admin/openinghour/_partial/form.html.twig" with { form: form } %}
diff --git a/src/AppBundle/Controller/OpeningHourController.php b/src/AppBundle/Controller/OpeningHourController.php index 9b9e9e7a8..372bece64 100644 --- a/src/AppBundle/Controller/OpeningHourController.php +++ b/src/AppBundle/Controller/OpeningHourController.php @@ -27,15 +27,15 @@ class OpeningHourController extends Controller /** * List all opening hours. * - * @Route("/", name="admin_openinghour_list", methods={"GET"}) + * @Route("/", name="admin_openinghour_index", methods={"GET"}) * @Security("has_role('ROLE_ADMIN')") */ - public function listAction(Request $request) + public function indexAction(Request $request) { $em = $this->getDoctrine()->getManager(); $openingHours = $em->getRepository('AppBundle:OpeningHour')->findAll(); - return $this->render('admin/openinghour/list.html.twig', array( + return $this->render('admin/openinghour/index.html.twig', array( 'openingHours' => $openingHours )); } @@ -66,7 +66,7 @@ public function newAction(Request $request) $em->flush(); $session->getFlashBag()->add('success', "L'horaire a bien été crée !"); - return $this->redirectToRoute('admin_openinghour_list'); + return $this->redirectToRoute('admin_openinghour_index'); } return $this->render('admin/openinghour/new.html.twig', array( @@ -103,7 +103,7 @@ public function editAction(Request $request, OpeningHour $openingHour) $em->flush(); $session->getFlashBag()->add('success', "L'horaire a bien été éditée !"); - return $this->redirectToRoute('admin_openinghour_list'); + return $this->redirectToRoute('admin_openinghour_index'); } return $this->render('admin/openinghour/edit.html.twig', array( @@ -131,10 +131,10 @@ public function deleteAction(Request $request, OpeningHour $openingHour) $em->flush(); $session->getFlashBag()->add('success', "L'horaire a bien été supprimée !"); - return $this->redirectToRoute('admin_openinghour_list'); + return $this->redirectToRoute('admin_openinghour_index'); } - return $this->redirectToRoute('admin_openinghour_list'); + return $this->redirectToRoute('admin_openinghour_index'); } /** From 38e75ef7266096a73abffd29088161d7eec8b4e6 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Wed, 26 Apr 2023 16:15:47 +0200 Subject: [PATCH 6/6] Simple widget to display opening hours --- .../openinghour/_partial/widget.html.twig | 22 +++++++++++++++++++ .../views/admin/openinghour/index.html.twig | 16 +++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 app/Resources/views/admin/openinghour/_partial/widget.html.twig diff --git a/app/Resources/views/admin/openinghour/_partial/widget.html.twig b/app/Resources/views/admin/openinghour/_partial/widget.html.twig new file mode 100644 index 000000000..3abc308cd --- /dev/null +++ b/app/Resources/views/admin/openinghour/_partial/widget.html.twig @@ -0,0 +1,22 @@ +
+
+ + {% set dayOfWeek = -1 %} + {% for openingHour in openingHours %} + {% if openingHour.dayOfWeek == dayOfWeek %} + & {{ openingHour.start | date('G\\hi') }}-{{ openingHour.end | date('G\\hi') }} + {% else %} + {# close previous day #} + {% if loop.index > 0 %}{% endif %} + {# open new day #} + + + + + +
{{ openingHour.dayOfWeekString | capitalize }} : {{ openingHour.start | date('G\\hi') }}-{{ openingHour.end | date('G\\hi') }} + {% endif %} + {% set dayOfWeek = openingHour.dayOfWeek %} + {% endfor %} +
+
diff --git a/app/Resources/views/admin/openinghour/index.html.twig b/app/Resources/views/admin/openinghour/index.html.twig index d23c0c53a..4c7f4fb0b 100644 --- a/app/Resources/views/admin/openinghour/index.html.twig +++ b/app/Resources/views/admin/openinghour/index.html.twig @@ -9,7 +9,21 @@ {% endblock %} {% block content %} -

Horaires d'ouverture ({{ openingHours | length }})

+

Horaires d'ouverture

+ +{% if openingHours %} +
+
+ {% include "/admin/openinghour/_partial/widget.html.twig" with { openingHours: openingHours } %} +
+
+{% else %} +
+ Aucune horaire d'ouverture à afficher. +
+{% endif %} + +

Liste des horaires d'ouverture ({{ openingHours | length }})