public function getCourseSubjectStudentResult(CourseSubjectStudent $course_subject_student, PropelPDO $con = null)
 {
     $average = $course_subject_student->getMarksAverage($con);
     if ($average >= $course_subject_student->getCourseSubject($con)->getCareerSubjectSchoolYear($con)->getConfiguration($con)->getCourseMinimunMark() && $course_subject_student->getMarkFor($course_subject_student->countCourseSubjectStudentMarks(null, false, $con), $con)->getMark() >= self::POSTPONED_NOTE) {
         $school_year = $course_subject_student->getCourseSubject($con)->getCourse($con)->getSchoolYear($con);
         $student_approved_course_subject = new StudentApprovedCourseSubject();
         $student_approved_course_subject->setCourseSubject($course_subject_student->getCourseSubject($con));
         $student_approved_course_subject->setStudent($course_subject_student->getStudent($con));
         $student_approved_course_subject->setSchoolYear($school_year);
         $student_approved_course_subject->setMark($average);
         $course_subject_student->setStudentApprovedCourseSubject($student_approved_course_subject);
         ###Liberando memoria ####
         $school_year->clearAllReferences(true);
         unset($school_year);
         SchoolYearPeer::clearInstancePool();
         unset($average);
         ##########################
         return $student_approved_course_subject;
     } else {
         $student_disapproved_course_subject = new StudentDisapprovedCourseSubject();
         $student_disapproved_course_subject->setCourseSubjectStudent($course_subject_student);
         if ($course_subject_student->hasSomeMarkFree()) {
             if (is_null(StudentRepprovedCourseSubjectPeer::retrieveByCourseSubjectStudent($course_subject_student))) {
                 $srcs = new StudentRepprovedCourseSubject();
                 $srcs->setCourseSubjectStudent($course_subject_student);
                 $srcs->save();
             }
         }
         $examination_number = $this->getExaminationNumberFor($average, $course_subject_student->hasSomeMarkFree());
         $student_disapproved_course_subject->setExaminationNumber($examination_number);
         unset($average);
         return $student_disapproved_course_subject;
     }
 }
 public function getCourseSubjectStudentResult(CourseSubjectStudent $course_subject_student, PropelPDO $con = null)
 {
     $average = $course_subject_student->getMarksAverage($con);
     $sum_marks = 0;
     $year = $course_subject_student->getCourseSubject()->getCourse()->getYear();
     foreach ($course_subject_student->getCourseSubjectStudentMarks() as $cssm) {
         $sum_marks += $cssm->getMark();
     }
     if ($average >= $course_subject_student->getCourseSubject()->getCareerSubjectSchoolYear()->getConfiguration()->getCourseMinimunMark() && $course_subject_student->getMarkFor($course_subject_student->countCourseSubjectStudentMarks())->getMark() >= self::POSTPONED_NOTE || $year > 1 && $year < 5 && $sum_marks >= 21 && $course_subject_student->getMarkFor($course_subject_student->countCourseSubjectStudentMarks())->getMark() >= 4) {
         $school_year = $course_subject_student->getCourseSubject()->getCourse()->getSchoolYear();
         $student_approved_course_subject = new StudentApprovedCourseSubject();
         $student_approved_course_subject->setCourseSubject($course_subject_student->getCourseSubject());
         $student_approved_course_subject->setStudent($course_subject_student->getStudent());
         $student_approved_course_subject->setSchoolYear($school_year);
         $student_approved_course_subject->setMark($average);
         $course_subject_student->setStudentApprovedCourseSubject($student_approved_course_subject);
         ###Liberando memoria ####
         $school_year->clearAllReferences(true);
         unset($school_year);
         SchoolYearPeer::clearInstancePool();
         unset($average);
         unset($sum_marks);
         ##########################
         //$student_approved_course_subject->save();
         return $student_approved_course_subject;
     } else {
         $school_year = $course_subject_student->getCourseSubject()->getCourse()->getSchoolYear();
         $career_school_year = CareerSchoolYearPeer::retrieveBySchoolYear(null, $school_year);
         if ($course_subject_student->getCourseSubject()->getCareerSubjectSchoolYear()->getCareerSubject()->getIsOption() && $year == 6) {
             $student_disapproved_course_subject = new StudentDisapprovedCourseSubject();
             $student_disapproved_course_subject->setExaminationNumber(self::DECEMBER);
             $student_disapproved_course_subject->setCourseSubjectStudent($course_subject_student);
             unset($average);
             unset($sum_marks);
             return $student_disapproved_course_subject;
         } else {
             $student_disapproved_course_subject = new StudentDisapprovedCourseSubject();
             $student_disapproved_course_subject->setCourseSubjectStudent($course_subject_student);
             // si un alumno es de primer año, no puede ir a febrero siempre va a diciembre.
             if ($year == 1) {
                 $student_disapproved_course_subject->setExaminationNumber(self::DECEMBER);
             } elseif ($year > 1 && $year < 5 && $course_subject_student->countCourseSubjectStudentMarks() == 3) {
                 //Suma menor a 21 pero mayor o igual que 12: mesa de diciembre (examen regular)
                 if ($sum_marks < 21 && $sum_marks >= 12) {
                     $student_disapproved_course_subject->setExaminationNumber(self::DECEMBER);
                 } elseif ($sum_marks >= 21 && $course_subject_student->getMarkFor($course_subject_student->countCourseSubjectStudentMarks())->getMark() < 4) {
                     $student_disapproved_course_subject->setExaminationNumber(self::DECEMBER);
                 } elseif ($sum_marks < 12) {
                     $student_disapproved_course_subject->setExaminationNumber(self::FEBRUARY);
                 }
             } else {
                 $student_disapproved_course_subject->setExaminationNumber($this->getExaminationNumberFor($average));
             }
             unset($average);
             unset($sum_marks);
             //$student_disapproved_course_subject->save();
             return $student_disapproved_course_subject;
         }
     }
 }
 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();
     }
 }
 public function createStudentApprovedCourseSubject($course_subject_student, $average, $con)
 {
     $school_year = $course_subject_student->getCourseSubject($con)->getCourse($con)->getSchoolYear($con);
     $student_approved_course_subject = new StudentApprovedCourseSubject();
     $student_approved_course_subject->setCourseSubject($course_subject_student->getCourseSubject($con));
     $student_approved_course_subject->setStudent($course_subject_student->getStudent($con));
     $student_approved_course_subject->setSchoolYear($school_year);
     $student_approved_course_subject->setMark($average);
     $course_subject_student->setStudentApprovedCourseSubject($student_approved_course_subject);
     return $student_approved_course_subject;
 }