Esempio n. 1
0
 /**
  * Executes query and hydrate this object
  *
  * @param       string $query the query being searched for
  */
 public function query($query, PropelPDO $propelConnection = null)
 {
     $refQuery = trim($query);
     if (strlen($refQuery) < 3) {
         throw new Exception("Too few characters in the query string");
     } elseif (helperFunctions::isMaliciousString($refQuery)) {
         throw new Exception("Malicious string detected. Are you trying to wreck our system?");
     } else {
         // search for courses
         $c = new Criteria();
         $idCrit = $c->getNewCriterion(CoursePeer::ID, $refQuery . "%", Criteria::LIKE);
         $nameCrit = $c->getNewCriterion(CoursePeer::DESCR, "%" . $refQuery . "%", Criteria::LIKE);
         $idCrit->addOr($nameCrit);
         $c->addAnd($idCrit);
         $c->setDistinct();
         $c->addAscendingOrderByColumn(CoursePeer::ID);
         $this->_courseList = CoursePeer::doselect($c, $propelConnection);
         // search for professors
         $c = new Criteria();
         $firstNameCrit = $c->getNewCriterion(InstructorPeer::FIRST_NAME, "%" . $refQuery . "%", Criteria::LIKE);
         $lastNameCrit = $c->getNewCriterion(InstructorPeer::LAST_NAME, "%" . $refQuery . "%", Criteria::LIKE);
         $firstNameCrit->addOr($lastNameCrit);
         $c->addAnd($firstNameCrit);
         $c->setDistinct();
         $c->addAscendingOrderByColumn(InstructorPeer::LAST_NAME);
         $this->_profList = InstructorPeer::doSelect($c, $propelConnection);
         // search for programs
         $c = new Criteria();
         $descrCrit = $c->getNewCriterion(DisciplinePeer::DESCR, "%" . $refQuery . "%", Criteria::LIKE);
         $c->addAnd($descrCrit);
         $c->setDistinct();
         $c->addAscendingOrderByColumn(DisciplinePeer::DESCR);
         $this->_programList = DisciplinePeer::doSelect($c, $propelConnection);
     }
 }
Esempio n. 2
0
 /**
  * This method receives a Criteria and adds the joins necesary to join a preceptor with his division courses or commissions.
  *
  * @param integer $user_id
  *
  * @return Criteria
  */
 public static function retrieveCourseIdsjoinWithDivisionCourseOrCommission($user_id, $add_division_courses = false)
 {
     $preceptor = self::retrievePreceptorBySfGuardUserId($user_id);
     if (is_null($preceptor)) {
         return array();
     }
     $c1 = new Criteria();
     $c1->addJoin(CoursePeer::ID, CoursePreceptorPeer::COURSE_ID);
     $c1->add(CoursePreceptorPeer::PRECEPTOR_ID, $preceptor->getId());
     $c1->clearSelectColumns();
     $c1->addSelectColumn(CoursePeer::ID);
     $stmt = CoursePeer::doSelectStmt($c1);
     $course_ids = $stmt->fetchAll(PDO::FETCH_COLUMN);
     if ($add_division_courses) {
         $c2 = new Criteria();
         $c2->addJoin(CoursePeer::DIVISION_ID, DivisionPeer::ID);
         $c2->addJoin(DivisionPeer::ID, DivisionPreceptorPeer::DIVISION_ID);
         $c2->add(DivisionPreceptorPeer::PRECEPTOR_ID, $preceptor->getId());
         $c2->clearSelectColumns();
         $c2->addSelectColumn(CoursePeer::ID);
         $stmt = CoursePeer::doSelectStmt($c2);
         $course_ids = array_merge($course_ids, $stmt->fetchAll(PDO::FETCH_COLUMN));
     }
     return $course_ids;
 }
Esempio n. 3
0
 /**
  * Fetches a list of Course objects
  *
  * @param       int $instructorId ID of instructor object
  * @return      A list of course objects
  */
 public static function findCoursesByInstructorId($instructorId, PropelPDO $propelConnection = null)
 {
     $c = new Criteria();
     $c->addJoin(CoursePeer::ID, CourseInstructorAssociationPeer::COURSE_ID);
     $c->add(CourseInstructorAssociationPeer::INSTRUCTOR_ID, $instructorId);
     $c->setDistinct();
     $c->addAscendingOrderByColumn(CoursePeer::ID);
     return CoursePeer::doselect($c, $propelConnection);
 }
Esempio n. 4
0
 public function mis_cursos()
 {
     $c = new Criteria();
     $c->add(CourseRelUserPeer::USER_ID, Session::get('id'));
     $cursos = CourseRelUserPeer::doSelect($c);
     foreach ($cursos as $cu) {
         $cursos_codigos[] = $cu->getCourseCode();
     }
     $this->cursos = CoursePeer::retrieveByPKs($cursos_codigos);
 }
 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();
     // add your code here
     $courses = CoursePeer::doSelect(new Criteria());
     foreach ($courses as $course) {
         $division = new Division();
         $division->setName($course->getName());
         $division->setSchoolYearId($course->getSchoolYearId());
         foreach ($course->getCourseSubjects() as $course_subject) {
             $course_students = $course->getCourseStudents();
             if (isset($course_students[0])) {
                 $division->setCareerId($course_students[0]->getCareerSubject()->getCareerId());
             } else {
                 $division->setCareerId(1);
             }
             $new_course = new Course();
             $course->copyInto($new_course);
             $new_course->setName($course_subject->getSubject() . ' - ' . $course->getName());
             $new_course->save();
             $new_course_subject = new CourseSubject();
             $course_subject->copyInto($new_course_subject);
             $new_course_subject->setCourseId($new_course->getId());
             $new_course_subject->setCourseId($new_course->getId());
             $new_course_subject->save();
             $course_subject->delete();
             $c = new Criteria();
             $c->add(CourseStudentPeer::COURSE_ID, $course->getId());
             $c->addJoin(CourseStudentPeer::CAREER_SUBJECT_ID, CareerSubjectPeer::ID);
             $c->add(CareerSubjectPeer::SUBJECT_ID, $new_course_subject->getSubjectId());
             $course_students = CourseStudentPeer::doSelect($c);
             foreach ($course_students as $course_student) {
                 $new_course_student = new CourseStudent();
                 $course_student->copyInto($new_course_student);
                 $new_course_student->setCourseId($new_course->getId());
                 $new_course_student->save();
                 $course_student->delete();
             }
             $division_course = new DivisionCourse();
             $division_course->setCourse($new_course);
             $division->addDivisionCourse($division_course);
         }
         try {
             $course->delete();
         } catch (Exception $e) {
         }
         try {
             $division->save();
         } catch (Exception $e) {
         }
         $this->logSection('division+', 'Division ' . $division . ' created');
     }
 }
