/** * @param string $daysOfWeekString indice des jours de la semaine séparé par des ";" * @return Garderie[]|null */ public function reverseTransform($daysOfWeekString) { if (empty($daysOfWeekString)) { return array(); } $daysOfWeek = explode(';', $daysOfWeekString); $garderies_periode = $this->daysOfWeek->getListJoursGarderie(); $garderies_eleve = $this->manager->getRepository('WCSCantineBundle:Eleve')->findAllGarderiesForPeriode($this->eleve, $this->daysOfWeek->getPeriode(), true); $garderies = array(); foreach ($daysOfWeek as $dayOfWeek) { foreach ($garderies_periode[$dayOfWeek] as $date) { // si la réservation est déjà présente, // on se contente de l'ajouter dans la liste // sinon on créé une nouvelle réservation $dateT = new \DateTime($date); $found = false; $garderie = null; foreach ($garderies_eleve as $current) { if ($current->getDate() == $dateT) { if (substr($dayOfWeek, -2) == '-1' && $current->isEnableMorning()) { $garderie = $current; $found = true; } if (substr($dayOfWeek, -2) == '-2' && $current->isEnableEvening()) { $garderie = $current; $found = true; } } } if (!$found) { $garderie = new Garderie(); $garderie->setEleve($this->eleve); $garderie->setDate($dateT); if (substr($dayOfWeek, -2) == '-1') { $garderie->setEnableMorning(true); } if (substr($dayOfWeek, -2) == '-2') { $garderie->setEnableEvening(true); } $garderie->setSubscribedByParent(true); $this->manager->persist($garderie); } $garderies[] = $garderie; } } return $garderies; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $inscs = [['2016-06-21', 'Bouteiller-Isabelle', true, true], ['2016-06-21', 'Dupontel-Jean-Kevin', true, true], ['2016-06-21', 'Dupontel-Kevina', true, true], ['2016-06-21', 'Dupontel-Mathilde', true, true], ['2016-06-21', 'Robert-Mickael', true, false], ['2016-06-21', 'Larissa-Viviane', false, true], ['2016-06-21', 'Larissa-Gaelle', false, true], ['2016-06-21', 'Larissa-Melina', false, true], ['2016-06-21', 'Larissa-Astrid', false, true], ['2016-06-21', 'Veron-Matheos', false, true], ['2016-06-21', 'Veron-Kevin', false, true], ['2016-06-21', 'Batista-Jean', true, true], ['2016-06-22', 'Dupontel-Jean-Kevin', true, true], ['2016-06-22', 'Dupontel-Kevina', true, true], ['2016-06-22', 'Dupontel-Mathilde', true, true], ['2016-06-22', 'Robert-Mickael', true, false], ['2016-06-22', 'Larissa-Viviane', true, true], ['2016-06-22', 'Larissa-Gaelle', false, true], ['2016-06-22', 'Larissa-Melina', false, true], ['2016-06-22', 'Larissa-Astrid', false, true], ['2016-06-22', 'Veron-Matheos', false, true], ['2016-06-22', 'Veron-Kevin', false, true], ['2016-06-22', 'Batista-Jean', true, true]]; foreach ($inscs as $insc) { $entity = new Garderie(); $entity->setDate(new \DateTime($insc[0])); $entity->setEleve($this->getReference($insc[1])); $entity->setEnableMorning($insc[2]); $entity->setEnableEvening($insc[3]); $manager->persist($entity); } $manager->flush(); }