From d6bde1e3ec1d0b0fae7bb85e274e1bebb65d78db Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 29 Nov 2014 14:01:03 -0500 Subject: Add command line export/calculation for daily project summaries --- app/Console/OverdueNotification.php | 69 -------------------------- app/Console/ProjectDailySummaryCalculation.php | 29 +++++++++++ app/Console/ProjectDailySummaryExport.php | 35 +++++++++++++ app/Console/TaskExport.php | 2 +- app/Console/TaskOverdueNotification.php | 69 ++++++++++++++++++++++++++ 5 files changed, 134 insertions(+), 70 deletions(-) delete mode 100644 app/Console/OverdueNotification.php create mode 100644 app/Console/ProjectDailySummaryCalculation.php create mode 100644 app/Console/ProjectDailySummaryExport.php create mode 100644 app/Console/TaskOverdueNotification.php (limited to 'app/Console') diff --git a/app/Console/OverdueNotification.php b/app/Console/OverdueNotification.php deleted file mode 100644 index 0987bf2a..00000000 --- a/app/Console/OverdueNotification.php +++ /dev/null @@ -1,69 +0,0 @@ -setName('notification:overdue-tasks') - ->setDescription('Send notifications for overdue tasks') - ->addOption('show', null, InputOption::VALUE_NONE, 'Show sent overdue tasks'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $projects = array(); - $tasks = $this->taskFinder->getOverdueTasks(); - - // Group tasks by project - foreach ($tasks as $task) { - $projects[$task['project_id']][] = $task; - } - - // Send notifications for each project - foreach ($projects as $project_id => $project_tasks) { - - $users = $this->notification->getUsersList($project_id); - - $this->notification->sendEmails( - 'task_due', - $users, - array('tasks' => $project_tasks, 'project' => $project_tasks[0]['project_name']) - ); - } - - if ($input->getOption('show')) { - $this->showTable($output, $tasks); - } - } - - public function showTable(OutputInterface $output, array $tasks) - { - $rows = array(); - - foreach ($tasks as $task) { - $rows[] = array( - $task['id'], - $task['title'], - date('Y-m-d', $task['date_due']), - $task['project_id'], - $task['project_name'], - $task['assignee_name'] ?: $task['assignee_username'], - ); - } - - $table = new Table($output); - $table - ->setHeaders(array('Id', 'Title', 'Due date', 'Project Id', 'Project name', 'Assignee')) - ->setRows($rows) - ->render(); - } -} diff --git a/app/Console/ProjectDailySummaryCalculation.php b/app/Console/ProjectDailySummaryCalculation.php new file mode 100644 index 00000000..04c4083d --- /dev/null +++ b/app/Console/ProjectDailySummaryCalculation.php @@ -0,0 +1,29 @@ +setName('projects:daily-summary') + ->setDescription('Calculate daily summary data for all projects'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $projects = $this->project->getAllByStatus(Project::ACTIVE); + + foreach ($projects as $project) { + $output->writeln('Run calculation for '.$project['name']); + $this->projectDailySummary->updateTotals($project['id'], date('Y-m-d')); + } + } +} diff --git a/app/Console/ProjectDailySummaryExport.php b/app/Console/ProjectDailySummaryExport.php new file mode 100644 index 00000000..6b96fddd --- /dev/null +++ b/app/Console/ProjectDailySummaryExport.php @@ -0,0 +1,35 @@ +setName('export:daily-project-summary') + ->setDescription('Daily project summary CSV export (number of tasks per column and per day)') + ->addArgument('project_id', InputArgument::REQUIRED, 'Project id') + ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)') + ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $data = $this->projectDailySummary->getAggregatedMetrics( + $input->getArgument('project_id'), + $input->getArgument('start_date'), + $input->getArgument('end_date') + ); + + if (is_array($data)) { + Tool::csv($data); + } + } +} diff --git a/app/Console/TaskExport.php b/app/Console/TaskExport.php index b9f151fb..dea71fe6 100644 --- a/app/Console/TaskExport.php +++ b/app/Console/TaskExport.php @@ -14,7 +14,7 @@ class TaskExport extends Base { $this ->setName('export:tasks') - ->setDescription('Tasks export (CSV)') + ->setDescription('Tasks CSV export') ->addArgument('project_id', InputArgument::REQUIRED, 'Project id') ->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)') ->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)'); diff --git a/app/Console/TaskOverdueNotification.php b/app/Console/TaskOverdueNotification.php new file mode 100644 index 00000000..aa70fd01 --- /dev/null +++ b/app/Console/TaskOverdueNotification.php @@ -0,0 +1,69 @@ +setName('notification:overdue-tasks') + ->setDescription('Send notifications for overdue tasks') + ->addOption('show', null, InputOption::VALUE_NONE, 'Show sent overdue tasks'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $projects = array(); + $tasks = $this->taskFinder->getOverdueTasks(); + + // Group tasks by project + foreach ($tasks as $task) { + $projects[$task['project_id']][] = $task; + } + + // Send notifications for each project + foreach ($projects as $project_id => $project_tasks) { + + $users = $this->notification->getUsersList($project_id); + + $this->notification->sendEmails( + 'task_due', + $users, + array('tasks' => $project_tasks, 'project' => $project_tasks[0]['project_name']) + ); + } + + if ($input->getOption('show')) { + $this->showTable($output, $tasks); + } + } + + public function showTable(OutputInterface $output, array $tasks) + { + $rows = array(); + + foreach ($tasks as $task) { + $rows[] = array( + $task['id'], + $task['title'], + date('Y-m-d', $task['date_due']), + $task['project_id'], + $task['project_name'], + $task['assignee_name'] ?: $task['assignee_username'], + ); + } + + $table = new Table($output); + $table + ->setHeaders(array('Id', 'Title', 'Due date', 'Project Id', 'Project name', 'Assignee')) + ->setRows($rows) + ->render(); + } +} -- cgit v1.2.3