public function closeCourseSubjectStudentExamination(CourseSubjectStudentExamination $course_subject_student_examination, PropelPDO $con = null) { $con = is_null($con) ? Propel::getConnection() : $con; $course_subject_student = $course_subject_student_examination->getCourseSubjectStudent(); // si aprueba la mesa de examen if ($course_subject_student_examination->getMark() >= 6) { // se crea el approved course subject $sacs = StudentApprovedCourseSubjectPeer::retrieveForCourseSujectStudent($course_subject_student_examination->getCourseSubjectStudent()); if (is_null($sacs)) { $result = new StudentApprovedCourseSubject(); $result->setCourseSubjectId($course_subject_student->getCourseSubjectId()); $result->setStudentId($course_subject_student->getStudentId()); $result->setSchoolYearId($course_subject_student_examination->getExaminationSubject()->getExamination()->getSchoolYearId()); $average = (string) (($course_subject_student->getMarksAverage() + $course_subject_student_examination->getMark()) / 2); $average = sprintf('%.4s', $average); // se guarda la NOTA FINAL de la materia if ($course_subject_student->getCourseSubject()->getCareerSubjectSchoolYearId() == $this->getCurrentHistoriaDelArte()->getId()) { $average = $course_subject_student_examination->getMark(); } $result->setMark($average); $result->save($con); $this->closeCourseSubjectStudent($result, $con, $course_subject_student); } } else { // TODO: arreglar esto: pedir a la configuración // Pasa de diciembre a febrero (se copia el course_subject_student_examination con examination_number + 1) $student_repproved_course_subject = StudentRepprovedCourseSubjectPeer::retrieveCourseSubjectStudent($course_subject_student); if (is_null($student_repproved_course_subject)) { // se crea una previa $student_repproved_course_subject = new StudentRepprovedCourseSubject(); $student_repproved_course_subject->setCourseSubjectStudentId($course_subject_student->getId()); $student_repproved_course_subject->save($con); } } }
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 }
public function evaluateCareerSchoolYearStudent(CareerSchoolYear $career_school_year, Student $student, PropelPDO $con = null) { $con = is_null($con) ? Propel::getConnection() : $con; // obtenemos mas materias de este año #$course_subject_students = CourseSubjectStudentPeer::retrieveByCareerSchoolYearAndStudent($career_school_year, $student, $con); //$c = CourseSubjectStudentPeer::retrieveCriteriaByCareerSchoolYearAndStudent($career_school_year, $student, $con); //$c->addJoin(CourseSubjectStudentPeer::COURSE_SUBJECT_ID, CourseSubjectPeer::ID, Criteria::INNER_JOIN); //$c->add(CourseSubjectPeer::CAREER_SUBJECT_SCHOOL_YEAR_ID, $this->getCurrentHistoriaDelArte()->getId(), Criteria::NOT_EQUAL); // para todas las materias cursadas este año //$course_subject_students = CourseSubjectStudentPeer::doSelect($c); $school_year = SchoolYearPeer::retrieveCurrent(); $course_subject_students = $student->getCourseSubjectStudentsForSchoolYear($school_year); CourseSubjectStudentPeer::clearInstancePool(); unset($school_year); foreach ($course_subject_students as $course_subject_student) { // obtenemos el resultado (aprobada o desaprobada) y la cerramos. // para el caso de las aprobadas, se crea la mesa de examen final (StudentApprovedCareerSubject) // de lo contrario, la inscripción a la mesa de examen (TODO) $result = $course_subject_student->getCourseResult($con); if (!is_null($result)) { $result->close($con); ###Liberando memoria ### $result->clearAllReferences(true); unset($result); } $course_subject_student->clearAllReferences(true); unset($course_subject_student); ########################### } ###Liberando memoria ### unset($course_subject_students); StudentApprovedCourseSubjectPeer::clearInstancePool(); StudentDisapprovedCourseSubjectPeer::clearInstancePool(); ################################ if ($this->getCurrentHistoriaDelArte()) { $this->evaluateHistoriaDelArteCareerSchoolYearStudent($career_school_year, $student, $con); } }
public function getApprovationInstance() { // Caso Regular: aprueba en primer instancia $instance = StudentApprovedCourseSubjectPeer::retrieveByStudentApprovedCareerSubject($this); if (!is_null($instance)) { return $instance; } // Caso Mesa de Diciembre, Marzo $instance = StudentDisapprovedCourseSubjectPeer::retrieveByStudentApprovedCareerSubject($this); if (!is_null($instance)) { return $instance; } // Caso de previa $instance = StudentRepprovedCourseSubjectPeer::retrieveByStudentApprovedCareerSubject($this); if (!is_null($instance)) { return $instance; } return null; }
public function evaluateCareerSchoolYearStudent(CareerSchoolYear $career_school_year, Student $student, PropelPDO $con = null) { $con = is_null($con) ? Propel::getConnection() : $con; // obtenemos las materias de este año #$course_subject_students = CourseSubjectStudentPeer::retrieveByCareerSchoolYearAndStudent($career_school_year, $student, $con); $c = CourseSubjectStudentPeer::retrieveCriteriaByCareerSchoolYearAndStudent($career_school_year, $student, $con); $pager = new sfPropelPager('CourseSubjectStudent', 100); $pager->setCriteria($c); $pager->init(); for ($i = 1; $i < $pager->getLastPage() + 1; $i++) { $course_subject_students = $pager->getResults(); // para todas las materias cursadas este año foreach ($course_subject_students as $course_subject_student) { // obtenemos el resultado (aprobada o desaprobada) y la cerramos. // para el caso de las aprobadas, se crea la mesa de examen final (StudentApprovedCareerSubject) // de lo contrario, la inscripción a la mesa de examen (TODO) $result = $course_subject_student->getCourseResult($con); if (!is_null($result)) { $result->close($con); } } ###Liberando memoria ### CourseSubjectStudentPeer::clearInstancePool(); StudentApprovedCourseSubjectPeer::clearInstancePool(); StudentDisapprovedCourseSubjectPeer::clearInstancePool(); ################################ $pager->setPage($pager->getPage() + 1); $pager->init(); } unset($pager); unset($c); }
/** * 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; } }
public function hasApprovedCareerSubject($career_subject, PropelPDO $con = null) { $c = new Criteria(); $c->add(StudentApprovedCourseSubjectPeer::STUDENT_ID, $this->getID()); $c->addJoin(StudentApprovedCourseSubjectPeer::COURSE_SUBJECT_ID, CourseSubjectPeer::ID); $c->addJoin(CourseSubjectPeer::CAREER_SUBJECT_SCHOOL_YEAR_ID, CareerSubjectSchoolYearPeer::ID); $c->addJoin(CareerSubjectSchoolYearPeer::CAREER_SUBJECT_ID, CareerSubjectPeer::ID); $c->add(CareerSubjectPeer::ID, $career_subject->getId()); return StudentApprovedCourseSubjectPeer::doCount($c, false, $con); }
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); }