/**
  * @param Request       $request
  * @param SubjectEntity $subject
  * @param string        $studentId
  *
  * @return JsonResponse
  */
 public function saveAction(Request $request, SubjectEntity $subject, $studentId)
 {
     $firstname = $request->get('firstname');
     $lastname = $request->get('lastname');
     $em = $this->get('doctrine.orm.default_entity_manager');
     if (is_numeric($studentId)) {
         $new = false;
         $student = $em->getRepository('SubjectBundle:StudentEntity')->find($studentId);
     } else {
         $new = true;
         $student = new StudentEntity();
         $student->setEducationClass($subject->getEducationClass());
     }
     $student->setFirstname($firstname)->setLastname($lastname);
     $em->persist($student);
     $em->flush();
     return new JsonResponse(['id' => $student->getId(), 'firstname' => $student->getFirstname(), 'lastname' => $student->getLastname(), 'new' => $new]);
 }
 public function indexAction(Subject $subject)
 {
     $data = [];
     $students = $subject->getEducationClass()->getStudents();
     $teachingUnits = $subject->getTeachingUnits();
     foreach ($students as $student) {
         $studentData = ['id' => $student->getId(), 'firstname' => $student->getFirstname(), 'lastname' => $student->getLastname(), 'teachingUnits' => []];
         $marks = $student->getMarks();
         foreach ($teachingUnits as $teachingUnit) {
             /** @var $teachingUnit TeachingUnit */
             $studentData['teachingUnits'][$teachingUnit->getId()] = null;
         }
         foreach ($marks as $mark) {
             /** @var MarkEntity $mark */
             $markSubject = $mark->getTeachingUnit()->getSubject();
             if ($markSubject->getId() === $subject->getId()) {
                 $studentData['teachingUnits'][$mark->getTeachingUnit()->getId()] = $mark->getMark();
             }
         }
         $data[] = $studentData;
     }
     return $this->render('MarkBundle:mark:index.html.php', ['data' => $data, 'teachingUnits' => $teachingUnits, 'subject' => $subject]);
 }