Example #1
0
 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;
         }
     }
 }