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;
         }
     }
 }
 public function isApproved(CourseSubjectStudent $course_subject_student, $average, PropelPDO $con = null)
 {
     $sum = 0;
     foreach ($course_subject_student->getCourseSubjectStudentMarks(null, $con) as $cssm) {
         $sum += $cssm->getMark();
     }
     $first_integrator_mark = $course_subject_student->getMarkFor(self::FIRST_INTEGRATOR_MARK, $con);
     $last_integrator_mark = $course_subject_student->getMarkFor(self::LAST_INTEGRATOR_MARK, $con);
     return $sum > 26 && isset($first_integrator_mark) && $first_integrator_mark->getMark() >= $course_subject_student->getCourseMinimunMarkForCurrentSchoolYear($con) && isset($last_integrator_mark) && $course_subject_student->getMarkFor(self::LAST_INTEGRATOR_MARK, $con)->getMark() >= $course_subject_student->getCourseMinimunMarkForCurrentSchoolYear($con);
 }
 /**
  * This method returns the marks average of a student.
  *
  * @param CourseSubjectStudent $course_subject_student
  * @return <type>
  */
 public function getMarksAverage($course_subject_student, PropelPDO $con = null)
 {
     $sum = 0;
     $subject_configuration = $course_subject_student->getCourseSubject()->getCareerSubjectSchoolYear()->getConfiguration();
     $tmp_sum = 0;
     $final_mark = 0;
     foreach ($course_subject_student->getCourseSubjectStudentMarks() as $cssm) {
         $sum += $cssm->getMark();
     }
     $avg = (string) ($sum / $course_subject_student->countCourseSubjectStudentMarks());
     $avg = sprintf('%.4s', $avg);
     return $avg;
 }
 /**
  * This method returns the marks average of a student in a course_subject_student given.
  *
  * @param CourseSubjectStudent $course_subject_student
  * @return <type>
  */
 public function getMarksAverage($course_subject_student, PropelPDO $con = null)
 {
     if (!is_null($course_subject_student->getStudentApprovedCourseSubject())) {
         $average = $course_subject_student->getStudentApprovedCourseSubject()->getMark();
     } else {
         $sum = 0;
         foreach ($course_subject_student->getCourseSubjectStudentMarks() as $cssm) {
             $sum += $cssm->getMark();
         }
         $average = (string) ($sum / $course_subject_student->countCourseSubjectStudentMarks(null, false, $con));
     }
     $average = sprintf('%.4s', $average);
     return $average;
 }