protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $con = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $this->createContextInstance('backend');
     $criteria = new Criteria();
     $criteria->add(CoursePeer::IS_CLOSED, false);
     $criteria->addJoin(CoursePeer::ID, CourseSubjectPeer::COURSE_ID, Criteria::INNER_JOIN);
     $criteria->addJoin(CourseSubjectPeer::ID, CourseSubjectStudentPeer::COURSE_SUBJECT_ID, Criteria::INNER_JOIN);
     $course_subject_students = CourseSubjectStudentPeer::doSelect($criteria);
     $this->log('Cant. Course Subject Students a procesar:');
     $this->log(count($course_subject_students));
     foreach ($course_subject_students as $course_subject_student) {
         $course_subject_student_marks = CourseSubjectStudentMarkPeer::retrieveByCourseSubjectStudent($course_subject_student->getId());
         $this->log('Id del course subject student Actual:');
         $this->log($course_subject_student->getId());
         foreach ($course_subject_student_marks as $mark) {
             $mark->setIsClosed(true);
             $mark->save($con);
         }
         $student_approved_course_subject = new StudentApprovedCourseSubject();
         $student_approved_course_subject->setCourseSubject($course_subject_student->getCourseSubject());
         $student_approved_course_subject->setStudentId($course_subject_student->getStudentId());
         $student_approved_course_subject->setSchoolYear($course_subject_student->getCourseSubject()->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear());
         $student_approved_career_subject = new StudentApprovedCareerSubject();
         $student_approved_career_subject->setStudentId($course_subject_student->getStudentId());
         $student_approved_career_subject->setCareerSubject($course_subject_student->getCourseSubject()->getCareerSubjectSchoolYear()->getCareerSubject());
         $student_approved_career_subject->setSchoolYear($course_subject_student->getCourseSubject()->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear());
         $student_approved_career_subject->save($con);
         $student_approved_course_subject->setStudentApprovedCareerSubject($student_approved_career_subject);
         $student_approved_course_subject->save($con);
         $course_subject_student->setStudentApprovedCourseSubject($student_approved_course_subject);
         $course_subject_student->save($con);
     }
     $criteria = new Criteria();
     $criteria->add(CoursePeer::IS_CLOSED, false);
     $courses = CoursePeer::doSelect($criteria);
     foreach ($courses as $c) {
         $c->setIsClosed(true);
         $c->save($con);
     }
 }
 protected function execute($arguments = array(), $options = array())
 {
     $this->createContextInstance();
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     /** @var $connection PropelPDO */
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $username = '******';
     $date_from = '2013-11-23 00:00:00';
     $date_to = '2013-11-23 23:59:59';
     $class = 'CourseSubjectStudentMark';
     /** @var $user sfGuardSecurityUser */
     $user = sfContext::getInstance()->getUser();
     $sf_user = sfGuardUserPeer::retrieveByUsername($username);
     $user->signin($sf_user, false);
     $connection->beginTransaction();
     try {
         $c = new Criteria();
         $c->add(ncChangeLogEntryPeer::CLASS_NAME, $class);
         $c->add(ncChangeLogEntryPeer::USERNAME, $username);
         $cri = $c->getNewCriterion(ncChangeLogEntryPeer::CREATED_AT, $date_from, Criteria::GREATER_EQUAL);
         $cri->addAnd($c->getNewCriterion(ncChangeLogEntryPeer::CREATED_AT, $date_to, Criteria::LESS_EQUAL));
         $c->add($cri);
         $cambios = ncChangeLogEntryPeer::doSelect($c, $connection);
         /** @var $nc_change_log_entry ncChangeLogEntry */
         foreach ($cambios as $nc_change_log_entry) {
             $obj = unserialize(base64_decode($nc_change_log_entry->getChangesDetail()));
             if (isset($obj['changes']) && isset($obj['changes']['mark'])) {
                 $old = $obj['changes']['mark']['raw']['old'];
                 $new = $obj['changes']['mark']['raw']['new'];
                 $id = $obj['pk'];
                 $mark = CourseSubjectStudentMarkPeer::retrieveByPK($id, $connection);
                 $mark->setMark($old);
                 $mark->save($connection);
             }
         }
         $connection->commit();
     } catch (Exception $e) {
         $connection->rollBack();
         $this->log($e->getMessage());
         $this->log($e->getTraceAsString());
     }
 }
 protected function doSave($con = null)
 {
     $values = $this->getValues();
     $course_subject = CourseSubjectPeer::retrieveByPk($values['course_subject_id']);
     $course = $course_subject->getCourse();
     $con = is_null($con) ? $this->getConnection() : $con;
     try {
         $con->beginTransaction();
         foreach ($values['student_list'] as $student_id) {
             $course_subject_student = CourseSubjectStudentPeer::retrievebyCourseSubjectAndStudent($course_subject->getid(), $student_id);
             $course_subject_student->setIsNotAverageable(true);
             $course_subject_student_marks = CourseSubjectStudentMarkPeer::retrieveByCourseSubjectStudent($course_subject_student->getId());
             foreach ($course_subject_student_marks as $mark) {
                 if ($mark->getMarkNumber() < $course->getCurrentPeriod()) {
                     $mark->setIsClosed(true);
                 } else {
                     if ($mark->getMarkNumber() >= $course->getCurrentPeriod() && !$course->getIsClosed()) {
                         $mark->setIsClosed(false);
                     }
                 }
                 $mark->save($con);
             }
             //elimino el student_approved_course_subject y el student_approved_career_subject
             $student_approved_course_subject = $course_subject_student->getStudentApprovedCourseSubject();
             $student_approved_career_subject = $student_approved_course_subject->getStudentApprovedCareerSubject();
             $student_approved_course_subject->delete($con);
             $student_approved_career_subject->delete($con);
             $course_subject_student->setStudentApprovedCourseSubject(null);
             $course_subject_student->setIsNotAverageable(false);
             $course_subject_student->save($con);
         }
         //chequeo si la cantidad de alumnos deseximidos es mayor a cero y le curso esta cerrado.
         if (count($course->getIsAverageableCourseSubjectStudent()) > 0 && $course->getIsClosed()) {
             //abro el curso.
             $course->setIsClosed(false);
             $course->save($con);
         }
         $con->commit();
     } catch (Exception $e) {
         throw $e;
         $con->rollBack();
     }
 }
 protected function doSave($con = null)
 {
     $values = $this->getValues();
     $course_subject = CourseSubjectPeer::retrieveByPk($values['course_subject_id']);
     $course = $course_subject->getCourse();
     $con = is_null($con) ? $this->getConnection() : $con;
     try {
         $con->beginTransaction();
         if ($values['set_all_course_subject_non_numerical_califications'] == 1) {
             //tomo todos los alumnos que No tienen seteado el flag is_not_averageable
             $course_subject_students = $course->getIsAverageableCourseSubjectStudent();
             foreach ($course_subject_students as $course_subject_student) {
                 $course_subject_student->setIsNotAverageable(true);
                 $course_subject_student_marks = CourseSubjectStudentMarkPeer::retrieveByCourseSubjectStudent($course_subject_student->getId());
                 foreach ($course_subject_student_marks as $mark) {
                     $mark->setIsClosed(true);
                     $mark->save($con);
                 }
                 $student_id = $course_subject_student->getStudentId();
                 $student_approved_course_subject = new StudentApprovedCourseSubject();
                 $student_approved_course_subject->setCourseSubject($course_subject);
                 $student_approved_course_subject->setStudentId($student_id);
                 $student_approved_course_subject->setSchoolYear($course_subject->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear());
                 $student_approved_career_subject = new StudentApprovedCareerSubject();
                 $student_approved_career_subject->setStudentId($student_id);
                 $student_approved_career_subject->setCareerSubject($course_subject->getCareerSubjectSchoolYear()->getCareerSubject());
                 $student_approved_career_subject->setSchoolYear($course_subject->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear());
                 $student_approved_career_subject->save($con);
                 $student_approved_course_subject->setStudentApprovedCareerSubject($student_approved_career_subject);
                 $student_approved_course_subject->save($con);
                 $course_subject_student->setStudentApprovedCourseSubject($student_approved_course_subject);
                 $course_subject_student->save($con);
             }
         } else {
             foreach ($values['student_list'] as $student_id) {
                 $course_subject_student = CourseSubjectStudentPeer::retrievebyCourseSubjectAndStudent($course_subject->getid(), $student_id);
                 $course_subject_student->setIsNotAverageable(true);
                 $course_subject_student_marks = CourseSubjectStudentMarkPeer::retrieveByCourseSubjectStudent($course_subject_student->getId());
                 foreach ($course_subject_student_marks as $mark) {
                     $mark->setIsClosed(true);
                     $mark->save($con);
                 }
                 $student_approved_course_subject = new StudentApprovedCourseSubject();
                 $student_approved_course_subject->setCourseSubject($course_subject);
                 $student_approved_course_subject->setStudentId($student_id);
                 $student_approved_course_subject->setSchoolYear($course_subject->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear());
                 $student_approved_career_subject = new StudentApprovedCareerSubject();
                 $student_approved_career_subject->setStudentId($student_id);
                 $student_approved_career_subject->setCareerSubject($course_subject->getCareerSubjectSchoolYear()->getCareerSubject());
                 $student_approved_career_subject->setSchoolYear($course_subject->getCareerSubjectSchoolYear()->getCareerSchoolYear()->getSchoolYear());
                 $student_approved_career_subject->save($con);
                 $student_approved_course_subject->setStudentApprovedCareerSubject($student_approved_career_subject);
                 $student_approved_course_subject->save($con);
                 $course_subject_student->setStudentApprovedCourseSubject($student_approved_course_subject);
                 $course_subject_student->save($con);
             }
         }
         //chequeo si la cantidad de alumnos eximidos es igual a la cantidad de alumnos inscriptos en el curso y el curso esta abierto .
         if (count($course->getIsNotAverageableCourseSubjectStudent()) == $course->countStudents() && !$course->getIsClosed()) {
             //cierro el curso.
             $course->setIsClosed(true);
             $course->save($con);
         }
         $con->commit();
     } catch (Exception $e) {
         throw $e;
         $con->rollBack();
     }
 }
