/** * @param Request $request * @param Form $form * @param Eleve $eleve * @return bool */ private function processPostedForm(Request $request, Form $form, Eleve $eleve, Period $periode) { $em = $this->getDoctrine()->getManager(); $form->handleRequest($request); if ($form->isValid()) { $temporary_taps_to_persist = $eleve->getTaps(); // retire toutes les inscriptions au TAP pour la période qui ne sont pas // et qui n'ont pas été enregistré par le parent // dans la nouvelle sélection $repo = $em->getRepository('WCSCantineBundle:Eleve'); $eleve_taps_periode = $repo->findAllTapsForPeriode($eleve, $periode, true); foreach ($eleve_taps_periode as $item) { if (!$temporary_taps_to_persist->contains($item)) { $em->remove($item); } } // retire toutes les inscriptions à la garderie pour la période qui ne sont pas // et qui n'ont pas été enregistré par le parent // dans la nouvelle sélection $temporary_garderies_to_persist = $eleve->getGarderies(); $eleve_garderies_periode = $repo->findAllGarderiesForPeriode($eleve, $periode, true); foreach ($eleve_garderies_periode as $item) { if (!$temporary_garderies_to_persist->contains($item)) { $em->remove($item); } } $eleve->setTapgarderieSigned(true); $em->flush(); return true; } return false; }
/** * @param Request $request * @param Form $form * @param Eleve $eleve * @return bool */ private function processPostedForm(Request $request, Form $form, Eleve $eleve) { $em = $this->getDoctrine()->getManager(); $form->handleRequest($request); if ($form->isValid()) { // la nouvelle sélection de dates (avec celles déjà présentes en // base de données, et les nouvelles à ajouter // (cette liste a été mise à jour avec LunchToStringTransformer) $lunchesNew = $eleve->getLunches(); // récupère les réservations actuellement en base de données $lunchesOld = $em->getRepository("WCSCantineBundle:Lunch")->findByEleve($eleve); // supprime les dates qui ne sont plus sélectionnées foreach ($lunchesOld as $lunchOld) { if (!$lunchesNew->contains($lunchOld)) { $em->remove($lunchOld); } } $eleve->setCanteenSigned(true); // met à jour la fiche élève (le régime alimentaire,...) $em->persist($eleve); $em->flush(); return true; } return false; }
/** * @param EleveFormEntity $eleveForm * @return boolean $confirmation * @throws \Exception */ public function process(EleveFormEntity $eleveForm) { $this->form->handleRequest($this->request); if ($this->form->isValid()) { if (!$eleveForm->getCertifie()) { throw new \Exception('Toutes les autorisations doivent être cochées !'); } if (!($eleveForm->getNom() && $eleveForm->getPrenom())) { throw new \Exception('Vous devez remplir le nom et prénom'); } if (!$eleveForm->getDateDeNaissance()) { throw new \Exception('Vous devez renseigner la date de naissance de votre enfant !'); } $eleve = new Eleve(); $eleve->setNom($eleveForm->getNom()); $eleve->setPrenom($eleveForm->getPrenom()); $eleve->setDateDeNaissance($eleveForm->getDateDeNaissance()); $eleve->setDivision($eleveForm->getDivision()); $eleve->setRegimeSansPorc(false); $eleve->setUser($this->user); $this->em->persist($eleve); $this->em->flush(); return true; } return false; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $eleves = [['Dupontel', 'Dupontel', 'Jean-Kevin', '2007-01-01', false, '', 'division-catteeu'], ['Dupontel', 'Dupontel', 'Kevina', '2008-08-15', false, '', 'division-catteeu'], ['Dupontel', 'Dupontel', 'Mathilde', '2009-08-15', false, '', 'division-catteeu'], ['Robert', 'Robert', 'Mickael', '2010-08-15', false, 'gluten', 'division-pichodo'], ['Robert', 'Robert', 'Franck', '2007-08-15', false, 'gluten', 'division-lucien'], ['Larissa', 'Larissa', 'Viviane', '2008-08-15', true, '', 'division-nouaille'], ['Larissa', 'Larissa', 'Gaelle', '2007-08-15', true, '', 'division-lucien'], ['Larissa', 'Larissa', 'Melina', '2010-08-15', true, '', 'division-pichodo'], ['Larissa', 'Larissa', 'Astrid', '2010-08-15', true, 'poivre', 'division-pichodo'], ['Veron', 'Veron', 'Matheos', '2010-08-15', false, '', 'division-pichodo'], ['Veron', 'Veron', 'Kevin', '2010-08-15', false, '', 'division-pichodo'], ['Bouteiller', 'Bouteiller', 'Thomas', '2007-08-15', false, '', 'division-lucien'], ['Bouteiller', 'Bouteiller', 'Isabelle', '2008-08-15', false, '', 'division-nouaille'], ['Butin', 'Butin', 'Arnold', '2008-08-15', false, '', 'division-nouaille'], ['Butin', 'Butin', 'Willy', '2010-08-15', false, '', 'division-pichodo'], ['Dorel', 'Dorel', 'Maelis', '2009-08-15', false, '', 'division-nouaille'], ['Batista', 'Batista', 'Jean', '2010-08-15', false, '', 'division-pichodo'], ['Nelon', 'Nelon', 'Aurianne', '2009-08-15', false, '', 'division-lemoue'], ['Nelon', 'Nelon', 'Enora', '2010-08-10', false, '', 'division-pichodo']]; foreach ($eleves as $eleve) { $entity = new Eleve(); $entity->setUser($this->getReference($eleve[0])); $entity->setNom($eleve[1]); $entity->setPrenom($eleve[2]); $entity->setDateDeNaissance(new \DateTime($eleve[3])); $entity->setRegimeSansPorc($eleve[4]); $entity->setAllergie($eleve[5]); $entity->setDivision($this->getReference($eleve[6])); $manager->persist($entity); $this->setReference($eleve[1] . "-" . $eleve[2], $entity); } $manager->flush(); }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('regimeSansPorc', 'checkbox', array('required' => false))->add('allergie', 'text', array('label' => 'allergie', 'required' => false))->add('habits', 'choice', array('choices' => Eleve::getHabitDaysLabels(), 'expanded' => true, 'multiple' => true, 'required' => false))->add('lunches', 'hidden', array('required' => false)); $builder->get('lunches')->addModelTransformer(new LunchToStringTransformer($this->manager, $builder->getData())); /** * @var \WCS\CantineBundle\Entity\Eleve $entity */ $entity = $builder->getData(); if (!$entity->isCanteenSigned()) { $builder->add('canteen_atteste', 'checkbox', array('required' => true, 'mapped' => false))->add('canteen_autorise', 'checkbox', array('required' => true, 'mapped' => false))->add('canteen_certifie', 'checkbox', array('required' => true, 'mapped' => false)); } }
public function inscrireAction(Request $request, Eleve $eleve) { //------------------------------------------------------------------------ // inscriptions possible à partir de la date du jour + un délai de N jours // pour les voyages //------------------------------------------------------------------------ $first_day_available = $this->get('wcs.gesty.scheduler')->getFirstAvailableDate($this->get('wcs.datenow')->getDate(), ActivityType::TRAVEL); // créer une instance d'un formulaire $options = array('method' => 'POST', 'action' => $this->generateUrl('voyage_inscription', array('id' => $eleve->getId())), 'division' => $eleve->getDivision(), 'date_day' => $first_day_available); $form = $this->createForm(new VoyageType(), $eleve, $options); // gère la requête du formulaire $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $eleve->setVoyageSigned(true); $em->persist($eleve); $em->flush(); return $this->redirectToRoute('wcs_cantine_dashboard'); } return $this->render("WCSCantineBundle:Voyage:inscription.html.twig", array("eleve" => $eleve, "first_day_available" => $first_day_available, "form" => $form->createView())); }
public static function getHabitDaysLabels() { $result = array(); foreach (Eleve::getHabitDays() as $key => $day) { $result[$key] = 'Tous les ' . $day . 's'; } return $result; }
protected function execute(InputInterface $input, OutputInterface $output) { $file = $input->getArgument('file'); $em = $this->getContainer()->get('doctrine')->getManager(); if (!$this->askConfirmation($input, $output, '<question>Careful, database will be purged. Do you want to continue y/N ?</question>', false)) { return; } $purger = new ORMPurger($em); $purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE); $executor = new ORMExecutor($em, $purger); $executor->setLogger(function ($message) use($output) { $output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message)); }); $executor->purge(); // Load users $stream = fopen($file, 'r'); while ($line = fgets($stream)) { if (strpos($line, 'COPY multipass_users (id') !== FALSE) { break; } } $userManager = $this->getUserManager(); $userAdmin = $userManager->createUser(); $userAdmin->setPlainPassword('admin'); $userAdmin->setEnabled(true); $userAdmin->setEmail('*****@*****.**'); $userAdmin->setRoles(array('ROLE_SUPER_ADMIN')); $userAdmin->setFirstname('Romain'); $userAdmin->setLastname('Coeur'); $userAdmin->setPhone('0628974930'); $userManager->updateUser($userAdmin); $users = array('admin' => $userAdmin); while ($line = fgets($stream)) { $data = explode(' ', $line); if ($data[0] == "\\.\n") { break; } $entity = $userManager->createUser(); $entity->setUsername($data[1]); $entity->setUsernameCanonical($data[1]); $entity->setEmail($data[1]); $entity->setEmailCanonical($data[1]); $entity->setEnabled(true); $entity->setPlainPassword('wild1234'); $entity->setPassword('9908e42e69c19bc0e6c0ce1bf05b381fbc94ca10aa7e6b648815d676248f8a3fe2ee124f7d9d375e9f909036e45cc9e766e3c9369655c1db1f331e71c17bc2c9'); $userManager->updateUser($entity); $users[$data[0]] = $entity; } $em->flush(); $output->writeln(sprintf(' <comment>></comment> <info>%s users loaded</info>', count($users))); // Add home data to users rewind($stream); while ($line = fgets($stream)) { if (strpos($line, 'COPY multipass_homes (id') !== FALSE) { break; } } $nb = 0; while ($line = fgets($stream)) { $data = explode(' ', $line); if ($data[0] == "\\.\n") { break; } $user = $users[$data[11]]; $user->setFirstname($data[1]); $user->setLastname($data[2]); $user->setPhone($data[3]); $user->setTelephoneSecondaire($data[4]); $user->setAdresse($data[5]); $user->setCodePostal($data[6]); $user->setCommune($data[7]); $user->setModeDePaiement($data[8]); $user->setGender($data[9]); $user->setCaf($data[10]); $em->persist($user); $nb++; } $em->flush(); $output->writeln(sprintf(' <comment>></comment> <info>%s users updated</info>', $nb)); // Load schools rewind($stream); while ($line = fgets($stream)) { if (strpos($line, 'COPY multipass_schools (id') !== FALSE) { break; } } $schools = array(); while ($line = fgets($stream)) { $data = explode(' ', $line); if ($data[0] == "\\.\n") { break; } $entity = new School(); $entity->setName($data[1]); $entity->setAdress($data[2]); $em->persist($entity); $schools[$data[0]] = $entity; } $em->flush(); $output->writeln(sprintf(' <comment>></comment> <info>%s schools loaded</info>', count($schools))); // Load divisions rewind($stream); while ($line = fgets($stream)) { if (strpos($line, 'COPY multipass_classrooms (id') !== FALSE) { break; } } $divisions = array(); while ($line = fgets($stream)) { $data = explode(' ', $line); if ($data[0] == "\\.\n") { break; } $entity = new Division(); $entity->setSchool($schools[$data[10]]); $gradeAndTeacher = explode(' DE ', $data[1]); $entity->setGrade($gradeAndTeacher[0]); $entity->setHeadTeacher($gradeAndTeacher[1]); $em->persist($entity); $divisions[$data[0]] = $entity; } $em->flush(); $output->writeln(sprintf(' <comment>></comment> <info>%s divisions loaded</info>', count($divisions))); // Load children rewind($stream); while ($line = fgets($stream)) { if (strpos($line, 'COPY multipass_children (id') !== FALSE) { break; } } $nb = 0; while ($line = fgets($stream)) { $data = explode(' ', $line); if ($data[0] == "\\.\n") { break; } if ($data[5] == '\\N') { continue; } $entity = new Eleve(); $entity->setPrenom($data[1]); $entity->setNom($data[2]); $entity->setDateDeNaissance(new \DateTime($data[3])); $entity->setUser($users[$data[4]]); $entity->setDivision($divisions[$data[5]]); $habits = array(); if ($data[8] == 't') { $habits[] = "lundi"; } if ($data[9] == 't') { $habits[] = "mardi"; } if ($data[10] == 't') { $habits[] = "jeudi"; } if ($data[11] == 't') { $habits[] = "vendredi"; } $entity->setHabits($habits); $entity->setAllergie($data[13]); $entity->setRegimeSansPorc($data[14]); $em->persist($entity); $nb++; } $em->flush(); $output->writeln(sprintf(' <comment>></comment> <info>%s divisions loaded</info>', $nb)); fclose($stream); $output->writeln(sprintf('<info>done</info>')); }