예제 #1
0
 /**
  * Configura os dados para o modo render em tabela
  * 
  * @param array $dados
  * @param array $schema
  * @return string
  */
 public function getTable($dados, $schema)
 {
     $thead = array_keys($schema);
     $action = getValueFromArray($this->config, Crud::SHOW_TABLE_ACTIONS, true);
     if ($action) {
         $thead[] = 'Ações';
         #@todo refatorar init
         $dao_pks = $this->dao->getPKFieldName();
         if (is_string($dao_pks)) {
             $pk = $dao_pks;
         } else {
             if (is_array($dao_pks)) {
                 $pk = isset($dao_pks[0]) ? $dao_pks[0] : "no-primary-key-setted";
             } else {
                 $pk = "id";
                 //daoname_id
             }
         }
         $default_edit_url = str_replace('<id>', $pk, $this->urlbase . 'edit/{{<id>}}');
         $default_delete_url = str_replace('<id>', $pk, $this->urlbase . 'delete/{{<id>}}');
         $urledit = getValueFromArray($this->config, Crud::ACTION_URL_EDIT, $default_edit_url);
         $urldelete = getValueFromArray($this->config, Crud::ACTION_URL_DELETE, $default_delete_url);
         #refatorar end
     }
     $r = ['tfoot' => count($dados) . ' registro(s)', 'thead' => $thead, 'tbody' => [], 'class' => 'table-striped table-hover table-bordered browsetable'];
     $t = Template::singleton();
     foreach ($dados as $row) {
         $td = [];
         foreach ($schema as $template) {
             //date format would can be here :)
             $td[] = $t->renderHTML($template, $row);
         }
         if ($action) {
             $actions = HTML::link($t->renderHTML($urledit, $row), '<span class="glyphicon glyphicon-pencil"></span>', 'Editar este item', ['class' => 'btn btn-default btn-xs']);
             $actions .= ' ' . $this->getUserActions($t, $row);
             $showDelete = getValueFromArray($this->config, Crud::SHOW_DELETE_LINK, true);
             if ($showDelete) {
                 $actions .= ' ' . HTML::link($t->renderHTML($urldelete, $row), '<span class="glyphicon glyphicon-trash"></span>', 'Excluir este item', ['class' => 'btn btn-danger  btn-xs confirmacao']);
             }
             $td[] = $actions;
         }
         $r['tbody'][] = $td;
     }
     return $r;
 }