private function initializeStudentBelt($student)
 {
     $studentRank = new StudentRank();
     $studentRank->setStudent($student);
     $studentRank->setRank($this->em->getRepository('TSK\\RankBundle\\Entity\\Rank')->find(1));
     // WHITE BELT  -- config options?
     $studentRank->setRankType($this->em->getRepository('TSK\\RankBundle\\Entity\\RankType')->find(1));
     // BELT TYPE  -- config options?
     $this->em->persist($studentRank);
     $this->em->flush();
 }
 /**
  * @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));
 }
示例#3
0
 protected function processStudent($row)
 {
     if ($row) {
         $manager = $this->getContainer()->get('doctrine.orm.entity_manager');
         $studentRepo = $manager->getRepository('TSK\\StudentBundle\\Entity\\Student');
         $statesRepo = $manager->getRepository('TSK\\UserBundle\\Entity\\States');
         $studentStatusRepo = $manager->getRepository('TSK\\StudentBundle\\Entity\\StudentStatus');
         $rankRepo = $manager->getRepository('TSK\\RankBundle\\Entity\\Rank');
         $schoolRepo = $manager->getRepository('TSK\\SchoolBundle\\Entity\\School');
         $row[0] = preg_replace('/-/', '', $row[0]);
         $student = $studentRepo->findOneBy(array('legacyStudentId' => $row[0]));
         if (!$student) {
             $student = new Student();
             $contactManager = $this->getContainer()->get('tsk_user.contact_manager');
             $contact = $contactManager->createContact();
             $contact->setOrganization($this->org);
             $contact->setFirstName($row[1]);
             $contact->setLastName($row[2]);
             $contact->setEmail($row[13]);
             $contact->setAddress1($row[3]);
             $contact->setAddress2($row[4]);
             $contact->setCity($row[5]);
             $contact->setState($statesRepo->find($row[6]));
             $contact->setPostalCode($row[7]);
             $contact->setPhone($row[8]);
             $contact->setMobile($row[9]);
             $contact->setDateOfBirth(new \DateTime($row[10]));
             $contact->addSchool($this->school);
             $contactManager->updateCanonicalFields($contact);
             $student->setContact($contact);
             $student->setLegacyStudentId($row[0]);
             $student->setStudentStatus($studentStatusRepo->findOneBy(array('name' => 'active')));
             $rank = $rankRepo->findOneBy(array('fullDescription' => $row[12]));
             if (!$rank) {
                 print 'Bad rank [' . $row[12] . ']' . "\n";
                 try {
                 } catch (\Exception $e) {
                     // throw new \Exception('Bad Rank [' . $row[12] . ']');
                 }
             } else {
                 $student->setRank($rank);
                 $studentRank = new StudentRank();
                 $studentRank->setStudent($student);
                 $studentRank->setRank($rank);
                 $studentRank->setRankType($rank->getRankType());
                 $studentRank->setAwardedDate(new \DateTime($row[14]));
                 $manager->persist($studentRank);
             }
             $manager->persist($student);
             $manager->flush();
         }
     }
 }
 /**
  * @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);
 }