/** * 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; }
/** * Declares an association between this object and a Discipline object. * * @param Discipline $v * @return CourseDisciplineAssociation The current object (for fluent API support) * @throws PropelException */ public function setDiscipline(Discipline $v = null) { if ($v === null) { $this->setDisciplineId(NULL); } else { $this->setDisciplineId($v->getId()); } $this->aDiscipline = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the Discipline object, it will not be re-added. if ($v !== null) { $v->addCourseDisciplineAssociation($this); } return $this; }
/** * 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 Discipline $value A Discipline object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(Discipline $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }