Пример #1
0
 /**
  * Display stats.
  * @return bool
  */
 public function showStatsList()
 {
     $sql = "SELECT groupid, MIN(timeadded) AS mintime, MAX(timeadded) AS maxtime, COUNT(id) AS numactions\n                FROM dbtrack_actions\n                GROUP BY groupid\n                ORDER BY MIN(timeadded)";
     $results = $this->dbms->getResults($sql);
     if (empty($results)) {
         $this->display->outputMessage('No stats found.');
         return true;
     }
     $this->display->setHeader(array('Group', 'From', 'To', 'Actions'));
     $this->display->setPadding(array(5, 19, 19, 10));
     $this->display->showHeader();
     foreach ($results as $result) {
         $line = array($result->groupid, date('d/m/Y H:i:s', $result->mintime), date('d/m/Y H:i:s', $result->maxtime), $result->numactions);
         $this->display->showLine($line);
     }
     return true;
 }
Пример #2
0
 /**
  * Display final output.
  * @param array $fullRows
  * @param array $actions
  * @throws \Exception
  */
 protected function displayRows(array $fullRows, array $actions)
 {
     // The position is the same for $fullRows and $changedRows (for cross referencing purposes).
     $rowCount = 0;
     foreach ($fullRows as $row) {
         // First column is the row's table and then all the columns.
         $header = array_merge(array($row->table), array_keys((array) $row->data));
         // Add action type as the first column in the data row.
         $line = array($this->dbms->getTrackTypeDescription($row->type));
         $padding = strlen($header[0]) > strlen($line[0]) ? array(strlen($header[0])) : array(strlen($line[0]));
         // Column counter.
         $pos = 0;
         foreach ($row->data as $column => $value) {
             ++$pos;
             if ($this->valueDisplayLength > 0 && strlen($value) > $this->valueDisplayLength) {
                 $value = substr($value, 0, 20) . '...';
             }
             // Make sure the column's display width is long enough.
             $padding[] = strlen($value) > strlen($header[$pos]) ? strlen($value) : strlen($header[$pos]);
             // Highlight only changed columns.
             if ($row->type == Database::TRIGGER_ACTION_UPDATE) {
                 if (isset($actions[$rowCount]->data->{$column}) && $row->primarycolumn != $column) {
                     $value = $this->display->getColourText($value, 'yellow');
                 }
             }
             $line[] = $value;
         }
         // Display line.
         $this->display->setHeader($header);
         $this->display->setPadding($padding);
         $this->display->showHeader();
         $this->display->showLine($line);
         $this->display->showLine();
         ++$rowCount;
     }
 }