Example #1
0
 protected function _applySelectOptions(Zend_Db_Table_Select $select, array $options = array())
 {
     if (isset($options[self::OPTION_WHERE])) {
         foreach ((array) $options[self::OPTION_WHERE] as $where) {
             $select->where($where);
         }
     }
     if (isset($options[self::OPTION_OR_WHERE])) {
         foreach ((array) $options[self::OPTION_OR_WHERE] as $orWhere) {
             $select->orWhere($orWhere);
         }
     }
     if (isset($options[self::OPTION_HAVING])) {
         foreach ((array) $options[self::OPTION_HAVING] as $having) {
             $select->having($having);
         }
     }
     if (isset($options[self::OPTION_ORDER])) {
         foreach ((array) $options[self::OPTION_ORDER] as $order) {
             $select->order($order);
         }
     }
     $limit = isset($options[self::OPTION_LIMIT]) ? $options[self::OPTION_LIMIT] : null;
     $offset = isset($options[self::OPTION_OFFSET]) ? $options[self::OPTION_OFFSET] : null;
     $select->limit($limit, $offset);
     return $select;
 }
Example #2
0
 public function limit($count = null, $offset = null)
 {
     if (is_array($count)) {
         $offset = $count['start'];
         $count = $count['limit'];
     }
     return parent::limit($count, $offset);
 }
 /**
  * Builds order expression
  *
  * @param array $limitArray
  * 
  * @return Zend_Db_Select
  */
 private function _buildSelectObjLimitExpr($limitArray)
 {
     if (isset($limitArray['offset'])) {
         $this->select->limit($limitArray['limit'], $limitArray['offset']);
     } else {
         $this->select->limit($limitArray['limit']);
     }
     return $this->select;
 }
Example #4
0
 function __construct(Zend_Controller_Request_Abstract $request, array $orderFields, array $searchFields, Zend_Db_Table_Select $select, Zend_Db_Table_Select $selectFiltered)
 {
     // Load the params
     $iDisplayStart = $request->getParam('iDisplayStart');
     $iDisplayLength = $request->getParam('iDisplayLength');
     $iSortingCols = intval($request->getParam('iSortingCols'));
     $sSearch = $request->getParam('sSearch');
     // Build sort array
     $order = array();
     if ($iSortingCols > 0) {
         for ($i = 0; $i < $iSortingCols; $i++) {
             if (array_key_exists($request->getParam('iSortCol_' . $i), $orderFields)) {
                 $order[] = $orderFields[$request->getParam('iSortCol_' . $i)] . ' ' . strtoupper($request->getParam('sSortDir_' . $i));
             }
         }
     }
     // Count the total rows
     $selectCount = clone $select;
     if (count($selectCount->getPart(Zend_Db_Table_Select::GROUP)) <= 0) {
         $selectCount->reset(Zend_Db_Table_Select::COLUMNS)->columns(array('count' => 'COUNT(*)'));
         $this->_totalCount = $selectCount->getTable()->fetchRow($selectCount)->count;
     } else {
         $this->_totalCount = $selectCount->getTable()->fetchAll($selectCount)->count();
     }
     // Append search
     if ($sSearch !== null && $sSearch != '') {
         $sSearch = '\'%' . $sSearch . '%\'';
         $selectFiltered->where('(' . implode(' LIKE ' . $sSearch . ') OR (', $searchFields) . ' LIKE ' . $sSearch . ')');
     }
     // Count the filtered rows
     $selectCount = clone $selectFiltered;
     if (count($selectCount->getPart(Zend_Db_Table_Select::GROUP)) <= 0) {
         $selectCount->reset(Zend_Db_Table_Select::COLUMNS)->columns(array('count' => 'COUNT(*)'));
         $this->_filteredCount = $selectCount->getTable()->fetchRow($selectCount)->count;
     } else {
         $this->_filteredCount = $selectCount->getTable()->fetchAll($selectCount)->count();
     }
     // Load the limited result
     $selectFiltered->limit($iDisplayLength, $iDisplayStart);
     if (count($order) > 0) {
         $selectFiltered->order($order);
     }
     $this->_data = $selectFiltered->getTable()->fetchAll($selectFiltered);
 }