Esempio n. 1
0
 /**
  * Busca os dados da consulta
  */
 protected function _make()
 {
     $rs = $this->_getRecordset();
     $this->_printParams();
     $this->_verifyLineJump($this->_columns);
     $this->_addRow($this->_columns, true);
     if ($this->_options['driver'] == 'PDF') {
         #$this->_report->drawLine();
     }
     $row = $rs->getRow();
     if ($this->_options['log']) {
         $this->_log->finishDb();
     }
     $numRows = 0;
     if ($row) {
         if (count($this->_columnsBreak) > 0) {
             $current = '';
             $orderBreak = array();
             foreach ($this->_columnsBreak as $columnName => &$columnBreak) {
                 $orderBreak[] = $columnName;
                 $current .= $row[$columnName]->get();
                 $columnBreak['prev'] = $current;
             }
             $orderBreakReverse = array_reverse($orderBreak);
         }
         do {
             $numRows++;
             if (count($this->_columnsBreak) > 0) {
                 $current = '';
                 foreach ($this->_columnsBreak as $columnName => &$columnBreak) {
                     $current .= $row[$columnName]->get();
                     $columnBreak['current'] = $current;
                 }
                 foreach ($orderBreakReverse as $columnName) {
                     if ($this->_columnsBreak[$columnName]['current'] != $this->_columnsBreak[$columnName]['prev']) {
                         if ($this->_options['advanced']['order_column'] == '' && $this->_columnsBreak[$columnName]['subtotal']) {
                             $rowBreak = array();
                             $this->_labelBreak = 'Subtotal';
                             $rowBreak[$columnName] = $this->_labelBreak;
                             foreach ($this->_columnsBreak[$columnName]['subtotal'] as $column => $total) {
                                 $rowBreak[$column] = $total->getTotal($this->_mapper->getModel()->getAdapter());
                                 $this->_columnsBreak[$columnName]['subtotal'] = null;
                             }
                             $this->_addRow($rowBreak, false, true, array(), false);
                             /**
                              * Pula uma linha
                              */
                             foreach ($rowBreak as &$value) {
                                 $value = '';
                             }
                             $this->_addRow($rowBreak, false, true, array(), true);
                             #$this->_report->drawLine();
                         }
                         $this->_columnsBreak[$columnName]['prev'] = $this->_columnsBreak[$columnName]['current'];
                     }
                 }
             }
             $this->_verifyLineJump($row);
             $this->_addRow($row, false);
         } while ($row = $rs->getRow());
     }
     if ($this->_options['log']) {
         $this->_log->finish($numRows);
     }
     if (count($this->_columnsBreak) > 0) {
         foreach ($orderBreakReverse as $columnName) {
             if ($this->_options['advanced']['order_column'] == '' && $this->_columnsBreak[$columnName]['subtotal']) {
                 $rowBreak = array();
                 $this->_labelBreak = 'Subtotal';
                 $rowBreak[$columnName] = $this->_labelBreak;
                 foreach ($this->_columnsBreak[$columnName]['subtotal'] as $column => $total) {
                     $rowBreak[$column] = $total->getTotal($this->_mapper->getModel()->getAdapter());
                     $this->_columnsBreak[$columnName]['subtotal'] = null;
                 }
                 $this->_addRow($rowBreak, false, true);
                 #$this->_report->drawLine();
             }
         }
     }
     if (count($this->_total) > 0) {
         #$this->_report->drawLine();
         $row = array();
         foreach ($this->_columns as $column => $atributes) {
             break;
         }
         $this->_labelBreak = 'Total';
         $row[$column] = $this->_labelBreak;
         foreach ($this->_total as $columnName => $total) {
             $row[$columnName] = $total->getTotal($this->_mapper->getModel()->getAdapter());
         }
         $this->_addRow($row, false, true);
     }
 }
Esempio n. 2
0
 /**
  * Formata um dado de acordo com o tipo e a máscara definido
  * que será apresentado para o usuário
  *
  * @param string $value
  * @param string $format
  * @param string $locale
  * @return string
  */
 public function format($value, $format = null, $locale = null)
 {
     if ($format === null) {
         $format = $this->_mask;
     }
     if (!is_object($this->_mapper)) {
         if ($this->_mapper != '') {
             $this->_mapper = new $this->_mapper();
         }
     }
     if (is_object($this->_mapper)) {
         $columnName = substr($this->_index, strpos($this->_index, '.') + 1);
         return $this->_mapper->format($value, $columnName, $format, $locale);
     } else {
         $type = $this->getType();
         if ($type == 'Number' || $type == 'Numeric' || $type == 'Integer') {
             return ZendT_Type_Number::fromIso($value, $locale)->get($format);
         } else {
             if ($type == 'Date' || $type == 'DateTime') {
                 if ($format == '' || $format === null) {
                     if ($type == 'Date') {
                         $format = 'dd/MM/YYYY';
                     } else {
                         $format = 'dd/MM/YYYY HH:mm:s';
                     }
                 }
                 return ZendT_Type_Date::fromIso($value, $locale)->get($format);
             } else {
                 if ($this->_mask) {
                     return ZendT_Format::string($value, $this->_mask);
                 } else {
                     return $value;
                 }
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * Altera o registro da tabela
  *
  * @param ZendT_Db_Where
  * @return int|array
  */
 public function update($where = null)
 {
     if ($where == null) {
         $where = $this->getValueOld()->getWhere();
     }
     return parent::update($where);
 }
Esempio n. 4
0
 /**
  * Altera um registro da tabela
  * 
  * @param array|ZendT_Db_Mapper $data 
  * @param array|ZendT_Db_Where $where
  */
 public function update($data, $where)
 {
     if ($data instanceof ZendT_Db_Mapper) {
         if (!$where) {
             $where = $data->getWhere();
         }
         $data = $data->getData();
     }
     $bindWhere = array();
     if (is_array($where)) {
         $_where = new ZendT_Db_Where('AND');
         foreach ($where as $column => $value) {
             $_where->addFilter($column, $value);
         }
         $where = $_where;
         $bindWhere = $where->getBinds();
         $cmdWhere = $where->getSqlWhere();
     } elseif ($where instanceof ZendT_Db_Where) {
         $bindWhere = $where->getBinds();
         $cmdWhere = $where->getSqlWhere();
     } elseif (is_string($where)) {
         $cmdWhere = $where;
     }
     if (count($bindWhere) > 0) {
         $cmdWhere = $this->mergeWhereToString($cmdWhere, $bindWhere);
     }
     $newData = array();
     foreach ($data as $columName => $value) {
         #@todo verificar motivo das colunas que represetam a chave primária estar sendo populado para update
         if (in_array(strtolower($columName), $this->_primary) && count($this->_primary) == 1) {
             unset($data[$columName]);
         } else {
             $newData[strtolower($columName)] = $value;
         }
     }
     $data = $newData;
     $this->_setAdapter($this->_adapter);
     if ($data) {
         $tableSpec = $this->getTableName() . ' ' . $this->getAlias();
         $result = $this->_db->update($tableSpec, $data, $cmdWhere);
         //$result = parent::update($data, $cmdWhere);
     }
     /*if (!$result) {
           return false;
       }*/
     return $data;
 }
Esempio n. 5
0
 /**
  * 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);
 }