summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-10-17 22:19:49 -0400
committerFrederic Guillot <fred@kanboard.net>2015-10-17 22:19:49 -0400
commit09da289c2fb18475f372bee24e885617da484e0b (patch)
tree95d1869ba3236ccdd9234d7909fc16c495c84d44 /app/Model
parent9283fb88d80cb355ff98364a9a57b657fc511d98 (diff)
Move slack, hipchat and jabber integrations to plugins
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Acl.php2
-rw-r--r--app/Model/Notification.php142
-rw-r--r--app/Model/NotificationType.php16
-rw-r--r--app/Model/ProjectActivity.php52
-rw-r--r--app/Model/ProjectIntegration.php66
-rw-r--r--app/Model/ProjectNotification.php38
-rw-r--r--app/Model/ProjectNotificationType.php6
-rw-r--r--app/Model/UserNotificationType.php5
-rw-r--r--app/Model/UserUnreadNotification.php63
9 files changed, 204 insertions, 186 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php
index 92ce0c5a..62f850cb 100644
--- a/app/Model/Acl.php
+++ b/app/Model/Acl.php
@@ -64,7 +64,7 @@ class Acl extends Base
'column' => '*',
'export' => '*',
'taskimport' => '*',
- 'project' => array('edit', 'update', 'share', 'integration', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'),
+ 'project' => array('edit', 'update', 'share', 'integrations', 'notifications', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'),
'swimlane' => '*',
'gantt' => array('project', 'savetaskdate', 'task', 'savetask'),
);
diff --git a/app/Model/Notification.php b/app/Model/Notification.php
new file mode 100644
index 00000000..f1122993
--- /dev/null
+++ b/app/Model/Notification.php
@@ -0,0 +1,142 @@
+<?php
+
+namespace Kanboard\Model;
+
+/**
+ * Notification
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class Notification extends Base
+{
+ /**
+ * Get the event title with author
+ *
+ * @access public
+ * @param string $event_author
+ * @param string $event_name
+ * @param array $event_data
+ * @return string
+ */
+ public function getTitleWithAuthor($event_author, $event_name, array $event_data)
+ {
+ switch ($event_name) {
+ case Task::EVENT_ASSIGNEE_CHANGE:
+ $assignee = $event_data['task']['assignee_name'] ?: $event_data['task']['assignee_username'];
+
+ if (! empty($assignee)) {
+ return e('%s change the assignee of the task #%d to %s', $event_author, $event_data['task']['id'], $assignee);
+ }
+
+ return e('%s remove the assignee of the task %s', $event_author, e('#%d', $event_data['task']['id']));
+ case Task::EVENT_UPDATE:
+ return e('%s updated the task #%d', $event_author, $event_data['task']['id']);
+ case Task::EVENT_CREATE:
+ return e('%s created the task #%d', $event_author, $event_data['task']['id']);
+ case Task::EVENT_CLOSE:
+ return e('%s closed the task #%d', $event_author, $event_data['task']['id']);
+ case Task::EVENT_OPEN:
+ return e('%s open the task #%d', $event_author, $event_data['task']['id']);
+ case Task::EVENT_MOVE_COLUMN:
+ return e(
+ '%s moved the task #%d to the column "%s"',
+ $event_author,
+ $event_data['task']['id'],
+ $event_data['task']['column_title']
+ );
+ case Task::EVENT_MOVE_POSITION:
+ return e(
+ '%s moved the task #%d to the position %d in the column "%s"',
+ $event_author,
+ $event_data['task']['id'],
+ $event_data['task']['position'],
+ $event_data['task']['column_title']
+ );
+ case Task::EVENT_MOVE_SWIMLANE:
+ if ($event_data['task']['swimlane_id'] == 0) {
+ return e('%s moved the task #%d to the first swimlane', $event_author, $event_data['task']['id']);
+ }
+
+ return e(
+ '%s moved the task #%d to the swimlane "%s"',
+ $event_author,
+ $event_data['task']['id'],
+ $event_data['task']['swimlane_name']
+ );
+ case Subtask::EVENT_UPDATE:
+ return e('%s updated a subtask for the task #%d', $event_author, $event_data['task']['id']);
+ case Subtask::EVENT_CREATE:
+ return e('%s created a subtask for the task #%d', $event_author, $event_data['task']['id']);
+ case Comment::EVENT_UPDATE:
+ return e('%s updated a comment on the task #%d', $event_author, $event_data['task']['id']);
+ case Comment::EVENT_CREATE:
+ return e('%s commented on the task #%d', $event_author, $event_data['task']['id']);
+ case File::EVENT_CREATE:
+ return e('%s attached a file to the task #%d', $event_author, $event_data['task']['id']);
+ default:
+ return e('Notification');
+ }
+ }
+
+ /**
+ * Get the event title without author
+ *
+ * @access public
+ * @param string $event_name
+ * @param array $event_data
+ * @return string
+ */
+ public function getTitleWithoutAuthor($event_name, array $event_data)
+ {
+ switch ($event_name) {
+ case File::EVENT_CREATE:
+ $title = e('New attachment on task #%d: %s', $event_data['file']['task_id'], $event_data['file']['name']);
+ break;
+ case Comment::EVENT_CREATE:
+ $title = e('New comment on task #%d', $event_data['comment']['task_id']);
+ break;
+ case Comment::EVENT_UPDATE:
+ $title = e('Comment updated on task #%d', $event_data['comment']['task_id']);
+ break;
+ case Subtask::EVENT_CREATE:
+ $title = e('New subtask on task #%d', $event_data['subtask']['task_id']);
+ break;
+ case Subtask::EVENT_UPDATE:
+ $title = e('Subtask updated on task #%d', $event_data['subtask']['task_id']);
+ break;
+ case Task::EVENT_CREATE:
+ $title = e('New task #%d: %s', $event_data['task']['id'], $event_data['task']['title']);
+ break;
+ case Task::EVENT_UPDATE:
+ $title = e('Task updated #%d', $event_data['task']['id']);
+ break;
+ case Task::EVENT_CLOSE:
+ $title = e('Task #%d closed', $event_data['task']['id']);
+ break;
+ case Task::EVENT_OPEN:
+ $title = e('Task #%d opened', $event_data['task']['id']);
+ break;
+ case Task::EVENT_MOVE_COLUMN:
+ $title = e('Column changed for task #%d', $event_data['task']['id']);
+ break;
+ case Task::EVENT_MOVE_POSITION:
+ $title = e('New position for task #%d', $event_data['task']['id']);
+ break;
+ case Task::EVENT_MOVE_SWIMLANE:
+ $title = e('Swimlane changed for task #%d', $event_data['task']['id']);
+ break;
+ case Task::EVENT_ASSIGNEE_CHANGE:
+ $title = e('Assignee changed on task #%d', $event_data['task']['id']);
+ break;
+ case Task::EVENT_OVERDUE:
+ $nb = count($event_data['tasks']);
+ $title = $nb > 1 ? e('%d overdue tasks', $nb) : e('Task #%d is overdue', $event_data['tasks'][0]['id']);
+ break;
+ default:
+ $title = e('Notification');
+ }
+
+ return $title;
+ }
+}
diff --git a/app/Model/NotificationType.php b/app/Model/NotificationType.php
index e05cc686..bc9c6fdc 100644
--- a/app/Model/NotificationType.php
+++ b/app/Model/NotificationType.php
@@ -108,4 +108,20 @@ abstract class NotificationType extends Base
{
return $this->hiddens;
}
+
+ /**
+ * Keep only loaded notification types
+ *
+ * @access public
+ * @param string[] $types
+ * @return array
+ */
+ public function filterTypes(array $types)
+ {
+ $classes = $this->classes;
+
+ return array_filter($types, function($type) use ($classes) {
+ return isset($classes[$type]);
+ });
+ }
}
diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php
index 032c1fa6..309bab9a 100644
--- a/app/Model/ProjectActivity.php
+++ b/app/Model/ProjectActivity.php
@@ -153,7 +153,7 @@ class ProjectActivity extends Base
unset($event['data']);
$event['author'] = $event['author_name'] ?: $event['author_username'];
- $event['event_title'] = $this->getTitle($event);
+ $event['event_title'] = $this->notification->getTitleWithAuthor($event['author'], $event['event_name'], $event);
$event['event_content'] = $this->getContent($event);
}
@@ -196,56 +196,6 @@ class ProjectActivity extends Base
}
/**
- * Get the event title (translated)
- *
- * @access public
- * @param array $event Event properties
- * @return string
- */
- public function getTitle(array $event)
- {
- switch ($event['event_name']) {
- case Task::EVENT_ASSIGNEE_CHANGE:
- $assignee = $event['task']['assignee_name'] ?: $event['task']['assignee_username'];
-
- if (! empty($assignee)) {
- return t('%s change the assignee of the task #%d to %s', $event['author'], $event['task']['id'], $assignee);
- }
-
- return t('%s remove the assignee of the task %s', $event['author'], e('#%d', $event['task']['id']));
- case Task::EVENT_UPDATE:
- return t('%s updated the task #%d', $event['author'], $event['task']['id']);
- case Task::EVENT_CREATE:
- return t('%s created the task #%d', $event['author'], $event['task']['id']);
- case Task::EVENT_CLOSE:
- return t('%s closed the task #%d', $event['author'], $event['task']['id']);
- case Task::EVENT_OPEN:
- return t('%s open the task #%d', $event['author'], $event['task']['id']);
- case Task::EVENT_MOVE_COLUMN:
- return t('%s moved the task #%d to the column "%s"', $event['author'], $event['task']['id'], $event['task']['column_title']);
- case Task::EVENT_MOVE_POSITION:
- return t('%s moved the task #%d to the position %d in the column "%s"', $event['author'], $event['task']['id'], $event['task']['position'], $event['task']['column_title']);
- case Task::EVENT_MOVE_SWIMLANE:
- if ($event['task']['swimlane_id'] == 0) {
- return t('%s moved the task #%d to the first swimlane', $event['author'], $event['task']['id']);
- }
- return t('%s moved the task #%d to the swimlane "%s"', $event['author'], $event['task']['id'], $event['task']['swimlane_name']);
- case Subtask::EVENT_UPDATE:
- return t('%s updated a subtask for the task #%d', $event['author'], $event['task']['id']);
- case Subtask::EVENT_CREATE:
- return t('%s created a subtask for the task #%d', $event['author'], $event['task']['id']);
- case Comment::EVENT_UPDATE:
- return t('%s updated a comment on the task #%d', $event['author'], $event['task']['id']);
- case Comment::EVENT_CREATE:
- return t('%s commented on the task #%d', $event['author'], $event['task']['id']);
- case File::EVENT_CREATE:
- return t('%s attached a file to the task #%d', $event['author'], $event['task']['id']);
- default:
- return '';
- }
- }
-
- /**
* Decode event data, supports unserialize() and json_decode()
*
* @access public
diff --git a/app/Model/ProjectIntegration.php b/app/Model/ProjectIntegration.php
deleted file mode 100644
index d07e4167..00000000
--- a/app/Model/ProjectIntegration.php
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-
-namespace Kanboard\Model;
-
-/**
- * Project integration
- *
- * @package model
- * @author Frederic Guillot
- */
-class ProjectIntegration extends Base
-{
- /**
- * SQL table name
- *
- * @var string
- */
- const TABLE = 'project_integrations';
-
- /**
- * Get all parameters for a project
- *
- * @access public
- * @param integer $project_id
- * @return array
- */
- public function getParameters($project_id)
- {
- return $this->db->table(self::TABLE)->eq('project_id', $project_id)->findOne() ?: array();
- }
-
- /**
- * Save parameters for a project
- *
- * @access public
- * @param integer $project_id
- * @param array $values
- * @return boolean
- */
- public function saveParameters($project_id, array $values)
- {
- if ($this->db->table(self::TABLE)->eq('project_id', $project_id)->exists()) {
- return $this->db->table(self::TABLE)->eq('project_id', $project_id)->update($values);
- }
-
- return $this->db->table(self::TABLE)->insert($values + array('project_id' => $project_id));
- }
-
- /**
- * Check if a project has the given parameter/value
- *
- * @access public
- * @param integer $project_id
- * @param string $option
- * @param string $value
- * @return boolean
- */
- public function hasValue($project_id, $option, $value)
- {
- return $this->db
- ->table(self::TABLE)
- ->eq('project_id', $project_id)
- ->eq($option, $value)
- ->exists();
- }
-}
diff --git a/app/Model/ProjectNotification.php b/app/Model/ProjectNotification.php
index 49fcc61d..a355902f 100644
--- a/app/Model/ProjectNotification.php
+++ b/app/Model/ProjectNotification.php
@@ -22,8 +22,44 @@ class ProjectNotification extends Base
{
$project = $this->project->getById($project_id);
- foreach ($this->projectNotificationType->getSelectedTypes($project_id) as $type) {
+ $types = array_merge(
+ $this->projectNotificationType->getHiddenTypes(),
+ $this->projectNotificationType->getSelectedTypes($project_id)
+ );
+
+ foreach ($types as $type) {
$this->projectNotificationType->getType($type)->notifyProject($project, $event_name, $event_data);
}
}
+
+ /**
+ * Save settings for the given project
+ *
+ * @access public
+ * @param integer $project_id
+ * @param array $values
+ */
+ public function saveSettings($project_id, array $values)
+ {
+ $this->db->startTransaction();
+
+ $types = empty($values['notification_types']) ? array() : array_keys($values['notification_types']);
+ $this->projectNotificationType->saveSelectedTypes($project_id, $types);
+
+ $this->db->closeTransaction();
+ }
+
+ /**
+ * Read user settings to display the form
+ *
+ * @access public
+ * @param integer $project_id
+ * @return array
+ */
+ public function readSettings($project_id)
+ {
+ return array(
+ 'notification_types' => $this->projectNotificationType->getSelectedTypes($project_id),
+ );
+ }
}
diff --git a/app/Model/ProjectNotificationType.php b/app/Model/ProjectNotificationType.php
index d8568589..a4719598 100644
--- a/app/Model/ProjectNotificationType.php
+++ b/app/Model/ProjectNotificationType.php
@@ -26,13 +26,13 @@ class ProjectNotificationType extends NotificationType
*/
public function getSelectedTypes($project_id)
{
- $selectedTypes = $this->db
+ $types = $this->db
->table(self::TABLE)
->eq('project_id', $project_id)
->asc('notification_type')
->findAllByColumn('notification_type');
- return array_merge($this->getHiddenTypes(), $selectedTypes);
+ return $this->filterTypes($types);
}
/**
@@ -52,6 +52,6 @@ class ProjectNotificationType extends NotificationType
$results[] = $this->db->table(self::TABLE)->insert(array('project_id' => $project_id, 'notification_type' => $type));
}
- return ! in_array(false, $results);
+ return ! in_array(false, $results, true);
}
}
diff --git a/app/Model/UserNotificationType.php b/app/Model/UserNotificationType.php
index d2613440..89beb480 100644
--- a/app/Model/UserNotificationType.php
+++ b/app/Model/UserNotificationType.php
@@ -26,7 +26,8 @@ class UserNotificationType extends NotificationType
*/
public function getSelectedTypes($user_id)
{
- return $this->db->table(self::TABLE)->eq('user_id', $user_id)->asc('notification_type')->findAllByColumn('notification_type');
+ $types = $this->db->table(self::TABLE)->eq('user_id', $user_id)->asc('notification_type')->findAllByColumn('notification_type');
+ return $this->filterTypes($types);
}
/**
@@ -46,6 +47,6 @@ class UserNotificationType extends NotificationType
$results[] = $this->db->table(self::TABLE)->insert(array('user_id' => $user_id, 'notification_type' => $type));
}
- return ! in_array(false, $results);
+ return ! in_array(false, $results, true);
}
}
diff --git a/app/Model/UserUnreadNotification.php b/app/Model/UserUnreadNotification.php
index 98a337a2..cc0f326a 100644
--- a/app/Model/UserUnreadNotification.php
+++ b/app/Model/UserUnreadNotification.php
@@ -48,7 +48,7 @@ class UserUnreadNotification extends Base
foreach ($events as &$event) {
$event['event_data'] = json_decode($event['event_data'], true);
- $event['title'] = $this->getTitleFromEvent($event['event_name'], $event['event_data']);
+ $event['title'] = $this->notification->getTitleWithoutAuthor($event['event_name'], $event['event_data']);
}
return $events;
@@ -90,65 +90,4 @@ class UserUnreadNotification extends Base
{
return $this->db->table(self::TABLE)->eq('user_id', $user_id)->exists();
}
-
- /**
- * Get title from event
- *
- * @access public
- * @param string $event_name
- * @param array $event_data
- * @return string
- */
- public function getTitleFromEvent($event_name, array $event_data)
- {
- switch ($event_name) {
- case File::EVENT_CREATE:
- $title = t('New attachment on task #%d: %s', $event_data['file']['task_id'], $event_data['file']['name']);
- break;
- case Comment::EVENT_CREATE:
- $title = t('New comment on task #%d', $event_data['comment']['task_id']);
- break;
- case Comment::EVENT_UPDATE:
- $title = t('Comment updated on task #%d', $event_data['comment']['task_id']);
- break;
- case Subtask::EVENT_CREATE:
- $title = t('New subtask on task #%d', $event_data['subtask']['task_id']);
- break;
- case Subtask::EVENT_UPDATE:
- $title = t('Subtask updated on task #%d', $event_data['subtask']['task_id']);
- break;
- case Task::EVENT_CREATE:
- $title = t('New task #%d: %s', $event_data['task']['id'], $event_data['task']['title']);
- break;
- case Task::EVENT_UPDATE:
- $title = t('Task updated #%d', $event_data['task']['id']);
- break;
- case Task::EVENT_CLOSE:
- $title = t('Task #%d closed', $event_data['task']['id']);
- break;
- case Task::EVENT_OPEN:
- $title = t('Task #%d opened', $event_data['task']['id']);
- break;
- case Task::EVENT_MOVE_COLUMN:
- $title = t('Column changed for task #%d', $event_data['task']['id']);
- break;
- case Task::EVENT_MOVE_POSITION:
- $title = t('New position for task #%d', $event_data['task']['id']);
- break;
- case Task::EVENT_MOVE_SWIMLANE:
- $title = t('Swimlane changed for task #%d', $event_data['task']['id']);
- break;
- case Task::EVENT_ASSIGNEE_CHANGE:
- $title = t('Assignee changed on task #%d', $event_data['task']['id']);
- break;
- case Task::EVENT_OVERDUE:
- $nb = count($event_data['tasks']);
- $title = $nb > 1 ? t('%d overdue tasks', $nb) : t('Task #%d is overdue', $event_data['tasks'][0]['id']);
- break;
- default:
- $title = e('Notification');
- }
-
- return $title;
- }
}