public function executeDeleteStudent(sfWebRequest $request, $con = null) { $ps = PathwayStudentPeer::retrieveByStudentAndSchoolYear($request->getParameter('student_id')); $trs = TentativeRepprovedStudentPeer::retrieveByStudentId($request->getParameter('student_id')); try { $ps->delete(); $trs->setIsDeleted(false); $trs->save(); $this->getUser()->setFlash("notice", "The item was deleted successfully."); } catch (PropelException $e) { $this->getUser()->setFlash('error', 'A problem occurs when deleting the selected items.'); } $this->redirect("@school_year"); }
public function saveCourseSubjectStudentList($con = null) { if (!$this->isValid()) { throw $this->getErrorSchema(); } if (!isset($this->widgetSchema['course_subject_student_list'])) { // somebody has unset this widget return; } if (is_null($con)) { $con = $this->getConnection(); } $this->values = $this->getValue('course_subject_student_list'); foreach ($this->getObject()->getCourseSubjectStudentPathways() as $course_subject_student) { //if student has marks it can't be deleted from course if (!in_array($course_subject_student->getStudentId(), $this->values)) { if ($this->canDeleteCourseSubjectStudent($course_subject_student->getStudentId()) && $course_subject_student->countValidCourseSubjectStudentPathwayMarks() == 0) { $course_subject_student->delete($con); } else { throw new Exception('El/Los alumno/s seleccionado/s poseen calificaciones cargadas que le/s impide/n ser borrado/s de este curso.'); } } } $already_ids = array_map(create_function('$c', 'return $c->getStudentId();'), $this->getObject()->getCourseSubjectStudentPathways()); $this->filterValues($already_ids); if (is_array($this->values)) { $con->beginTransaction(); try { foreach ($this->values as $value) { $course_subject_student = new CourseSubjectStudentPathway(); $course_subject_student->setCourseSubject($this->getObject()); $course_subject_student->setStudentId($value); $course_subject_student->setPathwayStudent(PathwayStudentPeer::retrieveByStudentAndSchoolYear($value, $this->getObject()->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYearId())); $course_subject_student->save($con); } $con->commit(); } catch (Exception $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; } }