|
1 | | -<?php |
2 | | -/* |
3 | | - * @version $Id: notificationtargettaskcategory.class.php tomolimo $ |
4 | | -------------------------------------------------------------------------- |
5 | | -
|
6 | | - */ |
7 | | - |
8 | | -if (!defined('GLPI_ROOT')) { |
9 | | - die("Sorry. You can't access directly to this file"); |
10 | | -} |
11 | | - |
12 | | -// Class NotificationTarget |
13 | | -class PluginProcessmakerNotificationTargetCase extends PluginProcessmakerNotificationTargetProcessmaker { |
14 | | - |
15 | | - // type |
16 | | - const EMAIL_RECIPIENTS = 200; |
17 | | - |
18 | | - // user type |
19 | | - const RECIPIENTS = 1; |
20 | | - |
21 | | - /** |
22 | | - * Summary of getEvents |
23 | | - * @return string[] |
24 | | - */ |
25 | | - public function getEvents() { |
26 | | - return ['send_email' => __('Send email', 'processmaker')]; |
27 | | - } |
28 | | - |
29 | | - |
30 | | - /** |
31 | | - * Summary of addAdditionalTargets |
32 | | - * @param mixed $event |
33 | | - */ |
34 | | - function addAdditionalTargets($event = '') { |
35 | | - $this->notification_targets = []; |
36 | | - $this->notification_targets_labels = []; |
37 | | - $this->addTarget(self::RECIPIENTS, __('eMail recipients', 'processmaker'), self::EMAIL_RECIPIENTS); |
38 | | - } |
39 | | - |
40 | | - |
41 | | - /** |
42 | | - * Summary of addSpecificTargets |
43 | | - * @param mixed $data |
44 | | - * @param mixed $options |
45 | | - */ |
46 | | - function addSpecificTargets($data, $options) { |
47 | | - |
48 | | - // test if we are in the good notification |
49 | | - // then in this case add the targets from the ['recipients'] |
50 | | - if (isset($options['glpi_send_email'])) { |
51 | | - // normalize $options['glpi_send_email'] to an array of email parameters |
52 | | - $options['glpi_send_email'] = isset($options['glpi_send_email']['notifications_id']) ? [$options['glpi_send_email']] : $options['glpi_send_email']; |
53 | | - |
54 | | - foreach($options['glpi_send_email'] as $params) { |
55 | | - if (isset($params['notifications_id']) |
56 | | - && $params['notifications_id'] == $data['notifications_id']) { |
57 | | - //Look for all targets whose type is Notification::ITEM_USER |
58 | | - switch ($data['type']) { |
59 | | - case self::EMAIL_RECIPIENTS: |
60 | | - |
61 | | - switch ($data['items_id']) { |
62 | | - |
63 | | - case self::RECIPIENTS : |
64 | | - $this->addUsers($params); |
65 | | - break; |
66 | | - } |
67 | | - } |
68 | | - } |
69 | | - } |
70 | | - } |
71 | | - |
72 | | - // if no target is added to $this, then the notification will not be sent. |
73 | | - |
74 | | - } |
75 | | - |
76 | | - |
77 | | - /** |
78 | | - * Add users from $options['glpi_send_email']['to'] |
79 | | - * |
80 | | - * @param array $email_param should contain 'recipients' |
81 | | - * |
82 | | - * @return void |
83 | | - */ |
84 | | - function addUsers($email_param = []) { |
85 | | - global $DB, $CFG_GLPI; |
86 | | - |
87 | | - if (isset($email_param['recipients'])) { |
88 | | - $id_list = []; // for users with ids |
89 | | - $email_list = []; // for standalone emails |
90 | | - |
91 | | - // normalize into array the recipient list |
92 | | - $email_param['recipients'] = is_array($email_param['recipients']) ? $email_param['recipients'] : [$email_param['recipients']]; |
93 | | - foreach ($email_param['recipients'] as $user) { |
94 | | - if (is_numeric($user)) { |
95 | | - $id_list[] = intval($user); |
96 | | - } else { |
97 | | - $email_list[] = $user; |
98 | | - } |
99 | | - } |
100 | | - |
101 | | - $query = $this->getDistinctUserSql()." |
102 | | - FROM `glpi_users` ". |
103 | | - $this->getProfileJoinSql()." |
104 | | - WHERE `glpi_users`.`id` IN (".implode(',', $id_list).")"; |
105 | | - |
106 | | - foreach ($DB->request($query) as $data) { |
107 | | - $this->addToRecipientsList($data); |
108 | | - } |
109 | | - |
110 | | - foreach($email_list as $email){ |
111 | | - $this->addToRecipientsList([ |
112 | | - 'email' => $email, |
113 | | - 'language' => $CFG_GLPI["language"], |
114 | | - 'users_id' => -1 |
115 | | - ]); |
116 | | - } |
117 | | - } |
118 | | - } |
119 | | - |
120 | | -} |
| 1 | +<?php |
| 2 | +/* |
| 3 | + * @version $Id: notificationtargettaskcategory.class.php tomolimo $ |
| 4 | +------------------------------------------------------------------------- |
| 5 | +
|
| 6 | + */ |
| 7 | + |
| 8 | +if (!defined('GLPI_ROOT')) { |
| 9 | + die("Sorry. You can't access directly to this file"); |
| 10 | +} |
| 11 | + |
| 12 | +// Class NotificationTarget |
| 13 | +class PluginProcessmakerNotificationTargetCase extends PluginProcessmakerNotificationTargetProcessmaker { |
| 14 | + |
| 15 | + // type |
| 16 | + const EMAIL_RECIPIENTS = 200; |
| 17 | + |
| 18 | + // user type |
| 19 | + const RECIPIENTS = 1; |
| 20 | + |
| 21 | + /** |
| 22 | + * Summary of getEvents |
| 23 | + * @return string[] |
| 24 | + */ |
| 25 | + public function getEvents() { |
| 26 | + return ['send_email' => __('Send email', 'processmaker')]; |
| 27 | + } |
| 28 | + |
| 29 | + |
| 30 | + /** |
| 31 | + * Summary of addAdditionalTargets |
| 32 | + * @param mixed $event |
| 33 | + */ |
| 34 | + function addAdditionalTargets($event = '') { |
| 35 | + $this->notification_targets = []; |
| 36 | + $this->notification_targets_labels = []; |
| 37 | + $this->addTarget(self::RECIPIENTS, __('eMail recipients', 'processmaker'), self::EMAIL_RECIPIENTS); |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + /** |
| 42 | + * Summary of addSpecificTargets |
| 43 | + * @param mixed $data |
| 44 | + * @param mixed $options |
| 45 | + */ |
| 46 | + function addSpecificTargets($data, $options) { |
| 47 | + |
| 48 | + // test if we are in the good notification |
| 49 | + // then in this case add the targets from the ['recipients'] |
| 50 | + if (isset($options['glpi_send_email'])) { |
| 51 | + // normalize $options['glpi_send_email'] to an array of email parameters |
| 52 | + $options['glpi_send_email'] = isset($options['glpi_send_email']['notifications_id']) ? [$options['glpi_send_email']] : $options['glpi_send_email']; |
| 53 | + |
| 54 | + foreach($options['glpi_send_email'] as $params) { |
| 55 | + if (isset($params['notifications_id']) |
| 56 | + && $params['notifications_id'] == $data['notifications_id']) { |
| 57 | + //Look for all targets whose type is Notification::ITEM_USER |
| 58 | + switch ($data['type']) { |
| 59 | + case self::EMAIL_RECIPIENTS: |
| 60 | + |
| 61 | + switch ($data['items_id']) { |
| 62 | + |
| 63 | + case self::RECIPIENTS : |
| 64 | + $this->addUsers($params); |
| 65 | + break; |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + // if no target is added to $this, then the notification will not be sent. |
| 73 | + |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | + /** |
| 78 | + * Add users from $email_param['recipients'] |
| 79 | + * |
| 80 | + * @param array $email_param should contain 'recipients' |
| 81 | + * |
| 82 | + * @return void |
| 83 | + */ |
| 84 | + function addUsers($email_param = []) { |
| 85 | + global $DB, $CFG_GLPI; |
| 86 | + |
| 87 | + if (isset($email_param['recipients'])) { |
| 88 | + $id_list = []; // for users with ids |
| 89 | + $email_list = []; // for standalone emails |
| 90 | + |
| 91 | + // normalize into array the recipient list |
| 92 | + $email_param['recipients'] = is_array($email_param['recipients']) ? $email_param['recipients'] : [$email_param['recipients']]; |
| 93 | + foreach ($email_param['recipients'] as $user) { |
| 94 | + if (is_numeric($user)) { |
| 95 | + $id_list[] = intval($user); |
| 96 | + } else { |
| 97 | + $email_list[] = $user; |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + $user = new User(); |
| 102 | + foreach ($id_list as $users_id) { |
| 103 | + if ($user->getFromDB($users_id)) { |
| 104 | + |
| 105 | + $author_email = UserEmail::getDefaultForUser($user->fields['id']); |
| 106 | + $author_lang = $user->fields["language"]; |
| 107 | + $author_id = $user->fields['id']; |
| 108 | + |
| 109 | + if (empty($author_lang)) { |
| 110 | + $author_lang = $CFG_GLPI["language"]; |
| 111 | + } |
| 112 | + if (empty($author_id)) { |
| 113 | + $author_id = -1; |
| 114 | + } |
| 115 | + |
| 116 | + $user = [ |
| 117 | + 'language' => $author_lang, |
| 118 | + 'users_id' => $author_id |
| 119 | + ]; |
| 120 | + if ($this->isMailMode()) { |
| 121 | + $user['email'] = $author_email; |
| 122 | + } |
| 123 | + $this->addToRecipientsList($user); |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + foreach($email_list as $email){ |
| 128 | + $this->addToRecipientsList([ |
| 129 | + 'email' => $email, |
| 130 | + 'language' => $CFG_GLPI["language"], |
| 131 | + 'users_id' => -1 |
| 132 | + ]); |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | +} |
0 commit comments