/** * Generate table output * * @param VcsStats_Table $table Table * @return void */ public function renderTable(VcsStats_Report_Element_Table $table) { $result = ''; $output = new ezcConsoleOutput(); $output->formats->title->style = array('bold'); $alignments = array('center' => ezcConsoleTable::ALIGN_CENTER, 'left' => ezcConsoleTable::ALIGN_LEFT, 'right' => ezcConsoleTable::ALIGN_RIGHT); $consoleTable = new ezcConsoleTable($output, 78); // Display header $consoleTable[0]->align = ezcConsoleTable::ALIGN_CENTER; foreach ($table->getColumns() as $column) { $consoleTable[0][]->content = $column->getTitle(); } // Display values foreach ($table->getRows() as $i => $row) { $j = 0; foreach ($row as $code => $value) { $alignment = $table->getColumn($code)->getAlignment(); $consoleTable[$i + 1][$j]->align = $alignments[$alignment]; $consoleTable[$i + 1][$j]->content = $value; $j++; } } ob_start(); $output->outputLine(); $output->outputLine($table->getTitle(), 'title'); $consoleTable->outputTable(); $output->outputLine(); $output->outputLine(); $result .= ob_get_clean(); echo $result; }
/** * Computes the number of revisions commited by each user * * @param int $startRevision First revision to work on * @param int $endRevision Last revision to work on * @return array Computed data */ protected function _computeRevisionsCountByAuthor($startRevision, $endRevision) { VcsStats_Runner_Cli::displayMessage('Calculating revisions count by author'); $table = new VcsStats_Report_Element_Table(); $table->setCode('revisions_count_by_author'); $table->setTitle('Revisions count by author'); $table->addColumn(new VcsStats_Report_Element_Table_Column('Author', 'author')); $table->addColumn(new VcsStats_Report_Element_Table_Column('Count', 'count', VcsStats_Report_Element_Table_Column::ALIGNMENT_RIGHT)); $where = ''; if (null !== $startRevision && null != $endRevision) { $where = "WHERE id >= {$startRevision} AND id <= {$endRevision}"; } $sql = "SELECT author, COUNT(*) AS count\n FROM revisions\n {$where}\n GROUP BY author\n ORDER BY count DESC"; $data = $this->_cache->fetchAll($sql); $table->setRows($data); return $table; }
public function testSetRowsExistingRowsShouldBeReplaced() { $table = new VcsStats_Report_Element_Table(); $table->addRow(array('Value 0a', 'Value 0b', 'Value 0c')); $rows = array(array('Value 1a', 'Value 1b', 'Value 1c'), array('Value 2a', 'Value 2b', 'Value 2c'), array('Value 3a', 'Value 3b', 'Value 3c')); $table->setRows($rows); $this->assertSame($rows, $table->getRows()); }