public function doSave($con = null) { parent::doSave($con); $student = StudentPeer::retrieveByPk($this->getValue('student_id')); $career_school_year_period = CareerSchoolYearPeriodPeer::retrieveByPk($this->getValue('career_school_year_period_id')); $student_career_school_year = StudentCareerSchoolYearPeer::getCurrentForStudentAndCareerSchoolYear($student, $career_school_year_period->getCareerSchoolYear()); $course_subject = CourseSubjectPeer::retrieveByPk($this->getValue('course_subject_id')); $student_free = StudentFreePeer::retrieveByStudentCareerSchoolYearCareerSchoolYearPeriodAndCourse($student_career_school_year, $career_school_year_period, $course_subject); $student_free->setIsFree(false); $student_free->save($con); }
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'); $c = new Criteria(); //$c->add(CareerStudentPeer::STUDENT_ID, 1080); $school_year = SchoolYearPeer::retrieveCurrent(); try { $connection->beginTransaction(); foreach (CareerStudentPeer::doSelect($c) as $career_student) { $student = $career_student->getStudent(); $career_school_year = CareerSchoolYearPeer::retrieveByCareerAndSchoolYear($career_student->getCareer(), $school_year); $student_career_school_year = StudentCareerSchoolYearPeer::getCurrentForStudentAndCareerSchoolYear($student, $career_school_year); if (is_null($student_career_school_year)) { $this->logSection("Continue", '1'); continue; } $year = $student_career_school_year->getYear(); $c = new Criteria(); $c->add(CareerSubjectPeer::CAREER_ID, $career_student->getCareerId()); $c->add(CareerSubjectPeer::YEAR, $year); foreach (CareerSubjectPeer::doSelect($c) as $career_subject) { if (StudentCareerSubjectAllowedPeer::doCountStudentAndCareerSubject($student, $career_subject) == 0) { $obj = new StudentCareerSubjectAllowed(); $obj->setStudentId($student->getId()); $obj->setCareerSubject($career_subject); $obj->save($connection); $this->logSection("Allowed agregado: ", $career_subject->getId()); } } } $connection->commit(); } catch (PropelException $e) { $connection->rollback(); throw $e; } }
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(); // add your code here $this->createContextInstance(); $i = 0; $students = StudentPeer::doSelect(new Criteria()); $career_school_year = CareerSchoolYearPeer::retrieveByPK(4); foreach ($students as $student) { $this->logSection("Evaluando student ID = ", $student->getId()); $career_student = $student->getCareerStudent(); if ($career_student == null) { $this->logSection("ceando CarrerStudent", $student->getId()); $career_student = new CareerStudent(); $career_student->setStudent($student); $career_student->setCareerId(1); $career_student->setStartYear(1); $career_student->setFileNumber($student->getGlobalFileNumber()); $career_student->save($connection); #$career_student->createStudentsCareerSubjectAlloweds(1, $connection); $this->logSection("Fin creacion careerStudent", $career_student->getId()); } $student_career_school_year = StudentCareerSchoolYearPeer::getCurrentForStudentAndCareerSchoolYear($student, $career_school_year); if ($student_career_school_year == null) { $i++; $this->logSection("Creando studentCareerSchoolYear", $student->getId()); $student_career_school_year = new StudentCareerSchoolYear(); $student_career_school_year->setCareerSchoolYear($career_school_year); $student_career_school_year->setStudent($student); $student_career_school_year->setYear($student->getCareerStudent()->getStartYear()); $student_career_school_year->save($connection); $this->logSection("Fin creacion studentCareerSchoolYear", $career_student->getId()); $this->logSection("Guardando", $student); echo $i; } } }
<?php } ?> </tr> </thead> <tbody> <?php foreach ($students as $student) { ?> <tr> <td><?php echo $student; ?> </td> <?php $student_career_school_year = StudentCareerSchoolYearPeer::getCurrentForStudentAndCareerSchoolYear($student, $division->getCareerSchoolYear()); ?> <?php foreach ($periods as $period) { ?> <td><?php echo $form['conduct_' . $student->getId() . '_' . $period->getId()]->render(); include_partial('changelog', array('student_career_school_year_conduct' => StudentCareerSchoolYearConductPeer::retrieveOrCreate($student_career_school_year, $period))); ?> </td> <?php echo $form->renderHiddenFields(); ?> <?php } ?>
/** * This method check if exists a student_free with the parameters. * IF NOT exists then the student inst free, otherwise check the value of the student_free * * @see StudentPeer::retrieveByStudentCarreerSchoolyearPeriodAndCourse * * @param Student $student * @param CareerSchoolYearPeriod $career_school_year_period * @param type $course_subject * * @return boolean */ public function isFreeStudent(Student $student, CareerSchoolYearPeriod $career_school_year_period = null, CourseSubject $course_subject = null, CareerSchoolYear $career_school_year) { $student_career_school_year = StudentCareerSchoolYearPeer::getCurrentForStudentAndCareerSchoolYear($student, $career_school_year); $student_free = StudentFreePeer::retrieveByStudentCareerSchoolYearCareerSchoolYearPeriodAndCourse($student_career_school_year, $career_school_year_period, $course_subject); return is_null($student_free) ? false : $student_free->getIsFree(); }
public function close(array $errors = array(), PropelPDO $con = null) { $con = is_null($con) ? Propel::getConnection() : $con; $c = new Criteria(); $c->add(CareerSchoolYearPeer::ID, $this->getId()); $c->addJoin(StudentCareerSchoolYearPeer::CAREER_SCHOOL_YEAR_ID, CareerSchoolYearPeer::ID); $c->addJoin(StudentPeer::ID, StudentCareerSchoolYearPeer::STUDENT_ID); //$c->add(StudentCareerSchoolYearPeer::STATUS, StudentCareerSchoolYearStatus::IN_COURSE); $c->add(StudentCareerSchoolYearPeer::IS_PROCESSED, false); $c->setDistinct(StudentPeer::ID); sfConfig::set('sf_logging_enabled', FALSE); $cant = 0; try { $pager = new sfPropelPager('Student', 500); $pager->setCriteria($c); $pager->init(); $last_page = $pager->getLastPage(); for ($i = 1; $i <= $last_page; $i++) { $pager->setPage($i); $pager->init(); $students = $pager->getResults(); $con->beginTransaction(); Propel::disableInstancePooling(); foreach ($students as $student) { $cant++; $student_errors = $student->getErrorsWithCourseSubjectsStudent($this); //si el alumno tiene errores guardo el error y sigo evaluando a los demas alumnos if (!empty($student_errors)) { $errors[$student->getId()] = $student_errors; if (count($errors) > sfConfig::get('app_close_course_subject_schol_year_max_error')) { throw new Exception('Maximo de errores alcanzado >' . sfConfig::get('app_close_course_subject_schol_year_max_error')); } } else { $student_career_school_year = StudentCareerSchoolYearPeer::getCurrentForStudentAndCareerSchoolYear($student, $this); //si el alumno tiene reserva de banco no deberia hacer nada. if ($student_career_school_year->getStatus() != StudentCareerSchoolYearStatus::WITHDRAWN_WITH_RESERVE) { $student->closeCareerSchoolYear($this, $con); $student_career_school_year->setIsProcessed(true); $student_career_school_year->save($con); $student_career_school_year->clearAllReferences(true); unset($student_career_school_year); } } ####Liberando memoria### $student->clearAllReferences(true); unset($student_errors); unset($student); ##################*/ } ####Liberando memoria### StudentPeer::clearInstancePool(); unset($students); ############################## $con->commit(); } if (count($errors)) { throw new Exception('Hay errores no se puede cerrar el año!'); } //Se setea a la carrera como procesada. $this->setIsProcessed(true); $this->save($con); Propel::enableInstancePooling(); } catch (Exception $e) { $con->rollBack(); throw $e; } return true; }
public function save($con = null) { if (!$this->isValid()) { throw $this->getErrorSchema(); } if (is_null($con)) { $con = Propel::getConnection(); } try { $con->beginTransaction(); $values = $this->getValues(); $students = $this->getStudents(); $periods = $this->getPeriods(); $career_school_year = $this->getCareerSchoolYear(); foreach ($students as $student) { $student_career_school_year = StudentCareerSchoolYearPeer::getCurrentForStudentAndCareerSchoolYear($student, $career_school_year); foreach ($periods as $period) { if (!$period->getIsClosed()) { $conduct_id = $values['conduct_' . $student->getId() . '_' . $period->getId()]; $scsyc = StudentCareerSchoolYearConductPeer::retrieveOrCreate($student_career_school_year, $period); if (!is_null($conduct_id)) { $scsyc->setConductId($conduct_id); $scsyc->save(); } elseif (!is_null($scsyc->getConduct())) { $scsyc->delete(); } } } } $con->commit(); } catch (Exception $e) { $con->rollBack(); throw $e; } }
public function getStudentsWithDisapprovedSubjects() { $students = array(); foreach ($this->getStudents() as $student) { $student_career_school_year = StudentCareerSchoolYearPeer::getCurrentForStudentAndCareerSchoolYear($student, $this->getCareerSchoolYear()); if (is_null($student_career_school_year->getAnualAverage())) { $students[] = $student; } } return $students; }
protected function doSave($con = null) { if (!$this->isValid()) { throw $this->getErrorSchema(); } if (is_null($con)) { $con = $this->getConnection(); } // Delete only the subjects off the selected career $c = new Criteria(); $c->add(StudentCareerSubjectAllowedPeer::STUDENT_ID, $this->object->getPrimaryKey()); // added: $subc = new Criteria(); $subc->clearSelectColumns(); $subc->addSelectColumn(CareerSubjectPeer::ID); $subc->add(CareerSubjectPeer::CAREER_ID, $this->getValue("career_id")); $stmt = CareerSubjectPeer::doSelectStmt($subc); $ids = $stmt->fetchAll(PDO::FETCH_COLUMN); $c->add(StudentCareerSubjectAllowedPeer::CAREER_SUBJECT_ID, $ids, Criteria::IN); $allowed = StudentCareerSubjectAllowedPeer::doSelectOne($c, $con); if ($allowed) { // Se consulta si el alumno esta en trayectorias antes de eliminarlo $student_id = $this->object->getPrimaryKey(); $criteria = new Criteria(); $criteria->add(PathwayStudentPeer::STUDENT_ID, $student_id); $pathway = PathwayStudentPeer::doSelectOne($criteria, $con); if (!$pathway) { StudentCareerSubjectAllowedPeer::doDelete($c, $con); } } $year = $this->getValue('year'); $career_school_year = CareerSchoolYearPeer::retrieveByCareerAndSchoolYear(CareerPeer::retrieveByPK($this->getValue('career_id')), SchoolYearPeer::retrieveCurrent()); //First update the year at student_career_school_year // var_dump($career_school_year);die(); $student_career_school_year = StudentCareerSchoolYearPeer::getCurrentForStudentAndCareerSchoolYear($this->getObject(), $career_school_year); // if (!$student_career_school_year) // { // $student_career_school_year = new StudentCareerSchoolYear(); // $student_career_school_year->setCareerSchoolYear($career_school_year); // $student_career_school_year->setStudent($this->getObject()); // $student_career_school_year->save(); // } $career_student = CareerStudentPeer::retrieveByCareerAndStudent($this->getValue('career_id'), $this->getObject()->getId()); try { $con->beginTransaction(); $student_career_school_year->setYear($year); $student_career_school_year->save($con); $c = new Criteria(); $c->add(CareerSubjectPeer::CAREER_ID, $this->getValue('career_id')); $c->add(CareerSubjectPeer::YEAR, $year); foreach (CareerSubjectPeer::doSelect($c) as $career_subject) { $obj = new StudentCareerSubjectAllowed(); $obj->setStudentId($this->object->getPrimaryKey()); $obj->setCareerSubject($career_subject); $obj->save($con); } $prev_school_year = SchoolYearPeer::retrieveLastYearSchoolYear($career_school_year->getSchoolYear()); if ($prev_school_year) { $prev_student_career_school_year = StudentCareerSchoolYearPeer::retrieveCareerSchoolYearForStudentAndYear($this->getObject(), $prev_school_year); } if (!empty($prev_student_career_school_year)) { $prev_student_career_school_year = array_shift($prev_student_career_school_year); if ($year <= $prev_student_career_school_year->getYear()) { $prev_student_career_school_year->setStatus(StudentCareerSchoolYearStatus::REPPROVED); $prev_student_career_school_year->save($con); } } $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } }
public function getConductPeriod(CareerSchoolYearPeriod $period) { $scsy = StudentCareerSchoolYearPeer::getCurrentForStudentAndCareerSchoolYear($this, $period->getCareerSchoolYear()); return StudentCareerSchoolYearConductPeer::retriveByStudentCareerSchoolYearAndPeriod($scsy, $period); }