public function addStudentAction(Request $request) { $data = json_decode($request->getContent()); $em = $this->getDoctrine()->getManager(); $educationForm = $em->getRepository('AppBundle:EducationForm')->find($data->educationForm); $group = $em->getRepository('AppBundle:Group')->find($data->group); $sex = $em->getRepository('AppBundle:Sex')->find($data->sex); $student = new Student(); $student->setEducationForm($educationForm); $student->setGroupa($group); $student->setFirstName($data->firstName); $student->setLastName($data->lastName); $student->setSex($sex); $student->setDisabled(0); $em->persist($student); $em->flush(); return new JsonResponse($student->jsonSerialize()); }
/** * @param Student $student * @param Course $course * @param Speciality $speciality * @param $studentData * @return Student * @throws ValidatorException */ public function updateStudent(Student $student, Course $course, Speciality $speciality, $studentData) { $student->setCourse($course); $student->setSpeciality($speciality); $student->setFirstName($studentData['firstName']); $student->setLastName($studentData['lastName']); $student->setFacultyNumber($studentData['facultyNumber']); $student->setEmail($studentData['email']); $student->setEducationForm($studentData['educationForm']); $errors = $this->validator->validate($student, null, array('edit')); if (count($errors) > 0) { throw new ValidatorException($errors); } $this->studentManager->saveChanges(); return $student; }