public static function retrieveByStudentApprovedCareerSubject($studentApprovedCareerSubject, $criteria = null)
 {
     if (is_null($criteria)) {
         $criteria = new Criteria();
     }
     $criteria->add(StudentApprovedCourseSubjectPeer::STUDENT_APPROVED_CAREER_SUBJECT_ID, $studentApprovedCareerSubject->getId());
     return StudentApprovedCourseSubjectPeer::doSelectOne($criteria);
 }
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $this->createContextInstance('backend');
     try {
         $connection->beginTransaction();
         $c = new Criteria();
         $c->add(StudentApprovedCareerSubjectPeer::SCHOOL_YEAR_ID, 1);
         $student_approved_career_subjects = StudentApprovedCareerSubjectPeer::doSelect($c);
         $arreglados = 0;
         foreach ($student_approved_career_subjects as $student_approved_career_subject) {
             if (!($student_approved_career_subject->hasStudentApprovedCourseSubject() || $student_approved_career_subject->hasStudentDisapprovedCourseSubject() || $student_approved_career_subject->hasStudentRepprovedCourseSubject())) {
                 $evaluetor = new LvmEvaluatorBehaviour();
                 $c = new Criteria();
                 $course_subject_student = CourseSubjectStudentPeer::retrieveByStudentApprovedCareerSubject($student_approved_career_subject, SchoolYearPeer::retrieveByPK(1));
                 if ($course_subject_student) {
                     $instanceResult = $evaluetor->getCourseSubjectStudentResult($course_subject_student, $connection);
                     if ($instanceResult instanceof StudentApprovedCourseSubject) {
                         $criteria = new Criteria();
                         $criteria->add(StudentApprovedCourseSubjectPeer::STUDENT_ID, $instanceResult->getStudentId());
                         $criteria->add(StudentApprovedCourseSubjectPeer::SCHOOL_YEAR_ID, $instanceResult->getSchoolYearId());
                         $criteria->add(StudentApprovedCourseSubjectPeer::COURSE_SUBJECT_ID, $instanceResult->getCourseSubjectId());
                         if (StudentApprovedCourseSubjectPeer::doCount($criteria)) {
                             $instanceResult = StudentApprovedCourseSubjectPeer::doSelectOne($criteria);
                         }
                         $instanceResult->setStudentApprovedCareerSubject($student_approved_career_subject);
                         $instanceResult->setStudentApprovedCareerSubjectId($student_approved_career_subject->getId());
                         $instanceResult->save();
                         $this->logSection("arreglado", $arreglados);
                         $this->logSection("alumno", $instanceResult->getStudent());
                         $this->logSection("careerSubject", $instanceResult->getCareerSubject());
                         $this->logSection("StudentApprovedCourseSubject", $instanceResult);
                         $this->logSection("StudentApprovedCareerSubject ID: ", $student_approved_career_subject->getId());
                         //var_dump($instanceResult);die();
                         $arreglados++;
                     }
                 } else {
                     $this->logSection("No se pudieron ubicar", $student_approved_career_subject->getStudent() . '- ' . $student_approved_career_subject->getCareerSubject() . '' . $student_approved_career_subject->getId());
                 }
             }
         }
         $this->logSection("arreglados", $arreglados);
         $connection->commit();
         $connection->beginTransaction();
         $c = new Criteria();
         $c->add(StudentApprovedCourseSubjectPeer::SCHOOL_YEAR_ID, 1);
         $c->add(StudentApprovedCourseSubjectPeer::STUDENT_APPROVED_CAREER_SUBJECT_ID, null, Criteria::ISNULL);
         //Se actualizan los cursos aprobados con la materia aprobada, esto existe por que hubo una version que no lo hacia de forma correcta y esto corrige dicho error.
         $update = 0;
         $news = 0;
         $student_approved_course_subjects_null = StudentApprovedCourseSubjectPeer::doSelect($c);
         foreach ($student_approved_course_subjects_null as $student_approved_course_subject) {
             $course_subject_student = $student_approved_course_subject->getCourseSubjectStudent();
             if ($course_subject_student) {
                 $student_approved_career_subject = StudentApprovedCareerSubjectPeer::retrieveOrCreateByCareerSubjectAndStudent($course_subject_student->getCourseSubject()->getCareerSubject()->getId(), $student_approved_course_subject->getCourseSubjectStudent()->getStudentId());
             } else {
                 $this->logSection("Cuak!", $student_approved_course_subject->getId(), $student_approved_course_subject);
             }
             $student_approved_career_subject->setSchoolYearId(1);
             $student_approved_course_subject->setStudentApprovedCareerSubject($student_approved_career_subject);
             $student_approved_career_subject->isNew() ? $news++ : $update++;
             $student_approved_course_subject->save($connection);
             $student_approved_career_subject->save($connection);
         }
         $this->logSection("Actualizados", $update);
         $this->logSection("Nuevos", $news);
         //Este foreach corrige el error de una version, que creaba tambien el student_approved_course_subject, cuando no es real.
         $c = new Criteria();
         $student_dissapproved_course_subjects = StudentDisapprovedCourseSubjectPeer::doSelect($c);
         $delete = 0;
         foreach ($student_dissapproved_course_subjects as $student_dissapproved_course_subject) {
             $course_subject_student = $student_dissapproved_course_subject->getCourseSubjectStudent();
             $c = new Criteria();
             $c->add(StudentApprovedCourseSubjectPeer::STUDENT_ID, $course_subject_student->getStudentId());
             $c->add(StudentApprovedCourseSubjectPeer::COURSE_SUBJECT_ID, $course_subject_student->getCourseSubjectId());
             $student_approved_course_subject = StudentApprovedCourseSubjectPeer::doSelectOne($c);
             if (!is_null($student_approved_course_subject)) {
                 $student_approved_course_subject->delete($connection);
                 $delete++;
             }
         }
         $this->logSection("Borrados", $delete);
         $connection->commit();
         /*
          $c = new Criteria();
          $c->add(StudentDisapprovedCourseSubjectPeer::STUDENT_APPROVED_CAREER_SUBJECT_ID, null, Criteria::ISNULL);
         
          $student_dissapproved_course_subjects = StudentDisapprovedCourseSubjectPeer::doSelect($c);
          foreach ($student_dissapproved_course_subjects as $student_dissapproved_course_subject)
          {
          $student_approved_career_subject = StudentApprovedCareerSubjectPeer::retrieveOrCreateByCareerSubjectAndStudent(
          $student_dissapproved_course_subject->getCourseSubjectStudent()->getCourseSubject()->getCareerSubject()->getId(),
          $student_dissapproved_course_subject->getCourseSubjectStudent()->getStudentId());
         
          if (!is_null($student_approved_career_subject) && !$student_approved_career_subject->isNew())
          {
          $student_dissapproved_course_subject->setStudentApprovedCareerSubjectId($student_approved_career_subject->getId());
          $student_dissapproved_course_subject->save($connection);
          }
          else
          {
          $student_repproved_course_subject = StudentRepprovedCourseSubjectPeer::retrieveCourseSubjectStudent($student_dissapproved_course_subject->getCourseSubjectStudent());
         
          if (is_null($student_repproved_course_subject))
          {
          die(var_dump($student_dissapproved_course_subject->getId()));
          }
          }
          }
         */
         //$this->fixComissions($connection);
         //$this->fixCourseSubjectStudents($connection);
         //$this->fixStudentCareerSchoolYearStatus($connection);
         //$this->fixRepetidores($connection);
         //$this->fixApproved($connection);
     } catch (PropelException $e) {
         $connection->rollback();
         throw $e;
     }
     // add your code here
 }