Example #5
0
 public function executeShowMarkChangeLog(sfWebRequest $request)
 {
     $this->mark = CourseSubjectStudentMarkPeer::retrieveByPK($request->getParameter('id'));
     return $this->renderPartial('show_change_log', array('mark' => $this->mark));
 }
Example #6
0
 /**
  * This method back the period to last one.
  */
 public function backPeriod()
 {
     if ($this->getCurrentPeriod() == 1) {
         return null;
     }
     $con = Propel::getConnection();
     $con->beginTransaction();
     try {
         $c = new Criteria();
         $c->add(CourseSubjectStudentMarkPeer::MARK_NUMBER, $this->getCurrentPeriod() - 1);
         $c->addJoin(CourseSubjectStudentMarkPeer::COURSE_SUBJECT_STUDENT_ID, CourseSubjectStudentPeer::ID);
         $c->addJoin(CourseSubjectStudentPeer::COURSE_SUBJECT_ID, CourseSubjectPeer::ID);
         $c->add(CourseSubjectPeer::COURSE_ID, $this->getId());
         $course_subject_students_marks = CourseSubjectStudentMarkPeer::doSelect($c);
         foreach ($course_subject_students_marks as $course_subject_student_mark) {
             $course_subject_student_mark->setIsClosed(false);
             $course_subject_student_mark->save($con);
             //Seleccionamos todos los StudentDisapprovedCourseSubjec y StudentApprovedCourseSubject si es que tiene y los borramos
             $c = new Criteria();
             $c->add(StudentDisapprovedCourseSubjectPeer::COURSE_SUBJECT_STUDENT_ID, $course_subject_student_mark->getCourseSubjectStudentId());
             StudentDisapprovedCourseSubjectPeer::doDelete($c);
             //eliminando StudentApprovedCourseSubject
             $c = new Criteria();
             $course_subject_student = CourseSubjectStudentPeer::retrieveByPK($course_subject_student_mark->getCourseSubjectStudentId());
             $c->add(StudentApprovedCourseSubjectPeer::STUDENT_ID, $course_subject_student->getStudentId());
             $c->add(StudentApprovedCourseSubjectPeer::COURSE_SUBJECT_ID, $course_subject_student->getCourseSubjectId());
             StudentApprovedCourseSubjectPeer::doDelete($c);
         }
         $this->setCurrentPeriod($this->getCurrentPeriod() - 1);
         $this->setIsClosed(false);
         $this->save($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }
Example #7
0
 public function getAverageForMarkNumber($mark_number = null)
 {
     if ($mark_number < $this->getCourse()->getCurrentPeriod() || is_null($mark_number) && $this->getCourse()->getIsClosed()) {
         $c = new Criteria();
         $c->add(CourseSubjectStudentPeer::COURSE_SUBJECT_ID, $this->getId());
         $c->addJoin(CourseSubjectStudentMarkPeer::COURSE_SUBJECT_STUDENT_ID, CourseSubjectStudentPeer::ID);
         if (!is_null($mark_number)) {
             $c->add(CourseSubjectStudentMarkPeer::MARK_NUMBER, $mark_number);
         }
         $c->clearSelectColumns();
         $c->addSelectColumn("SUM(" . CourseSubjectStudentMarkPeer::MARK . ") as sum");
         $stmt = CourseSubjectStudentMarkPeer::doSelectStmt($c);
         $sum = $stmt->fetchAll(PDO::FETCH_COLUMN);
         return sprintf('%.4s', $sum[0] / CourseSubjectStudentMarkPeer::doCount($c));
     }
 }
Example #8
0
 public function setCourseSubjectStudentMarksForSchoolYear($school_year, $value = true)
 {
     $c = new Criteria();
     $c->add(CoursePeer::SCHOOL_YEAR_ID, $school_year->getId());
     $c->addJoin(CourseSubjectPeer::COURSE_ID, CoursePeer::ID);
     $c->addJoin(CourseSubjectStudentPeer::COURSE_SUBJECT_ID, CourseSubjectPeer::ID);
     $c->add(CourseSubjectStudentPeer::STUDENT_ID, $this->getId());
     $c->addJoin(CourseSubjectStudentMarkPeer::COURSE_SUBJECT_STUDENT_ID, CourseSubjectStudentPeer::ID);
     $list_cssm = CourseSubjectStudentMarkPeer::doSelect($c);
     foreach ($list_cssm as $cssm) {
         $cssm->setIsClosed($value);
         $cssm->save();
     }
 }
 public function updateCourseMarks($cant_marks, $con = null)
 {
     CourseSubjectStudentMarkPeer::deleteByCourseSubjectStudent($this->getId(), $con);
     for ($i = 1; $i <= $cant_marks; $i++) {
         $course_subject_student_mark = new CourseSubjectStudentMark();
         $course_subject_student_mark->setCourseSubjectStudent($this);
         $course_subject_student_mark->setMarkNumber($i);
         $course_subject_student_mark->save($con);
     }
 }