Esempio n. 6
0
 public function executeCreate(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod('post'));
     $this->forward404Unless($request->hasParameter("course") && $request->hasParameter("year") && $request->hasParameter("term"));
     $this->courseId = $request->getParameter("course");
     $this->year = $request->getParameter("year") . $request->getParameter("term");
     $this->forward404Unless($course = CoursePeer::retrieveByPk($this->courseId), sprintf("Object course does not exist"));
     $this->form = new ExamForm(new Exam());
     $this->processForm($request, $this->form);
     // at this point, save has failed
     $this->examList = $this->getExamList($this->courseId, $this->year);
     $this->setTemplate('custom');
 }
 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);
     }
 }
Esempio n. 8
0
 public function executeDelete(sfWebRequest $request)
 {
     $request->checkCSRFProtection();
     $this->forward404Unless($course = CoursePeer::retrieveByPk($request->getParameter('id')), sprintf('Object course does not exist (%s).', $request->getParameter('id')));
     try {
         $discipline = $course->getCourseDisciplineAssociations();
         if ($discipline !== null) {
             //deleting discipline dependency
             foreach ($discipline as $dis) {
                 $dis->delete();
             }
         }
         $instructorassoc = null;
         $instructorassoc = $course->getCourseInstructorAssociations();
         if ($instructorassoc !== null) {
             //deleting instructor dependency
             foreach ($instructorassoc as $instruct) {
                 $instruct->delete();
             }
         }
         // finally, delete the course obj
         $course->delete();
         $par = "";
         if ($request->hasParameter("page")) {
             $par = "?page=" . $request->getParameter("page");
         }
         $this->redirect('admincourse/index' . $par);
     } catch (Exception $e) {
         $this->globalErrors = $e->getMessage();
         $this->course_list = $this->getCourselist(new Criteria());
         $this->courseDetail = CourseDetailPeer::getObjectForCourseId($course->getId());
         $values = array('edit' => 'true');
         $this->form = new CourseForm($course, $values);
         if ($this->courseDetail !== null) {
             $this->form2 = new CourseDetailForm($this->courseDetail);
         } else {
             $this->form2 = new CourseDetailForm(new CourseDetail());
         }
         $this->setTemplate('index');
     }
 }
 protected function doSave($con = null)
 {
     $con = is_null($con) ? $this->getConnection() : $con;
     $course = $this->getObject();
     $from_course = CoursePeer::retrieveByPK($this->values['course_id']);
     try {
         $con->beginTransaction();
         foreach ($from_course->getStudents() as $student) {
             foreach ($course->getCourseSubjects() as $course_subject) {
                 $course_subject_student = new CourseSubjectStudent();
                 $course_subject_student->setCourseSubjectId($course_subject->getId());
                 $course_subject_student->setStudentId($student->getId());
                 $course_subject_student->save($con);
             }
         }
         $con->commit();
     } catch (Exception $e) {
         throw $e;
         $con->rollBack();
     }
 }
 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();
     echo "Leyendo cursos en la base de datos...[No se puede hacer mas lento :)]\n";
     foreach (CoursePeer::doSelect(new Criteria()) as $course) {
         echo "Arreglando curso '" . $course . "'...\n";
         $students_ids = array();
         foreach ($course->getCourseStudents() as $course_student) {
             if (!in_array($course_student->getStudentId(), $students_ids)) {
                 $students_ids[] = $course_student->getStudentId();
             }
             $course_student->delete();
         }
         foreach ($students_ids as $id) {
             if (!CourseStudentPeer::generateInscriptionToCourse($id, $course->getId())) {
                 echo "Error. Curso con cupo maximo superado o inscripcion ya existente.\n";
             }
         }
     }
 }
