summaryrefslogtreecommitdiff
path: root/app/Model/Notification.php
blob: c252aa31990bb04c1599ce1c7e1bb3b087acd229 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?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 TaskFile::EVENT_CREATE:
                return e('%s attached a file to the task #%d', $event_author, $event_data['task']['id']);
            case Task::EVENT_USER_MENTION:
                return e('%s mentioned you in the task #%d', $event_author, $event_data['task']['id']);
            case Comment::EVENT_USER_MENTION:
                return e('%s mentioned you in a comment on 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 TaskFile::EVENT_CREATE:
                return e('New attachment on task #%d: %s', $event_data['file']['task_id'], $event_data['file']['name']);
            case Comment::EVENT_CREATE:
                return e('New comment on task #%d', $event_data['comment']['task_id']);
            case Comment::EVENT_UPDATE:
                return e('Comment updated on task #%d', $event_data['comment']['task_id']);
            case Subtask::EVENT_CREATE:
                return e('New subtask on task #%d', $event_data['subtask']['task_id']);
            case Subtask::EVENT_UPDATE:
                return e('Subtask updated on task #%d', $event_data['subtask']['task_id']);
            case Task::EVENT_CREATE:
                return e('New task #%d: %s', $event_data['task']['id'], $event_data['task']['title']);
            case Task::EVENT_UPDATE:
                return e('Task updated #%d', $event_data['task']['id']);
            case Task::EVENT_CLOSE:
                return e('Task #%d closed', $event_data['task']['id']);
            case Task::EVENT_OPEN:
                return e('Task #%d opened', $event_data['task']['id']);
            case Task::EVENT_MOVE_COLUMN:
                return e('Column changed for task #%d', $event_data['task']['id']);
            case Task::EVENT_MOVE_POSITION:
                return e('New position for task #%d', $event_data['task']['id']);
            case Task::EVENT_MOVE_SWIMLANE:
                return e('Swimlane changed for task #%d', $event_data['task']['id']);
            case Task::EVENT_ASSIGNEE_CHANGE:
                return e('Assignee changed on task #%d', $event_data['task']['id']);
            case Task::EVENT_OVERDUE:
                $nb = count($event_data['tasks']);
                return $nb > 1 ? e('%d overdue tasks', $nb) : e('Task #%d is overdue', $event_data['tasks'][0]['id']);
            case Task::EVENT_USER_MENTION:
                return e('You were mentioned in the task #%d', $event_data['task']['id']);
            case Comment::EVENT_USER_MENTION:
                return e('You were mentioned in a comment on the task #%d', $event_data['task']['id']);
            default:
                return e('Notification');
        }
    }
}