public function getSummary($date = 19780101, $check = FALSE, $exact = FALSE) { $data = $this->repository->review($date, $check); if (count($data) == 0 && !$check) { throw new \Exception('All entries stored in remote system'); } $total = 0; $offline = FALSE; try { $categories = $this->connector->fetchCategories(); } catch (ConnectException $e) { $offline = TRUE; } $exact_total = 0; foreach ($data as $record) { $total += $record->duration; $details = $this->connector->ticketDetails($record->tid); $category_id = str_pad($record->category, 3, 0, STR_PAD_LEFT); $category = ''; if ($record->category) { if ($offline) { $category = 'Offline'; } elseif (isset($categories[$category_id])) { $category = $categories[$category_id]; } else { $category = 'Unknown'; } } $row = [$record->id, $record->tid, $record->duration]; if ($exact) { $row[] = Formatter::formatDuration($record->end - $record->start); $exact_total += $record->end - $record->start; } $row = array_merge($row, [substr($details->getTitle(), 0, 25) . '...', $category, $record->comment]); $rows[] = $row; } $rows[] = new TableSeparator(); if ($exact) { $rows[] = ['', '<comment>Total</comment>', '<info>' . $total . ' h</info>', '<info>' . Formatter::formatDuration($exact_total) . '</info>', '', '', '']; } else { $rows[] = ['', '<comment>Total</comment>', '<info>' . $total . ' h</info>', '', '', '']; } return $rows; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $entries = $this->repository->review(Review::ALL, TRUE); $helper = $this->getHelper('question'); $last = FALSE; $categories = $this->connector->fetchCategories(); $question = new ChoiceQuestion(sprintf('Select tag to use:[%s]', $last ?: Tag::DEFAULT_TAG), $categories, $last ?: Tag::DEFAULT_TAG); $tag_id = $helper->ask($input, $output, $question); $tag = $categories[$tag_id]; list(, $tag) = explode(':', $tag); foreach ($entries as $entry) { if ($entry->category) { continue; } $this->repository->tag($tag, $entry->id); $last = $tag; } if (!$last) { $output->writeln('<error>All items already tagged, use --retag to retag</error>'); } }
/** * Tag single entry. * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @param $slot_id */ protected function tagOne(InputInterface $input, OutputInterface $output, $slot_id) { if ($entry = $this->repository->slot($slot_id)) { $helper = $this->getHelper('question'); try { $title = $this->connector->ticketDetails($entry->tid); $categories = $this->connector->fetchCategories(); } catch (ConnectException $e) { $output->writeln('<error>You are offline, please try again later.</error>'); return; } $question = new ChoiceQuestion(sprintf('Enter tag for slot <comment>%d</comment> [<info>%d</info>]: %s [<info>%s h</info>] [%s]', $entry->id, $entry->tid, $title->getTitle(), Formatter::formatDuration($entry->end - $entry->start), static::DEFAULT_TAG), $categories, static::DEFAULT_TAG); $tag_id = $helper->ask($input, $output, $question); $tag = $categories[$tag_id]; list(, $tag) = explode(':', $tag); $this->repository->tag($tag, $entry->id); } else { $output->writeln('<error>No such slot - please check your slot ID</error>'); } }