protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $con = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $this->createContextInstance('backend');
     $criteria = new Criteria();
     $criteria->add(CoursePeer::IS_CLOSED, false);
     $criteria->addJoin(CoursePeer::ID, CourseSubjectPeer::COURSE_ID, Criteria::INNER_JOIN);
     $criteria->addJoin(CourseSubjectPeer::ID, CourseSubjectStudentPeer::COURSE_SUBJECT_ID, Criteria::INNER_JOIN);
     $course_subject_students = CourseSubjectStudentPeer::doSelect($criteria);
     $this->log('Cant. Course Subject Students a procesar:');
     $this->log(count($course_subject_students));
     foreach ($course_subject_students as $course_subject_student) {
         $course_subject_student_marks = CourseSubjectStudentMarkPeer::retrieveByCourseSubjectStudent($course_subject_student->getId());
         $this->log('Id del course subject student Actual:');
         $this->log($course_subject_student->getId());
         foreach ($course_subject_student_marks as $mark) {
             $mark->setIsClosed(true);
             $mark->save($con);
         }
         $student_approved_course_subject = new StudentApprovedCourseSubject();
         $student_approved_course_subject->setCourseSubject($course_subject_student->getCourseSubject());
         $student_approved_course_subject->setStudentId($course_subject_student->getStudentId());
         $student_approved_course_subject->setSchoolYear($course_subject_student->getCourseSubject()->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear());
         $student_approved_career_subject = new StudentApprovedCareerSubject();
         $student_approved_career_subject->setStudentId($course_subject_student->getStudentId());
         $student_approved_career_subject->setCareerSubject($course_subject_student->getCourseSubject()->getCareerSubjectSchoolYear()->getCareerSubject());
         $student_approved_career_subject->setSchoolYear($course_subject_student->getCourseSubject()->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear());
         $student_approved_career_subject->save($con);
         $student_approved_course_subject->setStudentApprovedCareerSubject($student_approved_career_subject);
         $student_approved_course_subject->save($con);
         $course_subject_student->setStudentApprovedCourseSubject($student_approved_course_subject);
         $course_subject_student->save($con);
     }
     $criteria = new Criteria();
     $criteria->add(CoursePeer::IS_CLOSED, false);
     $courses = CoursePeer::doSelect($criteria);
     foreach ($courses as $c) {
         $c->setIsClosed(true);
         $c->save($con);
     }
 }
 protected function doSave($con = null)
 {
     $values = $this->getValues();
     $course_subject = CourseSubjectPeer::retrieveByPk($values['course_subject_id']);
     $course = $course_subject->getCourse();
     $con = is_null($con) ? $this->getConnection() : $con;
     try {
         $con->beginTransaction();
         if ($values['set_all_course_subject_non_numerical_califications'] == 1) {
             //tomo todos los alumnos que No tienen seteado el flag is_not_averageable
             $course_subject_students = $course->getIsAverageableCourseSubjectStudent();
             foreach ($course_subject_students as $course_subject_student) {
                 $course_subject_student->setIsNotAverageable(true);
                 $course_subject_student_marks = CourseSubjectStudentMarkPeer::retrieveByCourseSubjectStudent($course_subject_student->getId());
                 foreach ($course_subject_student_marks as $mark) {
                     $mark->setIsClosed(true);
                     $mark->save($con);
                 }
                 $student_id = $course_subject_student->getStudentId();
                 $student_approved_course_subject = new StudentApprovedCourseSubject();
                 $student_approved_course_subject->setCourseSubject($course_subject);
                 $student_approved_course_subject->setStudentId($student_id);
                 $student_approved_course_subject->setSchoolYear($course_subject->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear());
                 $student_approved_career_subject = new StudentApprovedCareerSubject();
                 $student_approved_career_subject->setStudentId($student_id);
                 $student_approved_career_subject->setCareerSubject($course_subject->getCareerSubjectSchoolYear()->getCareerSubject());
                 $student_approved_career_subject->setSchoolYear($course_subject->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear());
                 $student_approved_career_subject->save($con);
                 $student_approved_course_subject->setStudentApprovedCareerSubject($student_approved_career_subject);
                 $student_approved_course_subject->save($con);
                 $course_subject_student->setStudentApprovedCourseSubject($student_approved_course_subject);
                 $course_subject_student->save($con);
             }
         } else {
             foreach ($values['student_list'] as $student_id) {
                 $course_subject_student = CourseSubjectStudentPeer::retrievebyCourseSubjectAndStudent($course_subject->getid(), $student_id);
                 $course_subject_student->setIsNotAverageable(true);
                 $course_subject_student_marks = CourseSubjectStudentMarkPeer::retrieveByCourseSubjectStudent($course_subject_student->getId());
                 foreach ($course_subject_student_marks as $mark) {
                     $mark->setIsClosed(true);
                     $mark->save($con);
                 }
                 $student_approved_course_subject = new StudentApprovedCourseSubject();
                 $student_approved_course_subject->setCourseSubject($course_subject);
                 $student_approved_course_subject->setStudentId($student_id);
                 $student_approved_course_subject->setSchoolYear($course_subject->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear());
                 $student_approved_career_subject = new StudentApprovedCareerSubject();
                 $student_approved_career_subject->setStudentId($student_id);
                 $student_approved_career_subject->setCareerSubject($course_subject->getCareerSubjectSchoolYear()->getCareerSubject());
                 $student_approved_career_subject->setSchoolYear($course_subject->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear());
                 $student_approved_career_subject->save($con);
                 $student_approved_course_subject->setStudentApprovedCareerSubject($student_approved_career_subject);
                 $student_approved_course_subject->save($con);
                 $course_subject_student->setStudentApprovedCourseSubject($student_approved_course_subject);
                 $course_subject_student->save($con);
             }
         }
         //chequeo si la cantidad de alumnos eximidos es igual a la cantidad de alumnos inscriptos en el curso y el curso esta abierto .
         if (count($course->getIsNotAverageableCourseSubjectStudent()) == $course->countStudents() && !$course->getIsClosed()) {
             //cierro el curso.
             $course->setIsClosed(true);
             $course->save($con);
         }
         $con->commit();
     } catch (Exception $e) {
         throw $e;
         $con->rollBack();
     }
 }