/**
  * @param School $school
  * @param string $activity
  * @return boolean true if the activity is enabled for the school
  */
 protected function isActivityEnabled(School $school, $activity)
 {
     if ($activity == 'cantine' && $school->getActiveCantine()) {
         return true;
     }
     if ($activity == 'tap' && $school->getActiveTap()) {
         return true;
     }
     if ($activity == 'garderie_matin' && $school->getActiveGarderie()) {
         return true;
     }
     if ($activity == 'garderie_soir' && $school->getActiveGarderie()) {
         return true;
     }
     return false;
 }
 /**
  * @param Request $request
  * @param School $school
  * @param $activity
  * @param $id_activity
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function removeAction(Request $request, School $school, $activity, $id_activity)
 {
     // ensure the current day is not off
     if ($this->isDayOff($activity)) {
         return $this->redirectToRoute('wcs_employee_home');
     }
     // get the mapper
     $mapper = $this->getActivityMapper($activity);
     if (is_null($mapper)) {
         return $this->redirectToRoute('wcs_employee_home');
     }
     $key = $request->get('activity') . '_list_eleves';
     $this->get('session')->set($key, $request->get("list_eleves"));
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository($mapper->getEntityClassName())->find($id_activity);
     $em->remove($entity);
     $em->flush();
     return $this->redirectToRoute('wcs_employee_daylist', array('activity' => $activity, 'id' => $school->getId()));
 }
 /**
  * @param Request $request
  * @param School $school
  * @param $activity
  * @return array
  */
 public function buildView(Request $request, School $school, $activity)
 {
     // prepare local variables
     $entityClass = $this->mapper->getEntityClassName();
     $entity = new $entityClass();
     $redirectTo = '';
     // merge all options to transmit to the getActivityDayList repository's method
     $options = array_merge($this->mapper->getDayListAdditionalOptions(), array('school' => $school, 'date_day' => $this->getDateDay()));
     // create the form
     $form = $this->createForm(new ListType(), $entity, ['additional_options' => ['school_id' => $school->getId(), 'date_day' => $this->getDateDay(), 'activity_type' => $this->mapper->getActivityType()]]);
     // process the form if any POST
     if ($this->processForm($request, $form, $entity)) {
         $redirectTo = $this->generateUrl('wcs_employee_daylist', array('activity' => $activity, 'id' => $school->getId()));
     }
     // load the list (important : let this instruction AFTER creating the form in order to get
     // new registrations or removing from a previous post taken in account.
     $entities = $this->loadRegisteredPupilsList($options);
     // return the array with all data
     return array('entities' => $entities, 'form_register' => $form->createView(), 'redirect_to' => $redirectTo);
 }
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $schools = [['Les écureuils', 'La Loupe', true, true, true, false, 'school-ecureuils'], ['Notre Dame des Fleurs', 'La Loupe', true, false, false, false, 'school-nddf'], ['Roland-Garros', 'La Loupe', true, true, true, true, 'school-rg']];
     foreach ($schools as $school) {
         $entity = new School();
         $entity->setName($school[0]);
         $entity->setAdress($school[1]);
         $entity->setActiveCantine($school[2]);
         $entity->setActiveGarderie($school[3]);
         $entity->setActiveTap($school[4]);
         $entity->setActiveVoyage($school[5]);
         $manager->persist($entity);
         $this->setReference($school[6], $entity);
     }
     $manager->flush();
 }
 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>'));
 }