/**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return string
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $table = new TextTable(['columnWidths' => [25, 10, 20, 36], 'decorator' => 'ascii', 'AutoSeparate' => TextTable::AUTO_SEPARATE_HEADER, 'padding' => 1]);
     $table->appendRow(['store_name', 'store_id', 'springbot_store_id', 'springbot_guid']);
     foreach ($this->storeManager->getStores() as $store) {
         $springbotStoreId = $this->storeConfig->getSpringbotStoreId($store->getId());
         $springbotGuid = strtolower($this->storeConfig->getGuid($store->getId()));
         $table->appendRow([substr($store->getName(), 0, 23), $store->getId(), $springbotStoreId, $springbotGuid]);
     }
     $output->writeln($table->render());
 }
 public function queuesAction()
 {
     $resque = $this->getResqueService();
     $queue_stats = [];
     foreach ($resque->queues() as $queue) {
         $queue_stats[$queue] = ['size' => $resque->size($queue)];
     }
     $table = new Table(['columnWidths' => [25, 10]]);
     $table->appendRow(['Queue', 'Size']);
     foreach ($queue_stats as $key => $queue) {
         $table->appendRow([$key, $queue['size']]);
     }
     echo $this->getConsole()->colorize('Queue Statistics', ColorInterface::RED);
     echo $table;
 }
Example #3
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return string
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $headers = ['queue', 'class', 'method', 'args', 'priority', 'attempts', 'error'];
     $this->_jobCollection->setCurPage($input->getArgument(self::PAGE_ARGUMENT));
     $this->_jobCollection->setPageSize($input->getArgument(self::PER_PAGE_ARGUMENT));
     $this->_jobCollection->addOrder('priority', JobCollection::SORT_ORDER_ASC);
     $this->_jobCollection->addOrder('next_run_at', JobCollection::SORT_ORDER_ASC);
     if ($queue = $input->getArgument(self::QUEUE_ARGUMENT)) {
         $this->_jobCollection->addFieldToFilter('queue', $queue);
     }
     $jobs = $this->_jobCollection->toArray();
     // Pre-calculate the max column widths
     $maxWidths = [];
     foreach ($headers as $header) {
         $maxWidths[$header] = strlen($header) + 2;
     }
     foreach ($jobs['items'] as $job) {
         foreach ($headers as $header) {
             $newLength = strlen($job[$header]) + 2;
             if ($newLength > $maxWidths[$header]) {
                 $maxWidths[$header] = $newLength;
             }
         }
     }
     $maxWidths = array_values($maxWidths);
     $table = new TextTable(['columnWidths' => $maxWidths, 'decorator' => 'ascii', 'AutoSeparate' => TextTable::AUTO_SEPARATE_HEADER, 'padding' => 1]);
     $table->appendRow($headers);
     foreach ($jobs['items'] as $job) {
         $rowArr = [];
         foreach ($headers as $header) {
             $rowArr[$header] = $job[$header];
         }
         $table->appendRow($rowArr);
     }
     $output->writeln($table->render());
 }
 /**
  * Render a text table containing the data provided, that will fit inside console window's width.
  *
  * @param  $data
  * @param  $cols
  * @param  $consoleWidth
  * @return string
  */
 protected function renderTable($data, $cols, $consoleWidth)
 {
     $result = '';
     $padding = 2;
     // If there is only 1 column, just concatenate it
     if ($cols == 1) {
         foreach ($data as $row) {
             $result .= $row[0] . "\n";
         }
         return $result;
     }
     // Get the string wrapper supporting UTF-8 character encoding
     $strWrapper = StringUtils::getWrapper('UTF-8');
     // Determine max width for each column
     $maxW = array();
     for ($x = 1; $x <= $cols; $x += 1) {
         $maxW[$x] = 0;
         foreach ($data as $row) {
             $maxW[$x] = max($maxW[$x], $strWrapper->strlen($row[$x - 1]) + $padding * 2);
         }
     }
     /*
      * Check if the sum of x-1 columns fit inside console window width - 10
      * chars. If columns do not fit inside console window, then we'll just
      * concatenate them and output as is.
      */
     $width = 0;
     for ($x = 1; $x < $cols; $x += 1) {
         $width += $maxW[$x];
     }
     if ($width >= $consoleWidth - 10) {
         foreach ($data as $row) {
             $result .= implode("    ", $row) . "\n";
         }
         return $result;
     }
     /*
      * Use Zend\Text\Table to render the table.
      * The last column will use the remaining space in console window
      * (minus 1 character to prevent double wrapping at the edge of the
      * screen).
      */
     $maxW[$cols] = $consoleWidth - $width - 1;
     $table = new Table\Table();
     $table->setColumnWidths($maxW);
     $table->setDecorator(new Table\Decorator\Blank());
     $table->setPadding(2);
     foreach ($data as $row) {
         $table->appendRow($row);
     }
     return $table->render();
 }
Example #5
0
 /**
  * list available view scripts
  */
 public function listviewscriptsAction()
 {
     $config = $this->getServiceLocator()->get('Config');
     $table = new Table(array('columnWidths' => array(40, 40, 40), 'decorator' => 'ascii'));
     $table->appendRow(array('Module', 'Name', 'Description'));
     $offset = strlen(getcwd()) + 1;
     $links = "";
     $github = 'https://github.com/cross-solution/YAWIK/blob/master/';
     foreach ($config['view_manager']['template_map'] as $key => $absolute_filename) {
         // strip the application_root plus an additional slash
         $filename = substr(realpath($absolute_filename), $offset);
         if (preg_match('~module/([^/]+)~', $filename, $match)) {
             $module = $match[1];
         } else {
             $module = "not found ({$key})";
         }
         $viewModel = new ViewModel();
         $viewModel->setTemplate($key);
         $row = new Row();
         $row->appendColumn(new Column($module));
         if ($filename) {
             $row->appendColumn(new Column('`' . $key . '`_'));
             $links .= '.. _' . $key . ': ' . $github . $filename . PHP_EOL;
         } else {
             $row->appendColumn(new Column("WRONG CONFIGURATION"));
         }
         $comment = "";
         if (file_exists($absolute_filename)) {
             $src = file_get_contents($absolute_filename);
             $comment = "file exists";
             if (preg_match("/{{rtd:\\s*(.*)}}/", $src, $match)) {
                 $comment = $match['1'];
             }
         }
         $row->appendColumn(new Column($comment));
         $table->appendRow($row);
     }
     echo $table . PHP_EOL;
     echo $links;
     return PHP_EOL;
 }
Example #6
0
 public function testTableMagicToString()
 {
     $table = new Table\Table(array('columnWidths' => array(10)));
     $row = new Table\Row();
     $row->appendColumn(new Table\Column('foobar'));
     $table->appendRow($row);
     $this->assertEquals((string) $table, "┌──────────┐\n│foobar    │\n└──────────┘\n");
 }
Example #7
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;
 }
Example #8
0
 private function parseTable(\DOMElement $node, $context)
 {
     /*{{{*/
     $trs = $this->xpath->query('txt:tr', $node);
     $num_cols = 0;
     $rows = array();
     foreach ($trs as $tr) {
         $row = new Zend_Row();
         $tds = $this->xpath->query('txt:td', $tr);
         $len = $tds->length;
         if ($len > $num_cols) {
             $num_cols = $len;
         }
         foreach ($tds as $td) {
             $td_text = "";
             foreach ($td->childNodes as $child) {
                 $td_text .= $this->parseNode($child, $context);
             }
             $column = new Zend_Column($td_text);
             if ($td->hasAttribute('colspan')) {
                 $column->setColSpan((int) $td->getAttribute('colspan'));
             }
             $row->appendColumn($column);
         }
         $rows[] = $row;
     }
     if ($num_cols) {
         $col_width = (int) floor($this->wordwrap / $num_cols);
         $table = new Zend_Table(array('columnWidths' => array_fill(0, $num_cols, $col_width), 'decorator' => 'ascii', 'padding' => 1));
         foreach ($rows as $row) {
             $table->appendRow($row);
         }
         return $table->render();
     }
 }
Example #9
0
 /**
  * Convert the table tag
  *
  * @param  DOMElement $node
  * @return string
  */
 public static function table($node)
 {
     // check if thead exists
     if (0 !== $node[0]->getElementsByTagName('thead')->length) {
         $head = true;
     } else {
         $head = false;
     }
     $rows = $node[0]->getElementsByTagName('row');
     $table = array();
     $totRow = $rows->length;
     $j = 0;
     foreach ($rows as $row) {
         $cols = $row->getElementsByTagName('entry');
         $totCol = $cols->length;
         if (!isset($widthCol)) {
             $widthCol = array_fill(0, $totCol, 0);
         }
         $i = 0;
         foreach ($cols as $col) {
             $table[$j][$i] = self::formatText($col->nodeValue);
             $length = strlen($table[$j][$i]);
             if ($length > $widthCol[$i]) {
                 $widthCol[$i] = $length;
             }
             $i++;
         }
         $j++;
     }
     $tableText = new Table\Table(array('columnWidths' => $widthCol, 'decorator' => 'ascii'));
     for ($j = 0; $j < $totRow; $j++) {
         $row = new Table\Row();
         for ($i = 0; $i < $totCol; $i++) {
             $row->appendColumn(new Table\Column($table[$j][$i]));
         }
         $tableText->appendRow($row);
     }
     $output = $tableText->render();
     // if thead exists change the table style with head (= instead of -)
     if ($head) {
         $table = explode("\n", $output);
         $newOutput = '';
         $i = 0;
         foreach ($table as $row) {
             if ('+-' === substr($row, 0, 2)) {
                 $i++;
             }
             if (2 === $i) {
                 $row = str_replace('-', '=', $row);
             }
             $newOutput .= "{$row}\n";
         }
         return $newOutput;
     }
     return $output;
 }
 /**
  * @param TextTable      $table
  * @param StoreInterface $store
  * @param                $message
  * @param bool|false     $appendIfUnregistered
  * @return bool
  */
 private function addToTable(TextTable $table, StoreInterface $store, $message, $appendIfUnregistered = false)
 {
     $springbotStoreId = $this->storeConfig->getSpringbotStoreId($store->getId());
     $springbotGuid = strtolower($this->storeConfig->getGuid($store->getId()));
     if ($springbotStoreId && $springbotGuid || $appendIfUnregistered) {
         $table->appendRow([substr($store->getName(), 0, 23), $store->getId(), $springbotStoreId, $message]);
         return true;
     }
     return false;
 }
Example #11
0
 /**
  * Generic function to find matches
  * Tested for expense attachments
  *
  * @param Table $table
  * @param array $options
  * [
  *      id => 'id',
  *      filename => 'filename',
  *      dir      => '/ginosi/uploads/expense',
  *     'type'    => 'Purchase Order Ticket'
  *     'depth'    => 4
  *      sql      => 'select filename, from ga_expense_attachments'
  * ]
  */
 private function matchAttachments(Table $table, array $options)
 {
     /**
      * @var Adapter $dbAdapter
      */
     $dbAdapter = $this->getServiceLocator()->get('dbadapter');
     $rows = $dbAdapter->createStatement($options['sql'])->execute();
     $dbFileNames = [];
     foreach ($rows as $row) {
         $dbFileNames[] = $row['filename'];
     }
     $dirStr = '';
     for ($i = 1; $i <= $options['depth']; $i++) {
         $dirStr .= '/*';
     }
     $files = glob($options['dir'] . $dirStr . '/*.*');
     $diskFileNames = [];
     foreach ($files as $file) {
         $diskFileNames[] = basename($file);
     }
     $missingOnDisk = array_diff($dbFileNames, $diskFileNames);
     $missingOnDb = array_diff($diskFileNames, $dbFileNames);
     foreach ($missingOnDb as $missingFileOnDb) {
         // 'Missing on db - ' . $match . PHP_EOL;
         $table->appendRow([$this->runCounter(), 'type: ' . $options['type'] . PHP_EOL . 'filename: ' . $missingFileOnDb, 'x']);
     }
     foreach ($missingOnDisk as $missingFileOnDisk) {
         $table->appendRow([$this->runCounter(), 'x', $options['type'] . PHP_EOL . $missingFileOnDisk]);
     }
 }
Example #12
0
 public function showAction()
 {
     /**
      * @var \DDD\Service\Currency\Currency $currencyService
      */
     $currencyService = $this->getServiceLocator()->get('service_currency_currency');
     $currencies = $currencyService->getCurrencyList();
     $table = new Table(array('columnWidths' => array(3, 20, 5, 7, 14, 12, 5, 20)));
     $table->appendRow(array('id', 'label', 'code', 'symbol', 'current value', 'auto update', 'gate', 'last updated'));
     foreach ($currencies as $row) {
         $table->appendRow(array($row->getId(), $row->getName(), $row->getCode(), $row->getSymbol(), $row->getValue(), $row->getAutoUpdate(), $row->getGate(), $row->getLastUpdated()));
     }
     echo $table;
 }