/** * 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; }
/** * Modify results after update * * @param Array $response The original response * @param Array $request The original request * @return String */ protected function _modifyAfterUpdate($response, $request) { if ($this->_methodFailed($response)) { return $response; } $methodParts = explode('.', $request['method']); $modelClass = Garp_Content_Api::modelAliasToClass(array_shift($methodParts)); $man = new Garp_Content_Manager($modelClass); $rows = $man->fetch(array('query' => array('id' => $request['params'][0]['rows']['id']))); $response['result'] = array('rows' => $rows); return $response; }