function registerStudent() { $request = Slim::getInstance()->request(); $stdJson = json_decode($request->getBody()); $stdJson->student_id = 0; // because student_id is autoincrement $std = new \Entity\Student(); $std->parseJsonObject($stdJson); $std->setApproved(false); $dao = new \DAO\StudentDAO(); if ($dao->insertStudent($std)) { echo 'Success'; } else { die("Error"); } }
public function save_student($params, $id) { $classroom = $this->user_classrooms[$params['classroom_id']]; if ($classroom) { $classroom = $classroom->getClassroom(); if ($classroom->cannotBeEditedBy($this->user)) { return -2; } } $student = $this->ci->doctrine->em->getRepository('Entity\\Student')->find($id); if ($student == null) { $student = new \Entity\Student(); } $student->setName($params['name']); $student->setEmail($params['email']); $student->setPhone($params['phone']); $student->setSexe($params['sexe']); $student->setImg($params['img']); $student->setClassroom($classroom); $this->ci->doctrine->em->persist($student); if (!$id) { $tests = $this->get_classroom_tests($params['classroom_id']); for ($i = 0, $max = count($tests); $i < $max; ++$i) { $mark = new \Entity\Mark(); $mark->setTest($tests[$i]); $mark->setStudent($student); $this->ci->doctrine->em->persist($mark); } } $this->ci->doctrine->em->flush(); return $student; }
public function addStudent() { $student = new \Entity\Student("Jorge Huarachi"); $mentor = new \Entity\Student("Maria Lopez"); $student->setMentor($mentor); $this->em->persist($mentor); $this->em->persist($student); $this->em->flush(); }