Пример #1
0
 /**
  * @Route("/test/{id}")
  * @Template()
  * @Method({"GET"})
  */
 public function testAction(Student $student)
 {
     $em = $this->getDoctrine()->getManager();
     $forms = array();
     $eligibleRanks = $student->getEligibleRanks();
     foreach ($eligibleRanks as $rank) {
         $studentRank = new StudentRank();
         $studentRank->setStudent($student);
         $studentRank->setRank($rank);
         $studentRank->setRankType($rank->getRankType());
         $form = $this->createForm(new StudentPromotionFormType(), $studentRank);
         $forms[] = $form->createView();
     }
     $srRepo = $em->getRepository('TSKStudentBundle:StudentRank');
     $studentCreditRepo = $em->getRepository('TSKStudentBundle:StudentCreditLog');
     return array('student' => $student, 'forms' => $forms, 'currentRank' => $student->getRank()->getId(), 'numberStripesEarnedAtCurrentBelt' => $srRepo->getNumberStripesEarnedAtCurrentBelt($student), 'numberKbStripesEarnedAtCurrentBelt' => $srRepo->getNumberKbStripesEarnedAtCurrentBelt($student), 'numberGrStripesEarnedAtCurrentBelt' => $srRepo->getNumberGrStripesEarnedAtCurrentBelt($student), 'lastPromotionDate' => $srRepo->getLastPromotionDate($student), 'lastKbPromotionDate' => $srRepo->getLastKbPromotionDate($student), 'lastGrPromotionDate' => $srRepo->getLastGrPromotionDate($student), 'creditsEarnedSinceLastPromotion' => $studentCreditRepo->getCreditsEarnedSinceLastPromotion($student), 'kbCreditsEarnedSinceLastKbPromotion' => $studentCreditRepo->getKbCreditsEarnedSinceLastKbPromotion($student), 'grCreditsEarnedSinceLastGrPromotion' => $studentCreditRepo->getGrCreditsEarnedSinceLastGrPromotion($student));
 }
Пример #2
0
 /**
  * @Route("/promote/{id}")
  * @Template()
  * @Method({"GET","POST"})
  */
 public function promoteAction(Student $student)
 {
     $eligibleRanks = $student->getEligibleRanks();
     $forms = array();
     foreach ($eligibleRanks as $rank) {
         $studentRank = new StudentRank();
         $studentRank->setStudent($student);
         $studentRank->setRank($rank);
         $studentRank->setRankType($rank->getRankType());
         $form = $this->createForm(new StudentPromotionFormType(), $studentRank);
         $forms[] = $form->createView();
     }
     $request = $this->get('request');
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         if ($form->isValid()) {
             if ($studentRank->getRank() == $student->getRank()) {
                 $this->get('session')->getFlashBag()->add('error', 'ERROR:  Cannot promote student to same rank');
             } else {
                 $em = $this->getDoctrine()->getManager();
                 $em->persist($studentRank);
                 $em->flush();
                 // Dispatch student progress event ...
                 $studentProgressEvent = new StudentProgressEvent($student);
                 $dispatcher = $this->get('event_dispatcher');
                 $dispatcher->dispatch(StudentEvents::STUDENT_PROGRESS, $studentProgressEvent);
                 $this->get('session')->getFlashBag()->add('success', 'Student Promoted!');
                 // Force a redirect here to get the updated data
                 return $this->redirect($this->getRequest()->headers->get('referer'));
             }
         }
     }
     return array('student' => $student, 'forms' => $forms);
 }