Example #1
0
 /**
  * Fetch max amount of chunks.
  * @param Zend_Db_Select $select The specific select for this instance.
  * @param Garp_Browsebox $browsebox The browsebox, made available to fetch metadata from.
  * @return Void
  */
 public function fetchMaxChunks(Zend_Db_Select $select, Garp_Browsebox $browsebox)
 {
     if (!empty($this->_params)) {
         $model = $browsebox->getModel();
         $filterModel = new $this->_config['model']();
         $bindingModel = new $this->_config['bindingOptions']['bindingModel']();
         $rule1 = !empty($this->_config['bindingOptions']['rule']) ? $this->_config['bindingOptions']['rule'] : null;
         $rule2 = !empty($this->_config['bindingOptions']['rule2']) ? $this->_config['bindingOptions']['rule2'] : null;
         $modelReference = $bindingModel->getReference(get_class($model), $rule1);
         $filterModelReference = $bindingModel->getReference($this->_config['model'], $rule2);
         $joinConditions = array();
         foreach ($modelReference['refColumns'] as $i => $refColumn) {
             $column = $modelReference['columns'][$i];
             $joinCondition = '';
             $joinCondition .= $bindingModel->getAdapter()->quoteIdentifier($refColumn);
             $joinCondition .= ' = ';
             $joinCondition .= $bindingModel->getAdapter()->quoteIdentifier($column);
             $joinConditions[] = $joinCondition;
         }
         $joinConditions = implode(' AND ', $joinConditions);
         $countSelect = $model->select()->from($model->getName(), array('c' => 'COUNT(*)'))->join($bindingModel->getName(), $joinConditions, array());
         if ($where = $browsebox->getOption('conditions')) {
             $countSelect->where($where);
         }
         foreach ($filterModelReference['columns'] as $i => $foreignKey) {
             $countSelect->where($bindingModel->getAdapter()->quoteIdentifier($foreignKey) . ' = ?', $this->_params[$i]);
         }
         $result = $model->fetchRow($countSelect);
         return $result->c;
     } else {
         throw new Garp_Browsebox_Filter_Exception_NotApplicable();
     }
 }
 /**
  * Fetch a Browsebox object configured based on parameters found in the request.
  *
  * @param Zend_Controller_Request_Abstract $request The current request
  * @return Garp_Browsebox
  */
 protected function _initBrowsebox(Zend_Controller_Request_Abstract $request)
 {
     $bb = Garp_Browsebox::factory($request->getParam('id'));
     if ($request->getParam('conditions')) {
         $options = unserialize(base64_decode($request->getParam('conditions')));
         if (!empty($options['filters'])) {
             $conditions = base64_decode($options['filters']);
             $conditions = explode(Garp_Browsebox::BROWSEBOX_QUERY_FILTER_SEPARATOR, $conditions);
             foreach ($conditions as $condition) {
                 $parts = explode(':', $condition);
                 if (count($parts) < 2) {
                     continue;
                 }
                 $filterId = $parts[0];
                 $params = explode(Garp_Browsebox::BROWSEBOX_QUERY_FILTER_PROP_SEPARATOR, $parts[1]);
                 $bb->setFilter($filterId, $params);
             }
         }
         unset($options['filters']);
         foreach ($options as $key => $value) {
             $bb->setOption($key, $value);
         }
     }
     $chunk = $request->getParam('chunk');
     if ($chunk < 1) {
         $chunk = 1;
     }
     $bb->init($chunk);
     return $bb;
 }