public function executeProduct(sfWebRequest $request) { //возвращаем объект json для нашего фронтенд // заголовок $this->getResponse()->setContentType('application/json'); //реализован ОРМ Пропел, испотльзуем его прелести + дописаные кастомные методы; $productID = $request->getParameter('id'); $product = ProductPeer::retrieveByPK($productID); if (is_object($product)) { $result = ProductPeer::getProductDetails($productID); } else { $result = array(); } $data_json = json_encode($result); return $this->renderText($data_json); }
/** * 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 = ProductPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setPrice($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setAPrimaryString($arr[$keys[2]]); } }
/** * Selects a collection of CategoryHasProduct objects pre-filled with all related objects except Category. * * @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 CategoryHasProduct objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptCategory(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden // $criteria->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(self::DATABASE_NAME); } CategoryHasProductPeer::addSelectColumns($criteria); $startcol2 = CategoryHasProductPeer::NUM_COLUMNS - CategoryHasProductPeer::NUM_LAZY_LOAD_COLUMNS; ProductPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (ProductPeer::NUM_COLUMNS - ProductPeer::NUM_LAZY_LOAD_COLUMNS); $criteria->addJoin(CategoryHasProductPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior); // symfony_behaviors behavior foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) { call_user_func($sf_hook, 'BaseCategoryHasProductPeer', $criteria, $con); } $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = CategoryHasProductPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = CategoryHasProductPeer::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 = CategoryHasProductPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); CategoryHasProductPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Product rows $key2 = ProductPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = ProductPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = ProductPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); ProductPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (CategoryHasProduct) to the collection in $obj2 (Product) $obj2->addCategoryHasProduct($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Get the associated Product object * * @param PropelPDO Optional Connection object. * @return Product The associated Product object. * @throws PropelException */ public function getProduct(PropelPDO $con = null) { if ($this->aProduct === null && $this->id !== null) { $this->aProduct = ProductPeer::retrieveByPk($this->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->aProduct->addTranslations($this); */ } return $this->aProduct; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @return Product[] * @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(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(ProductPeer::DATABASE_NAME); $criteria->add(ProductPeer::ENTITY_ID, $pks, Criteria::IN); $objs = ProductPeer::doSelect($criteria, $con); } return $objs; }
public function executeProducts() { $this->products = ProductPeer::doSelect(new Criteria()); }
/** * Find object by primary key using raw SQL to go fast. * Bypass doSelect() and the object formatter by using generated code. * * @param mixed $key Primary key to use for the query * @param PropelPDO $con A connection object * * @return Product A model object, or null if the key is not found * @throws PropelException */ protected function findPkSimple($key, $con) { $sql = 'SELECT `id`, `name`, `created_at`, `deleted`, `data` FROM `product` WHERE `id` = :p0'; try { $stmt = $con->prepare($sql); $stmt->bindValue(':p0', $key, PDO::PARAM_INT); $stmt->execute(); } catch (Exception $e) { Propel::log($e->getMessage(), Propel::LOG_ERR); throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e); } $obj = null; if ($row = $stmt->fetch(PDO::FETCH_NUM)) { $obj = new Product(); $obj->hydrate($row); ProductPeer::addInstanceToPool($obj, (string) $key); } $stmt->closeCursor(); return $obj; }
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = ProductPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setLabel($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setImage($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setShortDescription($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setDescription($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setPrice($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setCurrency($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setCreatedAt($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setUpdatedAt($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setPublicationStatus($arr[$keys[9]]); } }
public function getProduct($con = null) { if ($this->aProduct === null && $this->id !== null) { include_once 'lib/model/om/BaseProductPeer.php'; $this->aProduct = ProductPeer::retrieveByPK($this->id, $con); } return $this->aProduct; }
public static function doSelectJoinAll(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { foreach (sfMixer::getCallables('BaseProductI18nPeer:doSelectJoinAll:doSelectJoinAll') as $callable) { call_user_func($callable, 'BaseProductI18nPeer', $c, $con); } $c = clone $c; if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } ProductI18nPeer::addSelectColumns($c); $startcol2 = ProductI18nPeer::NUM_COLUMNS - ProductI18nPeer::NUM_LAZY_LOAD_COLUMNS; ProductPeer::addSelectColumns($c); $startcol3 = $startcol2 + (ProductPeer::NUM_COLUMNS - ProductPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(ProductI18nPeer::ID), array(ProductPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = ProductI18nPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = ProductI18nPeer::getInstanceFromPool($key1))) { } else { $omClass = ProductI18nPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); ProductI18nPeer::addInstanceToPool($obj1, $key1); } $key2 = ProductPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = ProductPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = ProductPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); ProductPeer::addInstanceToPool($obj2, $key2); } $obj2->addProductI18n($obj1); } $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * 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 BasePeer::TYPE_PHPNAME * * @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 = ProductPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setName($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setCreatedAt($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setDeleted($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setData($arr[$keys[4]]); } }
/** * 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 BasePeer::TYPE_PHPNAME * * @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 = ProductPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setEntityId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setName($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setPrice($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setSku($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setDateCreated($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setCategoryId($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setUrlKey($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setProductImage($arr[$keys[7]]); } }
/** * 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 = ProductPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setTitle($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setDescription($arr[$keys[2]]); } }
public static function doSelectJoinAll(Criteria $c, $con = null) { $c = clone $c; if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } ProductI18nPeer::addSelectColumns($c); $startcol2 = ProductI18nPeer::NUM_COLUMNS - ProductI18nPeer::NUM_LAZY_LOAD_COLUMNS + 1; ProductPeer::addSelectColumns($c); $startcol3 = $startcol2 + ProductPeer::NUM_COLUMNS; $c->addJoin(ProductI18nPeer::ID, ProductPeer::ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = ProductI18nPeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); $omClass = ProductPeer::getOMClass(); $cls = Propel::import($omClass); $obj2 = new $cls(); $obj2->hydrate($rs, $startcol2); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj2 = $temp_obj1->getProduct(); if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addProductI18n($obj1); break; } } if ($newObject) { $obj2->initProductI18ns(); $obj2->addProductI18n($obj1); } $results[] = $obj1; } return $results; }
/** * Selects a collection of {@link Product} objects with a {@link ProductI18n} translation populated. * * @param Criteria $criteria * @param string $culture * @param PropelPDO $con * @param string $join_behavior * * @return array */ public static function doSelectWithI18n(Criteria $criteria, $culture = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; if (null === $culture) { $culture = sfPropel::getDefaultCulture(); } // Set the correct dbName if it has not been overridden if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(self::DATABASE_NAME); } ProductPeer::addSelectColumns($criteria); $startcol = ProductPeer::NUM_COLUMNS - ProductPeer::NUM_LAZY_LOAD_COLUMNS; ProductI18nPeer::addSelectColumns($criteria); $criteria->addJoin(ProductPeer::ID, ProductI18nPeer::ID, $join_behavior); $criteria->add(ProductI18nPeer::CULTURE, $culture); foreach (sfMixer::getCallables('BaseProduct:doSelectJoin:doSelectJoin') as $sf_hook) { call_user_func($sf_hook, 'Product', $criteria, $con); } $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = ProductPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = ProductPeer::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 = ProductPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); ProductPeer::addInstanceToPool($obj1, $key1); } // if $obj1 already loaded $key2 = ProductI18nPeer::getPrimaryKeyHashFromRow($row, $startcol); if ($key2 !== null) { $obj2 = ProductI18nPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = ProductI18nPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol); ProductI18nPeer::addInstanceToPool($obj2, $key2); } // if obj2 already loaded $obj1->setTranslationForCulture($obj2, $culture); } // if joined row was not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
public function getProduct(PropelPDO $con = null) { if ($this->aProduct === null && $this->id !== null) { $c = new Criteria(ProductPeer::DATABASE_NAME); $c->add(ProductPeer::ID, $this->id); $this->aProduct = ProductPeer::doSelectOne($c, $con); } return $this->aProduct; }
/** * Selects a collection of ProductPlugin objects pre-filled with all related objects except Plugin. * * @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 ProductPlugin objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptPlugin(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden // $criteria->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(ProductPluginPeer::DATABASE_NAME); } ProductPluginPeer::addSelectColumns($criteria); $startcol2 = ProductPluginPeer::NUM_HYDRATE_COLUMNS; ProductPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + ProductPeer::NUM_HYDRATE_COLUMNS; $criteria->addJoin(ProductPluginPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior); $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = ProductPluginPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = ProductPluginPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://www.propelorm.org/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = ProductPluginPeer::getOMClass(); $obj1 = new $cls(); $obj1->hydrate($row); ProductPluginPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Product rows $key2 = ProductPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = ProductPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = ProductPeer::getOMClass(); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); ProductPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (ProductPlugin) to the collection in $obj2 (Product) $obj2->addProductPlugin($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * 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 = ProductPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setTitle($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setContent($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setSize($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setComplement($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setSpecifications($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setAssortment($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setCreatedAt($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setUpdatedAt($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setMetaDescription($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setMetaKeywords($arr[$keys[10]]); } }