diff options
| author | Frederic Guillot <fred@kanboard.net> | 2015-10-17 09:51:15 -0400 |
|---|---|---|
| committer | Frederic Guillot <fred@kanboard.net> | 2015-10-17 09:51:15 -0400 |
| commit | 73a5b9bc75d40a30e7c9674b292957657ac01f63 (patch) | |
| tree | ff5bb8a90452a2ff1351c192575e5d241a8b4417 /app/Model/NotificationFilter.php | |
| parent | 98b203fe691ec1ea9d6d19e916827185b575b05a (diff) | |
Make user notifications pluggable
Diffstat (limited to 'app/Model/NotificationFilter.php')
| -rw-r--r-- | app/Model/NotificationFilter.php | 199 |
1 files changed, 0 insertions, 199 deletions
diff --git a/app/Model/NotificationFilter.php b/app/Model/NotificationFilter.php deleted file mode 100644 index f1ad367b..00000000 --- a/app/Model/NotificationFilter.php +++ /dev/null @@ -1,199 +0,0 @@ -<?php - -namespace Kanboard\Model; - -/** - * Notification Filter model - * - * @package model - * @author Frederic Guillot - */ -class NotificationFilter extends Base -{ - /** - * SQL table name - * - * @var string - */ - const PROJECT_TABLE = 'user_has_notifications'; - - /** - * User filters - * - * @var integer - */ - const FILTER_NONE = 1; - const FILTER_ASSIGNEE = 2; - const FILTER_CREATOR = 3; - const FILTER_BOTH = 4; - - /** - * Get the list of filters - * - * @access public - * @return array - */ - public function getFilters() - { - return array( - self::FILTER_NONE => t('All tasks'), - self::FILTER_ASSIGNEE => t('Only for tasks assigned to me'), - self::FILTER_CREATOR => t('Only for tasks created by me'), - self::FILTER_BOTH => t('Only for tasks created by me and assigned to me'), - ); - } - - /** - * Get user selected filter - * - * @access public - * @param integer $user_id - * @return integer - */ - public function getUserSelectedFilter($user_id) - { - return $this->db->table(User::TABLE)->eq('id', $user_id)->findOneColumn('notifications_filter'); - } - - /** - * Save selected filter for a user - * - * @access public - * @param integer $user_id - * @param string $filter - */ - public function saveUserFilter($user_id, $filter) - { - $this->db->table(User::TABLE)->eq('id', $user_id)->update(array( - 'notifications_filter' => $filter, - )); - } - - /** - * Get user selected projects - * - * @access public - * @param integer $user_id - * @return array - */ - public function getUserSelectedProjects($user_id) - { - return $this->db->table(self::PROJECT_TABLE)->eq('user_id', $user_id)->findAllByColumn('project_id'); - } - - /** - * Save selected projects for a user - * - * @access public - * @param integer $user_id - * @param integer[] $project_ids - */ - public function saveUserSelectedProjects($user_id, array $project_ids) - { - $this->db->table(self::PROJECT_TABLE)->eq('user_id', $user_id)->remove(); - - foreach ($project_ids as $project_id) { - $this->db->table(self::PROJECT_TABLE)->insert(array( - 'user_id' => $user_id, - 'project_id' => $project_id, - )); - } - } - - /** - * Return true if the user should receive notification - * - * @access public - * @param array $user - * @param array $event_data - * @return boolean - */ - public function shouldReceiveNotification(array $user, array $event_data) - { - $filters = array( - 'filterNone', - 'filterAssignee', - 'filterCreator', - 'filterBoth', - ); - - foreach ($filters as $filter) { - if ($this->$filter($user, $event_data)) { - return $this->filterProject($user, $event_data); - } - } - - return false; - } - - /** - * Return true if the user will receive all notifications - * - * @access public - * @param array $user - * @return boolean - */ - public function filterNone(array $user) - { - return $user['notifications_filter'] == self::FILTER_NONE; - } - - /** - * Return true if the user is the assignee and selected the filter "assignee" - * - * @access public - * @param array $user - * @param array $event_data - * @return boolean - */ - public function filterAssignee(array $user, array $event_data) - { - return $user['notifications_filter'] == self::FILTER_ASSIGNEE && $event_data['task']['owner_id'] == $user['id']; - } - - /** - * Return true if the user is the creator and enabled the filter "creator" - * - * @access public - * @param array $user - * @param array $event_data - * @return boolean - */ - public function filterCreator(array $user, array $event_data) - { - return $user['notifications_filter'] == self::FILTER_CREATOR && $event_data['task']['creator_id'] == $user['id']; - } - - /** - * Return true if the user is the assignee or the creator and selected the filter "both" - * - * @access public - * @param array $user - * @param array $event_data - * @return boolean - */ - public function filterBoth(array $user, array $event_data) - { - return $user['notifications_filter'] == self::FILTER_BOTH && - ($event_data['task']['creator_id'] == $user['id'] || $event_data['task']['owner_id'] == $user['id']); - } - - /** - * Return true if the user want to receive notification for the selected project - * - * @access public - * @param array $user - * @param array $event_data - * @return boolean - */ - public function filterProject(array $user, array $event_data) - { - $projects = $this->getUserSelectedProjects($user['id']); - - if (! empty($projects)) { - return in_array($event_data['task']['project_id'], $projects); - } - - return true; - } -} |
