summaryrefslogtreecommitdiff
path: root/app/Model/ProjectNotification.php
blob: a355902fd316d1515e13e98031e1b096713023c3 (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
<?php

namespace Kanboard\Model;

/**
 * Project Notification
 *
 * @package  model
 * @author   Frederic Guillot
 */
class ProjectNotification extends Base
{
    /**
     * Send notifications
     *
     * @access public
     * @param  integer  $project_id
     * @param  string   $event_name
     * @param  array    $event_data
     */
    public function sendNotifications($project_id, $event_name, array $event_data)
    {
        $project = $this->project->getById($project_id);

        $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),
        );
    }
}