/**
  * 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      CourseDisciplineAssociation $value A CourseDisciplineAssociation object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(CourseDisciplineAssociation $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Пример #2
0
 /**
  * Save the course_discipline_assocs
  * @param $discipline
  * @param $request
  * @return true if ready for saving, false otherwise
  */
 protected function parseDisAssoc(Discipline $discipline, sfWebRequest $request)
 {
     $conn = Propel::getConnection();
     // retrieve existing assoc objects
     $criteria = new Criteria();
     $criteria->addAscendingOrderByColumn(CourseDisciplineAssociationPeer::YEAR_OF_STUDY);
     $criteria->addAscendingOrderByColumn(CourseDisciplineAssociationPeer::COURSE_ID);
     $extObjs = $discipline->getCourseDisciplineAssociations($criteria, $conn);
     $delList = $extObjs;
     for ($year = 1; $year <= 4; $year++) {
         // 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->getYearOfStudy() == $year) {
                     $existed = true;
                     $key = array_search($obj, $delList);
                     if ($key !== false) {
                         unset($delList[$key]);
                     }
                     break;
                 }
             }
             if (!$existed) {
                 // save the new assoc
                 $assoc = new CourseDisciplineAssociation();
                 $assoc->setCourseId($cCode);
                 $assoc->setDisciplineId($discipline->getId());
                 $assoc->setYearOfStudy($year);
                 $assoc->save($conn);
             }
         }
     }
     // delete old assocs that no longer exist
     foreach ($delList as $obj) {
         $obj->delete($conn);
     }
     return true;
 }