Exemplo n.º 1
0
 public function __invoke($value, $precision = 2, $locale = 'pt_BR')
 {
     return \Cityware\Format\Number::decimalNumber($value, $precision, $locale);
 }
Exemplo n.º 2
0
 /**
  * Função que pega os dados da grid de acordo com o parametro
  * @param string $url
  * @param boolean $isDumpGrid
  * @return array 
  */
 public function recordSet($url, array $options = array(), $useLimit = true, array $recordSetData = null)
 {
     /* Arquivo de configuração do datagrid */
     $configGrid = ZendConfigFile::fromFile($this->sessionAdapter->moduleIni . $this->request['__CONTROLLER__'] . DS . ((isset($options['iniGridName']) and !empty($options['iniGridName'])) ? $options['iniGridName'] . ".ini" : "datagrid.ini"));
     $getParamsFieldGrid = $configGrid['gridfieldsconfig'];
     $getGridConfig = $configGrid['gridconfig']['grid'];
     if (isset($configGrid['gridbuttons'])) {
         $getParamsGridButtons = $configGrid['gridbuttons'];
     }
     $row = array();
     /* Colunas do datagrid */
     $headerColNames = $columNames = array();
     $primaryKey = null;
     $countHeaders = 0;
     foreach ($getParamsFieldGrid as $key => $value) {
         $columNames[] = $key;
         $headerColNames[] = $this->translate->translate($key);
         if (strtolower($value['type']) == 'primarykey') {
             $primaryKey = $key;
         }
         $countHeaders++;
     }
     /* Colunas do datagrid para busca */
     $columNamesSearchSort = array();
     // Verificar se a montagem da datagrid está utilizando checkbox para seleção
     if (!isset($getGridConfig['disableckeckall']) or $getGridConfig['disableckeckall'] != 'true') {
         $columNamesSearchSort[] = null;
         $countHeaders += 1;
     }
     // Pega os nomes das colunas para busca
     foreach ($getParamsFieldGrid as $key => $value) {
         $columNamesSearchSort[] = $key;
     }
     // Verificar se a montagem da datagrid está habilitados os botões de ação
     if (!isset($getGridConfig['disablebuttons']) or $getGridConfig['disablebuttons'] != 'true') {
         $columNamesSearchSort[] = null;
         $countHeaders += 1;
     }
     /* Recebe os dados do banco */
     if (!empty($recordSetData)) {
         $rsData = $recordSetData;
     } else {
         $rsData = $this->getDataRs($options, $useLimit);
     }
     $pagination = $rsData['page'];
     /* Formata a saida dos registros */
     $output = array();
     $output['total_rows'] = $pagination->getTotalItemCount();
     $output['headers'] = $headerColNames;
     $output['countColumns'] = $countHeaders;
     $output['aSorting']['tableColNames'] = $columNames;
     $output['aPagination'] = json_decode(json_encode($pagination->getPages()), true);
     if (!isset($getGridConfig['disablelimit']) or $getGridConfig['disablelimit'] != 'true') {
         $output['aPagination']['itensPage'] = (isset($this->request['itensPage']) and !empty($this->request['itensPage'])) ? $this->request['itensPage'] : 10;
     } else {
         $output['aPagination']['itensPage'] = 99999999999;
     }
     /* Popula os dados de registro do datagrid */
     $primaryValue = null;
     foreach ($rsData['db'] as $key => $value) {
         // Verificar se a montagem da datagrid á ou não para exportação
         if (!isset($options['export']) or $options['export'] !== true) {
             // Verificar se a montagem da datagrid está utilizando checkbox para seleção
             if (!isset($getGridConfig['disableckeckall']) or $getGridConfig['disableckeckall'] != 'true') {
                 foreach ($columNames as $name) {
                     switch (strtolower($getParamsFieldGrid[$name]['type'])) {
                         case 'integer':
                         case 'int2':
                         case 'int4':
                         case 'int8':
                         case 'primarykey':
                             if ($name == $primaryKey) {
                                 $row[$key][] = '<input type="checkbox" class="selection" name="idselect[]" value="' . $value[$name] . '" />';
                             }
                             break;
                     }
                 }
             }
         }
         foreach ($columNames as $name) {
             // Verifica e formata o valor de acordo com o tipo do campo
             switch (strtolower($getParamsFieldGrid[$name]['type'])) {
                 case 'integer':
                 case 'int2':
                 case 'int4':
                 case 'int8':
                 case 'primarykey':
                     $row[$key][] = (int) $value[$name];
                     if ($name == $primaryKey) {
                         $primaryValue = $value[$name];
                     }
                     break;
                 case 'text':
                 case 'string':
                 case 'varchar':
                 case 'char':
                     $row[$key][] = (string) $value[$name];
                     break;
                 case 'datetime':
                 case 'timestamp':
                     $format = (isset($getParamsFieldGrid[$name]['format']) and !empty($getParamsFieldGrid[$name]['format'])) ? $getParamsFieldGrid[$name]['format'] : 'd/m/Y H:i:s';
                     $row[$key][] = \Cityware\Format\FieldGrid::fieldMask($value[$name], "DATETIME", $format);
                     break;
                 case 'date':
                     $format = (isset($getParamsFieldGrid[$name]['format']) and !empty($getParamsFieldGrid[$name]['format'])) ? $getParamsFieldGrid[$name]['format'] : 'd/m/Y';
                     $row[$key][] = \Cityware\Format\FieldGrid::fieldMask($value[$name], "DATE", $format);
                     break;
                 case 'double':
                 case 'float':
                 case 'float4':
                 case 'float8':
                 case 'decimal':
                     $precision = (isset($getParamsFieldGrid[$name]['precision']) and !empty($getParamsFieldGrid[$name]['precision'])) ? $getParamsFieldGrid[$name]['precision'] : 2;
                     $row[$key][] = \Cityware\Format\Number::decimalNumber((double) $value[$name], $precision, $this->translate->getLocale());
                     break;
                 case 'money':
                     $precision = (isset($getParamsFieldGrid[$name]['precision']) and !empty($getParamsFieldGrid[$name]['precision'])) ? $getParamsFieldGrid[$name]['precision'] : 2;
                     $row[$key][] = \Cityware\Format\Number::currency((double) $value[$name], $precision, $this->translate->getLocale());
                     break;
                 case 'status':
                     $row[$key][] = \Cityware\Format\FieldGrid::fieldMask($value[$name], "STATUS");
                     break;
                 case 'boolean':
                     $row[$key][] = \Cityware\Format\FieldGrid::fieldMask($value[$name], "BOOLEAN");
                     break;
                 case 'custom':
                     $aValuesCustom = explode(',', $getParamsFieldGrid[$name]['values']);
                     $valuesCustomTranslate = explode(",", $this->translate->translate($name . '_values'));
                     foreach ($aValuesCustom as $keyCustom => $valueCustom) {
                         if ($valueCustom == $value[$name]) {
                             $return = $valuesCustomTranslate[$keyCustom];
                         }
                     }
                     $row[$key][] = $return;
                     break;
                 default:
                     $row[$key][] = $value[$name];
                     break;
             }
         }
         // Verificar se a montagem da datagrid á ou não para exportação
         if (!isset($options['export']) or $options['export'] !== true) {
             // Verificar se a montagem da datagrid está habilitados os botões de ação
             if (!isset($getGridConfig['disablebuttons']) or $getGridConfig['disablebuttons'] != 'true') {
                 // Verifica se é Lixeira ou não
                 if (isset($options['trash']) and $options['trash'] == true) {
                     $returnButtons = '<a title="Restaurar" href="' . $url . '/gorestore/id/' . $primaryValue . '" data-id="' . $primaryValue . '" class="btn btn-info restorebtn"><i class="fa fa-reply icon-white"></i></a>' . '<a title="Excluir" href="' . $url . '/godelete/id/' . $primaryValue . '" data-id="' . $primaryValue . '" class="btn btn-danger deletebtn"><i class="fa fa-trash-o"></i></a>';
                 } else {
                     if (isset($getParamsGridButtons) and !empty($getParamsGridButtons)) {
                         $aButtons = array();
                         foreach ($getParamsGridButtons['button'] as $keyButons => $valueButons) {
                             $classPopUp = $dataPopUp = $classConfirm = $dataConfirm = null;
                             if (strtolower($keyButons) != 'custom' and (isset($valueButons['confirm']) and $valueButons['confirm'] = 'true')) {
                                 $dataConfirm = ' data-confirm="' . $valueButons['confirmmsg'] . '" ';
                                 $classConfirm = ' ' . $valueButons['confirmclass'] . ' ';
                             }
                             if (strtolower($keyButons) != 'custom' and (isset($valueButons['popup']) and $valueButons['popup'] = 'true')) {
                                 $dataPopUp = ' data-popup="' . $valueButons['popup'] . '" ';
                                 $classPopUp = ' ' . $valueButons['popupclass'] . ' ';
                             }
                             if ($keyButons == 'edit' and is_array($valueButons) ? $getParamsGridButtons['button'][$keyButons]['show'] == 'true' : $getParamsGridButtons['button'][$keyButons] == 'true') {
                                 $aButtons[] = '<a title="Editar" href="' . $url . '/edit/id/' . $primaryValue . '" data-id="' . $primaryValue . '" ' . $dataConfirm . ' ' . $dataPopUp . ' class="btn btn-success editbtn ' . $classConfirm . ' ' . $classPopUp . '"><i class="fa fa-pencil"></i></a>';
                             } else {
                                 if ($keyButons == 'active' and is_array($valueButons) ? $getParamsGridButtons['button'][$keyButons]['show'] == 'true' : $getParamsGridButtons['button'][$keyButons] == 'true') {
                                     $aButtons[] = '<a title="Ativar" href="' . $url . '/goactive/id/' . $primaryValue . '" data-id="' . $primaryValue . '" ' . $dataConfirm . ' ' . $dataPopUp . ' class="btn btn-primary activebtn ' . $classConfirm . ' ' . $classPopUp . '"><i class="fa fa-check-square-o"></i></a>';
                                 } else {
                                     if ($keyButons == 'block' and is_array($valueButons) ? $getParamsGridButtons['button'][$keyButons]['show'] == 'true' : $getParamsGridButtons['button'][$keyButons] == 'true') {
                                         $aButtons[] = '<a title="Bloquear" href="' . $url . '/goblock/id/' . $primaryValue . '" data-id="' . $primaryValue . '" ' . $dataConfirm . ' ' . $dataPopUp . ' class="btn btn-warning blockbtn ' . $classConfirm . ' ' . $classPopUp . '"><i class="fa fa-ban"></i></a>';
                                     } else {
                                         if ($keyButons == 'trash' and is_array($valueButons) ? $getParamsGridButtons['button'][$keyButons]['show'] == 'true' : $getParamsGridButtons['button'][$keyButons] == 'true') {
                                             $aButtons[] = '<a title="Lixeira" href="' . $url . '/gotrash/id/' . $primaryValue . '" data-id="' . $primaryValue . '" ' . $dataConfirm . ' ' . $dataPopUp . ' class="btn btn-danger trashbtn ' . $classConfirm . ' ' . $classPopUp . '"><i class="fa fa-recycle"></i></a>';
                                         }
                                     }
                                 }
                             }
                             if (strtolower($keyButons) == 'custom') {
                                 if (isset($valueButons['url']) and !empty($valueButons['url'])) {
                                     foreach ($valueButons['url'] as $keyButtonCustom => $valueButtonCustom) {
                                         if (!empty($valueButons['url'][$keyButtonCustom])) {
                                             $urlButton = $valueButons['url'][$keyButtonCustom];
                                         } else {
                                             throw new \Exception('Nenhuma url definida para o botão personalizado no indice "' . $key . '"!', 500);
                                         }
                                         $urlButton = $this->preparePhpTagWhere($urlButton, false);
                                         if (isset($valueButons['confirm'][$keyButtonCustom]) and $valueButons['confirm'][$keyButtonCustom] = true) {
                                             $dataConfirm = ' data-confirm="' . $valueButons['confirmmsg'][$keyButtonCustom] . '" ';
                                             $classConfirm = ' ' . $valueButons['confirmclass'][$keyButtonCustom] . ' ';
                                         }
                                         if (isset($valueButons['popup'][$keyButtonCustom]) and $valueButons['popup'][$keyButtonCustom] = true) {
                                             $dataPopUp = ' data-popup="' . $urlButton . '" ';
                                             $classPopUp = ' ' . $valueButons['popupclass'][$keyButtonCustom] . ' ';
                                         }
                                         $name = (isset($valueButons['name'][$keyButtonCustom]) and !empty($valueButons['name'][$keyButtonCustom])) ? $valueButons['name'][$keyButtonCustom] : '';
                                         $extraClass = (isset($valueButons['extraClass'][$keyButtonCustom]) and !empty($valueButons['extraClass'][$keyButtonCustom])) ? $valueButons['extraClass'][$keyButtonCustom] : '';
                                         $btColor = (isset($valueButons['classBtColor'][$keyButtonCustom]) and !empty($valueButons['classBtColor'][$keyButtonCustom])) ? $valueButons['classBtColor'][$keyButtonCustom] : 'btn-success';
                                         $classIcon = (isset($valueButons['classIcon'][$keyButtonCustom]) and !empty($valueButons['classIcon'][$keyButtonCustom])) ? $valueButons['classIcon'][$keyButtonCustom] : 'fa fa-pencil';
                                         $nameIcon = (isset($valueButons['nameIcon'][$keyButtonCustom]) and !empty($valueButons['nameIcon'][$keyButtonCustom])) ? $valueButons['nameIcon'][$keyButtonCustom] : '';
                                         $aButtons[] = '<a title="' . $name . '" href="' . $urlButton . '/id/' . $primaryValue . '" data-id="' . $primaryValue . '" ' . $dataConfirm . ' ' . $dataPopUp . ' class="' . $extraClass . 'btn ' . $btColor . ' ' . $classConfirm . ' ' . $classPopUp . '"><i class="' . $classIcon . '">' . $nameIcon . '</i></a>';
                                     }
                                 } else {
                                     throw new \Exception('Nenhuma url definida para o botão personalizado!', 500);
                                 }
                             }
                         }
                         $returnButtons = implode('', $aButtons);
                     } else {
                         $returnButtons = '<a title="Editar" href="' . $url . '/edit/id/' . $primaryValue . '" data-id="' . $primaryValue . '" class="btn btn-success editbtn"><i class="fa fa-pencil"></i></a>' . '<a title="Ativar" href="' . $url . '/goactive/id/' . $primaryValue . '" data-id="' . $primaryValue . '" class="btn btn-primary activebtn"><i class="fa fa-check-square-o"></i></a>' . '<a title="Bloquear" href="' . $url . '/goblock/id/' . $primaryValue . '" data-id="' . $primaryValue . '" class="btn btn-warning blockbtn"><i class="fa fa-ban"></i></a>' . '<a title="Lixeira" href="' . $url . '/gotrash/id/' . $primaryValue . '" data-id="' . $primaryValue . '" class="btn btn-danger trashbtn"><i class="fa fa-recycle"></i></a>';
                     }
                 }
                 $row[$key][] = $returnButtons;
             }
         }
         $output['rows'] = $row;
     }
     /* Retorna os dados do datagrid */
     return $output;
 }