Esempio n. 11
0
 protected function getCourselist(Criteria $c = null)
 {
     if ($c === null) {
         return CoursePeer::doSelect(new Criteria());
     } else {
         return CoursePeer::doSelect($c);
     }
 }
 /**
  * Start browsing the directory and register files
  *
  * @return       Exception code = 400 if directory non-existent
  *               An array containing list of non-imported files if successful
  */
 public function doImport()
 {
     if (!file_exists($this->_dir)) {
         throw new Exception("directory non-existent", 400);
     }
     $errArr = array();
     $handler = opendir($this->_dir);
     // TODO: does not do recrusive listing, do we need that?
     while (false !== ($file = readdir($handler))) {
         if ($file != '.' && $file != '..') {
             $err = false;
             $pos = strrpos($file, '.');
             $fileName = strtoupper(substr($file, 0, $pos));
             $token = strtok($fileName, '_');
             $counter = 0;
             while (false !== $token) {
                 switch ($counter) {
                     case 0:
                         if (strlen($token) != 7) {
                             $err = true;
                         }
                         $rawCourseCode = $token;
                         break;
                     case 1:
                         if ($token != substr($this->_year, 0, 4)) {
                             $err = true;
                         }
                         break;
                     case 2:
                         if ($token != "EXAM") {
                             if (substr($token, 0, 5) == "EXAM(") {
                                 // name could have the following syntax: AER205S_2009_EXAM(2).pdf
                                 $count = strtok($token, '(');
                                 $count = strtok('(');
                                 $count = strtok($count, ')');
                                 if ($count === false || !is_numeric($count)) {
                                     $err = true;
                                 }
                             } else {
                                 $err = true;
                             }
                         }
                         break;
                 }
                 $token = strtok("_");
                 $counter++;
             }
             if ($counter != 3 || $err) {
                 $err = true;
             } else {
                 // assume course code is 7 chars in length with the last char being either S, F or Y
                 $part1 = substr($rawCourseCode, 0, 6);
                 //e.g. AER205
                 $part2 = substr($rawCourseCode, 6, 1);
                 //e.g. F
                 switch ($part2) {
                     case "F":
                     case "S":
                         $courseCode = $part1 . "H1";
                         $descr = $part1 . " " . $this->_year . " Official Exam" . (isset($count) ? ' (' . $count . ')' : '');
                         break;
                     case "Y":
                         $courseCode = $part1 . "Y1";
                         $descr = $part1 . " " . $this->_year . " Official Exam" . (isset($count) ? ' (' . $count . ')' : '');
                         break;
                     default:
                         $err = true;
                         break;
                 }
                 if (!$err) {
                     $conn = Propel::getConnection();
                     // check if we have exam of this descr already
                     $examArr = ExamPeer::getExamsForYearAndCourseId($courseCode, $this->_year, $conn);
                     foreach ($examArr as $ex) {
                         if ($ex->getType() == EnumItemPeer::EXAM && $ex->getDescr() == $descr) {
                             $err = true;
                             break;
                         }
                     }
                     if (!$err) {
                         // first check if course exists
                         $course = CoursePeer::retrieveByPK($courseCode, $conn);
                         if (!isset($course)) {
                             $course = new Course();
                             //$course->setDeptId(substr($courseCode, 0, 3));
                             $course->setDescr($courseCode);
                             $course->setIsEng(1);
                             $course->setId($courseCode);
                             $dept = DepartmentPeer::retrieveByPK(substr($courseCode, 0, 3), $conn);
                             if (!isset($dept)) {
                                 $dept = new Department();
                                 $dept->setId(substr($courseCode, 0, 3));
                                 $dept->setDescr(substr($courseCode, 0, 3));
                                 $dept->save($conn);
                             }
                             $course->setDepartment($dept);
                             $course->save($conn);
                         }
                         // register exam
                         $exam = new Exam();
                         $exam->setType(EnumItemPeer::EXAM);
                         $exam->setDescr($descr);
                         $exam->setCourseId($courseCode);
                         $exam->setFilePath($this->_dir . $file);
                         $exam->setYear($this->_year);
                         $exam->save();
                     }
                 }
             }
             if ($err) {
                 $errArr[] = $file;
             }
         }
     }
     closedir($handler);
     return $errArr;
 }
