Esempio n. 1
0
 /**
  * This method back the period to last one.
  */
 public function backPeriod()
 {
     if ($this->getCurrentPeriod() == 1) {
         return null;
     }
     $con = Propel::getConnection();
     $con->beginTransaction();
     try {
         $c = new Criteria();
         $c->add(CourseSubjectStudentMarkPeer::MARK_NUMBER, $this->getCurrentPeriod() - 1);
         $c->addJoin(CourseSubjectStudentMarkPeer::COURSE_SUBJECT_STUDENT_ID, CourseSubjectStudentPeer::ID);
         $c->addJoin(CourseSubjectStudentPeer::COURSE_SUBJECT_ID, CourseSubjectPeer::ID);
         $c->add(CourseSubjectPeer::COURSE_ID, $this->getId());
         $course_subject_students_marks = CourseSubjectStudentMarkPeer::doSelect($c);
         foreach ($course_subject_students_marks as $course_subject_student_mark) {
             $course_subject_student_mark->setIsClosed(false);
             $course_subject_student_mark->save($con);
             //Seleccionamos todos los StudentDisapprovedCourseSubjec y StudentApprovedCourseSubject si es que tiene y los borramos
             $c = new Criteria();
             $c->add(StudentDisapprovedCourseSubjectPeer::COURSE_SUBJECT_STUDENT_ID, $course_subject_student_mark->getCourseSubjectStudentId());
             StudentDisapprovedCourseSubjectPeer::doDelete($c);
             //eliminando StudentApprovedCourseSubject
             $c = new Criteria();
             $course_subject_student = CourseSubjectStudentPeer::retrieveByPK($course_subject_student_mark->getCourseSubjectStudentId());
             $c->add(StudentApprovedCourseSubjectPeer::STUDENT_ID, $course_subject_student->getStudentId());
             $c->add(StudentApprovedCourseSubjectPeer::COURSE_SUBJECT_ID, $course_subject_student->getCourseSubjectId());
             StudentApprovedCourseSubjectPeer::doDelete($c);
         }
         $this->setCurrentPeriod($this->getCurrentPeriod() - 1);
         $this->setIsClosed(false);
         $this->save($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }