示例#1
0
 /**
  *
  * @return TextTable
  */
 private function getTable()
 {
     $paginator = $this->getPaginator();
     $translator = $this->getTranslator();
     $options = ['columnWidths' => $this->getColumnWidths()];
     $table = new TextTable($options);
     $table->setDecorator('ascii');
     /*
      * Title
      */
     $tableRow = new Table\Row();
     $tableColumn = new Table\Column($this->getTitle());
     $tableColumn->setColSpan(count($options['columnWidths']));
     $tableColumn->setAlign(Table\Column::ALIGN_CENTER);
     $tableRow->appendColumn($tableColumn);
     $table->appendRow($tableRow);
     /**
      * Header
      */
     $tableRow = new Table\Row();
     foreach ($this->getColumnsToDisplay() as $column) {
         $label = $column->getLabel();
         if ($this->getTranslator() !== null) {
             $label = $this->getTranslator()->translate($label);
         }
         if (function_exists('mb_strtoupper')) {
             $label = mb_strtoupper($label);
         } else {
             $label = strtoupper($label);
         }
         $tableColumn = new Table\Column($label);
         if ($column->getType() instanceof Type\Number) {
             $tableColumn->setAlign(Table\Column::ALIGN_RIGHT);
         } else {
             $tableColumn->setAlign(Table\Column::ALIGN_LEFT);
         }
         $tableRow->appendColumn($tableColumn);
     }
     $table->appendRow($tableRow);
     /*
      * Data
      */
     foreach ($this->getData() as $row) {
         $tableRow = new Table\Row();
         foreach ($this->getColumnsToDisplay() as $column) {
             $value = '';
             if (isset($row[$column->getUniqueId()])) {
                 $value = $row[$column->getUniqueId()];
             }
             if (is_array($value)) {
                 $value = implode(', ', $value);
             }
             $tableColumn = new Table\Column($value);
             if ($column->getType() instanceof Type\Number) {
                 $tableColumn->setAlign(Table\Column::ALIGN_RIGHT);
             } else {
                 $tableColumn->setAlign(Table\Column::ALIGN_LEFT);
             }
             $tableRow->appendColumn($tableColumn);
         }
         $table->appendRow($tableRow);
     }
     /*
      * Pagination
      */
     $tableRow = new Table\Row();
     $footer = $translator->translate('Page') . ' ';
     $footer .= $paginator->getCurrentPageNumber() . ' ' . $translator->translate('of') . ' ' . $paginator->count();
     $footer .= ' / ';
     $footer .= $translator->translate('Showing') . ' ' . $paginator->getCurrentItemCount() . ' ' . $translator->translate('of') . ' ' . $paginator->getTotalItemCount() . ' ' . $translator->translate('items');
     $tableColumn = new Table\Column($footer);
     $tableColumn->setColSpan(count($options['columnWidths']));
     $tableColumn->setAlign(Table\Column::ALIGN_CENTER);
     $tableRow->appendColumn($tableColumn);
     $table->appendRow($tableRow);
     return $table;
 }