config = $configuration; // @TODO generalize tracking service. $this->trackingService = $tracking_service; $this->csv = $csv; parent::__construct($name); } protected function configure() : void { $this->setName('report'); $this->setDescription('Get a time-tracking report into command line.'); $this->addOption( 'report', 'r', InputOption::VALUE_OPTIONAL, 'Select a report from list ofo your reports' ); // Not supported by by ReportCsv service! // @TODO Build factory for time tracking service (youtrack-csv-export, // youtrack-api, jira-api, kimai-api (biro.radiostudent.si)). $this->addOption( 'time-range', 't', InputOption::VALUE_REQUIRED, 'Calculates report from tracking service work items directly for time range' ); $this->addOption( 'file', 'f', InputOption::VALUE_REQUIRED, 'Specify the input csv file to generate report from.' ); } protected function execute(InputInterface $input, OutputInterface $output) : int { if ($timeRange = $input->getOption('time-range')) { // @TODO: Implement time range option: // - Request workTime items from tracking service // - Filter them, join by issue, project ... // This will came in other report service that will gather data // directly from cache. if ($output->isVerbose()) { $output->writeln("Time range: {$timeRange}"); } $output->writeln('This option is not supported yet.'); return Command::FAILURE; } // Currently we only support csv download. $file = $this->getReportCsvFilePath($input, $output); $report_name = $this->trackingService->getReportName(); $output->writeln("report: {$report_name}"); $data = $this->csv->generateReportTable($file); $table = $this->buildTable($output, $data); $table->render(); return Command::SUCCESS; } /** * Builds table from the report csv data. * * @TODO: Code duplication with InvoiceCommand::getTable. */ protected function buildTable(OutputInterface $output, array $rows) : Table { $table = new Table($output); $table->setHeaders([ 'Ticket Id', 'Name', 'Time', 'Estimation', ]); foreach ($rows as $key => $row) { if (! $row) { $rows[$key] = new TableSeparator(); } elseif (is_array($row) && is_null($row[0]) && is_null($row[2])) { // Check which elements in array are null. $rows[$key] = [ new TableCell($row[1], ['colspan' => 2]), new TableCell((string) $row[3], ['colspan' => 2]), ]; } } $table->setRows($rows); return $table; } }