Exemplo n.º 1
0
 /**
  * index
  * manage class roster based on scheduleentity
  *
  * @Route("/admin/schedule/{id}/roster/{class}/{date}")
  * @Template("TSKScheduleBundle:Default:roster2.html.twig")
  * @Method({"GET"})
  */
 public function indexAction(ScheduleEntity $scheduleEntity, Classes $class, \DateTime $date)
 {
     // TODO:  Need to verify that scheduleEntity even exists as of $date
     // verify that scheduleEntity has a scheduleInstance on date
     $em = $this->getDoctrine()->getManager();
     $rosters = $this->getRoster($scheduleEntity, $date);
     $roster = new Roster();
     $roster->setClass($class);
     $roster->setSchedule($scheduleEntity);
     $roster->setStart($date);
     $form = $this->createForm(new RosterFormType($this->get('tsk.admin.student'), 'tsk.admin.student'), $roster);
     return array('class' => $class, 'scheduleEntity' => $scheduleEntity, 'rosters' => $rosters, 'date' => $date->format('Y-m-d'), 'form' => $form->createView());
 }
 /**
  * remove
  * Removes a single attendance records
  * @Route("/admin/schedule/attendance/remove/{id}/{date}", options={"expose"=true})
  * @Template("TSKScheduleBundle:Default:attendance_save.html.twig")
  * @Method("GET")
  */
 public function removeAction(Roster $roster, \DateTime $date)
 {
     $em = $this->getDoctrine()->getManager();
     $attendance = $em->getRepository('TSK\\ScheduleBundle\\Entity\\ScheduleAttendance')->findOneBy(array('student' => $roster->getStudent(), 'class' => $roster->getClass(), 'schedule' => $roster->getSchedule(), 'attDate' => $date));
     if ($attendance) {
         // TODO:  Need try-catch here ...
         $em->getConnection()->beginTransaction();
         $em->remove($attendance);
         $em->flush();
         $em->getConnection()->commit();
         if ($this->getRequest()->isXmlHttpRequest()) {
             return new Response(1);
         } else {
             $this->get('session')->getFlashBag()->add('success', 'Attendance record removed');
         }
     } else {
         return new Response(0);
     }
     return $this->redirect($this->getRequest()->headers->get('referer'));
 }