Example #1
0
 /**
  * Cria linhas no relatório
  * 
  * @param array $columns
  * @param bool $title
  */
 protected function _addRow($columns, $title = false, $subtotal = false, $columnsTitle = array(), $borderTop = true)
 {
     $styles = array();
     if ($this->_styleRow && !$title) {
         $styles = $this->_mapper->getStylesRow($columns, $this->_options['id'], $subtotal);
     }
     if ($title && count($this->_columnsTitle) > 0) {
         foreach ($this->_columnsTitle as $column) {
             $_cell = new ZendT_Report_Cell();
             $_cell->setValue($column['label']);
             $_cell->setWidth($column['width']);
             if ($column['colspan']) {
                 $_cell->setColspan($column['colspan'] - 1);
             }
             $_cell->setTextAlign('center');
             $_cell->setFontWeight(true);
             $_cell->setFontSize($this->_fontSize);
             //$this->_configBorder($_cell,$column['border']);
             $this->_report->addCell($_cell);
         }
         $this->_report->printCells(false, $title);
     }
     /* echo '<pre>';
        print_r($columns);
        echo '</pre>';
        $this->count++;
        if ($this->count > 3) {
        exit;
        } */
     foreach ($this->_columns as $column => $atributes) {
         /**
          * @todo Verificar qual o melhor lugar para colocar o replace abaixo 
          */
         $column = str_replace('-distinct', '', $column);
         $column = str_replace('_distinct', '', $column);
         if ($title) {
             $value = $atributes['label'];
         } else {
             if (isset($columns[$column])) {
                 $value = $columns[$column];
             } else {
                 $value = '';
             }
         }
         $_cell = new ZendT_Report_Cell();
         if ($title) {
             $column = 'title_' . $column;
         }
         if ($subtotal) {
             $column = 'total_' . $column;
         }
         $_cell->setName($column);
         $_cell->setValue($value);
         $parseUrl = false;
         if ($value instanceof ZendT_Type) {
             $valueColumn = $value->getValueToDb();
             if (isset($this->_columnsJumped[$column])) {
                 $jumpedRow = in_array($valueColumn, $this->_columnsJumped[$column]);
             }
             if ($atributes['first_record'] && $valueColumn) {
                 if ($this->_columnsRepeat[$column] == $valueColumn) {
                     $_cell->setValue(NULL);
                 }
                 $this->_columnsRepeat[$column] = $valueColumn;
             }
             $parseUrl = true;
         }
         $url = str_replace("?", "&", $atributes['url']);
         $urlView = current(explode('&', $url));
         if ($urlView) {
             $isUrlView = strpos($urlView, "view=") || is_numeric($urlView);
             if ($isUrlView) {
                 $urlParams = explode('&', substr($url, strpos($url, "&") + 1));
                 $newParams = '';
                 foreach ($urlParams as $key => $val) {
                     $data = explode("=", $urlParams[$key]);
                     if ($data[0] && $data[1]) {
                         $newParams[$data[0]] = $data[1];
                     }
                 }
                 $urlView = end(explode("view=", $urlView));
                 $urlParams = $newParams;
                 $atributes['url'] = '';
                 foreach ($this->_params as $param => $key) {
                     $atributes['url'] .= "&{$param}=:{$param}";
                 }
                 if (!$this->_arrayUrl) {
                     foreach ($this->_columnsOrig as $param => $key) {
                         if (!$key['subtotal']) {
                             $this->_arrayUrl[] = $param;
                         }
                     }
                 }
                 if ($subtotal) {
                     if ($this->_labelBreak == 'Subtotal') {
                         foreach ($this->_columnsBreak as $param => $key) {
                             $atributes['url'] .= "&{$param}=:{$param}";
                         }
                     } else {
                         if ($this->_labelBreak == 'Total') {
                         }
                     }
                 } else {
                     foreach ($this->_arrayUrl as $key => $param) {
                         $atributes['url'] .= "&{$param}=:{$param}";
                     }
                 }
                 if ($urlParams) {
                     foreach ($urlParams as $key => $val) {
                         if ($key == $val) {
                             $val = ":{$val}";
                         }
                         $atributes['url'] .= "&{$key}={$val}";
                     }
                 }
             }
         }
         if ($atributes['input'] && $this->_configColumns[$column]['input'] != null) {
             $atributes['input'] = $this->_configColumns[$column]['input'];
         }
         $_cell->setInput($atributes['input']);
         if ($atributes['url'] && !$title && $parseUrl) {
             $url = trim($atributes['url']);
             if (strpos($url, ':') !== false) {
                 preg_match_all("/\\:(.*?)\\&/", $url . "&", $params);
                 #print_r($params);die;
                 list($aliasName, $aliasName2) = explode('_', $column);
                 $paramKey = array();
                 $paramValues = array();
                 foreach ($params[1] as $paramName) {
                     $paramValue = '';
                     if (isset($this->_columnsOrig[$paramName])) {
                         $paramValue = $this->_columnsOrig[$paramName];
                     } else {
                         if (isset($columns[$paramName])) {
                             $paramValue = $columns[$paramName];
                         } else {
                             if (isset($this->_columnsPivot[$paramName]['labels'][$aliasName])) {
                                 $paramValue = $this->_columnsPivot[$paramName]['labels'][$aliasName];
                             } else {
                                 if (isset($this->_columnsPivot[$paramName]['labels'][$aliasName2])) {
                                     $paramValue = $this->_columnsPivot[$paramName]['labels'][$aliasName2];
                                 } else {
                                     if (isset($this->_params[$paramName])) {
                                         $paramValue = $this->_params[$paramName];
                                     } else {
                                         foreach ($this->_columns as $column => $keys) {
                                             if ($keys['columnName'] == $paramName) {
                                                 $subtotalColumn = $paramName . "_" . $keys['subtotal'];
                                                 if ($columns[$paramName]) {
                                                     $paramValue = $columns[$paramName]->get();
                                                 } else {
                                                     if ($columns[$subtotalColumn]) {
                                                         $paramValue = $columns[$subtotalColumn]->get();
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     /* if (substr($paramName,0,3) == 'exp'){
                        $paramValue = utf8_decode($paramValue);
                        } */
                     $paramKey[] = ':' . $paramName;
                     $paramValues[] = utf8_decode($paramValue);
                 }
                 $url = str_replace($paramKey, $paramValues, $url);
             } else {
                 $url .= $value;
             }
             if ($isUrlView) {
                 $url = ZendT_Url::getUri() . "?profile=" . $urlView . $url;
             }
             $url = str_replace('{host}', ZendT_Url::getHostName(), $url);
             $url = str_replace('{baseUrl}', ZendT_Url::getHostName() . ZendT_Url::getBaseUrl(), $url);
             $_cell->setUrl($url);
         }
         if ($atributes['width']) {
             if (strpos($atributes['width'], ',') !== false) {
                 $atributes['width'] = (double) str_replace(array('.', ','), array('', '.'), $atributes['width']);
             }
             $_cell->setWidth($atributes['width']);
         } else {
             $_cell->setWidth($atributes['width']);
         }
         $_cell->setTextAlign($atributes['align']);
         $_cell->setFontWeight($title || $subtotal || $jumpedRow);
         $this->_configBorder($_cell, $atributes['border']);
         if ($title) {
             $_cell->setBorderBottom(0.4, 'solid', '#000000');
         }
         if ($this->firstLine) {
             $_cell->setBorderTop(0.2, 'solid', '#000000');
         }
         if ($subtotal && $borderTop) {
             $_cell->setBorderTop(0.2, 'solid', '#000000');
         }
         if ($atributes['font-size']) {
             if (strpos($atributes['font-size'], ',') !== false) {
                 $atributes['font-size'] = (double) str_replace(array('.', ','), array('', '.'), $atributes['font-size']);
             }
             $_cell->setFontSize($atributes['font-size']);
         } else {
             $_cell->setFontSize($this->_fontSize);
         }
         if (isset($styles[$column])) {
             $_cell->setStyles($styles[$column]);
         }
         $this->_report->addCell($_cell);
         if ($atributes['subtotal'] && $subtotal == false && ($value instanceof ZendT_Type_Number || $value instanceof ZendT_Type_NumberTime)) {
             if (!isset($this->_total[$column])) {
                 $this->_total[$column] = clone $value;
             }
             if (isset($atributes['calctotal'])) {
                 $this->_total[$column]->setTotalCalc($columns, $atributes['calctotal']);
             } else {
                 $this->_total[$column]->setTotal($value, $atributes['subtotal']);
             }
             if (count($this->_columnsBreak) > 0) {
                 foreach ($this->_columnsBreak as &$columnBreak) {
                     if (!isset($columnBreak['subtotal'][$column])) {
                         $columnBreak['subtotal'][$column] = clone $value;
                     }
                     if (isset($atributes['calctotal'])) {
                         $columnBreak['subtotal'][$column]->setTotalCalc($columns, $atributes['calctotal']);
                     } else {
                         $columnBreak['subtotal'][$column]->setTotal($value, $atributes['subtotal']);
                     }
                 }
             }
         }
     }
     $zebra = true;
     if ($subtotal && $borderTop) {
         $zebra = false;
     }
     if ($title) {
         $this->firstLine = true;
         $zebra = false;
     } else {
         $this->firstLine = false;
     }
     $this->_report->printCells($zebra, $title);
 }