public function holidaysAction(Request $request) { if ($request->isMethod('POST')) { $eventName = $request->request->get('event'); $eventDate = $request->request->get('date'); if (!is_null($eventDate) && !empty($eventName)) { $dateForHoliday = DateTime::createFromFormat("d/m/Y", $eventDate); $dateForHoliday->setTime(0, 0); $em = $this->getDoctrine()->getManager(); $repositoryFS = $em->getRepository('STXCroissantsBundle:Friday_Subscriptions'); $subscription = $repositoryFS->findOneBy(array('date' => $dateForHoliday)); if (!is_null($subscription)) { /* THROW ERROR and return form */ $this->get('session')->getFlashBag()->add('danger', 'Il y a déjà un évènement ce jour!'); //return $this->render('STXCroissantsBundle:CroissantsAdmin:holidays.html.twig'); } else { /* Create new friday_subscription for holiday */ $holidayToAdd = new Friday_Subscriptions(); $holidayToAdd->setDate($dateForHoliday); $holidayToAdd->setRemark('FERIE - ' . $eventName); $em->persist($holidayToAdd); $em->flush(); $this->get('session')->getFlashBag()->add('success', 'Jour férié ajouté au calendrier'); //return $this->render('STXCroissantsBundle:CroissantsAdmin:holidays.html.twig'); } } else { /* THROW ERROR and return form */ $this->get('session')->getFlashBag()->add('danger', 'Un des champs est vide!'); //return $this->render('STXCroissantsBundle:CroissantsAdmin:holidays.html.twig'); } } return $this->render('STXCroissantsBundle:CroissantsAdmin:holidays.html.twig'); }
/** * Ajax function to enter a remark for a day in the grid. * * This is used only by the Admin * * @return \Symfony\Component\HttpFoundation\Response */ public function updateRemarkAction() { $request = $this->getRequest(); if ($request->isXmlHttpRequest()) { $response = new Response(); try { $dayOfSubscription = DateTime::createFromFormat("dmY", $request->request->get('date')); $dayOfSubscription->setTime(0, 0); $em = $this->getDoctrine()->getManager(); $repositoryFS = $em->getRepository('STXCroissantsBundle:Friday_Subscriptions'); $friday_subscribtion = $repositoryFS->findOneBy(array('date' => $dayOfSubscription)); if (is_null($friday_subscribtion)) { $friday_subscribtion = new Friday_Subscriptions(); $friday_subscribtion->setDate($dayOfSubscription); } $friday_subscribtion->setRemark($request->request->get('remark')); $em->persist($friday_subscribtion); $em->flush(); $output = array('success' => TRUE, 'message' => 'Confirmation complete!'); } catch (\Exception $e) { //$this->get('session')->getFlashBag()->add('error', 'Erreur survenue!'); $output = array('success' => FALSE, 'message' => 'An undefined exception occurred!'); } $response->headers->set('Content-Type', 'application/json'); $response->setContent(json_encode($output)); return $response; } }
/** * * @param Friday_Subscriptions $otherSub * @return \STX\CroissantsBundle\Entity\Friday_Subscriptions */ public function updateFromSubscription(Friday_Subscriptions $otherSub) { if (is_null($otherSub->getUser())) { $this->removeUser(); } else { $this->setUser($otherSub->getUser()); } if (is_null($otherSub->getBackupUser())) { $this->removeBackupUser(); } else { $this->setBackupUser($otherSub->getBackupUser()); } if (is_null($otherSub->getConfirmationUser())) { $this->confirmation_user = NULL; } else { $this->setConfirmationUser($otherSub->getConfirmationUser()); } if (is_null($otherSub->getRemark())) { $this->remark = NULL; } else { $this->setRemark($otherSub->getRemark()); } return $this; }