Exemplo n.º 1
0
 public function createCourseSubject($course, PropelPDO $con = null)
 {
     if ($this->hasChoices()) {
         foreach ($this->getChoices() as $choice) {
             $course_subject = new CourseSubject();
             $course_subject->setCourse($course);
             $course_subject->setCareerSubjectSchoolYear($choice->getCareerSubjectSchoolYearRelatedByChoiceCareerSubjectSchoolYearId());
             $course_subject->save($con);
         }
     } else {
         $course_subject = new CourseSubject();
         $course_subject->setCourse($course);
         $course_subject->setCareerSubjectSchoolYear($this);
         $course_subject->save($con);
         if ($course->getDivision()) {
             foreach ($course->getDivision()->getDivisionStudents() as $ds) {
                 $course_subject_student = new CourseSubjectStudent();
                 $course_subject_student->setCourseSubject($course_subject);
                 $course_subject_student->setStudent($ds->getStudent());
                 $course_subject_student->save($con);
             }
         }
     }
 }
 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;
         }
     }
 }
Exemplo n.º 3
0
 public function createFor($student, PropelPDO $con = null)
 {
     $course_student = new CourseSubjectStudent();
     $course_student->setCourseSubject($this);
     $course_student->setStudent($student);
     $course_student->save($con);
     $course_student->clearAllReferences();
     unset($course_student);
 }