/** * Construtor da Classe * * @param string $driver * @param Zend_Db_Mapper $mapperView * @param string $title */ public function __construct($driver, $mapperView, $options) { $this->_options = $options; if (!isset($this->_options['log'])) { $this->_options['log'] = true; } if ($driver == '') { $driver = 'PDF'; } $this->_report = ZendT_Report::factory($driver, $options); $this->_report->setTitle($options['title']['value']); $this->_report->addPage(); $this->_mapper = $mapperView; $this->_columns = $this->_mapper->getColumns()->toArray(); $this->_fontSize = $options['fontSize']; if (!$this->_fontSize) { $this->_fontSize = 7; } if ($this->_options['log']) { $this->_log = new ZendT_Log_Report(get_class($this->_mapper), $options['title']['value']); } $this->_total = array(); $this->_type = array(); $this->_styleRow = false; if (method_exists($mapperView, 'getStylesRow')) { $this->_styleRow = true; } $this->_driver = $driver; }
/** * Ação de montagem dos dados para o Grid */ public function gridDataAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $postData = $this->getRequest()->getParams(); $whereGroup = $this->getWherePostData(); if ($this->_mapper instanceof ZendT_Db_View) { $dataGrid = $this->getMapper()->getDataGrid($whereGroup, $postData); } else { $dataGrid = $this->getModel()->getDataGrid($whereGroup, $postData); } $this->getGrid()->setRecords($dataGrid->getNumRows()); $rowsByPage = $postData['rows']; $listOptions = $this->getModel()->getListOptions(); $hasStylesRow = method_exists($this->getMapper(), 'getStylesRow'); $line = array(); $columns = $this->getColumns(true); $profileId = $this->getRequest()->getParam('profile'); $configColumns = $this->_mapper->getColumns()->toArray(); while ($row = $dataGrid->getRow()) { $stylesRow = array(); if ($hasStylesRow) { $stylesRow = $this->getMapper()->getStylesRow($row, $profileId); } #$line['id'] = $row['id']; foreach ($columns as $column) { $key = $column->getName(); if ($dataGrid->getType()) { $line[$key] = $row[strtolower($key)]->get(); } elseif ($dataGrid->isRowFormated()) { $line[$key] = $row[strtolower($key)]; } else { $line[$key] = $column->format($row[strtolower($key)]); } if (isset($listOptions[$key][$line[$key]])) { $line[$key] = $listOptions[$key][$line[$key]]; } if (trim($configColumns[$key]['subtotal'])) { $subtotal = $configColumns[$key]['subtotal']; if (!$this->_subtotal[$key]) { $options = array('numDecimal' => 2); if ($subtotal == 'count') { $options = array('numDecimal' => 0); } $this->_subtotal[$key] = new ZendT_Type_Number(0, $options); } $value = $row[strtolower($key)]->getValueToDb(); $this->_subtotal[$key]->setTotal($value, $configColumns[$key]['subtotal']); } } $this->getGrid()->addRow($line, $stylesRow); } if (isset($this->_subtotal)) { foreach ($this->_subtotal as $column => $key) { $columnBase = $configColumns[$column]['aliasTable'] . "_" . $column; $userData[$columnBase] = $this->_subtotal[$column]->getTotal()->get(); } $this->getGrid()->setUserData($userData); } echo $this->getGrid()->toJson($dataGrid->getNumPage(), $rowsByPage); }