diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-11-29 12:28:35 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-11-29 12:28:35 -0500 |
commit | e8fa25f9ca246fea085da46ea705a74b6de30d10 (patch) | |
tree | abf0fd767540e89ba5cfbbb7b6cabb64c4fcbb4e /app/Console/OverdueNotification.php | |
parent | d9879161281785c8e11fd074cec98f09df94dd46 (diff) |
Replace Core\Cli by Symfony\Console
Diffstat (limited to 'app/Console/OverdueNotification.php')
-rw-r--r-- | app/Console/OverdueNotification.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/app/Console/OverdueNotification.php b/app/Console/OverdueNotification.php new file mode 100644 index 00000000..0987bf2a --- /dev/null +++ b/app/Console/OverdueNotification.php @@ -0,0 +1,69 @@ +<?php + +namespace Console; + +use Symfony\Component\Console\Helper\Table; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class OverdueNotification extends Base +{ + protected function configure() + { + $this + ->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(); + } +} |