public function executeIndex(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(); } // courseDetail $detList = $this->courseObj->getCourseDetails(null, $conn); if (count($detList) > 0) { $this->courseDetail = $detList[0]; } // instructor $detList = CourseInstructorAssociationPeer::getLatestInstructorsForCourseId($this->courseObj->getId(), $conn); $newList = CourseInstructorAssociationPeer::getHistoricalInstructorsForCourseId($this->courseObj->getId(), $conn); if (count($detList) > 0) { $this->currentInstructorList = $detList; $this->pastInstructorList = $newList; } // program $detList = CourseDisciplineAssociationPeer::getRelatedDisciplinesForCourse($this->courseObj, $conn); if (count($detList) > 0) { $this->programList = $detList; } // full exam data $conn = Propel::getConnection(); $c = new Criteria(); $courseCrit = $c->getNewCriterion(ExamPeer::COURSE_ID, $this->courseObj->getId()); $c->addAnd($courseCrit); $c->addAscendingOrderByColumn(ExamPeer::YEAR); $c->addAscendingOrderByColumn(ExamPeer::TYPE); $c->addAscendingOrderByColumn(ExamPeer::DESCR); $examData = ExamPeer::doSelect($c, $conn); // now splice the data up and send it to the frontend $this->examData = array(); $year = ""; $type = ""; foreach ($examData as $exam) { if ($year != $exam->getYear()) { $year = $exam->getYear(); $this->examData[$year] = array(); $type = ""; } if ($type != $exam->getType()) { $type = $exam->getType(); $this->examData[$year][$type] = array(); } $this->examData[$year][$type][] = $exam; } }
public function executeList(sfWebRequest $request) { $c = new Criteria(); if ($request->getParameter('course') !== null || $request->getParameter('course') != '') { $c->add(CourseInstructorAssociationPeer::COURSE_ID, $request->getParameter('course')); $this->course_id = $request->getParameter('course'); } //check for instructor info if ($request->getParameter('instructor') !== null || $request->getParameter('instructor') != '') { $c->add(CourseInstructorAssociationPeer::INSTRUCTOR_ID, $request->getParameter('instructor')); $this->instruct_id = $request->getParameter('instructor'); } $this->course_instructor_association_list = CourseInstructorAssociationPeer::doSelect($c); }
public static function getAvailableInstructorsForCourseIdAndYear($courseId, $year, PropelPDO $conn) { $query = "SELECT DISTINCT %s as i FROM %s JOIN %s ON %s=%s WHERE %s='%s' AND %s=%s"; $query = sprintf($query, CourseInstructorAssociationPeer::ID, AutoCourseRatingPeer::TABLE_NAME, CourseInstructorAssociationPeer::TABLE_NAME, AutoCourseRatingPeer::COURSE_INS_ID, CourseInstructorAssociationPeer::ID, CourseInstructorAssociationPeer::COURSE_ID, $courseId, CourseInstructorAssociationPeer::YEAR, $year); $statement = $conn->prepare($query); $statement->execute(); $ids = $statement->fetchAll(PDO::FETCH_COLUMN, 0); $results = array(); $c = new Criteria(); $c->addJoin(CourseInstructorAssociationPeer::INSTRUCTOR_ID, InstructorPeer::ID); foreach ($ids as $id) { $crit = $c->getNewCriterion(CourseInstructorAssociationPeer::ID, $id); $c->addOr($crit); } $c->addAscendingOrderByColumn(InstructorPeer::LAST_NAME); $c->addAscendingOrderByColumn(InstructorPeer::FIRST_NAME); $raw = CourseInstructorAssociationPeer::doSelectJoinInstructor($c, $conn); foreach ($raw as $obj) { $results[] = $obj->getInstructor(); } return $results; }
/** * Get the associated CourseInstructorAssociation object * * @param PropelPDO Optional Connection object. * @return CourseInstructorAssociation The associated CourseInstructorAssociation object. * @throws PropelException */ public function getCourseInstructorAssociation(PropelPDO $con = null) { if ($this->aCourseInstructorAssociation === null && $this->course_ins_id !== null) { $c = new Criteria(CourseInstructorAssociationPeer::DATABASE_NAME); $c->add(CourseInstructorAssociationPeer::ID, $this->course_ins_id); $this->aCourseInstructorAssociation = CourseInstructorAssociationPeer::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->aCourseInstructorAssociation->addCourseRatings($this); */ } return $this->aCourseInstructorAssociation; }
/** * 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 = CourseInstructorAssociationPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setInstructorId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setCourseId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setYear($arr[$keys[3]]); } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Course is new, it will return * an empty collection; or if this Course has previously * been saved, it will retrieve related CourseInstructorAssociations 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 Course. */ public function getCourseInstructorAssociationsJoinInstructor($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(CoursePeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collCourseInstructorAssociations === null) { if ($this->isNew()) { $this->collCourseInstructorAssociations = array(); } else { $criteria->add(CourseInstructorAssociationPeer::COURSE_ID, $this->id); $this->collCourseInstructorAssociations = CourseInstructorAssociationPeer::doSelectJoinInstructor($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(CourseInstructorAssociationPeer::COURSE_ID, $this->id); if (!isset($this->lastCourseInstructorAssociationCriteria) || !$this->lastCourseInstructorAssociationCriteria->equals($criteria)) { $this->collCourseInstructorAssociations = CourseInstructorAssociationPeer::doSelectJoinInstructor($criteria, $con, $join_behavior); } } $this->lastCourseInstructorAssociationCriteria = $criteria; return $this->collCourseInstructorAssociations; }
public function saveToDatabase() { if (isset($this->_infoArr) && isset($this->_mappingArr)) { $err = ""; $conn = Propel::getConnection(); $dt = date("Y-m-d, H:i:s"); $len = count($this->_infoArr); for ($i = 0; $i < $len; $i++) { $course = CoursePeer::retrieveByPK($this->_infoArr[$i]["courseCode"]); if (!isset($course)) { // new course found, save to db $course = new Course(); $course->setDescr($this->_infoArr[$i]["courseName"]); $course->setIsEng(1); $course->setDeptId(substr($this->_infoArr[$i]["courseCode"], 0, 3)); $course->setId($this->_infoArr[$i]["courseCode"]); $course->save($conn); } elseif ($course->getDescr() == $course->getId()) { // exam importer registers course description as course id // if we encounter this situation, amend it with the proper description $course->setDescr($this->_infoArr[$i]["courseName"]); $course->save($conn); } try { $instr = InstructorPeer::findInstructorByName($this->_infoArr[$i]["instrFirstName"], $this->_infoArr[$i]["instrLastName"], $conn); } catch (Exception $e) { if ($e->getCode() == 1) { // no instructor found $instr = new Instructor(); $instr->setFirstName($this->_infoArr[$i]["instrFirstName"]); $instr->setLastName($this->_infoArr[$i]["instrLastName"]); $instr->setDeptId($course->getDeptId()); $instr->save($conn); } else { // TODO: big problem, duplicate instructors found // log error and move on continue; } } // create CourseInstructorAssociation if it doesn't exist try { $assoc = CourseInstructorAssociationPeer::findForYearAndInstructorIdAndCourseId($this->_year, $course->getId(), $instr->getId(), $conn); } catch (Exception $e) { if ($e->getCode() == 1) { // create new object $assoc = new CourseInstructorAssociation(); $assoc->setYear($this->_year); $assoc->setCourseId($course->getId()); $assoc->setInstructorId($instr->getId()); $assoc->save($conn); } else { // TODO: big problem, duplicate assocs found // log error and move on continue; } } // we can now save the real rating data $ratingArr = $this->_ratingArr[$i]; foreach ($ratingArr as $fieldId => $data) { foreach ($data as $rating => $number) { $ratingObj = new AutoCourseRating(); $ratingObj->setFieldId($fieldId); $ratingObj->setRating($rating); $ratingObj->setNumber($number); $ratingObj->setImportDt($dt); $ratingObj->setCourseInsId($assoc->getId()); $ratingObj->save(); } } } } else { throw new Exception("readCsv method has not been called."); } }
/** * 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 = InstructorPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related CourseInstructorAssociation objects $c = new Criteria(CourseInstructorAssociationPeer::DATABASE_NAME); $c->add(CourseInstructorAssociationPeer::INSTRUCTOR_ID, $obj->getId()); $affectedRows += CourseInstructorAssociationPeer::doDelete($c, $con); // delete related InstructorDetail objects $c = new Criteria(InstructorDetailPeer::DATABASE_NAME); $c->add(InstructorDetailPeer::INSTRUCTOR_ID, $obj->getId()); $affectedRows += InstructorDetailPeer::doDelete($c, $con); } return $affectedRows; }
/** * Selects a collection of AutoCourseRating objects pre-filled with all related objects except RatingField. * * @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 AutoCourseRating objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptRatingField(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { foreach (sfMixer::getCallables('BaseAutoCourseRatingPeer:doSelectJoinAllExcept:doSelectJoinAllExcept') as $callable) { call_user_func($callable, 'BaseAutoCourseRatingPeer', $c, $con); } $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } AutoCourseRatingPeer::addSelectColumns($c); $startcol2 = AutoCourseRatingPeer::NUM_COLUMNS - AutoCourseRatingPeer::NUM_LAZY_LOAD_COLUMNS; CourseInstructorAssociationPeer::addSelectColumns($c); $startcol3 = $startcol2 + (CourseInstructorAssociationPeer::NUM_COLUMNS - CourseInstructorAssociationPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(AutoCourseRatingPeer::COURSE_INS_ID), array(CourseInstructorAssociationPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = AutoCourseRatingPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = AutoCourseRatingPeer::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 = AutoCourseRatingPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); AutoCourseRatingPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined CourseInstructorAssociation rows $key2 = CourseInstructorAssociationPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = CourseInstructorAssociationPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = CourseInstructorAssociationPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); CourseInstructorAssociationPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (AutoCourseRating) to the collection in $obj2 (CourseInstructorAssociation) $obj2->addAutoCourseRating($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
public function executeCritique(sfWebRequest $request) { $this->buildSubmenu($request); $id = $request->getParameter("id"); $conn = Propel::getConnection(); $this->courseObj = CoursePeer::retrieveByPK($id, $conn); if ($request->hasParameter("year") && trim($request->getParameter("year")) != "") { $year = $request->getParameter("year"); // check if the year exists $yearArray = AutoCourseRatingPeer::getAvailableYearsForCourseId($id, $conn); $err = true; foreach ($yearArray as $y) { if ($year == $y) { $err = false; break; } } if ($err) { $this->forward404(); } $this->year = $year; $this->instructorArr = CourseInstructorAssociationPeer::getInstructorsForCourseAndYear($id, $year, $conn); if ($request->hasParameter("instructor")) { $insId = $request->getParameter("instructor"); } else { $insId = $this->instructorArr[0]->getId(); } $this->currInstructor = InstructorPeer::retrieveByPK($insId, $conn); // note that the below logic is predicated on getCourseDataArrayForCourseAndInstructorAndYear // sorting by Field, Id, Rating, in the respective order $dataObjArr = AutoCourseRatingPeer::getCourseDataArrayForCourseAndInstructorAndYear($id, $insId, $year, $conn); // $dataArr is an array of dictionaries (arr) that contain ratings/info $this->dataArr = array(); // $arr = dictionary $arr = array(); foreach ($dataObjArr as $obj) { // this sytem does not differentiate between different sections // when multiple sections with the SAME instructor is encountered, the data are aggregated switch ($obj->getFieldId()) { case RatingFieldPeer::NUMBER_ENROLLED: // number enrolled, special field if (isset($this->numberEnrolled)) { $this->numberEnrolled += $obj->getNumber(); } else { $this->numberEnrolled = $obj->getNumber(); } break; case RatingFieldPeer::NUMBER_RESPONDED: // number responded, special field if (isset($this->numberResponded)) { $this->numberResponded += $obj->getNumber(); } else { $this->numberResponded = $obj->getNumber(); } break; case RatingFieldPeer::RETAKE: // percent retake if (isset($this->retake)) { $this->retake += $obj->getNumber(); } else { $this->retake = $obj->getNumber(); } break; default: // ordinary rating data if (!isset($currentNode)) { $currentNode = $obj->getFieldId(); $arr["type"] = $obj->getRatingField()->getRatingTypeString($conn); $arr["field"] = $obj->getRatingField()->getDescr(); $arr["instructor"] = $obj->getCourseInstructorAssociation($conn)->getInstructor()->getLastName(); $arr["typeObj"] = $obj->getRatingField()->getEnumItem($conn); } if ($currentNode != $obj->getFieldId()) { $arr = $this->setMeanAndMedian($arr); $arr["chart"] = $this->getFusionChartFromDataArr($arr); $this->dataArr[] = $arr; unset($arr); $currentNode = $obj->getFieldId(); $arr["type"] = $obj->getRatingField()->getRatingTypeString($conn); $arr["field"] = $obj->getRatingField()->getDescr(); $arr["instructor"] = $obj->getCourseInstructorAssociation($conn)->getInstructor()->getLastName(); $arr["typeObj"] = $obj->getRatingField()->getEnumItem($conn); } if (isset($arr[$obj->getRating()])) { $arr[$obj->getRating()] += $obj->getNumber(); } else { $arr[$obj->getRating()] = $obj->getNumber(); } break; } } // for the last critique field $arr = $this->setMeanAndMedian($arr); // $arr["NA"] = number who did not respond to this question $arr["chart"] = $this->getFusionChartFromDataArr($arr); $this->dataArr[] = $arr; $this->aggregatedRating = $this->calcAggregatedRating($this->dataArr); } else { $this->forward404(); } }
/** * 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 CourseSection objects $c = new Criteria(CourseSectionPeer::DATABASE_NAME); $c->add(CourseSectionPeer::COURSE_ID, $obj->getId()); $affectedRows += CourseSectionPeer::doDelete($c, $con); // delete related CourseTypeAssociation objects $c = new Criteria(CourseTypeAssociationPeer::DATABASE_NAME); $c->add(CourseTypeAssociationPeer::COURSE_ID, $obj->getId()); $affectedRows += CourseTypeAssociationPeer::doDelete($c, $con); // delete related CourseInstructorAssociation objects $c = new Criteria(CourseInstructorAssociationPeer::DATABASE_NAME); $c->add(CourseInstructorAssociationPeer::COURSE_ID, $obj->getId()); $affectedRows += CourseInstructorAssociationPeer::doDelete($c, $con); // delete related CourseDisciplineAssociation objects $c = new Criteria(CourseDisciplineAssociationPeer::DATABASE_NAME); $c->add(CourseDisciplineAssociationPeer::COURSE_ID, $obj->getId()); $affectedRows += CourseDisciplineAssociationPeer::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(CourseInstructorAssociationPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(CourseInstructorAssociationPeer::DATABASE_NAME); $criteria->add(CourseInstructorAssociationPeer::ID, $pks, Criteria::IN); $objs = CourseInstructorAssociationPeer::doSelect($criteria, $con); } return $objs; }