public function get() { $returnStr = "<div id='left'>"; $returnStr .= $this->getMenuStud(); if ($this->_menuOption < subMenuOptions::MAINTENANCE) { // courses and search menu styling $conn = Propel::getConnection(); if (isset($this->_courseId)) { if (!isset($this->_ratingYearArray)) { // get rating data $this->_ratingYearArray = AutoCourseRatingPeer::getAvailableYearsForCourseId($this->_courseId, $conn); } if (!isset($this->_examYearArray)) { // get exam data $this->_examYearArray = ExamPeer::getAvailableYearsForCourseId($this->_courseId, $conn); } if ($this->_menuOption == subMenuOptions::COURSE) { $returnStr .= "<dl><dt>" . $this->_courseId . "</dt>"; } else { $returnStr .= "<dl><dt>" . link_to($this->_courseId, "course/index?id=" . $this->_courseId) . "</dt>"; } // critique $returnStr .= "<div class='popupmenu' id='subCritique' onmouseover='mcancelclosetime()' onmouseout='mclosetime()'>"; if (count($this->_ratingYearArray) == 0) { $returnStr .= "<a>None Available</a>"; } else { foreach ($this->_ratingYearArray as $year) { $returnStr .= link_to(helperFunctions::translateTerm($year), "course/critique?id=" . $this->_courseId . "&year=" . $year); } } $returnStr .= "</div>\n\t \t<dd><a class='pointer' onmouseover='mopen(\"subCritique\")' onmouseout='mclosetime()'>Course Critiques</a></dd>"; // exams $returnStr .= "<div class='popupmenu' id='subExam' onmouseover='mcancelclosetime()' onmouseout='mclosetime()'>"; if (count($this->_examYearArray) == 0) { $returnStr .= "<a>None Available</a>"; } else { foreach ($this->_examYearArray as $year) { $returnStr .= link_to(helperFunctions::translateTerm($year), "course/exam?id=" . $this->_courseId . "&year=" . $year); } } $returnStr .= "<a onclick='grayout(\"submitExam\");'>Submit Exams</a>"; $returnStr .= "</div>\n\t \t<dd><a class='pointer' onmouseover='mopen(\"subExam\")' onmouseout='mclosetime()'>Exams Repository</a></dd></dl>"; } } elseif ($this->_menuOption == subMenuOptions::MAINTENANCE) { //TODO: make maintenance menu $returnStr .= "<dl><dt>" . link_to("Maintenance", "maintenance/index") . "</dt>"; foreach (subMenuOptions::getMaintenanceSections() as $key => $value) { $returnStr .= "<dd>" . link_to($key, $value) . "</dd>"; } } elseif ($this->_menuOption == subMenuOptions::ERROR) { $returnStr .= "<dl><dt>Error</dt></dl>"; } $returnStr .= "</div>"; return $returnStr; }
public static function getExamsForYearAndCourseId($courseId, $year, PropelPDO $propelConnection) { $c = new Criteria(); $crit1 = $c->getNewCriterion(ExamPeer::COURSE_ID, $courseId); $crit2 = $c->getNewCriterion(ExamPeer::YEAR, $year); $c->addAnd($crit1); $c->addAnd($crit2); $c->addAscendingOrderByColumn(ExamPeer::TYPE); $c->addAscendingOrderByColumn(ExamPeer::DESCR); return ExamPeer::doSelect($c, $propelConnection); }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this EnumItem is new, it will return * an empty collection; or if this EnumItem has previously * been saved, it will retrieve related Exams from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in EnumItem. */ public function getExamsJoinCourse($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(EnumItemPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collExams === null) { if ($this->isNew()) { $this->collExams = array(); } else { $criteria->add(ExamPeer::TYPE, $this->id); $this->collExams = ExamPeer::doSelectJoinCourse($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(ExamPeer::TYPE, $this->id); if (!isset($this->lastExamCriteria) || !$this->lastExamCriteria->equals($criteria)) { $this->collExams = ExamPeer::doSelectJoinCourse($criteria, $con, $join_behavior); } } $this->lastExamCriteria = $criteria; return $this->collExams; }
private function buildSubmenu(sfWebRequest $request) { if (!$request->hasParameter("id") || trim($request->getParameter("id")) == "") { $this->forward404(); } // set cookie to remember $id = $request->getParameter("id"); //$this->getResponse()->setCookie('courseId', $id); $conn = Propel::getConnection(); // get rating data $this->ratingYearArray = AutoCourseRatingPeer::getAvailableYearsForCourseId($id, $conn); // get exam data $this->examYearArray = ExamPeer::getAvailableYearsForCourseId($id, $conn); }
/** * 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; }
protected function getExamList(Criteria $c = null) { if (isset($c)) { return ExamPeer::doSelect($c); } else { return ExamPeer::doSelect(new Criteria()); } }
protected function getExamList($courseId, $year) { $c = new Criteria(); $crit1 = $c->getNewCriterion(ExamPeer::COURSE_ID, $courseId); $crit2 = $c->getNewCriterion(ExamPeer::YEAR, $year); $c->addAnd($crit1); $c->addAnd($crit2); $c->addAscendingOrderByColumn(ExamPeer::TYPE); $c->addAscendingOrderByColumn(ExamPeer::DESCR); return ExamPeer::doSelectJoinEnumItem($c); }
/** * 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 = CoursePeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related CourseComment objects $c = new Criteria(CourseCommentPeer::DATABASE_NAME); $c->add(CourseCommentPeer::COURSE_ID, $obj->getId()); $affectedRows += CourseCommentPeer::doDelete($c, $con); // delete related CourseDetail objects $c = new Criteria(CourseDetailPeer::DATABASE_NAME); $c->add(CourseDetailPeer::COURSE_ID, $obj->getId()); $affectedRows += CourseDetailPeer::doDelete($c, $con); // delete related Exam objects $c = new Criteria(ExamPeer::DATABASE_NAME); $c->add(ExamPeer::COURSE_ID, $obj->getId()); $affectedRows += ExamPeer::doDelete($c, $con); } return $affectedRows; }
/** * 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(ExamPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(ExamPeer::DATABASE_NAME); $criteria->add(ExamPeer::ID, $pks, Criteria::IN); $objs = ExamPeer::doSelect($criteria, $con); } return $objs; }
/** * Get the associated Exam object * * @param PropelPDO Optional Connection object. * @return Exam The associated Exam object. * @throws PropelException */ public function getExam(PropelPDO $con = null) { if ($this->aExam === null && $this->exam_id !== null) { $c = new Criteria(ExamPeer::DATABASE_NAME); $c->add(ExamPeer::ID, $this->exam_id); $this->aExam = ExamPeer::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->aExam->addExamComments($this); */ } return $this->aExam; }
/** * 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 = ExamPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setCourseId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setType($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setYear($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setDescr($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setFilePath($arr[$keys[5]]); } }
/** * Selects a collection of ExamComment 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 ExamComment 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('BaseExamCommentPeer:doSelectJoinAll:doSelectJoinAll') as $callable) { call_user_func($callable, 'BaseExamCommentPeer', $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); } ExamCommentPeer::addSelectColumns($c); $startcol2 = ExamCommentPeer::NUM_COLUMNS - ExamCommentPeer::NUM_LAZY_LOAD_COLUMNS; ExamPeer::addSelectColumns($c); $startcol3 = $startcol2 + (ExamPeer::NUM_COLUMNS - ExamPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(ExamCommentPeer::EXAM_ID), array(ExamPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = ExamCommentPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = ExamCommentPeer::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 = ExamCommentPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); ExamCommentPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Exam rows $key2 = ExamPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = ExamPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = ExamPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); ExamPeer::addInstanceToPool($obj2, $key2); } // if obj2 loaded // Add the $obj1 (ExamComment) to the collection in $obj2 (Exam) $obj2->addExamComment($obj1); } // if joined row not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }