/** * The returned array will contain objects of the default type or * objects that inherit from the default. * * @param DataFetcherInterface $dataFetcher * @return array * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function populateObjects(DataFetcherInterface $dataFetcher) { $results = array(); // set the class once to avoid overhead in the loop $cls = static::getOMClass(false); // populate the object(s) while ($row = $dataFetcher->fetch()) { $key = CategoryTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); if (null !== ($obj = CategoryTableMap::getInstanceFromPool($key))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj->hydrate($row, 0, true); // rehydrate $results[] = $obj; } else { /** @var Category $obj */ $obj = new $cls(); $obj->hydrate($row); $results[] = $obj; CategoryTableMap::addInstanceToPool($obj, $key); } // if key exists } return $results; }
/** * Update the tree to allow insertion of a leaf at the specified position * * @param ConnectionInterface $con Connection to use. */ public static function fixLevels(ConnectionInterface $con = null) { $c = new Criteria(); $c->addAscendingOrderByColumn(ChildCategory::LEFT_COL); $dataFetcher = ChildCategoryQuery::create(null, $c)->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); // set the class once to avoid overhead in the loop $cls = CategoryTableMap::getOMClass(false); $level = null; // iterate over the statement while ($row = $dataFetcher->fetch()) { // hydrate object $key = CategoryTableMap::getPrimaryKeyHashFromRow($row, 0); /** @var $obj ChildCategory */ if (null === ($obj = CategoryTableMap::getInstanceFromPool($key))) { $obj = new $cls(); $obj->hydrate($row); CategoryTableMap::addInstanceToPool($obj, $key); } // compute level // Algorithm shamelessly stolen from sfPropelActAsNestedSetBehaviorPlugin // Probably authored by Tristan Rivoallan if ($level === null) { $level = 0; $i = 0; $prev = array($obj->getRightValue()); } else { while ($obj->getRightValue() > $prev[$i]) { $i--; } $level = ++$i; $prev[$i] = $obj->getRightValue(); } // update level in node if necessary if ($obj->getLevel() !== $level) { $obj->setLevel($level); $obj->save($con); } } $dataFetcher->close(); }