Beispiel #1
0
 /**
  * Return the bytes representing the export format (for instance, binary code
  * describing a PDF or Excel file). These will be offered to download.
  *
  * @param Garp_Util_Configuration $params Various parameters describing which content to export
  * @return string
  */
 public function getOutput(Garp_Util_Configuration $params)
 {
     $mem = new Garp_Util_Memory();
     $mem->useHighMemory();
     $params->setDefault('rule', null)->setDefault('rule2', null);
     $filter = array();
     if (array_key_exists('filter', $params) && $params['filter']) {
         $filter = urldecode($params['filter']);
         $filter = Zend_Json::decode($params['filter']);
     }
     $fetchOptions = array('query' => $filter, 'rule' => $params['rule'], 'rule2' => $params['rule2']);
     if (!empty($params['fields'])) {
         $fields = is_array($params['fields']) ? $params['fields'] : explode(',', $params['fields']);
         $fetchOptions['fields'] = array_combine($fields, $fields);
     }
     if (isset($params['sortField']) && isset($params['sortDir'])) {
         $fetchOptions['sort'] = array($params['sortField'] . ' ' . $params['sortDir']);
     }
     switch ($params['selection']) {
         case 'id':
             // specific record
             $params->obligate('id');
             $fetchOptions['query']['id'] = Zend_Json::decode($params['id']);
             break;
         case 'page':
             $params->obligate('pageSize');
             // specific page
             if (isset($params['page'])) {
                 $fetchOptions['start'] = ($params['page'] - 1) * $params['pageSize'];
                 $fetchOptions['limit'] = $params['pageSize'];
                 // specific selection of pages
             } elseif (isset($params['from']) && isset($params['to'])) {
                 $pages = $params['to'] - $params['from'] + 1;
                 $fetchOptions['start'] = ($params['from'] - 1) * $params['pageSize'];
                 $fetchOptions['limit'] = $pages * $params['pageSize'];
             } else {
                 throw new Garp_Content_Exception(self::EXCEPTION_INVALID_CONFIG);
             }
             break;
     }
     $fetchOptions['filterForeignKeys'] = true;
     $className = Garp_Content_Api::modelAliasToClass($params['model']);
     $model = new $className();
     $this->_bindModels($model);
     // Allow the model or its observers to modify the fetchOptions
     $model->notifyObservers('beforeExport', array(&$fetchOptions));
     $manager = new Garp_Content_Manager($model);
     $data = $manager->fetch($fetchOptions);
     $data = (array) $data;
     // Allow the model or its observers to modify the data
     $model->notifyObservers('afterExport', array(&$data, &$fetchOptions));
     if (empty($data)) {
         $data = array(array('message' => __('no results found')));
     }
     $humanizedData = $this->_humanizeData($data, $model);
     $formattedData = $this->format($model, $humanizedData);
     return $formattedData;
 }
Beispiel #2
0
 /**
  * Set default options
  *
  * @param array $options
  * @return void
  */
 protected function _setDefaultOptions(&$options)
 {
     $options = new Garp_Util_Configuration($options);
     $options->setDefault('formatForRobots', '%Y-%m-%d')->setDefault('attributes', array());
     $options = (array) $options;
 }
Beispiel #3
0
 /**
  * Generate a Facebook facepile.
  *
  * @param array $params Various Facebook URL parameters
  * @param bool $useFacebookPageAsUrl
  * @return string
  */
 public function facebookFacepile(array $params = array(), $useFacebookPageAsUrl = false)
 {
     $this->_needsFacebookInit = true;
     $params = new Garp_Util_Configuration($params);
     $params->setDefault('href', array_key_exists('href', $params) && $params['href'] ? $params['href'] : $this->_getCurrentUrl())->setDefault('max_rows', 1)->setDefault('width', 450)->setDefault('colorscheme', 'light');
     if ($useFacebookPageAsUrl) {
         $this->_setFacebookPageUrlAsHref($params);
     }
     $html = '<fb:facepile ' . $this->_renderHtmlAttribs($params) . '></fb:facepile>';
     return $html;
 }