예제 #1
0
 public function executeEdit($request)
 {
     $this->form = new ArticleForm(ArticlePeer::doSelectOne(new Criteria()));
     if ($request->isMethod(sfRequest::POST)) {
         $this->form->bind($request->getParameter('article'));
         if ($this->form->isValid()) {
             $this->form->save();
             $this->redirect('unique/edit');
         }
     }
 }
예제 #2
0
 public function executeShowArchive(sfWebRequest $request)
 {
     $c = new Criteria();
     $year = $request->getParameter('year');
     $month = $request->getParameter('month');
     $nextMonth = mktime(0, 0, 0, $month + 1, 0, $year);
     $thisMonth = mktime(0, 0, 0, $month, 0, $year);
     $c->add(ArticlePeer::CREATED_AT, $nextMonth, Criteria::LESS_THAN);
     $c->addAnd(ArticlePeer::CREATED_AT, $thisMonth, Criteria::GREATER_THAN);
     // $c->addAnd(ArticlePeer::CREATED_AT,$thisMonth,'GREATERTHAN');
     $this->posts = ArticlePeer::doSelect($c);
 }
예제 #3
0
 public function getArticle(PropelPDO $con = null)
 {
     if ($this->aArticle === null && $this->article_id !== null) {
         $c = new Criteria(ArticlePeer::DATABASE_NAME);
         $c->add(ArticlePeer::ID, $this->article_id);
         $this->aArticle = ArticlePeer::doSelectOne($c, $con);
     }
     return $this->aArticle;
 }
 public function getArticle($con = null)
 {
     include_once 'lib/model/om/BaseArticlePeer.php';
     if ($this->aArticle === null && $this->article_id !== null) {
         $this->aArticle = ArticlePeer::retrieveByPK($this->article_id, $con);
     }
     return $this->aArticle;
 }
 /**
  * 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 = ArticlePeer::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]]);
     }
 }
예제 #6
0
 public function getArticle($con = null)
 {
     if ($this->aArticle === null && $this->article_id !== null) {
         $this->aArticle = ArticlePeer::retrieveByPK($this->article_id, $con);
     }
     return $this->aArticle;
 }
예제 #7
0
 /**
  * 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 = ArticlePeer::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->setBody($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setOnline($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setExcerpt($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setCategoryId($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setCreatedAt($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setEndDate($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setBookId($arr[$keys[8]]);
     }
 }
 /**
  * Selects a collection of AuthorArticle objects pre-filled with all related objects except Author.
  *
  * @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 AuthorArticle objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptAuthor(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);
     }
     AuthorArticlePeer::addSelectColumns($criteria);
     $startcol2 = AuthorArticlePeer::NUM_COLUMNS - AuthorArticlePeer::NUM_LAZY_LOAD_COLUMNS;
     ArticlePeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (ArticlePeer::NUM_COLUMNS - ArticlePeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(AuthorArticlePeer::ARTICLE_ID, ArticlePeer::ID, $join_behavior);
     // symfony_behaviors behavior
     foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
         call_user_func($sf_hook, 'BaseAuthorArticlePeer', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = AuthorArticlePeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = AuthorArticlePeer::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 = AuthorArticlePeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             AuthorArticlePeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Article rows
         $key2 = ArticlePeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = ArticlePeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = ArticlePeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 ArticlePeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (AuthorArticle) to the collection in $obj2 (Article)
             $obj2->addAuthorArticle($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
예제 #9
0
 protected function addSortCriteria($c)
 {
     if ($sort_column = $this->getUser()->getAttribute('sort', null, 'sf_admin/article/sort')) {
         $sort_column = sfInflector::camelize(strtolower($sort_column));
         $sort_column = ArticlePeer::translateFieldName($sort_column, BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME);
         if ($this->getUser()->getAttribute('type', null, 'sf_admin/article/sort') == 'asc') {
             $c->addAscendingOrderByColumn($sort_column);
         } else {
             $c->addDescendingOrderByColumn($sort_column);
         }
     }
 }
 /**
  * @WSMethod(name='getFixtureModel')
  *
  * @return Article[] All articles loaded from the database.
  */
 public function executeGetFixtureModel(sfWebRequest $request)
 {
     $this->result = ArticlePeer::doSelect(new Criteria());
     return sfView::SUCCESS;
 }
예제 #11
0
 protected function addSortCriteria($criteria)
 {
     if (array(null, null) == ($sort = $this->getSort())) {
         return;
     }
     $column = ArticlePeer::translateFieldName($sort[0], BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
     if ('asc' == $sort[1]) {
         $criteria->addAscendingOrderByColumn($column);
     } else {
         $criteria->addDescendingOrderByColumn($column);
     }
 }
예제 #12
0
 public function executeArchiveList()
 {
     $c = new Criteria();
     $c->addDescendingOrderByColumn('created_at');
     $this->posts = ArticlePeer::doSelect($c);
 }
 public function executeShoppingCart2(sfWebRequest $request)
 {
     $this->categories = CategoryPeer::getActiveCategories();
     $this->paths = array();
     $promoter = $promoter = PromoterPeer::getPromoterByUserId($this->getUser()->getId());
     $this->state = $promoter->getIdState();
     $this->articles = ArticlePeer::doSelect(new Criteria());
     if ($request->isMethod('post')) {
         $cart = $this->createCartIfNotExists();
         foreach ($this->articles as $key => $article) {
             $value = $request->getParameter($article->getId());
             if ($value > 0) {
                 $this->createCartArticle($cart, $article, $value);
             }
         }
     }
     $cart = CartPeer::getCart($promoter->getClientId());
     if (!isset($cart)) {
         $cart = new Cart();
     }
     $this->cart_articles = $cart->getCartArticles();
     //sacar articulos mayor a 1 mes en el carrito
     foreach ($this->cart_articles as $cart_article) {
         $fecha = $this->dateadd($cart_article->getUpdatedAt(), 0, 1, 0, 0, 0, 0);
         $date1 = new DateTime("now");
         $date2 = new DateTime($fecha);
         if ($date1 > $date2) {
             $cart_article->delete();
             $cart_article->save();
         }
     }
     $this->total = 0;
     foreach ($this->cart_articles as $cart_article) {
         $this->total += $cart_article->getPrice() * $cart_article->getQuantity();
     }
 }
예제 #14
0
 static function getArticle($id)
 {
     $c = new Criteria();
     $c->add(ArticlePeer::ID, $id);
     return ArticlePeer::doSelectOne($c);
 }
 public function getArticlesJoinBook($criteria = null, $con = null)
 {
     include_once 'lib/model/om/BaseArticlePeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collArticles === null) {
         if ($this->isNew()) {
             $this->collArticles = array();
         } else {
             $criteria->add(ArticlePeer::CATEGORY_ID, $this->getId());
             $this->collArticles = ArticlePeer::doSelectJoinBook($criteria, $con);
         }
     } else {
         $criteria->add(ArticlePeer::CATEGORY_ID, $this->getId());
         if (!isset($this->lastArticleCriteria) || !$this->lastArticleCriteria->equals($criteria)) {
             $this->collArticles = ArticlePeer::doSelectJoinBook($criteria, $con);
         }
     }
     $this->lastArticleCriteria = $criteria;
     return $this->collArticles;
 }
