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..1d1dc6e5e 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'ouverture + + + 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/_partial/form.html.twig b/app/Resources/views/admin/openinghour/_partial/form.html.twig new file mode 100644 index 000000000..2e233fadd --- /dev/null +++ b/app/Resources/views/admin/openinghour/_partial/form.html.twig @@ -0,0 +1,32 @@ +
+ {{ form_errors(form) }} +
+
+
+
+ {{ 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/_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/edit.html.twig b/app/Resources/views/admin/openinghour/edit.html.twig new file mode 100644 index 000000000..fba237f20 --- /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 +schedule Horaires d'ouverturechevron_right +edit Editer +{% endblock %} + +{% block content %} +

Editer l'horaire d'ouverture

+ +{{ form_start(form) }} +{% include "/admin/openinghour/_partial/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/index.html.twig b/app/Resources/views/admin/openinghour/index.html.twig new file mode 100644 index 000000000..4c7f4fb0b --- /dev/null +++ b/app/Resources/views/admin/openinghour/index.html.twig @@ -0,0 +1,57 @@ +{% extends 'layout.html.twig' %} + +{% block title %}Horaires d'ouverture - {{ site_name }}{% endblock %} + +{% block breadcrumbs %} +homechevron_right +build Administrationchevron_right +schedule Horaires d'ouverture +{% endblock %} + +{% block content %} +

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 }})

+ + + + + + + + + + + + {% 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 + +{% 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..8c182da36 --- /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 +schedule Horaires d'ouverturechevron_right +add Ajouter +{% endblock %} + +{% block content %} +

Nouvelle horaire d'ouverture

+ +{{ form_start(form) }} +{% include "/admin/openinghour/_partial/form.html.twig" with { form: form } %} +
+ +
+{{ form_end(form) }} +{% endblock %} 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/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/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 new file mode 100644 index 000000000..372bece64 --- /dev/null +++ b/src/AppBundle/Controller/OpeningHourController.php @@ -0,0 +1,151 @@ +getDoctrine()->getManager(); + $openingHours = $em->getRepository('AppBundle:OpeningHour')->findAll(); + + return $this->render('admin/openinghour/index.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()) { + $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(); + + $session->getFlashBag()->add('success', "L'horaire a bien été crée !"); + return $this->redirectToRoute('admin_openinghour_index'); + } + + 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(); + $em = $this->getDoctrine()->getManager(); + + $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)); + $end = $form->get('end')->getData(); + $openingHour->setEnd(new \DateTime($end)); + + $em->persist($openingHour); + $em->flush(); + + $session->getFlashBag()->add('success', "L'horaire a bien été éditée !"); + return $this->redirectToRoute('admin_openinghour_index'); + } + + 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 deleteAction(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_index'); + } + + return $this->redirectToRoute('admin_openinghour_index'); + } + + /** + * @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/Controller/PeriodController.php b/src/AppBundle/Controller/PeriodController.php index 25eab4338..f7140f6a5 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,28 +256,31 @@ 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 ($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()) { - $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'); } $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); 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 new file mode 100644 index 000000000..0c6fec0a0 --- /dev/null +++ b/src/AppBundle/Entity/OpeningHour.php @@ -0,0 +1,186 @@ +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; + } + + /** + * @Assert\IsTrue(message="L'heure de début doit être avant celle de fin") + */ + public function isStartBeforeEnd() + { + return $this->start < $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/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/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..02472e795 --- /dev/null +++ b/src/AppBundle/Repository/OpeningHourRepository.php @@ -0,0 +1,17 @@ +findBy(array(), array('dayOfWeek' => 'ASC', 'start' => 'ASC')); + } +}