summaryrefslogtreecommitdiff
path: root/app/Console
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-03-04 16:31:34 -0500
committerFrederic Guillot <fred@kanboard.net>2016-03-04 16:31:34 -0500
commita7c157df3c0005d7c875ce972056b0c8b8872a26 (patch)
tree95a17e65d73d0b65a98bc571e4bf661952a1f656 /app/Console
parentabe9371f32e55c3806c8dde41d1f555e5159752d (diff)
Remove model OverdueNotification
Diffstat (limited to 'app/Console')
-rw-r--r--app/Console/Base.php2
-rw-r--r--app/Console/TaskOverdueNotification.php68
2 files changed, 67 insertions, 3 deletions
diff --git a/app/Console/Base.php b/app/Console/Base.php
index ac89207d..04ee8a21 100644
--- a/app/Console/Base.php
+++ b/app/Console/Base.php
@@ -14,11 +14,9 @@ use Symfony\Component\Console\Command\Command;
* @property \Kanboard\Model\Notification $notification
* @property \Kanboard\Model\Project $project
* @property \Kanboard\Model\ProjectPermission $projectPermission
- * @property \Kanboard\Model\ProjectAnalytic $projectAnalytic
* @property \Kanboard\Model\ProjectDailyColumnStats $projectDailyColumnStats
* @property \Kanboard\Model\ProjectDailyStats $projectDailyStats
* @property \Kanboard\Model\SubtaskExport $subtaskExport
- * @property \Kanboard\Model\OverdueNotification $overdueNotification
* @property \Kanboard\Model\Task $task
* @property \Kanboard\Model\TaskExport $taskExport
* @property \Kanboard\Model\TaskFinder $taskFinder
diff --git a/app/Console/TaskOverdueNotification.php b/app/Console/TaskOverdueNotification.php
index ffb9fab5..43be4df8 100644
--- a/app/Console/TaskOverdueNotification.php
+++ b/app/Console/TaskOverdueNotification.php
@@ -2,6 +2,7 @@
namespace Kanboard\Console;
+use Kanboard\Model\Task;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -19,7 +20,7 @@ class TaskOverdueNotification extends Base
protected function execute(InputInterface $input, OutputInterface $output)
{
- $tasks = $this->overdueNotification->sendOverdueTaskNotifications();
+ $tasks = $this->sendOverdueTaskNotifications();
if ($input->getOption('show')) {
$this->showTable($output, $tasks);
@@ -47,4 +48,69 @@ class TaskOverdueNotification extends Base
->setRows($rows)
->render();
}
+
+ /**
+ * Send overdue tasks
+ *
+ * @access public
+ */
+ public function sendOverdueTaskNotifications()
+ {
+ $tasks = $this->taskFinder->getOverdueTasks();
+
+ foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) {
+ $users = $this->userNotification->getUsersWithNotificationEnabled($project_id);
+
+ foreach ($users as $user) {
+ $this->sendUserOverdueTaskNotifications($user, $project_tasks);
+ }
+ }
+
+ return $tasks;
+ }
+
+ /**
+ * Send overdue tasks for a given user
+ *
+ * @access public
+ * @param array $user
+ * @param array $tasks
+ */
+ public function sendUserOverdueTaskNotifications(array $user, array $tasks)
+ {
+ $user_tasks = array();
+
+ foreach ($tasks as $task) {
+ if ($this->userNotificationFilter->shouldReceiveNotification($user, array('task' => $task))) {
+ $user_tasks[] = $task;
+ }
+ }
+
+ if (! empty($user_tasks)) {
+ $this->userNotification->sendUserNotification(
+ $user,
+ Task::EVENT_OVERDUE,
+ array('tasks' => $user_tasks, 'project_name' => $tasks[0]['project_name'])
+ );
+ }
+ }
+
+ /**
+ * Group a collection of records by a column
+ *
+ * @access public
+ * @param array $collection
+ * @param string $column
+ * @return array
+ */
+ public function groupByColumn(array $collection, $column)
+ {
+ $result = array();
+
+ foreach ($collection as $item) {
+ $result[$item[$column]][] = $item;
+ }
+
+ return $result;
+ }
}