summaryrefslogtreecommitdiff
path: root/plugins/Group_assign/Action/EmailOtherAssignees.php
blob: f9ab091c110f086ada27a154111c2d6f636d76dd (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
<?php

namespace Kanboard\Plugin\Group_assign\Action;

use Kanboard\Model\TaskModel;
use Kanboard\Action\Base;

class EmailOtherAssignees extends Base
{
   
    public function getDescription()
    {
        return t('Send a task by email to the other assignees for a task.');
    }

   
    public function getCompatibleEvents()
    {
        return array(
            TaskModel::EVENT_MOVE_COLUMN,
            TaskModel::EVENT_CLOSE,
            TaskModel::EVENT_CREATE,
        );
    }

   
    public function getActionRequiredParameters()
    {
        return array(
            'column_id' => t('Column'),
	    'subject' => t('Email subject'),
        );
    }

   
    public function getEventRequiredParameters()
    {
        return array(
            'task_id',
            'task' => array(
                'project_id',
                'column_id',
		'owner_id',
		'owner_ms',
            ),
        );
    }

    
    public function doAction(array $data)
    {
	$multimembers = $this->multiselectMemberModel->getMembers($data['task']['owner_ms']);
	
             if (! empty($multimembers)) {
	       foreach ($multimembers as $members) {
               $user = $this->userModel->getById($members['id']);
               if (! empty($user['email'])) {
                 $this->emailClient->send(
                   $user['email'],
                   $user['name'] ?: $user['username'],
                   $this->getParam('subject'),
                   $this->template->render('notification/task_create', array(
                    'task' => $data['task'],
                    ))
                 );
	       }
	       }
             return true;
	     }

        return false;
    }


   
    public function hasRequiredCondition(array $data)
    {
        return $data['task']['column_id'] == $this->getParam('column_id');
    }
}