Пример #3
0
 public function getCourseResult(PropelPDO $con = null)
 {
     /* Si tengo alguna materia sin cerrar devuelvo null */
     if (!$this->areAllMarksClosed()) {
         return null;
     }
     /* Si tiene aprobada la cursada, entonces retornamos la cursada aprobada */
     if ($this->getStudentApprovedCourseSubject($con)) {
         return $this->getStudentApprovedCourseSubject($con);
     } else {
         $c = new Criteria();
         $c->add(StudentApprovedCourseSubjectPeer::STUDENT_ID, $this->getStudentId());
         $c->add(StudentApprovedCourseSubjectPeer::COURSE_SUBJECT_ID, $this->getCourseSubjectId());
         $c->add(StudentApprovedCourseSubjectPeer::SCHOOL_YEAR_ID, $this->getCourseSubject()->getCareerSubjectSchoolYear()->getSchoolYear()->getId());
         if ($result = StudentApprovedCourseSubjectPeer::doSelectOne($c)) {
             //aca encontramos la cursada aprobada y se la asociamos al course_subject_student
             $this->setStudentApprovedCourseSubject($result);
             $this->save($con);
             return $result;
         }
     }
     /* Si desaprobò la cursada entonces retornamos la cursada desaprobada */
     if ($this->countStudentDisapprovedCourseSubjects(null, false, $con)) {
         $disapproveds = $this->getStudentDisapprovedCourseSubjects(null, $con);
         return array_shift($disapproveds);
     }
     /* Si no aprobo o desaprobò, es porque tenemos que calcular què pasò y crear el resultado: aprobado o desaprobado..
      * Eso lo sabe el behavior
      */
     return SchoolBehaviourFactory::getEvaluatorInstance()->getCourseSubjectStudentResult($this, $con);
 }