Esempio n. 13
0
 /**
  * Selects a collection of CourseComment objects pre-filled with all related objects.
  *
  * @param      Criteria  $c
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of CourseComment objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAll(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     foreach (sfMixer::getCallables('BaseCourseCommentPeer:doSelectJoinAll:doSelectJoinAll') as $callable) {
         call_user_func($callable, 'BaseCourseCommentPeer', $c, $con);
     }
     $c = clone $c;
     // Set the correct dbName if it has not been overridden
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     CourseCommentPeer::addSelectColumns($c);
     $startcol2 = CourseCommentPeer::NUM_COLUMNS - CourseCommentPeer::NUM_LAZY_LOAD_COLUMNS;
     CoursePeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (CoursePeer::NUM_COLUMNS - CoursePeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(CourseCommentPeer::COURSE_ID), array(CoursePeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = CourseCommentPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = CourseCommentPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $omClass = CourseCommentPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             CourseCommentPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Course rows
         $key2 = CoursePeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = CoursePeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = CoursePeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 CoursePeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (CourseComment) to the collection in $obj2 (Course)
             $obj2->addCourseComment($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Esempio n. 14
0
 public function executeCreateCourse(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
     $this->forward404Unless($request->hasParameter("course"));
     $this->courseId = $request->getParameter("course");
     $this->forward404Unless($_course = CoursePeer::retrieveByPk($this->courseId), sprintf('Object course does not exist (%s).', $this->courseId));
     $comment = new CourseComment();
     $values = array('courseid' => $this->courseId);
     $this->form = new CourseCommentForm($comment, $values);
     $this->submitCourseForm($request, $this->form);
     // if we have reached this point, save has failed
     $this->commentList = $this->getCourseList($this->courseId);
     $this->setTemplate('coursecommenting');
 }
Esempio n. 15
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = CoursePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setDeptId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setDescr($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setIsEng($arr[$keys[3]]);
     }
 }
Esempio n. 16
0
 /**
  * Selects a collection of Section objects pre-filled with all related objects.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of Section objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     SectionPeer::addSelectColumns($criteria);
     $startcol2 = SectionPeer::NUM_HYDRATE_COLUMNS;
     CoursePeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + CoursePeer::NUM_HYDRATE_COLUMNS;
     $criteria->addJoin(SectionPeer::COURSE_ID, CoursePeer::ID, $join_behavior);
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = SectionPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = SectionPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://www.propelorm.org/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = SectionPeer::getOMClass();
             $obj1 = new $cls();
             $obj1->hydrate($row);
             SectionPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Course rows
         $key2 = CoursePeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = CoursePeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = CoursePeer::getOMClass();
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 CoursePeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (Section) to the collection in $obj2 (Course)
             $obj2->addSection($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Esempio n. 17
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = CoursePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setCode($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setDirectory($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setDbName($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setCourseLanguage($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setTitle($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setDescription($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setCategoryCode($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setVisibility($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setShowScore($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setTutorName($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setVisualCode($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setDepartmentName($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setDepartmentUrl($arr[$keys[12]]);
     }
     if (array_key_exists($keys[13], $arr)) {
         $this->setDiskQuota($arr[$keys[13]]);
     }
     if (array_key_exists($keys[14], $arr)) {
         $this->setLastVisit($arr[$keys[14]]);
     }
     if (array_key_exists($keys[15], $arr)) {
         $this->setLastEdit($arr[$keys[15]]);
     }
     if (array_key_exists($keys[16], $arr)) {
         $this->setCreationDate($arr[$keys[16]]);
     }
     if (array_key_exists($keys[17], $arr)) {
         $this->setExpirationDate($arr[$keys[17]]);
     }
     if (array_key_exists($keys[18], $arr)) {
         $this->setTargetCourseCode($arr[$keys[18]]);
     }
     if (array_key_exists($keys[19], $arr)) {
         $this->setSubscribe($arr[$keys[19]]);
     }
     if (array_key_exists($keys[20], $arr)) {
         $this->setUnsubscribe($arr[$keys[20]]);
     }
     if (array_key_exists($keys[21], $arr)) {
         $this->setRegistrationCode($arr[$keys[21]]);
     }
 }
Esempio n. 18
0
 public function canIndexCourseStudentMark($course)
 {
     if (!$course) {
         $course = CoursePeer::retrieveByPK(sfContext::getInstance()->getRequest()->getParameter("id"));
         return true;
         //Because is an extraordinary course, is not be in a division, and the preceptors are related to a course by a division.
         //So, we show all the extraordinary courses to a preceptor
     }
     if ($this->isPreceptor()) {
         return $course->canBeStudentMarksEditedByPreceptorUser($this->getGuardUser());
     } elseif ($this->isTeacher()) {
         return $course->canBeStudentMarksEditedByTeacherUser($this->getGuardUser());
     }
     return true;
 }
Esempio n. 19
0
 public static function retrievePathwayStudentsCriteria($course_id)
 {
     $course = CoursePeer::retrieveByPk($course_id);
     $c = new Criteria();
     $c->add(CourseSubjectPeer::COURSE_ID, $course_id);
     $c->addJoin(CourseSubjectPeer::ID, CourseSubjectStudentPathwayPeer::COURSE_SUBJECT_ID);
     $c->addJoin(CourseSubjectStudentPathwayPeer::STUDENT_ID, StudentPeer::ID);
     $c->addJoin(StudentPeer::PERSON_ID, PersonPeer::ID);
     $c->addJoin(SchoolYearStudentPeer::STUDENT_ID, StudentPeer::ID);
     $c->add(PersonPeer::IS_ACTIVE, true);
     $c->add(SchoolYearStudentPeer::SCHOOL_YEAR_ID, $course->getSchoolYearId());
     return $c;
 }
Esempio n. 20
0
 /**
  * Find object by primary key
  * Use instance pooling to avoid a database query if the object exists
  * <code>
  * $obj  = $c->findPk(12, $con);
  * </code>
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con an optional connection object
  *
  * @return    Course|array|mixed the result, formatted by the current formatter
  */
 public function findPk($key, $con = null)
 {
     if (null !== ($obj = CoursePeer::getInstanceFromPool((string) $key)) && $this->getFormatter()->isObjectFormatter()) {
         // the object is alredy in the instance pool
         return $obj;
     } else {
         // the object has not been requested yet, or the formatter is not an object formatter
         $criteria = $this->isKeepQuery() ? clone $this : $this;
         $stmt = $criteria->filterByPrimaryKey($key)->getSelectStatement($con);
         return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
     }
 }
Esempio n. 21
0
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return    Course A model object, or null if the key is not found
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `NUM`, `NB_SECTIONS`, `NAME`, `DEPT_ID`, `SPIDERED_AT`, `SHALLOW_SPIDERED_AT`, `TOUCHED`, `B_ID`, `BOOKSTORE_TYPE`, `ID`, `CREATED_AT`, `UPDATED_AT` FROM `course` WHERE `ID` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new Course();
         $obj->hydrate($row);
         CoursePeer::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }
Esempio n. 22
0
 public static function getCoursesForStudents($students_ids)
 {
     #Falta el año electivo actual
     $c = new Criteria();
     $c->add(CourseSubjectStudentPeer::STUDENT_ID, $students_ids, Criteria::IN);
     $c->addJoin(CourseSubjectStudentPeer::COURSE_SUBJECT_ID, CourseSubjectPeer::ID);
     $c->addJoin(CourseSubjectPeer::COURSE_ID, CoursePeer::ID);
     $c->setDistinct(CoursePeer::ID);
     return CoursePeer::doSelect($c);
 }
Esempio n. 23
0
 public function executeSaveClose(sfWebRequest $request)
 {
     // TODO
     // si es mayor que 7 crear el student approved career subject. si no mandarlo a previa.
     sfContext::getInstance()->getConfiguration()->loadHelpers('I18N');
     $this->course = CoursePeer::retrieveByPk($request->getParameter('id'));
     $this->course->pathwayClose();
     $this->getUser()->setFlash('notice', __('The course has been closed successfuly'));
     $this->setTemplate('close');
 }
 public function fixComissions($connection)
 {
     $c = new Criteria();
     //$c->add(CoursePeer::DIVISION_ID, null, Criteria::ISNULL);
     $c->add(CoursePeer::SCHOOL_YEAR_ID, 1);
     foreach (CoursePeer::doSelect($c) as $course) {
         $course_subjects = $course->getCourseSubjects();
         foreach ($course->getCourseSubjects() as $course_subject) {
             foreach ($course_subject->getCourseSubjectStudents() as $course_subject_student) {
                 $result = $course_subject_student->getCourseResult();
                 if (is_null($result->getStudentApprovedCareerSubjectId())) {
                     if (is_null($result->getId())) {
                         $result->save($connection);
                         if ($result instanceof StudentApprovedCourseSubject) {
                             $student_approved_career_subject = StudentApprovedCareerSubjectPeer::retrieveOrCreateByCareerSubjectAndStudent($course_subject_student->getCourseSubject()->getCareerSubject()->getId(), $course_subject_student->getStudentId());
                             $student_approved_career_subject->setSchoolYearId(1);
                             $student_approved_course_subject->setStudentApprovedCareerSubject($student_approved_career_subject);
                             $student_approved_course_subject->save($connection);
                             $student_approved_career_subject->save($connection);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 25
0
 /**
  * Get the associated Course object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Course The associated Course object.
  * @throws     PropelException
  */
 public function getCourse(PropelPDO $con = null)
 {
     if ($this->aCourse === null && ($this->course_id !== "" && $this->course_id !== null)) {
         $c = new Criteria(CoursePeer::DATABASE_NAME);
         $c->add(CoursePeer::ID, $this->course_id);
         $this->aCourse = CoursePeer::doSelectOne($c, $con);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aCourse->addCourseComments($this);
         		 */
     }
     return $this->aCourse;
 }
Esempio n. 26
0
 /**
  * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
  * feature (like MySQL or SQLite).
  *
  * This method is not very speedy because it must perform a query first to get
  * the implicated records and then perform the deletes by calling those Peer classes.
  *
  * This method should be used within a transaction if possible.
  *
  * @param      Criteria $criteria
  * @param      PropelPDO $con
  * @return     int The number of affected rows (if supported by underlying database driver).
  */
 protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
 {
     // initialize var to track total num of affected rows
     $affectedRows = 0;
     // first find the objects that are implicated by the $criteria
     $objects = DeptPeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         // delete related Course objects
         $criteria = new Criteria(CoursePeer::DATABASE_NAME);
         $criteria->add(CoursePeer::DEPT_ID, $obj->getId());
         $affectedRows += CoursePeer::doDelete($criteria, $con);
     }
     return $affectedRows;
 }
Esempio n. 27
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(CoursePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(CoursePeer::DATABASE_NAME);
         $criteria->add(CoursePeer::CODE, $pks, Criteria::IN);
         $objs = CoursePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * Event listener function that should be registered to
  * 'admin.build_criteria' event in order to add some
  * personalized criteria restrictions.
  *
  * @param sfEvent $event
  * @param Criteria $criteria
  */
 static function applyRestrictions(sfEvent $event, $criteria)
 {
     $user = sfContext::getInstance()->getUser();
     if ($event->getSubject() instanceof schoolyearActions) {
         // Restrictions for schoolyear module
         // $criteria->add(...);
     } elseif ($event->getSubject() instanceof career_subjectActions) {
         // Restrictions for careersubject module
         if ($user->getReferenceFor('career')) {
             $criteria->add(CareerSubjectPeer::CAREER_ID, $user->getReferenceFor('career'));
             CareerSubjectPeer::OrderByYearAndName($criteria);
         }
     } elseif ($event->getSubject() instanceof career_subject_optionActions) {
         // Restrictions for careersubject module
         if ($user->getReferenceFor('career')) {
             $criteria->add(CareerSubjectPeer::IS_OPTION, true);
             $criteria->add(CareerSubjectPeer::CAREER_ID, $user->getReferenceFor('career'));
         }
     } elseif ($event->getSubject() instanceof career_school_yearActions) {
         if ($school_year_id = $user->getReferenceFor('schoolyear')) {
             $criteria->add(CareerSchoolYearPeer::SCHOOL_YEAR_ID, $school_year_id);
         }
     } elseif ($event->getSubject() instanceof career_subject_school_yearActions) {
         if ($career_school_year_id = $user->getReferenceFor('career_school_year')) {
             $criteria->add(CareerSubjectSchoolYearPeer::CAREER_SCHOOL_YEAR_ID, $career_school_year_id);
             $criteria->add(CareerSubjectPeer::IS_OPTION, false);
             $criteria->addJoin(CareerSubjectPeer::ID, CareerSubjectSchoolYearPeer::CAREER_SUBJECT_ID);
             CareerSubjectSchoolYearPeer::sorted($criteria);
         }
     } elseif ($event->getSubject() instanceof optional_school_yearActions) {
         if ($career_school_year_id = $user->getReferenceFor('career_school_year')) {
             $criteria->add(CareerSubjectSchoolYearPeer::CAREER_SCHOOL_YEAR_ID, $career_school_year_id);
             $criteria->add(CareerSubjectPeer::HAS_OPTIONS, true);
             $criteria->addJoin(CareerSubjectPeer::ID, CareerSubjectSchoolYearPeer::CAREER_SUBJECT_ID);
         }
     } elseif ($event->getSubject() instanceof division_courseActions) {
         if ($division_id = $user->getReferenceFor('division')) {
             $criterion = $criteria->getNewCriterion(CoursePeer::DIVISION_ID, $division_id);
             $criterion->addOr($criteria->getNewCriterion(CoursePeer::RELATED_DIVISION_ID, $division_id));
             $criteria->add($criterion);
         }
         if ($user->isPreceptor()) {
             self::addCoursePreceptorCriteria($criteria, $user);
         }
         if ($user->isTeacher()) {
             self::addCourseTeacherCriteria($criteria, $user);
         }
         $criteria->setDistinct();
     } elseif ($event->getSubject() instanceof divisionActions) {
         DivisionPeer::sorted($criteria);
         if ($user->isPreceptor()) {
             self::addDivisionPreceptorCriteria($criteria, $user);
         } elseif ($user->isTeacher()) {
             self::addDivisionTeacherCriteria($criteria, $user);
         } elseif ($user->isHeadPreceptor()) {
             self::addDivisionHeadPersonalCriteria($criteria, $user);
         }
     } else {
         if ($event->getSubject() instanceof shared_studentActions) {
             $reference_array = sfContext::getInstance()->getUser()->getReferenceFor("shared_student");
             $peer = $reference_array["peer"];
             $fk = $reference_array["fk"];
             if (isset($reference_array["object_id"])) {
                 $object_id = $reference_array["object_id"];
             } else {
                 $object_ids = $reference_array["object_ids"];
             }
             $criteria->addJoin(constant("{$peer}::STUDENT_ID"), StudentPeer::ID);
             $criteria->addGroupByColumn(StudentPeer::ID);
             if (isset($object_id)) {
                 $criteria->add(constant("{$peer}::{$fk}"), $object_id);
             } else {
                 $criteria->add(constant("{$peer}::{$fk}"), $object_ids, Criteria::IN);
             }
             $criteria->addJoin(StudentPeer::PERSON_ID, PersonPeer::ID);
             $criteria->add(PersonPeer::IS_ACTIVE, true);
         } else {
             if ($event->getSubject() instanceof examinationActions || $event->getSubject() instanceof manual_examinationActions) {
                 $school_year_id = sfContext::getInstance()->getUser()->getReferenceFor("schoolyear");
                 $criteria->add(ExaminationPeer::SCHOOL_YEAR_ID, $school_year_id);
                 if ($user->isTeacher()) {
                     $criteria->addJoin(ExaminationPeer::ID, ExaminationSubjectPeer::EXAMINATION_ID);
                     $criteria->addJoin(ExaminationSubjectPeer::ID, ExaminationSubjectTeacherPeer::EXAMINATION_SUBJECT_ID);
                     $criteria->addJoin(ExaminationSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID);
                     $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID);
                     $criteria->add(PersonPeer::IS_ACTIVE, true);
                     $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId());
                 }
             } else {
                 if ($event->getSubject() instanceof examination_subjectActions) {
                     $examination_id = sfContext::getInstance()->getUser()->getReferenceFor("examination");
                     $criteria->add(ExaminationSubjectPeer::EXAMINATION_ID, $examination_id);
                     $criteria->addJoin(CareerSubjectSchoolYearPeer::ID, ExaminationSubjectPeer::CAREER_SUBJECT_SCHOOL_YEAR_ID);
                     $criteria->addJoin(CareerSubjectPeer::ID, CareerSubjectSchoolYearPeer::CAREER_SUBJECT_ID);
                     $criteria->addAscendingOrderByColumn(CareerSubjectPeer::YEAR);
                     if ($user->isTeacher()) {
                         $criteria->addJoin(ExaminationSubjectPeer::ID, ExaminationSubjectTeacherPeer::EXAMINATION_SUBJECT_ID);
                         $criteria->addJoin(ExaminationSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID);
                         $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID);
                         $criteria->add(PersonPeer::IS_ACTIVE, true);
                         $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId());
                     }
                 } else {
                     if ($event->getSubject() instanceof manual_examination_subjectActions) {
                         $examination_id = sfContext::getInstance()->getUser()->getReferenceFor("manual_examination");
                         $criteria->add(ExaminationSubjectPeer::EXAMINATION_ID, $examination_id);
                         if ($user->isTeacher()) {
                             $criteria->addJoin(ExaminationSubjectPeer::ID, ExaminationSubjectTeacherPeer::EXAMINATION_SUBJECT_ID);
                             $criteria->addJoin(ExaminationSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID);
                             $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID);
                             $criteria->add(PersonPeer::IS_ACTIVE, true);
                             $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId());
                         }
                     } elseif ($event->getSubject() instanceof examination_repprovedActions) {
                         $school_year_id = sfContext::getInstance()->getUser()->getReferenceFor("schoolyear");
                         $criteria->add(ExaminationRepprovedPeer::SCHOOL_YEAR_ID, $school_year_id);
                         if ($user->isTeacher()) {
                             $criteria->addJoin(ExaminationRepprovedPeer::ID, ExaminationRepprovedSubjectPeer::EXAMINATION_REPPROVED_ID);
                             $criteria->addJoin(ExaminationRepprovedSubjectPeer::ID, ExaminationRepprovedSubjectTeacherPeer::EXAMINATION_REPPROVED_SUBJECT_ID);
                             $criteria->addJoin(ExaminationRepprovedSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID);
                             $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID);
                             $criteria->add(PersonPeer::IS_ACTIVE, true);
                             $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId());
                         }
                     } elseif ($event->getSubject() instanceof examination_repproved_subjectActions) {
                         $examination_repproved_id = sfContext::getInstance()->getUser()->getReferenceFor("examination_repproved");
                         $criteria->add(ExaminationRepprovedSubjectPeer::EXAMINATION_REPPROVED_ID, $examination_repproved_id);
                         ExaminationRepprovedSubjectPeer::sortedBySubject($criteria);
                         if ($user->isTeacher()) {
                             $criteria->addJoin(ExaminationRepprovedSubjectPeer::ID, ExaminationRepprovedSubjectTeacherPeer::EXAMINATION_REPPROVED_SUBJECT_ID);
                             $criteria->addJoin(ExaminationRepprovedSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID);
                             $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID);
                             $criteria->add(PersonPeer::IS_ACTIVE, true);
                             $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId());
                         }
                     } else {
                         if ($event->getSubject() instanceof courseActions) {
                             $school_year = SchoolYearPeer::retrieveCurrent();
                             $criteria->add(CoursePeer::DIVISION_ID, null, Criteria::ISNULL);
                             $criteria->add(CoursePeer::SCHOOL_YEAR_ID, $school_year->getId());
                             if ($user->isPreceptor()) {
                                 PersonalPeer::joinWithCourse($criteria, $user->getGuardUser()->getId());
                             }
                             if ($user->isTeacher()) {
                                 $criteria->addJoin(CoursePeer::ID, CourseSubjectPeer::COURSE_ID);
                                 $criteria->addJoin(CourseSubjectPeer::ID, CourseSubjectTeacherPeer::COURSE_SUBJECT_ID);
                                 $criteria->addJoin(CourseSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID);
                                 $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID);
                                 $criteria->add(PersonPeer::IS_ACTIVE, true);
                                 $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId());
                                 $criteria->setDistinct();
                             }
                         } else {
                             if ($event->getSubject() instanceof commissionActions) {
                                 /*
                                 $school_year = SchoolYearPeer::retrieveCurrent();
                                 $criteria->add(CoursePeer::SCHOOL_YEAR_ID, $school_year->getId());
                                 */
                                 CoursePeer::sorted($criteria);
                                 $criteria->add(CoursePeer::DIVISION_ID, null, Criteria::ISNULL);
                                 $criteria->add(CoursePeer::IS_PATHWAY, false);
                                 if ($user->isPreceptor()) {
                                     PersonalPeer::joinWithCourse($criteria, $user->getGuardUser()->getId());
                                 } elseif ($user->isTeacher()) {
                                     TeacherPeer::joinWithCourses($criteria, $user->getGuardUser()->getId(), true);
                                 }
                                 if ($user->isHeadPreceptor()) {
                                     self::addCommissionHeadPreceptorCriteria($criteria, $user);
                                 }
                             } else {
                                 if ($event->getSubject() instanceof final_examinationActions) {
                                     $school_year_id = sfContext::getInstance()->getUser()->getReferenceFor("schoolyear");
                                     $criteria->add(FinalExaminationPeer::SCHOOL_YEAR_ID, $school_year_id);
                                 } else {
                                     if ($event->getSubject() instanceof final_examination_subjectActions) {
                                         $final_examination_id = sfContext::getInstance()->getUser()->getReferenceFor("final_examination");
                                         $criteria->add(FinalExaminationSubjectPeer::FINAL_EXAMINATION_ID, $final_examination_id);
                                         if ($user->isTeacher()) {
                                             $criteria->addJoin(FinalExaminationSubjectTeacherPeer::TEACHER_ID, TeacherPeer::ID);
                                             $criteria->addJoin(TeacherPeer::PERSON_ID, PersonPeer::ID);
                                             $criteria->add(PersonPeer::IS_ACTIVE, true);
                                             $criteria->add(PersonPeer::USER_ID, $user->getGuardUser()->getId());
                                         }
                                     } else {
                                         if ($event->getSubject() instanceof equivalenceActions) {
                                             $student_id = sfContext::getInstance()->getUser()->getReferenceFor("student");
                                             $criteria->add(StudentCareerSchoolYearPeer::STUDENT_ID, $student_id);
                                         } else {
                                             if ($event->getSubject() instanceof sub_orientationActions) {
                                                 $orientation_id = sfContext::getInstance()->getUser()->getReferenceFor("orientation");
                                                 $criteria->add(SubOrientationPeer::ORIENTATION_ID, $orientation_id);
                                             } else {
                                                 if ($event->getSubject() instanceof student_reincorporationActions) {
                                                     $student_id = sfContext::getInstance()->getUser()->getReferenceFor("student");
                                                     if (is_null($student_id)) {
                                                         $student_id = $user->getAttribute('student_id');
                                                     }
                                                     $criteria->add(StudentReincorporationPeer::STUDENT_ID, $student_id);
                                                     $criteria->addJoin(StudentReincorporationPeer::CAREER_SCHOOL_YEAR_PERIOD_ID, CareerSchoolYearPeriodPeer::ID);
                                                     $criteria->addJoin(CareerSchoolYearPeriodPeer::CAREER_SCHOOL_YEAR_ID, CareerSchoolYearPeer::ID);
                                                     $criteria->add(CareerSchoolYearPeer::SCHOOL_YEAR_ID, SchoolYearPeer::retrieveCurrent()->getId());
                                                 } elseif ($event->getSubject() instanceof shared_course_subjectActions) {
                                                     $teacher_id = sfContext::getInstance()->getUser()->getReferenceFor("teacher");
                                                     $criteria->addJoin(CourseSubjectPeer::ID, CourseSubjectTeacherPeer::COURSE_SUBJECT_ID);
                                                     $criteria->addJoin(CourseSubjectTeacherPeer::TEACHER_ID, $teacher_id);
                                                     $criteria->setDistinct();
                                                 } elseif ($event->getSubject() instanceof personalActions) {
                                                     $criteria->add(PersonalPeer::PERSONAL_TYPE, PersonalType::PRECEPTOR);
                                                 } elseif ($event->getSubject() instanceof head_personalActions) {
                                                     $criteria->add(PersonalPeer::PERSONAL_TYPE, PersonalType::HEAD_PRECEPTOR);
                                                 } elseif ($event->getSubject() instanceof student_officeActions) {
                                                     $criteria->add(PersonalPeer::PERSONAL_TYPE, PersonalType::STUDENTS_OFFICE);
                                                 } elseif ($event->getSubject() instanceof studentActions) {
                                                     if ($user->isPreceptor()) {
                                                         SchoolBehaviourFactory::getInstance()->joinPreceptorWithStudents($criteria, $user->getGuardUser()->getId());
                                                     } elseif ($user->isTeacher()) {
                                                         TeacherPeer::joinWithStudents($criteria, $user->getGuardUser()->getId());
                                                     }
                                                     if ($user->isHeadPreceptor()) {
                                                         $criteria->addJoin(DivisionStudentPeer::STUDENT_ID, StudentPeer::ID);
                                                         $criteria->addJoin(DivisionStudentPeer::DIVISION_ID, DivisionPeer::ID);
                                                         self::addDivisionHeadPersonalCriteria($criteria, $user);
                                                     }
                                                 } elseif ($event->getSubject() instanceof licenseActions) {
                                                     if (!is_null(sfContext::getInstance()->getUser()->getReferenceFor("teacher"))) {
                                                         $person_id = TeacherPeer::retrieveByPK(sfContext::getInstance()->getUser()->getReferenceFor("teacher"))->getPersonId();
                                                     } else {
                                                         $person_id = PersonalPeer::retrieveByPK(sfContext::getInstance()->getUser()->getReferenceFor("personal"))->getPersonId();
                                                     }
                                                     $criteria->add(LicensePeer::PERSON_ID, $person_id);
                                                 } elseif ($event->getSubject() instanceof teacherActions) {
                                                     $criteria->setDistinct();
                                                 } else {
                                                     if ($event->getSubject() instanceof career_school_year_periodActions) {
                                                         $career_school_year_id = sfContext::getInstance()->getUser()->getReferenceFor("career_school_year");
                                                         $criteria->add(CareerSchoolYearPeriodPeer::CAREER_SCHOOL_YEAR_ID, $career_school_year_id);
                                                     } else {
                                                         if ($event->getSubject() instanceof student_freeActions) {
                                                             $student_id = sfContext::getInstance()->getUser()->getReferenceFor("student");
                                                             if (is_null($student_id)) {
                                                                 $student_id = $user->getAttribute('student_id');
                                                             }
                                                             $criteria->add(StudentFreePeer::STUDENT_ID, $student_id);
                                                         } else {
                                                             if ($event->getSubject() instanceof course_subject_student_examinationActions) {
                                                                 $examination_subject_id = sfContext::getInstance()->getUser()->getReferenceFor("examination_subject");
                                                                 $criteria->add(CourseSubjectStudentExaminationPeer::EXAMINATION_SUBJECT_ID, $examination_subject_id);
                                                             } else {
                                                                 if ($event->getSubject() instanceof student_examination_repproved_subjectActions) {
                                                                     $examination_repproved_subject_id = sfContext::getInstance()->getUser()->getReferenceFor("examination_repproved_subject");
                                                                     $criteria->add(StudentExaminationRepprovedSubjectPeer::EXAMINATION_REPPROVED_SUBJECT_ID, $examination_repproved_subject_id);
                                                                 } else {
                                                                     if ($event->getSubject() instanceof pathway_commissionActions) {
                                                                         $criteria->add(CoursePeer::IS_PATHWAY, true);
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $criteria;
 }
Esempio n. 29
0
 public function executeExam(sfWebRequest $request)
 {
     $this->buildSubmenu($request);
     $id = $request->getParameter("id");
     $conn = Propel::getConnection();
     $this->courseObj = CoursePeer::retrieveByPK($id, $conn);
     if (!is_object($this->courseObj)) {
         $this->forward404();
     }
     if ($request->hasParameter("year") && trim($request->getParameter("year")) != "") {
         $this->year = $request->getParameter("year");
         $results = ExamPeer::getExamsForYearAndCourseId($id, $this->year, $conn);
         if (count($results) == 0) {
             $this->forward404();
         }
         $examArr = array();
         $testArr = array();
         $quizArr = array();
         $psetArr = array();
         foreach ($results as $exam) {
             switch ($exam->getType()) {
                 case EnumItemPeer::EXAM:
                     $examArr[] = array("descr" => $exam->getDescr(), "path" => $exam->getFilePath());
                     break;
                 case EnumItemPeer::TEST:
                     $testArr[] = array("descr" => $exam->getDescr(), "path" => $exam->getFilePath());
                     break;
                 case EnumItemPeer::QUIZ:
                     $quizArr[] = array("descr" => $exam->getDescr(), "path" => $exam->getFilePath());
                     break;
                 case EnumItemPeer::PROBLEM_SET:
                     $psetArr[] = array("descr" => $exam->getDescr(), "path" => $exam->getFilePath());
                     break;
             }
         }
         if (count($examArr) != 0) {
             $this->examArr = $examArr;
         }
         if (count($testArr) != 0) {
             $this->testArr = $testArr;
         }
         if (count($quizArr) != 0) {
             $this->quizArr = $quizArr;
         }
         if (count($psetArr) != 0) {
             $this->psetArr = $psetArr;
         }
     } else {
         $this->forward404();
     }
 }
Esempio n. 30
0
 public function executeSearchByProgram(sfWebRequest $request)
 {
     $conn = Propel::getConnection();
     $today = getdate();
     $this->searchType = searchActions::SEARCH_BY_PROGRAM;
     $rawProgList = DisciplinePeer::doSelectAll($conn);
     $this->programList = array();
     foreach ($rawProgList as $obj) {
         $this->programList[$obj->getId()] = $obj->getDescr();
     }
     $this->yearList = array("0" => "All", "1" => "First Year", "2" => "Second Year", "3" => "Third Year", "4" => "Fourth Year");
     if ($request->hasParameter("year") && $request->hasParameter("program")) {
         $this->programId = $request->getParameter("program");
         if (helperFunctions::isMaliciousString($this->programId)) {
             $this->forward404();
         }
         $this->year = $request->getParameter("year");
         if (helperFunctions::isMaliciousString($this->year)) {
             $this->forward404();
         }
         // get result set
         $discipline = DisciplinePeer::retrieveByPK($this->programId, $conn);
         if (!is_object($discipline)) {
             $this->forward404();
         }
         $this->resultTitle = "Results for " . $discipline->getDescr();
         $this->results = CoursePeer::findCoursesByDisciplineIdAndYear($this->programId, $this->year, $conn);
     } else {
         $this->programId = $rawProgList[0]->getId();
         $this->year = 1;
     }
 }