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 @@
{{ 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'));
+ }
+}