Ejemplo n.º 1
0
 /**
  *
  * @param <int> $start_year
  */
 public function createStudentsCareerSubjectAlloweds($start_year = null, PropelPDO $con = null)
 {
     if (is_null($start_year)) {
         $start_year = CareerSubjectPeer::FIRST_YEAR;
     }
     if ($con == null) {
         $con = Propel::getConnection(StudentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     try {
         $con->beginTransaction();
         $c = new Criteria();
         $c->add(CareerSubjectPeer::YEAR, $start_year);
         //This criterion checks if the careerSubject has orientation, if has an orientation then filters for studentCareer orientation.
         $criterion = $c->getNewCriterion(CareerSubjectPeer::ORIENTATION_ID, null, Criteria::ISNULL);
         $criterion->addOr($c->getNewCriterion(CareerSubjectPeer::ORIENTATION_ID, $this->getOrientationId()));
         $c->add($criterion);
         $career_subjects = $this->getCareer()->getCareerSubjects($c, $con);
         CareerSubjectPeer::clearInstancePool();
         unset($c);
         foreach ($career_subjects as $career_subject) {
             $student_career_subject_allowed = new StudentCareerSubjectAllowed();
             $student_career_subject_allowed->setStudent($this->getStudent($con));
             $student_career_subject_allowed->setCareerSubject($career_subject);
             $student_career_subject_allowed->save($con);
             unset($student_career_subject_allowed);
         }
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }
Ejemplo n.º 2
0
 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;
     }
 }
Ejemplo n.º 3
0
 public function addToCurrentCareerSchoolYear(PropelPDO $con = null)
 {
     if (is_null($con)) {
         $con = Propel::getConnection();
     }
     $career_school_year = $this->getCareerSchoolYear();
     try {
         $con->beginTransaction();
         $career_subject_school_year = new CareerSubjectSchoolYear();
         $career_subject_school_year->setCareerSubject($this);
         $career_subject_school_year->setCareerSchoolYear($career_school_year);
         $career_subject_school_year->save($con);
         $students = StudentPeer::retrieveForCareerSchoolYearAndYear($career_school_year, $this->getYear());
         foreach ($students as $student) {
             $student_career_subject_allowed = new StudentCareerSubjectAllowed();
             $student_career_subject_allowed->setCareerSubject($this);
             $student_career_subject_allowed->setStudent($student);
             $student_career_subject_allowed->save($con);
         }
         $con->commit();
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
 }
 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;
     }
 }