Esempio n. 1
0
 /**
  * Create the grid data structure
  * 
  * @return object
  */
 protected function _createGridData(Zend_Controller_Request_Abstract $request)
 {
     // Instantiate Zend_Paginator with the required data source adaptor
     if (!$this->_paginator instanceof Zend_Paginator) {
         $this->_paginator = new Zend_Paginator($this->_adapter);
         $this->_paginator->setDefaultItemCountPerPage($request->getParam('rows', $this->_defaultItemCountPerPage));
     }
     // Filter items by supplied search criteria
     if ($request->getParam('_search') == 'true') {
         $filter = $this->_getFilterParams($request);
         $this->_paginator->getAdapter()->filter($filter['field'], $filter['value'], $filter['expression'], $filter['options']);
     }
     // Sort items by the supplied column field
     if ($request->getParam('sidx')) {
         $this->_paginator->getAdapter()->sort($request->getParam('sidx'), $request->getParam('sord', 'asc'));
     }
     // Pass the current page number to paginator
     $this->_paginator->setCurrentPageNumber($request->getParam('page', 1));
     // Fetch a row of items from the adapter
     $rows = $this->_paginator->getCurrentItems();
     $grid = new stdClass();
     $grid->page = $this->_paginator->getCurrentPageNumber();
     $grid->total = $this->_paginator->getItemCountPerPage();
     $grid->records = $this->_paginator->getTotalItemCount();
     $grid->rows = array();
     foreach ($rows as $k => $row) {
         if (isset($row['id'])) {
             $grid->rows[$k]['id'] = $row['id'];
         }
         $grid->rows[$k]['cell'] = array();
         foreach ($this->_columns as $column) {
             array_push($grid->rows[$k]['cell'], $column->cellValue($row));
         }
     }
     return $grid;
 }
Esempio n. 2
0
 protected function _checkVariables($force = false)
 {
     if ($this->_paginator) {
         if ($force || $this->_currentPage || $this->_request) {
             $this->_paginator->setCurrentPageNumber($this->getCurrentPage());
         }
         if ($force || $this->_itemCount || $this->_request) {
             if (!$this->_itemCount) {
                 $this->getItemCount();
             }
             // Recently found trick, can save a complicated database query
             // Fetch the items first and get the count in the same query
             $adapter = $this->_paginator->getAdapter();
             if ($adapter instanceof \MUtil_Paginator_Adapter_PrefetchInterface) {
                 $offset = ($this->_currentPage - 1) * $this->_itemCount;
                 // Calculate correct offset
                 $adapter->getItems($offset, $this->_itemCount);
             }
             $this->_paginator->setItemCountPerPage($this->_itemCount);
         }
     }
 }