From 9eeded33f68872515954a2fc177fcb47a9273ae9 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Fri, 15 Aug 2014 17:23:41 -0700 Subject: Add email notifications --- kanboard | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'kanboard') diff --git a/kanboard b/kanboard index 95a977bd..34e183e4 100755 --- a/kanboard +++ b/kanboard @@ -8,8 +8,9 @@ use Core\Tool; use Core\Translator; use Model\Config; use Model\Task; +use Model\Notification; -$config = new Config($registry->shared('db'), $registry->shared('event')); +$config = new Config($registry); // Load translations $language = $config->get('language', 'en_US'); @@ -25,6 +26,7 @@ $cli = new Cli; $cli->register('help', function() { echo 'Kanboard command line interface'.PHP_EOL.'==============================='.PHP_EOL.PHP_EOL; echo '- Task export to stdout (CSV format): '.$GLOBALS['argv'][0].' export-csv '.PHP_EOL; + echo '- Send notifications for tasks due: '.$GLOBALS['argv'][0].' send-notifications-tasks-due'.PHP_EOL; }); // CSV Export @@ -40,12 +42,39 @@ $cli->register('export-csv', function() use ($cli, $registry) { Translator::disableEscaping(); - $task = new Task($registry->shared('db'), $registry->shared('event')); - $data = $task->export($project_id, $start_date, $end_date); + $taskModel = new Task($registry); + $data = $taskModel->export($project_id, $start_date, $end_date); if (is_array($data)) { Tool::csv($data); } }); +// Send notification for tasks due +$cli->register('send-notifications-tasks-due', function() use ($cli, $registry) { + + $notificationModel = new Notification($registry); + $taskModel = new Task($registry); + $tasks = $taskModel->getTasksDue(); + + // Group tasks by project + $projects = array(); + + foreach ($tasks as $task) { + $projects[$task['project_id']][] = $task; + } + + // Send notifications for each project + foreach ($projects as $project_id => $project_tasks) { + + $users = $notificationModel->getUsersList($project_id); + + $notificationModel->sendEmails( + 'notification_task_due', + $users, + array('tasks' => $project_tasks, 'project' => $project_tasks[0]['project_name']) + ); + } +}); + $cli->execute(); -- cgit v1.2.3