protected function addSortCriteria($criteria) { if (array(null, null) == ($sort = $this->getSort())) { return; } $column = ElementPeer::translateFieldName($sort[0], BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME); if ('asc' == $sort[1]) { $criteria->addAscendingOrderByColumn($column); } else { $criteria->addDescendingOrderByColumn($column); } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Category is new, it will return * an empty collection; or if this Category has previously * been saved, it will retrieve related Elements from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Category. */ public function getElementsJoinCompany($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(CategoryPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collElements === null) { if ($this->isNew()) { $this->collElements = array(); } else { $criteria->add(ElementPeer::CATEGORY_ID, $this->id); $this->collElements = ElementPeer::doSelectJoinCompany($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(ElementPeer::CATEGORY_ID, $this->id); if (!isset($this->lastElementCriteria) || !$this->lastElementCriteria->equals($criteria)) { $this->collElements = ElementPeer::doSelectJoinCompany($criteria, $con, $join_behavior); } } $this->lastElementCriteria = $criteria; return $this->collElements; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = ElementPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setCategoryId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setElementStatusId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setCompanyId($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setName($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setTitle($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setDateCreated($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setDateUpdated($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setPreview($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setDescription($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setViewCount($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setOrderCount($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setOwnerPrice($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setCompanyPrice($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setPriceType($arr[$keys[14]]); } }
/** * Description : Retrieves the elements of a production * * @param String $idProduction : The id of a production * @return : Returns a collection of elements */ public function retrieveProduction($idProduction) { try { $criteria = new Criteria(); $criteria->add(ElementPeer::PRODUCTION_ID, $idProduction); return ElementPeer::doSelect($criteria); } catch (Exception $e) { return null; } }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(ElementPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(ElementPeer::DATABASE_NAME); $criteria->add(ElementPeer::ID, $pks, Criteria::IN); $objs = ElementPeer::doSelect($criteria, $con); } return $objs; }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = ElementStatusPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related Element objects $criteria = new Criteria(ElementPeer::DATABASE_NAME); $criteria->add(ElementPeer::ELEMENT_STATUS_ID, $obj->getId()); $affectedRows += ElementPeer::doDelete($criteria, $con); } return $affectedRows; }
/** * Get the associated Element object * * @param PropelPDO Optional Connection object. * @return Element The associated Element object. * @throws PropelException */ public function getElement(PropelPDO $con = null) { if ($this->aElement === null && $this->element_id !== null) { $this->aElement = ElementPeer::retrieveByPk($this->element_id); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aElement->addElementFiles($this); */ } return $this->aElement; }
/** * Selects a collection of ElementFile objects pre-filled with all related objects. * * @param Criteria $criteria * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of ElementFile objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(self::DATABASE_NAME); } ElementFilePeer::addSelectColumns($criteria); $startcol2 = ElementFilePeer::NUM_COLUMNS - ElementFilePeer::NUM_LAZY_LOAD_COLUMNS; ElementPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (ElementPeer::NUM_COLUMNS - ElementPeer::NUM_LAZY_LOAD_COLUMNS); $criteria->addJoin(ElementFilePeer::ELEMENT_ID, ElementPeer::ID, $join_behavior); // symfony_behaviors behavior foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) { call_user_func($sf_hook, 'BaseElementFilePeer', $criteria, $con); } $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = ElementFilePeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = ElementFilePeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = ElementFilePeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); ElementFilePeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Element rows $key2 = ElementPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = ElementPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = ElementPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); ElementPeer::addInstanceToPool($obj2, $key2); } // if obj2 loaded // Add the $obj1 (ElementFile) to the collection in $obj2 (Element) $obj2->addElementFile($obj1); } // if joined row not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * This function performs the validation work for complex object models. * * In addition to checking the current object, all related objects will * also be validated. If all pass then <code>true</code> is returned; otherwise * an aggreagated array of ValidationFailed objects will be returned. * * @param array $columns Array of column names to validate. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise. */ protected function doValidate($columns = null) { if (!$this->alreadyInValidation) { $this->alreadyInValidation = true; $retval = null; $failureMap = array(); // We call the validate method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aProduction !== null) { if (!$this->aProduction->validate($columns)) { $failureMap = array_merge($failureMap, $this->aProduction->getValidationFailures()); } } if (($retval = ElementPeer::doValidate($this, $columns)) !== true) { $failureMap = array_merge($failureMap, $retval); } $this->alreadyInValidation = false; } return !empty($failureMap) ? $failureMap : true; }
public function executeView(sfWebRequest $request) { $element = ElementPeer::retrieveByPk($request->getParameter('element_id')); $this->forward404Unless($element); $this->element = $element; }
/** * Returns the number of related Elements. * * @param Criteria $criteria * @param boolean $distinct * @param Connection $con * @throws PropelException */ public function countElements($criteria = null, $distinct = false, $con = null) { // include the Peer class include_once 'src/model/whiteboard/om/BaseElementPeer.php'; if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } $criteria->add(ElementPeer::PRODUCTION_ID, $this->getProductionId()); return ElementPeer::doCount($criteria, $distinct, $con); }