mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-11-27 18:10:42 +00:00
render stats as table
This commit is contained in:
parent
8b67c33fa7
commit
0446009024
|
|
@ -6,9 +6,13 @@ use Symfony\Component\Console\Input\InputInterface;
|
|||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Helper\TableCell;
|
||||
use Symfony\Component\Console\Helper\TableSeparator;
|
||||
|
||||
use Seeddms\Seeddms\Settings;
|
||||
use Seeddms\Seeddms\Translator;
|
||||
use SeedDMS_Core_File;
|
||||
use Log_file;
|
||||
|
||||
class StatsCommand extends Command
|
||||
|
|
@ -30,9 +34,9 @@ class StatsCommand extends Command
|
|||
protected function configure()
|
||||
{
|
||||
$this->setName('dms:stats')
|
||||
->setDescription('Prints Statistics')
|
||||
->setHelp('Demonstration of custom commands created by Symfony Console component.')
|
||||
->addOption('json', '', InputOption::VALUE_NONE, 'Export data as json')
|
||||
->setDescription('Print statistics')
|
||||
->setHelp('Outputs the number of documents, folders, users, etc. in total and how many of them are owned by they users.')
|
||||
->addOption('json', '', InputOption::VALUE_NONE, 'Print data as json instead of a table')
|
||||
;
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +49,7 @@ class StatsCommand extends Command
|
|||
|
||||
require_once('inc/inc.DBInit.php');
|
||||
foreach (array('docstotal'=>'documents', 'folderstotal'=>'folders', 'userstotal'=>'users', 'groupstotal'=>'groups', 'categoriestotal'=>'categories') as $type=>$name) {
|
||||
$stats[$type] = $dms->getStatisticalData($type);
|
||||
$stats['total'][substr($type, 0, -5)] = $dms->getStatisticalData($type);
|
||||
}
|
||||
foreach (array('docsperuser'=>'documents', 'foldersperuser'=>'folders','sizeperuser'=>'size') as $type=>$name) {
|
||||
$stats[$type] = $dms->getStatisticalData($type);
|
||||
|
|
@ -53,6 +57,28 @@ class StatsCommand extends Command
|
|||
|
||||
if ($input->getOption('json')) {
|
||||
$output->writeln(json_encode($stats));
|
||||
} else {
|
||||
if(1) {
|
||||
$table = new Table($output);
|
||||
$table->setHeaders(['Name', 'Count/Size']);
|
||||
foreach($stats['total'] as $k=>$v)
|
||||
$table->addRow([$k, $v]);
|
||||
$table->addRow(new TableSeparator());
|
||||
$table->addRow([new TableCell($translator->translate('chart_docsperuser_title'), ['colspan' => 2])]);
|
||||
$table->addRow(new TableSeparator());
|
||||
foreach($stats['docsperuser'] as $v)
|
||||
$table->addRow([$v['key'], $v['total']]);
|
||||
$table->addRow(new TableSeparator());
|
||||
$table->addRow([new TableCell($translator->translate('chart_foldersperuser_title'), ['colspan' => 2])]);
|
||||
$table->addRow(new TableSeparator());
|
||||
foreach($stats['foldersperuser'] as $v)
|
||||
$table->addRow([$v['key'], $v['total']]);
|
||||
$table->addRow(new TableSeparator());
|
||||
$table->addRow([new TableCell($translator->translate('chart_sizeperuser_title'), ['colspan' => 2])]);
|
||||
$table->addRow(new TableSeparator());
|
||||
foreach($stats['sizeperuser'] as $v)
|
||||
$table->addRow([$v['key'], SeedDMS_Core_File::format_filesize((int)$v['total'])]);
|
||||
$table->render();
|
||||
} else {
|
||||
$outformat = '%-30s %-10d';
|
||||
$output->writeln(sprintf($outformat, 'Documents', $stats['docstotal']));
|
||||
|
|
@ -76,6 +102,7 @@ class StatsCommand extends Command
|
|||
$output->writeln(sprintf($outformat, $d['key'], $d['total']));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user