protected function doSave($con = null) { $con = is_null($con) ? $this->getConnection() : $con; $course = $this->getObject(); $from_course = CoursePeer::retrieveByPK($this->values['course_id']); try { $con->beginTransaction(); foreach ($from_course->getStudents() as $student) { foreach ($course->getCourseSubjects() as $course_subject) { $course_subject_student = new CourseSubjectStudent(); $course_subject_student->setCourseSubjectId($course_subject->getId()); $course_subject_student->setStudentId($student->getId()); $course_subject_student->save($con); } } $con->commit(); } catch (Exception $e) { throw $e; $con->rollBack(); } }
public function saveCourseSubjectStudentList($con = null) { if (!$this->isValid()) { throw $this->getErrorSchema(); } if (!isset($this->widgetSchema['course_subject_student_list'])) { // somebody has unset this widget return; } if (is_null($con)) { $con = $this->getConnection(); } $this->values = $this->getValue('course_subject_student_list'); foreach ($this->getObject()->getCourseSubjectStudents() as $course_subject_student) { //if student has marks it can't be deleted from course if (!in_array($course_subject_student->getStudentId(), $this->values)) { if ($this->canDeleteCourseSubjectStudent($course_subject_student->getStudentId()) && $course_subject_student->countValidCourseSubjectStudentMarks() == 0) { $course_subject_student->delete($con); } else { throw new Exception('El/Los alumno/s seleccionado/s poseen calificaciones cargadas que le/s impide/n ser borrado/s de este curso.'); } } } $already_ids = array_map(create_function('$c', 'return $c->getStudentId();'), $this->getObject()->getCourseSubjectStudents()); $this->filterValues($already_ids); if (is_array($this->values)) { $con->beginTransaction(); try { foreach ($this->values as $value) { $course_subject_student = new CourseSubjectStudent(); $course_subject_student->setCourseSubject($this->getObject()); $course_subject_student->setStudentId($value); $course_subject_student->save($con); } $con->commit(); } catch (Exception $e) { $con->rollBack(); throw $e; } } }