Beispiel #1
0
 /**
  * Initializes the collCategories collection.
  *
  * By default this just sets the collCategories collection to an empty array (like clearcollCategories());
  * however, you may wish to override this method in your stub class to provide setting appropriate
  * to your application -- for example, setting the initial array to the values stored in database.
  *
  * @param      boolean $overrideExisting If set to true, the method call initializes
  *                                        the collection even if it is not empty
  *
  * @return void
  */
 public function initCategories($overrideExisting = true)
 {
     if (null !== $this->collCategories && !$overrideExisting) {
         return;
     }
     $collectionClassName = CategoryTableMap::getTableMap()->getCollectionClassName();
     $this->collCategories = new $collectionClassName();
     $this->collCategories->setModel('\\App\\Propel\\Category');
 }
Beispiel #2
0
 /**
  * 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();
 }
Beispiel #3
0
 /**
  * Performs a DELETE on the database, given a Category or Criteria object OR a primary key value.
  *
  * @param mixed               $values Criteria or Category object or primary key or array of primary keys
  *              which is used to create the DELETE statement
  * @param  ConnectionInterface $con the connection to use
  * @return int             The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
  *                         if supported by native driver or if emulated using Propel.
  * @throws PropelException Any exceptions caught during processing will be
  *                         rethrown wrapped into a PropelException.
  */
 public static function doDelete($values, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(CategoryTableMap::DATABASE_NAME);
     }
     if ($values instanceof Criteria) {
         // rename for clarity
         $criteria = $values;
     } elseif ($values instanceof \App\Propel\Category) {
         // it's a model object
         // create criteria based on pk values
         $criteria = $values->buildPkeyCriteria();
     } else {
         // it's a primary key, or an array of pks
         $criteria = new Criteria(CategoryTableMap::DATABASE_NAME);
         $criteria->add(CategoryTableMap::COL_CATEGORY_ID, (array) $values, Criteria::IN);
     }
     $query = CategoryQuery::create()->mergeWith($criteria);
     if ($values instanceof Criteria) {
         CategoryTableMap::clearInstancePool();
     } elseif (!is_object($values)) {
         // it's a primary key, or an array of pks
         foreach ((array) $values as $singleval) {
             CategoryTableMap::removeInstanceFromPool($singleval);
         }
     }
     return $query->delete($con);
 }
Beispiel #4
0
 /**
  * Initializes the $collNestedSetChildren collection.
  *
  * @return     void
  */
 public function initNestedSetChildren()
 {
     $collectionClassName = \App\Propel\Map\CategoryTableMap::getTableMap()->getCollectionClassName();
     $this->collNestedSetChildren = new $collectionClassName();
     $this->collNestedSetChildren->setModel('\\App\\Propel\\Category');
 }