public function save($con = null) { if (!$this->isValid()) { throw $this->getErrorSchema(); } if (is_null($con)) { $con = Propel::getConnection(CareerStudentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } try { $con->beginTransaction(); $values = $this->getValues(); $career = CareerPeer::retrieveByPK($values["career_id"]); $orientation = OrientationPeer::retrieveByPK($values["orientation_id"]); $sub_orientation = SubOrientationPeer::retrieveByPK($values["sub_orientation_id"]); $start_year = $values["start_year"]; unset($values["career_id"]); unset($values["orientation_id"]); unset($values["sub_orientation_id"]); unset($values["start_year"]); foreach ($values as $student_id) { $student = StudentPeer::retrieveByPk($student_id, $con); if (!$student->isRegisteredToCareer($career, $con)) { $student->registerToCareer($career, $orientation, $sub_orientation, $start_year, $con); } } $con->commit(); } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * redefines preExecute because this action CANT BE RISED WITHOUT A REFERENCE * */ public function preExecute() { if (!$this->getUser()->getReferenceFor('career')) { $this->getUser()->setFlash('warning', 'Debe seleccionar una carrera para poder administrar sus materias.'); $this->redirect('@career'); } $this->career = CareerPeer::retrieveByPK($this->getUser()->getReferenceFor('career')); if (is_null($this->career)) { $this->getUser()->setFlash('warning', 'Debe seleccionar una carrera para poder administrar sus materias.'); $this->redirect('@career'); } parent::preExecute(); }
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(); $username = '******'; $user = sfContext::getInstance()->getUser(); $sf_user = sfGuardUserPeer::retrieveByUsername($username); $user->signin($sf_user, false); $new_career_school_year_2014 = CareerSchoolYearPeer::retrieveByCareerAndSchoolYear(CareerPeer::retrieveByPK(8), SchoolYearPeer::retrieveCurrent()); $old_career_school_year_2013 = CareerSchoolYearPeer::retrieveByPk(21); $new_career_school_year_2013 = CareerSchoolYearPeer::retrieveByPk(22); $old_career_school_year_2014 = CareerSchoolYearPeer::retrieveByCareerAndSchoolYear(CareerPeer::retrieveByPK(4), SchoolYearPeer::retrieveCurrent()); $last_year_school_year = SchoolYearPeer::retrieveLastYearSchoolYear(SchoolYearPeer::retrieveCurrent()); // ---------------------------------------------------------------------------------------------- // // Alumnos que promueven 6to deben seguir en el plan viejo $this->log('1 -Alumnos que promueven 6to deben seguir en el plan viejo'); $c = new Criteria(); $c->add(StudentCareerSchoolYearPeer::CAREER_SCHOOL_YEAR_ID, $old_career_school_year_2013->getId()); $c->add(StudentCareerSchoolYearPeer::IS_PROCESSED, true); $c->add(StudentCareerSchoolYearPeer::YEAR, 6); $c->add(StudentCareerSchoolYearPeer::STATUS, StudentCareerSchoolYearStatus::APPROVED); $students_to_old_career_school_years = StudentCareerSchoolYearPeer::doSelect($c); try { $connection->beginTransaction(); foreach ($students_to_old_career_school_years as $socsy) { $shift = $socsy->getStudent()->getShiftForSchoolYear($last_year_school_year); if (!$socsy->getStudent()->getIsRegistered($old_career_school_year_2014->getSchoolYear())) { $socsy->getStudent()->registerToSchoolYear($old_career_school_year_2014->getSchoolYear(), $shift, $connection); } } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } // ---------------------------------------------------------------------------------------------- // // 2 - Resto de los alumnos que no son del CBFE van al plan nuevo en el año que les corresponda $this->log('2 - Resto de los alumnos que no son del CBFE van al plan nuevo en el año que les corresponda'); try { $connection->beginTransaction(); // con este criteria voy a excluir a los que aprueban 6to y deben ir a 7mo del plan viejo $c = new Criteria(); $c->add(StudentCareerSchoolYearPeer::CAREER_SCHOOL_YEAR_ID, $old_career_school_year_2013->getId()); $c->add(StudentCareerSchoolYearPeer::IS_PROCESSED, true); $c->add(StudentCareerSchoolYearPeer::YEAR, 6); $c->add(StudentCareerSchoolYearPeer::STATUS, StudentCareerSchoolYearStatus::APPROVED); $c->clearSelectColumns(); $c->addSelectColumn(StudentCareerSchoolYearPeer::STUDENT_ID); $stmt = StudentCareerSchoolYearPeer::doSelectStmt($c); $students_to_old_career_school_years_ids = $stmt->fetchAll(PDO::FETCH_COLUMN); // con este criteria voy a excluir a los que son del CBFE $c = new Criteria(); $c->add(StudentCareerSchoolYearPeer::CAREER_SCHOOL_YEAR_ID, 23); $c->add(StudentCareerSchoolYearPeer::IS_PROCESSED, true); $c->clearSelectColumns(); $c->addSelectColumn(StudentCareerSchoolYearPeer::STUDENT_ID); $stmt = StudentCareerSchoolYearPeer::doSelectStmt($c); $student_cbfe_ids = $stmt->fetchAll(PDO::FETCH_COLUMN); // al total le saco $students_to_old_career_school_years_ids y los // student_cbfe_ids $c = new Criteria(); //$c = StudentCareerSchoolYearPeer::retrieveLastYearStudentNotGraduatedCriteria($new_career_school_year_2014); $c->add(StudentCareerSchoolYearPeer::YEAR, 7, Criteria::NOT_EQUAL); $c->addJoin(StudentCareerSchoolYearPeer::STUDENT_ID, StudentPeer::ID, Criteria::INNER_JOIN); $c->add(StudentPeer::ID, array_merge($students_to_old_career_school_years_ids, $student_cbfe_ids), Criteria::NOT_IN); $students = StudentPeer::doSelectActive($c); foreach ($students as $student) { $shift = $student->getShiftForSchoolYear($last_year_school_year); if (!$student->getIsRegistered($new_career_school_year_2014->getSchoolYear()) && $shift) { $slcsy = $student->getLastStudentCareerSchoolYear(); $slcs = $student->getLastCareerStudent(); if ($slcsy->getStatus() == StudentCareerSchoolYearStatus::APPROVED) { $start_year = $slcsy->getYear() + 1; } else { $start_year = $slcsy->getYear(); } if ($slcs->getCareerId() != $new_career_school_year_2014->getCareerId()) { $student->registerToCareer($new_career_school_year_2014->getCareer(), null, null, $start_year, $connection); $sys = new SchoolYearStudent(); $sys->setStudentId($student->getId()); $sys->setSchoolYearId($new_career_school_year_2014->getSchoolYear()->getId()); $sys->setShift($shift); $sys->save($connection); $this->verify($student, $new_career_school_year_2014, $connection); } else { $sys = new SchoolYearStudent(); $sys->setStudentId($student->getId()); $sys->setSchoolYearId($new_career_school_year_2014->getSchoolYear()->getId()); $sys->setShift($shift); $sys->save($connection); $this->verify($student, $new_career_school_year_2014, $connection); } if (!is_null($shift)) { $shift->clearAllReferences(true); } $student->clearAllReferences(true); unset($student); unset($shift); } StudentPeer::clearInstancePool(); unset($students); } $connection->commit(); } catch (PropelException $e) { $connection->rollBack(); throw $e; } }
/** * Adds the career menu to the main menu. * * @param pmJSCookMenu $menu * @return void */ public function addCareerMenu(pmJSCookMenu $menu) { $career = CareerPeer::retrieveByPK($this->getReferenceFor("career")); sfContext::getInstance()->getConfiguration()->loadHelpers(array("I18N")); if (!is_null($career)) { $menu->addChild("menu_separator", new pmJSCookMenuSeparator()); $submenu = new pmJSCookMenu(); $submenu->setTitle("<strong>" . __("Current career") . "</strong>")->setCredentials("edit_career"); $item = new pmJSCookMenuItem(); $item->setTitle($career); $submenu->addChild("career_name", $item); $submenu->addChild("first_separator", new pmJSCookMenuSeparator()); // edit if ($career->canBeEdited()) { $item = new pmJSCookMenuItem(); $item->setTitle("Edit")->setUrl("@career_edit?id=" . $career->getId())->setCredentials("edit_career"); $submenu->addChild("edit", $item); } // delete if ($career->canBeDeleted()) { // TODO: ver esto porque REST no funciona con JS $delete_url = url_for(array("sf_route" => "career_delete", "sf_subject" => $career, "sf_method" => "delete")); $item = new pmJSCookMenuItem(); $item->setTitle("Delete")->setUrl($delete_url)->setCredentials("edit_career"); $submenu->addChild("delete", $item); } if ($career->canBeEdited() || $career->canBeDeleted()) { $submenu->addChild("second_separator", new pmJSCookMenuSeparator()); } // copy $item = new pmJSCookMenuItem(); $item->setTitle("Copy")->setUrl("career/copy?id=" . $career->getId())->setCredentials("edit_career"); $submenu->addChild("copy", $item); // subjects $item = new pmJSCookMenuItem(); $item->setTitle("Subjects")->setUrl("career/subjects?id=" . $career->getId())->setCredentials("edit_career"); $submenu->addChild("subjects", $item); // subject options $item = new pmJSCookMenuItem(); $item->setTitle("Subject options")->setUrl("career/subjectOptions?id=" . $career->getId())->setCredentials("edit_career"); $submenu->addChild("subject_options", $item); // career view $item = new pmJSCookMenuItem(); $item->setTitle("Career view")->setUrl("career/careerView?id=" . $career->getId())->setCredentials("edit_career"); $submenu->addChild("career_view", $item); // show inscripted $item = new pmJSCookMenuItem(); $item->setTitle("Show inscripted")->setUrl("career/students?id=" . $career->getId())->setCredentials("edit_career"); $submenu->addChild("career_view", $item); $menu->addChild("career", $submenu); } }
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; } }