Exemplo n.º 1
0
 public function executeDelete(sfWebRequest $request)
 {
     $request->checkCSRFProtection();
     $this->forward404Unless($instructor = InstructorPeer::retrieveByPk($request->getParameter('id')), sprintf('Object instructor does not exist (%s).', $request->getParameter('id')));
     $instructor->delete();
     $this->redirect('admininstructor/index');
 }
Exemplo n.º 2
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);
     }
 }
 public static function getInstructorsForCourseAndYear($courseId, $year, PropelPDO $propelConnection)
 {
     $c = new Criteria();
     $c->addJoin(CourseInstructorAssociationPeer::INSTRUCTOR_ID, InstructorPeer::ID);
     $crit1 = $c->getNewCriterion(CourseInstructorAssociationPeer::COURSE_ID, $courseId);
     $crit2 = $c->getNewCriterion(CourseInstructorAssociationPeer::YEAR, $year);
     $c->addAnd($crit1);
     $c->addAnd($crit2);
     $c->addAscendingOrderByColumn(InstructorPeer::LAST_NAME);
     return InstructorPeer::doSelect($c, $propelConnection);
 }
Exemplo n.º 4
0
 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 = "";
         }
     }
 }
Exemplo n.º 5
0
 public function executeDelete(sfWebRequest $request)
 {
     $request->checkCSRFProtection();
     $this->forward404Unless($instructor = InstructorPeer::retrieveByPk($request->getParameter('id')), sprintf('Object instructor does not exist (%s).', $request->getParameter('id')));
     try {
         $instructor->delete();
         $par = "";
         if ($request->hasParameter("page")) {
             $par = "?page=" . $request->getParameter("page");
         }
         $this->redirect('admininstructor/index' . $par);
     } catch (Exception $e) {
         $this->globalErrors = $e->getMessage();
         $this->form = new InstructorForm($instructor);
         $this->getInsAssocListFromDB($instructor);
         $this->instructor_list = $this->getInstructorList();
         $this->setTemplate('index');
     }
 }
Exemplo n.º 6
0
 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();
     }
 }
Exemplo n.º 7
0
 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();
     }
 }
 /**
  * Selects a collection of InstructorDetail 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 InstructorDetail 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('BaseInstructorDetailPeer:doSelectJoinAll:doSelectJoinAll') as $callable) {
         call_user_func($callable, 'BaseInstructorDetailPeer', $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);
     }
     InstructorDetailPeer::addSelectColumns($c);
     $startcol2 = InstructorDetailPeer::NUM_COLUMNS - InstructorDetailPeer::NUM_LAZY_LOAD_COLUMNS;
     InstructorPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (InstructorPeer::NUM_COLUMNS - InstructorPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(InstructorDetailPeer::INSTRUCTOR_ID), array(InstructorPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = InstructorDetailPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = InstructorDetailPeer::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 = InstructorDetailPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             InstructorDetailPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Instructor rows
         $key2 = InstructorPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = InstructorPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = InstructorPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 InstructorPeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (InstructorDetail) to the collection in $obj2 (Instructor)
             $obj2->addInstructorDetail($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Exemplo n.º 9
0
 /**
  * Get the associated Instructor object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Instructor The associated Instructor object.
  * @throws     PropelException
  */
 public function getInstructor(PropelPDO $con = null)
 {
     if ($this->aInstructor === null && $this->instructor_id !== null) {
         $c = new Criteria(InstructorPeer::DATABASE_NAME);
         $c->add(InstructorPeer::ID, $this->instructor_id);
         $this->aInstructor = InstructorPeer::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->aInstructor->addInstructorDetails($this);
         		 */
     }
     return $this->aInstructor;
 }
 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.");
     }
 }
Exemplo n.º 11
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(InstructorPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(InstructorPeer::DATABASE_NAME);
         $criteria->add(InstructorPeer::ID, $pks, Criteria::IN);
         $objs = InstructorPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Exemplo n.º 12
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 = InstructorPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setLastName($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setFirstName($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setDeptId($arr[$keys[3]]);
     }
 }
Exemplo n.º 13
0
 public static function getAll(PropelPDO $propelConnection)
 {
     $c = new Criteria();
     $c->addAscendingOrderByColumn(InstructorPeer::LAST_NAME);
     return InstructorPeer::doSelect($c, $propelConnection);
 }
Exemplo n.º 14
0
 /**
  * Returns the number of related Instructor objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related Instructor objects.
  * @throws     PropelException
  */
 public function countInstructors(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(DepartmentPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collInstructors === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(InstructorPeer::DEPT_ID, $this->id);
             $count = InstructorPeer::doCount($criteria, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // 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 count of the collection.
             $criteria->add(InstructorPeer::DEPT_ID, $this->id);
             if (!isset($this->lastInstructorCriteria) || !$this->lastInstructorCriteria->equals($criteria)) {
                 $count = InstructorPeer::doCount($criteria, $con);
             } else {
                 $count = count($this->collInstructors);
             }
         } else {
             $count = count($this->collInstructors);
         }
     }
     return $count;
 }