public function deleteItemsFormularios() { $c = new Criteria(); $c->addJoin(ItemPeer::ID_ITEM_BASE, ItemBasePeer::ID_ITEM_BASE); $c->add(ItemBasePeer::ID_CAMPO, $this->getIdCampo(), Criteria::EQUAL); ItemPeer::doDelete($c); }
public function executeDelete(sfWebRequest $request) { $request->checkCSRFProtection(); $this->forward404Unless($Item = ItemPeer::retrieveByPk($request->getParameter('id')), sprintf('Object Item does not exist (%s).', $request->getParameter('id'))); $Item->delete(); $this->redirect('item/index'); }
public function getData($hero, $heroLevel, $items = array()) { $data = array(); //array_merge($data,$this->getHeroData(HeroPeer::retrieveByPK($hero),$heroLevel)); $data = $this->getHeroData(HeroPeer::retrieveByPK($hero), $heroLevel); if (!empty($items)) { foreach ($items as $item) { $data[] = $this->getItemData(ItemPeer::retrieveByPK($item)); } } return $data; }
public function executeSelectionSection() { // retrieve heroes // $this->heroes = HeroPeer::retrieveAll(); // $this->items = ItemPeer::retrieveAll(); $this->groupItems($this->items); $this->sentinelHeroes = HeroPeer::retrieveByAffiliation(HeroAffiliationPeer::retrieveByName('Sentinel')); $this->groupHeroes($this->sentinelHeroes); $this->scourgeHeroes = HeroPeer::retrieveByAffiliation(HeroAffiliationPeer::retrieveByName('Scourge')); $this->groupHeroes($this->scourgeHeroes); }
public function executeRightBox() { $category = $this->getRequestParameter('category'); $c = new Criteria(); $c->add(ItemPeer::IS_ACTIVE, true); $c->addDescendingOrderByColumn(ItemPeer::CREATED_AT); if ($category) { $c->add(ItemPeer::ITEM_TYPE_ID, $category); } $this->items = ItemPeer::doSelect($c); $this->itemTypes = ItemTypePeer::doSelect(new Criteria()); $this->user = $this->getUser()->getRaykuUser(); }
/** * Takes a Feed object and updates the Item table with new entries on that feed * Returns number of new records added **/ protected function updateFeed($feedRecord) { $feed = $this->getFeed($feedRecord->getLink()); echo "Feed: ", $feedRecord->getLink(), " (", count($feed->entries), " items)\n"; $itemCriteria = new Criteria(); $newItems = 0; // Short circuit if the feed parsing failed if (empty($feed) || empty($feed->entries)) { echo "ERROR: Returned feed not valid, or empty\n"; return 0; } foreach ($feed->entries as $entry) { //echo $entry->title, "\n"; // Check whether this entry already exists $itemCriteria->add(ItemPeer::ATOMID, $entry->id, Criteria::EQUAL); $num = ItemPeer::doCount($itemCriteria); // Skip the current entry if we already have it if ($num > 0) { //echo "INFO: Duplicate atom id: {$entry->id}. Skipping\n"; continue; } // Create a new Item record, and save $item = new Item(); $item->fromArray(array('Atomid' => $entry->id, 'Title' => $entry->title, 'Link' => $this->getLinkHref($entry->links, 'alternate'), 'Description' => '', 'Published' => $entry->published)); if (!empty($entry->content->text)) { $item->setDescription($entry->content->text); } elseif (!empty($entry->summary)) { $item->setDescription($entry->summary); } $item->setFeed($feedRecord); //print_r($item); $item->save(); $newItems++; } return $newItems; }
/** * Method perform a DELETE on the database, given a Size or Criteria object OR a primary key value. * * @param mixed $values Criteria or Size object or primary key or array of primary keys * which is used to create the DELETE statement * @param PropelPDO $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, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(SizePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { // invalidate the cache for all objects of this type, since we have no // way of knowing (without running a query) what objects should be invalidated // from the cache based on this Criteria. SizePeer::clearInstancePool(); // rename for clarity $criteria = clone $values; } elseif ($values instanceof Size) { // invalidate the cache for this single object SizePeer::removeInstanceFromPool($values); // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it must be the primary key $criteria = new Criteria(self::DATABASE_NAME); $criteria->add(SizePeer::ID, (array) $values, Criteria::IN); foreach ((array) $values as $singleval) { // we can invalidate the cache for this single object SizePeer::removeInstanceFromPool($singleval); } } // Set the correct dbName $criteria->setDbName(self::DATABASE_NAME); $affectedRows = 0; // initialize var to track total num of affected rows try { // use transaction because $criteria could contain info // for more than one table or we could emulating ON DELETE CASCADE, etc. $con->beginTransaction(); $affectedRows += BasePeer::doDelete($criteria, $con); // invalidate objects in ItemPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. ItemPeer::clearInstancePool(); $con->commit(); return $affectedRows; } catch (PropelException $e) { $con->rollBack(); throw $e; } }
private function gorde($request) { $id_fichero = $request->getParameter('id_fichero'); $c = new Criteria(); $c->addJoin(ItemPeer::ID_ITEM_BASE, ItemBasePeer::ID_ITEM_BASE, Criteria::JOIN); $c->addAnd(ItemPeer::ID_FORMULARIO, $id_fichero, Criteria::EQUAL); $c->addAnd(ItemBasePeer::ES_RESPONSABLE_FICHERO, true, Criteria::EQUAL); $item_encargado = ItemPeer::doSelectOne($c); if ($item_encargado != null) { $this->encargado = UsuarioPeer::retrieveByPk($item_encargado->getIdObjeto()); } else { $this->encargado = Usuario::getUsuarioActual()->getUsuario(); } }
/** * 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 = ItemPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setSizeId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setItemTypeId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setTitle($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setDescription($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setPricePerUnit($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setShippingChargePerUnit($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setActualValue($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setActualValueCurrency($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setQuantity($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setImage($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setFeatures($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setIsActive($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setCreatedAt($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setUpdatedAt($arr[$keys[14]]); } }
function addCriterionSelectPeriodo($campo) { $nombre_campo = "campo_" . $campo->getIdCampo() . ""; $item_base = $campo->getElementoUnico(); $recibido = isset($this->filters[$nombre_campo]) && $this->filters[$nombre_campo] !== '' ? $this->filters[$nombre_campo] : array(); $from_periodo = isset($recibido['from']['periodo']) ? $recibido['from']['periodo'] : null; $from_year = isset($recibido['from']['year']) ? $recibido['from']['year'] : null; $to_periodo = isset($recibido['to']['periodo']) ? $recibido['to']['periodo'] : null; $to_year = isset($recibido['to']['year']) ? $recibido['to']['year'] : null; $alias = "i" . $campo->getIdCampo(); //ALIAS. Arreglado if (isset($from_year) && $from_year != '') { $this->criteria->addAlias($alias, ItemPeer::TABLE_NAME); $this->criteria->addJoin(FormularioPeer::ID_FORMULARIO, ItemPeer::alias($alias, ItemPeer::ID_FORMULARIO), Criteria::JOIN); $cr_aux = $this->criteria->getNewCriterion(ItemPeer::alias($alias, ItemPeer::ID_ITEM_BASE), $item_base->getPrimaryKey()); if (isset($from_periodo) && $from_periodo != '') { $cr_aux_1 = $this->criteria->getNewCriterion(ItemPeer::alias($alias, ItemPeer::ANIO), $from_year); $cr_aux_1->addAnd($this->criteria->getNewCriterion(ItemPeer::alias($alias, ItemPeer::NUMERO), $from_periodo, Criteria::GREATER_EQUAL)); $cr_aux_2 = $this->criteria->getNewCriterion(ItemPeer::alias($alias, ItemPeer::ANIO), $from_year, Criteria::GREATER_THAN); $cr_aux_1->addOr($cr_aux_2); $cr_aux->addAnd($cr_aux_1); } else { $cr_aux->addAnd($this->criteria->getNewCriterion(ItemPeer::alias($alias, ItemPeer::ANIO), $from_year, Criteria::GREATER_EQUAL)); } $criterion = $this->criteria->getNewCriterion(ItemPeer::alias($alias, ItemPeer::ANIO), null, Criteria::ISNOTNULL); $criterion->addAnd($cr_aux); } if (isset($to_year) && $to_year != '') { $this->criteria->addAlias($alias, ItemPeer::TABLE_NAME); $this->criteria->addJoin(FormularioPeer::ID_FORMULARIO, ItemPeer::alias($alias, ItemPeer::ID_FORMULARIO), Criteria::JOIN); $cr_aux = $this->criteria->getNewCriterion(ItemPeer::alias($alias, ItemPeer::ID_ITEM_BASE), $item_base->getPrimaryKey()); if (isset($to_periodo) && $to_periodo != '') { $cr_aux_1 = $this->criteria->getNewCriterion(ItemPeer::alias($alias, ItemPeer::ANIO), $to_year); $cr_aux_1->addAnd($this->criteria->getNewCriterion(ItemPeer::alias($alias, ItemPeer::NUMERO), $to_periodo, Criteria::LESS_EQUAL)); $cr_aux_2 = $this->criteria->getNewCriterion(ItemPeer::alias($alias, ItemPeer::ANIO), $to_year, Criteria::LESS_THAN); $cr_aux_1->addOr($cr_aux_2); $cr_aux->addAnd($cr_aux_1); } else { $cr_aux->addAnd($this->criteria->getNewCriterion(ItemPeer::alias($alias, ItemPeer::ANIO), $to_year, Criteria::LESS_EQUAL)); } if (isset($criterion)) { $criterion->addAnd($cr_aux); } else { $criterion = $this->criteria->getNewCriterion(ItemPeer::alias($alias, ItemPeer::ANIO), null, Criteria::ISNOTNULL); $criterion->addAnd($cr_aux); } } if (isset($criterion)) { $this->criteria->addAnd($criterion); } }
echo '<?xml version="1.0" encoding="utf-8"?>'; ?> <feed xmlns="http://www.w3.org/2005/Atom"> <title>Isofarro</title> <subtitle>My writings around the web</subtitle> <link rel="self" href="<?php echo url_for('content/index?sf_format=atom', true); ?> " /> <link rel="alternate" type="text/html" href="<?php echo url_for('@homepage', true); ?> "/> <updated><?php echo gmstrftime('%Y-%m-%dT%H:%M:%SZ', ItemPeer::getLatestSiteItem(sfConfig::get('app_default_site'))->getPublished('U')); ?> </updated> <author> <name>Isofarro</name> </author> <id>http://isofarro.com/</id> <?php foreach ($entries['blog'] as $items) { $title = $items->getTitle(); $link = $items->getLink(); $atomid = $items->getAtomId(); $date = $items->getPublished('c'); $extract = $items->getExtract(); $site = $items->getFeed()->getTitle();
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this ItemBase is new, it will return * an empty collection; or if this ItemBase has previously * been saved, it will retrieve related Items 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 ItemBase. */ public function getItemsJoinFormulario($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(ItemBasePeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collItems === null) { if ($this->isNew()) { $this->collItems = array(); } else { $criteria->add(ItemPeer::ID_ITEM_BASE, $this->id_item_base); $this->collItems = ItemPeer::doSelectJoinFormulario($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(ItemPeer::ID_ITEM_BASE, $this->id_item_base); if (!isset($this->lastItemCriteria) || !$this->lastItemCriteria->equals($criteria)) { $this->collItems = ItemPeer::doSelectJoinFormulario($criteria, $con, $join_behavior); } } $this->lastItemCriteria = $criteria; return $this->collItems; }
public function getItemsFormularios() { $c = new Criteria(); $c->addJoin(ItemPeer::ID_FORMULARIO, FormularioPeer::ID_FORMULARIO); $c->addJoin(FormularioPeer::ID_TABLA, TablaPeer::ID_TABLA); $c->add(TablaPeer::ID_TABLA, $this->getIdTabla()); $items = ItemPeer::doSelect($c); return $items; }
/** * Selects a collection of ItemRecipe 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 ItemRecipe 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); } ItemRecipePeer::addSelectColumns($criteria); $startcol2 = ItemRecipePeer::NUM_COLUMNS - ItemRecipePeer::NUM_LAZY_LOAD_COLUMNS; ItemPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (ItemPeer::NUM_COLUMNS - ItemPeer::NUM_LAZY_LOAD_COLUMNS); $criteria->addJoin(ItemRecipePeer::ITEM_ID, ItemPeer::ID, $join_behavior); // symfony_behaviors behavior foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) { call_user_func($sf_hook, 'BaseItemRecipePeer', $criteria, $con); } $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = ItemRecipePeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = ItemRecipePeer::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 = ItemRecipePeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); ItemRecipePeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Item rows $key2 = ItemPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = ItemPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = ItemPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); ItemPeer::addInstanceToPool($obj2, $key2); } // if obj2 loaded // Add the $obj1 (ItemRecipe) to the collection in $obj2 (Item) $obj2->addItemRecipe($obj1); } // if joined row not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * 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 Item A model object, or null if the key is not found */ protected function findPkSimple($key, $con) { $sql = 'SELECT `ID`, `ISBN`, `PACKAGE_ID`, `IS_PACKAGE`, `TITLE`, `AUTHOR`, `EDITION`, `PUBLISHER`, `B_NEW`, `B_USED`, `B_EBOOK`, `IMAGE_URL`, `PRODUCT_ID`, `PART_NUMBER`, `SPIDERED_AT`, `SHALLOW_SPIDERED_AT`, `TOUCHED`, `B_ID`, `BOOKSTORE_TYPE`, `CREATED_AT`, `UPDATED_AT` FROM `item` 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 Item(); $obj->hydrate($row); ItemPeer::addInstanceToPool($obj, (string) $key); } $stmt->closeCursor(); return $obj; }
/** * 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 = ItemPeer::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->setImageFilename($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setDescription($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setAdditionalInfo($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setStrength($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setAgility($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setIntelligence($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setDamage($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setArmor($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setHp($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setMana($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setPrice($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setStoreId($arr[$keys[13]]); } }
public function executeDownload() { $item = ItemPeer::retrieveByPK($this->getRequestParameter('id_item', ''), $this->getRequestParameter('id_formulario', '')); if ($item instanceof Item) { if ($item->getTextoCorto() != "") { $filename = sfConfig::get('app_directorio_upload') . 'docs/' . $item->getTextoCorto(); //echo $filename."::".file_exists($filename); if (file_exists($filename)) { $fname = explode("_", basename($filename)); if (sizeof($fname) > 1) { $fname = substr(basename($filename), strlen($fname[0]) + 1); } else { $fname = $fname[0]; } header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header('Content-Disposition: attachment; filename="' . $fname . '"'); header('Content-Length: ' . filesize($filename)); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); $fp = fopen($filename, "r"); fpassthru($fp); flush(); fclose($fp); } } } die("EL FICHERO NO EXISTE"); }
} else { $remainingItems[$j] = $item->getId(); $j++; } ?> <?php } ?> <?php foreach ($remainingItems as $newitem) { ?> <?php $c = new Criteria(); $c->add(ItemPeer::IS_ACTIVE, true); $c->add(ItemPeer::ID, $newitem); $item = ItemPeer::doSelectOne($c); ?> <div class="item"> <div class="left"> <?php $ext = substr($item->getImage(), strpos($item->getImage(), ".")); $filename = str_replace($ext, '', $item->getImage()); ?> <div class="thumb" style="border:none"><?php echo image_tag('/uploads' . '/' . sfConfig::get('app_items_upload_folder') . '/' . $filename . "_t" . $ext, array('alt' => $item->getTitle())); ?> </div> <input type="button" onClick="parent.location='shop/itemDetail?id=<?php echo $item->getId(); ?> '" class="myButton" value="More Info" style="padding:3px;font-size:13px;"> </div>
/** * 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(ItemPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(ItemPeer::DATABASE_NAME); $criteria->add(ItemPeer::ID, $pks, Criteria::IN); $objs = ItemPeer::doSelect($criteria, $con); } return $objs; }
/** * The unit test assumes that sfGuardPlugin is installed and that the model * class Item is defined. */ include dirname(__FILE__) . '/../bootstrap/unit.php'; sfPropelBehavior::add('sfGuardUser', array('sfPropelActAsSlopeOneRaterBehavior')); //Setup values sfRatingPeer::doDeleteAll(); sfGuardUserPeer::doDeleteAll(); $users = array(); for ($i = 0; $i < 3; $i++) { $users[$i] = new sfGuardUser(); $users[$i]->setUsername(rand()); $users[$i]->save(); } $items = ItemPeer::doSelect(new Criteria()); $items[0]->setRating(5, $users[0]->getId()); $items[1]->setRating(3, $users[0]->getId()); $items[2]->setRating(2, $users[0]->getId()); $items[0]->setRating(3, $users[1]->getId()); $items[1]->setRating(4, $users[1]->getId()); $items[1]->setRating(2, $users[2]->getId()); $items[2]->setRating(5, $users[2]->getId()); $t = new lime_test(10, new lime_output_color()); //Build slope one tables foreach (array('sfPropelSlopeOnePhpBuilder', 'sfPropelSlopeOneMySqlBuilder') as $builder) { $builder = new $builder(new sfPropelSlopeOneSqlParser()); $builder->build(); $t->is(sfSlopeOnePeer::doCount(new Criteria()), sizeof($items) * (sizeof($items) - 1), 'Correct number of slope one values generated using ' . get_class($builder)); } $t->is(sizeof($items[0]->getRecommendations()), sizeof($items) - 1, 'Correct number of recommendations retrieved for item');
/** * Returns the number of related Item objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Item objects. * @throws PropelException */ public function countItems(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(FeedPeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collItems === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(ItemPeer::FEED_ID, $this->id); $count = ItemPeer::doCount($criteria, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // 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 count of the collection. $criteria->add(ItemPeer::FEED_ID, $this->id); if (!isset($this->lastItemCriteria) || !$this->lastItemCriteria->equals($criteria)) { $count = ItemPeer::doCount($criteria, $con); } else { $count = count($this->collItems); } } else { $count = count($this->collItems); } } return $count; }
/** * 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 = ItemPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setIdItem($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setIdFormulario($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setIdItemBase($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setTextoCorto($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setTextoLargo($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setSiNo($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setTextoAuxiliar($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setFecha($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setNumero($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setIdTabla($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setIdObjeto($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setAnio($arr[$keys[11]]); } }
/** * Method to invalidate the instance pool of all tables related to book * by a foreign key with ON DELETE CASCADE */ public static function clearRelatedInstancePool() { // Invalidate objects in ItemPeer instance pool, // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. ItemPeer::clearInstancePool(); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { // TODO: Check for the feed filter cookie // Get all the entries for this site, sorted into collections $this->entries = ItemPeer::getCollectedFeedItems(sfConfig::get('app_default_site')); }
/** * Retrieve object using using composite pkey values. * @param int $id_item @param int $id_formulario * @param PropelPDO $con * @return Item */ public static function retrieveByPK($id_item, $id_formulario, PropelPDO $con = null) { $key = serialize(array((string) $id_item, (string) $id_formulario)); if (null !== ($obj = ItemPeer::getInstanceFromPool($key))) { return $obj; } if ($con === null) { $con = Propel::getConnection(ItemPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $criteria = new Criteria(ItemPeer::DATABASE_NAME); $criteria->add(ItemPeer::ID_ITEM, $id_item); $criteria->add(ItemPeer::ID_FORMULARIO, $id_formulario); $v = ItemPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }
/** * 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 = ItemPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setIsbn($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setPackageId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setIsPackage($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setTitle($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setAuthor($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setEdition($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setPublisher($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setBNew($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setBUsed($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setBEbook($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setImageUrl($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setProductId($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setPartNumber($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setSpideredAt($arr[$keys[14]]); } if (array_key_exists($keys[15], $arr)) { $this->setShallowSpideredAt($arr[$keys[15]]); } if (array_key_exists($keys[16], $arr)) { $this->setTouched($arr[$keys[16]]); } if (array_key_exists($keys[17], $arr)) { $this->setBId($arr[$keys[17]]); } if (array_key_exists($keys[18], $arr)) { $this->setBookstoreType($arr[$keys[18]]); } if (array_key_exists($keys[19], $arr)) { $this->setCreatedAt($arr[$keys[19]]); } if (array_key_exists($keys[20], $arr)) { $this->setUpdatedAt($arr[$keys[20]]); } }
/** * Selects a collection of ShoppingCart objects pre-filled with all related objects except User. * * @param Criteria $c * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of ShoppingCart objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptUser(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } ShoppingCartPeer::addSelectColumns($c); $startcol2 = ShoppingCartPeer::NUM_COLUMNS - ShoppingCartPeer::NUM_LAZY_LOAD_COLUMNS; ItemPeer::addSelectColumns($c); $startcol3 = $startcol2 + (ItemPeer::NUM_COLUMNS - ItemPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(ShoppingCartPeer::ITEM_ID), array(ItemPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = ShoppingCartPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = ShoppingCartPeer::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 { $omClass = ShoppingCartPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); ShoppingCartPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Item rows $key2 = ItemPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = ItemPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = ItemPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); ItemPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (ShoppingCart) to the collection in $obj2 (Item) $obj2->addShoppingCart($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
public function executeCheckout() { $this->user = $this->getUser()->getRaykuUser(); $voucher_id = $this->getUser()->getAttribute('voucher_id'); $offer = OfferVoucherPeer::retrieveByPK($voucher_id); //$_SESSION['offerid'] = $offer->getId(); if ($this->getRequest()->getMethod() == sfRequest::POST) { $c = new Criteria(); $c->add(ShoppingCartPeer::IS_ACTIVE, true); $c->add(ShoppingCartPeer::USER_ID, $this->user->getId()); $c->addDescendingOrderByColumn(ShoppingCartPeer::CREATED_AT); $this->cart_items = ShoppingCartPeer::doSelect($c); $purchase_detail = $this->getRequestParameter('purchase'); foreach ($purchase_detail as $index => $value) { $purchaseDetail[$index] = trim($value); } if ($purchaseDetail['name'] == '' || $purchaseDetail['email'] == '' || $purchaseDetail['address_1'] == '' || $purchaseDetail['city'] == '' || $purchaseDetail['state'] == '' || $purchaseDetail['zip'] == '' || $purchaseDetail['country'] == '' || $purchaseDetail['tel'] == '') { sfProjectConfiguration::getActive()->loadHelpers(array('Url', 'Tag')); $this->msg = "<p>Please fill in all additional information on the <b>Purchase Cart</b> page.</p>"; $this->msg .= "<p>" . link_to('Go back to the <b>Purchase Cart</b> page.', 'shop/checkoutPage') . "</p>"; } else { if (count($this->cart_items) > 0) { $count = 0; $tot_price = 0; $tot_item_price = 0; $tot_shipping_price = 0; $tot_quantity = 0; foreach ($this->cart_items as $cart_item) { $tot_price = $tot_price + $cart_item->getTotalPrice() + $cart_item->getTotalShippingCharge(); if ($tot_price > $this->user->getPoints()) { break; } $sales_detail = new SalesDetail(); $sales_detail->setItemId($cart_item->getItemId()); $sales_detail->setTotalPrice($cart_item->getTotalPrice()); $sales_detail->setTotalShippingCharge($cart_item->getTotalShippingCharge()); $sales_detail->setQuantity($cart_item->getQuantity()); $sales_detail->save(); $count++; $tot_item_price = $tot_item_price + $cart_item->getTotalPrice(); $tot_shipping_price = $tot_shipping_price + $cart_item->getTotalShippingCharge(); $tot_quantity = $tot_quantity + $cart_item->getQuantity(); $itemPurchased = ItemPeer::retrieveByPK($cart_item->getItemId()); if (empty($purchasedItems)) { $purchasedItems = $itemPurchased->getTitle(); } else { $purchasedItems = $purchasedItems . "," . $itemPurchased->getTitle(); } $cart_item->delete(); } $sales = new Sales(); if ($offer instanceof OfferVoucher) { $tot_price = $tot_price - $offer->getPrice(); //$sales->setOfferVoucherId($offer->getId()); $offer->setIsUsed(true); $offer->save(); } $sales->setTotalSalePrice($tot_price); $sales->setTotalItemPrice($tot_item_price); $sales->setTotalShippingCharge($tot_shipping_price); $sales->setQuantity($tot_quantity); $sales->setStatusId(1); $sales->save(); $this->user->setPoints($this->user->getPoints() - $tot_price); $this->user->save(); $full_name = htmlentities($purchase_detail['name']); $email = htmlentities($purchase_detail['email']); $address_1 = htmlentities($purchase_detail['address_1']); $address_2 = htmlentities($purchase_detail['address_2']); $city = htmlentities($purchase_detail['city']); $state = htmlentities($purchase_detail['state']); $zip = htmlentities($purchase_detail['zip']); $country = htmlentities($purchase_detail['country']); $tel = htmlentities($purchase_detail['tel']); $purchase_detail = new PurchaseDetail(); $purchase_detail->setFullName($full_name); $purchase_detail->setUserId($this->user->getId()); $purchase_detail->setEmail($email); $purchase_detail->setAddress1($address_1); $purchase_detail->setAddress2($address_2); $purchase_detail->setCity($city); $purchase_detail->setZip($zip); $purchase_detail->setState($state); $purchase_detail->setCountry($country); $purchase_detail->setSalesId($sales->getId()); $purchase_detail->save(); $user = $this->getUser()->getRaykuUser(); $this->mail = Mailman::createCleanMailer(); $this->mail->setSubject('Rayku.com Shoping Item Purchase Details'); $this->mail->setFrom($user->getName() . ' <' . $user->getEmail() . '>'); $to = "*****@*****.**"; $items = "<b>" . $purchasedItems . "</b>"; sfProjectConfiguration::getActive()->loadHelpers(array('Partial')); $this->mail->setBody(get_partial('purchaseitem', array('name' => $user->getName(), 'user' => $user, 'items' => $items))); $this->mail->setContentType('text/html'); $this->mail->addAddress($to); $this->mail->send(); $this->msg = "<p style='font-size:14px;color:#444444'>You have just spent " . $tot_price . "RP to purchase " . $count . " item(s).<br /><br />A Rayku administrator has been notified, and will deliver your purchase as soon as possible. Once your order has been processed, you will be notified by private message here on Rayku.<br /><br />Thanks!<br />Rayku.com Staff</p>"; $this->getUser()->setAttribute('voucher_id', null); } else { $this->msg = "<p style='font-size:14px;color:#444444'>No items in cart</p>"; } } } else { $this->msg = "<p style='font-size:14px;color:#444444'>Unauthorized access.</p>"; } }
/** * Get the associated Item object * * @param PropelPDO Optional Connection object. * @return Item The associated Item object. * @throws PropelException */ public function getItem(PropelPDO $con = null) { if ($this->aItem === null && $this->item_id !== null) { $c = new Criteria(ItemPeer::DATABASE_NAME); $c->add(ItemPeer::ID, $this->item_id); $this->aItem = ItemPeer::doSelectOne($c, $con); /* 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->aItem->addShoppingCarts($this); */ } return $this->aItem; }
/** * 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 = ItemPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setFeedId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setAtomid($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setTitle($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setLink($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setDescription($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setPublished($arr[$keys[6]]); } }