/**
  * @Route("/placements-{year}/{id}-{auth}", requirements={"year" = "\d+", "id" = "\d+"}, name="public_placements")
  * @Template()
  */
 public function listAction(Year $year, Student $student, $auth)
 {
     if (strtolower($student->getAuth()) != strtolower($auth)) {
         return $this->redirect($this->generateUrl('student_loginreset'));
     }
     if (!$year->getPlacementsPublic()) {
         return $this->redirect($this->generateUrl('main_index'));
     }
     $repo = $this->getDoctrine()->getManager()->getRepository('MobilityPlacementBundle:Placement');
     $placements = $repo->getPlacements($year->getYear());
     return array('year' => $year->getYear(), 'placements' => $placements);
 }
 /**
  * @Route("/start-year", name="start_year")
  */
 public function startYearAction()
 {
     $now = new \DateTime();
     $year = 0;
     // Si mois >= sept, on prend l'année suivante
     if ($now->format('n') >= 9) {
         $year = $now->format('Y') + 1;
     } else {
         $year = $now->format('Y');
     }
     $em = $this->getDoctrine()->getManager();
     $repo = $em->getRepository('MobilityMainBundle:Year');
     if ($repo->findOneBy(array('year' => $year)) == null) {
         $y = new Year();
         $y->setYear($year);
         $em->persist($y);
         $em->flush();
     }
     return $this->redirect($this->generateUrl('student_list_year', array('year' => $year)));
 }
 /**
  * @Route("/lock-{year}-confirm/{token}", requirements={"year" = "\d+"}, name="placements_lock_confirm")
  */
 public function lockConfirmAction(Year $year, $token)
 {
     $csrf = $this->get('form.csrf_provider');
     if (!$csrf->isCsrfTokenValid('lock_placements', $token)) {
         $this->get('session')->getFlashBag()->add('error', 'Token invalide !');
         return $this->redirect($this->generateUrl('placement_list_year', array('year' => $year->getYear())));
     }
     $em = $this->getDoctrine()->getManager();
     $repo_students = $em->getRepository('MobilityStudentBundle:Student');
     $students = $repo_students->getStudents($year);
     foreach ($students as $s) {
         $s->setState(-1);
     }
     $repo_placements = $em->getRepository('MobilityPlacementBundle:Placement');
     $placements = $repo_placements->getPlacements($year);
     foreach ($placements as $p) {
         $p->setState(2);
         $p->getStudent()->setState(2);
     }
     $year->setPlacementsLocked(true);
     // TODO : mail
     $em->flush();
     $this->get('session')->getFlashBag()->add('success', 'Affectations validées et verrouillées !');
     return $this->redirect($this->generateUrl('placement_list_year', array('year' => $year->getYear())));
 }