/**
  * Declares an association between this object and a Instructor object.
  *
  * @param      Instructor $v
  * @return     InstructorDetail The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setInstructor(Instructor $v = null)
 {
     if ($v === null) {
         $this->setInstructorId(NULL);
     } else {
         $this->setInstructorId($v->getId());
     }
     $this->aInstructor = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Instructor object, it will not be re-added.
     if ($v !== null) {
         $v->addInstructorDetail($this);
     }
     return $this;
 }
 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.");
     }
 }
示例#3
0
 /**
  * Save the course_instructor_assocs
  * @param $instructor
  * @param $request
  * @return true if ready for saving, false otherwise
  */
 protected function parseInsAssoc(Instructor $instructor, sfWebRequest $request)
 {
     $conn = Propel::getConnection();
     // retrieve existing assoc objects
     $criteria = new Criteria();
     $criteria->addAscendingOrderByColumn(CourseInstructorAssociationPeer::YEAR);
     $criteria->addAscendingOrderByColumn(CourseInstructorAssociationPeer::COURSE_ID);
     $extObjs = $instructor->getCourseInstructorAssociations($criteria, $conn);
     $delList = $extObjs;
     for ($i = $this->date["year"] + 1; $i >= $this->earliestYear; $i--) {
         for ($j = 1; $j <= 9; $j += 4) {
             $year = $i . $j;
             // first get an array of items
             $itemArr = array();
             $token = strtok($request->getParameter("assoc[" . $year . "]"), $this->separator);
             while ($token !== false) {
                 if (trim($token) != "") {
                     $itemArr[] = $token;
                 }
                 $token = strtok($this->separator);
             }
             // check which ones exist, which ones are new and which ones need deletion
             foreach ($itemArr as $item) {
                 $cCode = substr($item, 0, 8);
                 $existed = false;
                 foreach ($extObjs as $obj) {
                     if ($obj->getCourseId() == $cCode && $obj->getYear() == $year) {
                         $existed = true;
                         $key = array_search($obj, $delList);
                         if ($key !== false) {
                             unset($delList[$key]);
                         }
                         break;
                     }
                 }
                 if (!$existed) {
                     // save the new assoc
                     $assoc = new CourseInstructorAssociation();
                     $assoc->setCourseId($cCode);
                     $assoc->setInstructorId($instructor->getId());
                     $assoc->setYear($year);
                     $assoc->save($conn);
                 }
             }
         }
     }
     // delete old assocs that no longer exist
     foreach ($delList as $obj) {
         $obj->delete($conn);
     }
     return true;
 }
示例#4
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Instructor $value A Instructor object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Instructor $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }