/** * gets a listing of products based on category * * (main method used in product listings) * * @param $categoryId category ID (can be more than one) * @param null $paged current page (null, no pagination; not null contains the current page) * @param null $order order clause * @return Zend_Db_Table_Rowset_Abstract|Zend_Paginator */ public function getProductByCategory($categoryId, $paged = null, $order = null) { // creating the select statement // using the IN clause is suitable as $categoryId is an array of categories $select = $this->select()->from('product')->where('categoryId IN (?)', $categoryId); // ordering according to order clause // (e.g., array('name ASC', 'price DESC') if (is_array($order) === true) { $select->order($order); } // paginating the result if ($paged !== null) { // adapter to configure the paginator instance $adapter = new Zend_Paginator_Adapter_DbTableSelect($select); // select statement that calculates the total amount of rows returned by the main statement $count = clone $select; // reseting the cloned statement $count->reset(Zend_Db_Select::COLUMNS); $count->reset(Zend_Db_Select::FROM); // creating the count expression with Zend_Db_Expr $count->from('product', new Zend_Db_Expr('COUNT(*) as `zend_paginator_row_count`')); // setting the count statement in the adapter $adapter->setRowCount($count); // creating the zend paginator instance using the adapter $paginator = new Zend_Paginator($adapter); $paginator->setItemCountPerPage(5)->setCurrentPageNumber((int) $paged); return $paginator; } return $this->fetchAll($select); }
public function findAnswersByQuestionId($questionId, $page = null, $limit = 10) { $select = $this->select(); $select->from('Answer', 'id'); $select->where('question_id = ?', intval($questionId)); $select->where('parent_id = 0'); $select->order('created_at'); if (null !== $page) { $adapter = new Zend_Paginator_Adapter_DbTableSelect($select); $count = clone $select; $count->reset(Zend_Db_Select::COLUMNS); $count->reset(Zend_Db_Select::FROM); $count->from('Answer', new Zend_Db_Expr('COUNT(*) AS `zend_paginator_row_count`')); $adapter->setRowCount($count); $paginator = new Zend_Paginator($adapter); $paginator->setItemCountPerPage(intval($limit))->setCurrentPageNumber(intval($page)); return $paginator; } }
public function getUsers($paged = false, $order = null) { $select = $this->select(); if (true === is_array($order)) { $select->order($order); } if (null !== $paged) { $adapter = new Zend_Paginator_Adapter_DbTableSelect($select); $count = clone $select; $count->reset(Zend_Db_Select::COLUMNS); $count->reset(Zend_Db_Select::FROM); $count->from('user', new Zend_Db_Expr('COUNT(*) AS `zend_paginator_row_count`')); $adapter->setRowCount($count); $paginator = new Zend_Paginator($adapter); $paginator->setItemCountPerPage(15)->setCurrentPageNumber((int) $paged); return $paginator; } return $this->fetchAll($select); }
/** * Get a list of product by their category * * @param int|array $categoryId The category id(s) * @param boolean $paged Use Zend_Paginator? * @param array $order Order results * @return Zend_Db_Table_Rowset|Zend_Paginator */ public function getProductsByCategory($categoryId, $paged = null, $order = null) { $select = $this->select(); $select->from('product')->where("categoryId IN(?)", $categoryId); if (true === is_array($order)) { $select->order($order); } if (null !== $paged) { $adapter = new Zend_Paginator_Adapter_DbTableSelect($select); $count = clone $select; $count->reset(Zend_Db_Select::COLUMNS); $count->reset(Zend_Db_Select::FROM); $count->from('product', new Zend_Db_Expr('COUNT(*) AS `zend_paginator_row_count`')); $adapter->setRowCount($count); $paginator = new Zend_Paginator($adapter); $paginator->setItemCountPerPage(5)->setCurrentPageNumber((int) $paged); return $paginator; } return $this->fetchAll($select); }
public function getOutboxPaginator(User_Model_User $user) { $paginator = new Zend_Paginator_Adapter_DbTableSelect($this->getOutboxSelect($user)); $paginator->setRowCount($this->getOutboxCountSelect($user)); return new Zend_Paginator($paginator); }
/** * @param $baseSelect * @param int $page * @param null $countSelect * @return Zend_Paginator */ protected function _paginator($baseSelect, $page = 0, $countSelect = null) { $adapter = new Zend_Paginator_Adapter_DbTableSelect($baseSelect); if (null != $countSelect) { $adapter->setRowCount($countSelect); } $paginator = new Zend_Paginator($adapter); $paginator->setDefaultItemCountPerPage($this->_maxItemsOnPage); if (!empty($page)) { $paginator->setCurrentPageNumber($page); } return $paginator; }
public function paginator($namespace = null, $moreActions = array()) { $this->getFilterData($namespace); if (!$this->paginator) { $db = $this->dbModelTable; $expr = new Zend_Db_Expr('(' . $this->getSql() . ')'); $select = $db->select()->from($expr)->setIntegrityCheck(false); if (isset($this->sort) && isset($this->order)) { $select->order($this->sort . ' ' . $this->order); } $adapter = new Zend_Paginator_Adapter_DbTableSelect($select); if ($this->getCountSql()) { $adapter->setRowCount($db->select()->from(new Zend_Db_Expr('(' . $this->getCountSql() . ')'), array(Zend_Paginator_Adapter_DbSelect::ROW_COUNT_COLUMN => 'zend_paginator_row_count'))->setIntegrityCheck(false)); } $paginator = new Base_Paginator($adapter, $moreActions); $paginator->setCurrentPageNumber(isset($this->page) ? $this->page : 1); if ($this->page_size) { $paginator->setItemCountPerPage($this->page_size); } $this->paginator = $paginator; } return $this->paginator; }