예제 #16
0
 /**
  * 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(ArticlePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(ArticlePeer::DATABASE_NAME);
         $criteria->add(ArticlePeer::ID, $pks, Criteria::IN);
         $objs = ArticlePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
예제 #17
0
 public function getArticlesJoinBook($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->collArticles === null) {
         if ($this->isNew()) {
             $this->collArticles = array();
         } else {
             $criteria->add(ArticlePeer::CATEGORY_ID, $this->id);
             $this->collArticles = ArticlePeer::doSelectJoinBook($criteria, $con, $join_behavior);
         }
     } else {
         $criteria->add(ArticlePeer::CATEGORY_ID, $this->id);
         if (!isset($this->lastArticleCriteria) || !$this->lastArticleCriteria->equals($criteria)) {
             $this->collArticles = ArticlePeer::doSelectJoinBook($criteria, $con, $join_behavior);
         }
     }
     $this->lastArticleCriteria = $criteria;
     return $this->collArticles;
 }
예제 #18
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Book is new, it will return
  * an empty collection; or if this Book has previously
  * been saved, it will retrieve related Articles 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 Book.
  */
 public function getArticlesJoinCategory($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     if ($criteria === null) {
         $criteria = new Criteria(BookPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collArticles === null) {
         if ($this->isNew()) {
             $this->collArticles = array();
         } else {
             $criteria->add(ArticlePeer::BOOK_ID, $this->id);
             $this->collArticles = ArticlePeer::doSelectJoinCategory($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(ArticlePeer::BOOK_ID, $this->id);
         if (!isset($this->lastArticleCriteria) || !$this->lastArticleCriteria->equals($criteria)) {
             $this->collArticles = ArticlePeer::doSelectJoinCategory($criteria, $con, $join_behavior);
         }
     }
     $this->lastArticleCriteria = $criteria;
     return $this->collArticles;
 }
예제 #19
0
 public static function doSelectJoinAllExceptAuthor(Criteria $c, $con = null)
 {
     $c = clone $c;
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     AuthorArticlePeer::addSelectColumns($c);
     $startcol2 = AuthorArticlePeer::NUM_COLUMNS - AuthorArticlePeer::NUM_LAZY_LOAD_COLUMNS + 1;
     ArticlePeer::addSelectColumns($c);
     $startcol3 = $startcol2 + ArticlePeer::NUM_COLUMNS;
     $c->addJoin(AuthorArticlePeer::ARTICLE_ID, ArticlePeer::ID);
     $rs = BasePeer::doSelect($c, $con);
     $results = array();
     while ($rs->next()) {
         $omClass = AuthorArticlePeer::getOMClass();
         $cls = Propel::import($omClass);
         $obj1 = new $cls();
         $obj1->hydrate($rs);
         $omClass = ArticlePeer::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->getArticle();
             if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
                 $newObject = false;
                 $temp_obj2->addAuthorArticle($obj1);
                 break;
             }
         }
         if ($newObject) {
             $obj2->initAuthorArticles();
             $obj2->addAuthorArticle($obj1);
         }
         $results[] = $obj1;
     }
     return $results;
 }
$finder->where('Title', 'bar')->findOne(); // write cache 2
$SQL1 = $finder->getLatestQuery();
$finder->where('Title', 'foo')->findOne(); // read cache 1
$SQL2 = $finder->getLatestQuery();
$t->is($SQL1, $SQL2, 'The same query asked within the lifetime uses the cache');
sleep(2);
$finder->where('Title', 'foo')->findOne(); // re-write cache 1
$SQL3 = $finder->getLatestQuery();
$t->isnt($SQL1, $SQL3, 'The same query asked after the lifetime does not use the cache');
*/

$t->diag('Cached results');

$cache->clear();

ArticlePeer::doDeleteAll();
$article1 = new Article();
$article1->setTitle('foo1');
$article1->save();
$article2 = new Article();
$article2->setTitle('foo2');
$article2->save();

$finder = DbFinder::from('Article')->useCache($cache, 10);
           $finder->where('Title', 'foo1')->findOne(); // normal query
$article = $finder->where('Title', 'foo1')->findOne(); // cached query
$t->isa_ok($article, 'Article', 'Cached finder queries return Model objects');
$t->is($article->getId(), $article1->getId(), 'find() finder queries can be cached');
      $finder->where('Title', 'foo1')->count(); // normal query
$nb = $finder->where('Title', 'foo1')->count(); // cached query
$t->is($nb, 1, 'count() finder queries can be cached');
예제 #21
0
 public static function doSelectJoinAllExceptAuthor(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     foreach (sfMixer::getCallables('BaseAuthorArticlePeer:doSelectJoinAllExcept:doSelectJoinAllExcept') as $callable) {
         call_user_func($callable, 'BaseAuthorArticlePeer', $c, $con);
     }
     $c = clone $c;
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     AuthorArticlePeer::addSelectColumns($c);
     $startcol2 = AuthorArticlePeer::NUM_COLUMNS - AuthorArticlePeer::NUM_LAZY_LOAD_COLUMNS;
     ArticlePeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (ArticlePeer::NUM_COLUMNS - ArticlePeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(AuthorArticlePeer::ARTICLE_ID), array(ArticlePeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = AuthorArticlePeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = AuthorArticlePeer::getInstanceFromPool($key1))) {
         } else {
             $omClass = AuthorArticlePeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             AuthorArticlePeer::addInstanceToPool($obj1, $key1);
         }
         $key2 = ArticlePeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = ArticlePeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = ArticlePeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 ArticlePeer::addInstanceToPool($obj2, $key2);
             }
             $obj2->addAuthorArticle($obj1);
         }
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
 /**
  * Get the associated Article object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Article The associated Article object.
  * @throws     PropelException
  */
 public function getArticle(PropelPDO $con = null)
 {
     if ($this->aArticle === null && $this->article_id !== null) {
         $this->aArticle = ArticlePeer::retrieveByPk($this->article_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->aArticle->addAttachments($this);
         		 */
     }
     return $this->aArticle;
 }
예제 #23
0
 public function getArticlesJoinCategory($criteria = null, $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collArticles === null) {
         if ($this->isNew()) {
             $this->collArticles = array();
         } else {
             $criteria->add(ArticlePeer::BOOK_ID, $this->getId());
             $this->collArticles = ArticlePeer::doSelectJoinCategory($criteria, $con);
         }
     } else {
         $criteria->add(ArticlePeer::BOOK_ID, $this->getId());
         if (!isset($this->lastArticleCriteria) || !$this->lastArticleCriteria->equals($criteria)) {
             $this->collArticles = ArticlePeer::doSelectJoinCategory($criteria, $con);
         }
     }
     $this->lastArticleCriteria = $criteria;
     return $this->collArticles;
 }