public function executeSearchByInstructor(sfWebRequest $request) { $conn = Propel::getConnection(); $today = getdate(); $this->searchType = searchActions::SEARCH_BY_INSTRUCTOR; $this->instructorList = array(); $this->categoryList = array(); for ($i = 'A'; $i != 'AA'; $i++) { $this->categoryList[$i] = $i; } if ($request->hasParameter("instructor")) { // we're searching for a specific instructor $this->instructorId = $request->getParameter("instructor"); if (helperFunctions::isMaliciousString($this->instructorId)) { $this->forward404(); } // get result set $instrObj = InstructorPeer::retrieveByPK($this->instructorId, $conn); if (!is_object($instrObj)) { $this->forward404(); } $lastname = $instrObj->getLastName(); $this->category = strtoupper(substr($lastname, 0, 1)); $this->resultTitle = "Results for " . $lastname . ", " . $instrObj->getFirstName(); $this->results = CoursePeer::findCoursesByInstructorId($this->instructorId, $conn); } elseif ($request->hasParameter("category")) { // we're searching for the initial of last name of an instructor $this->category = strtoupper($request->getParameter("category")); if (helperFunctions::isMaliciousString($this->category)) { $this->forward404(); } } else { // no constraint specified, display category='A' $this->category = 'A'; } $rawInstrList = InstructorPeer::findInstructorByLastNameInitial($this->category, $conn); foreach ($rawInstrList as $obj) { $this->instructorList[$obj->getId()] = $obj->getLastName() . ", " . $obj->getFirstName(); } if (!isset($this->instructorId)) { if (isset($rawInstrList[0])) { $this->instructorId = $rawInstrList[0]->getId(); } else { $this->instructorId = ""; } } }
public function executeSearchByInstructor(sfWebRequest $request) { $conn = Propel::getConnection(); $today = getdate(); $this->searchType = searchActions::SEARCH_BY_INSTRUCTOR; $rawInstrList = InstructorPeer::getAll($conn); $this->instructorList = array(); foreach ($rawInstrList as $obj) { $this->instructorList[$obj->getId()] = $obj->getLastName() . ", " . $obj->getFirstName(); } if ($request->hasParameter("instructor")) { $this->instructorId = $request->getParameter("instructor"); if (helperFunctions::isMaliciousString($this->instructorId)) { $this->forward404(); } // get result set $instrObj = InstructorPeer::retrieveByPK($this->instructorId, $conn); $this->resultTitle = "Results for " . $instrObj->getLastName() . ", " . $instrObj->getFirstName(); $this->results = CoursePeer::findCoursesByInstructorId($this->instructorId, $conn); } else { $this->instructorId = $rawInstrList[0]->getId(); } }
public function executeCritique(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")) != "") { $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 = AutoCourseRatingPeer::getAvailableInstructorsForCourseIdAndYear($id, $year, $conn); if ($request->hasParameter("instructor")) { $insId = $request->getParameter("instructor"); $found = false; foreach ($this->instructorArr as $ins) { if ($ins->getId() == $insId) { $found = true; break; } } if (!$found) { $this->forward404("ins not found"); } } 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(); $_prv = false; 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 ($obj->getRating() == 1) { if (isset($this->retakeYes)) { $this->retakeYes += $obj->getNumber(); } else { $this->retakeYes = $obj->getNumber(); } } else { if (isset($this->retakeNo)) { $this->retakeNo += $obj->getNumber(); } else { $this->retakeNo = $obj->getNumber(); } } break; default: // ordinary rating data $_prv = true; 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 if ($_prv) { $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(); } }