ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSystemNotification.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Mail/classes/class.ilMailNotification.php';
5
17{
18 protected $subject_lang_id; // [string]
19 protected $subject_direct; // [string]
20 protected $introduction; // [string]
21 protected $introduction_direct; // [string]
22 protected $task; // [string]
23 protected $reason; // [string]
24 protected $additional; // [array]
25 protected $goto_caption; // [string]
26 protected $changed_by; // [int]
27 protected $all_ref_ids; // [array]
28
34 public function setSubjectLangId($a_lang_id)
35 {
36 $this->subject_lang_id = (string) $a_lang_id;
37 }
38
44 public function setSubjectDirect($a_text)
45 {
46 $this->subject_direct = trim($a_text);
47 }
48
54 public function setIntroductionLangId($a_lang_id)
55 {
56 $this->introduction = (string) $a_lang_id;
57 }
58
64 public function setIntroductionDirect($a_text)
65 {
66 $this->introduction_direct = trim($a_text);
67 }
68
74 public function setTaskLangId($a_lang_id)
75 {
76 $this->task = (string) $a_lang_id;
77 }
78
84 public function setReasonLangId($a_lang_id)
85 {
86 $this->reason = (string) $a_lang_id;
87 }
88
94 public function setGotoLangId($a_lang_id)
95 {
96 $this->goto_caption = (string) $a_lang_id;
97 }
98
104 public function setChangedByUserId($a_id)
105 {
106 $this->changed_by = (int) $a_id;
107
108 include_once "Services/User/classes/class.ilUserUtil.php";
109 }
110
119 public function addAdditionalInfo($a_lang_id, $a_value, $a_multiline = false, $a_lang_direct = false)
120 {
121 $this->additional[$a_lang_id] = array(trim($a_value), (bool) $a_multiline, (bool) $a_lang_direct);
122 }
123
132 public function sendMail(array $a_user_ids, $a_goto_additional = null, $a_permission = "read")
133 {
134 $this->all_ref_ids = null;
135
136 // prepare object related info
137 if ($this->getObjId()) {
138 if (!$this->getRefId()) {
139 // try to find ref_id(s)
140 if (!$this->is_in_wsp) {
141 $ref_ids = ilObject::_getAllReferences($this->getObjId());
142 if (sizeof($ref_ids) == 1) {
143 $this->ref_id = array_shift($ref_ids);
144 } else {
145 $this->all_ref_ids = $ref_ids;
146 }
147 }
148 } elseif ($this->is_in_wsp) { // #11680
149 $this->ref_id = $this->wsp_tree->lookupNodeId($this->getObjId());
150 }
151
152 // default values
153 if (!$this->goto_caption) {
154 $this->goto_caption = "url";
155 }
156 }
157
158 $recipient_ids = array();
159 foreach (array_unique($a_user_ids) as $user_id) {
160 // author of change should not get notification
161 if ($this->changed_by == $user_id) {
162 continue;
163 }
164 if ($this->composeAndSendMail($user_id, $a_goto_additional, $a_permission)) {
165 $recipient_ids[] = $user_id;
166 }
167 }
168
169 return $recipient_ids;
170 }
171
181 public function compose($a_user_id, $a_goto_additional = null, $a_permission = "read", $a_append_signature_direct = false)
182 {
183 $this->initLanguage($a_user_id);
184 $this->initMail();
185
186 if ($this->subject_direct) {
187 $this->setSubject($this->subject_direct);
188 } else {
189 $this->setSubject(
190 sprintf($this->getLanguageText($this->subject_lang_id), $this->getObjectTitle(true))
191 );
192 }
193
194 $this->setBody(ilMail::getSalutation($a_user_id, $this->getLanguage()));
195 $this->appendBody("\n\n");
196
197 if ($this->introduction) {
198 $this->appendBody($this->getLanguageText($this->introduction));
199 $this->appendBody("\n\n");
200 }
201
202 if ($this->introduction_direct) {
203 $this->appendBody($this->introduction_direct);
204 $this->appendBody("\n\n");
205 }
206
207 if ($this->task) {
208 $this->appendBody($this->getLanguageText($this->task));
209 $this->appendBody("\n\n");
210 }
211
212 // details table
213 if ($this->getObjId()) {
214 $this->appendBody($this->getLanguageText("obj_" . $this->getObjType()) . ": " .
215 $this->getObjectTitle() . "\n");
216 }
217 if (is_array($this->additional)) {
218 foreach ($this->additional as $lang_id => $item) {
219 $caption = "";
220 if ($lang_id) {
221 $caption = (!$item[2])
222 ? $this->getLanguageText($lang_id)
223 : $lang_id;
224 }
225 if (!$item[1]) {
226 if ($caption) {
227 $caption .= ": ";
228 }
229 $this->appendBody($caption . $item[0] . "\n");
230 } else {
231 if ($caption) {
232 $caption .= "\n";
233 }
234 $this->appendBody("\n" . $caption .
235 $this->getBlockBorder() .
236 $item[0] . "\n" .
237 $this->getBlockBorder() . "\n");
238 }
239 }
240 }
241 $this->body = trim($this->body);
242 $this->appendBody("\n\n");
243
244 if ($this->changed_by) {
245 $this->appendBody($this->getLanguageText("system_notification_installation_changed_by") . ": " .
246 ilUserUtil::getNamePresentation($this->changed_by));
247 $this->appendBody("\n\n");
248 }
249
250 if ($this->getObjId()) {
251 // try to find accessible ref_id
252 if (!$this->getRefId() && $this->all_ref_ids) {
253 $find_ref_id = true;
254 foreach ($this->all_ref_ids as $ref_id) {
255 if ($this->isRefIdAccessible($a_user_id, $ref_id, $a_permission)) {
256 $this->ref_id = $ref_id;
257 break;
258 }
259 }
260 }
261
262 // check if initially given ref_id is accessible for current recipient
263 if ($this->getRefId() &&
264 !$find_ref_id &&
265 !$this->isRefIdAccessible($a_user_id, $this->getRefId(), $a_permission)) {
266 return false;
267 }
268
269 $goto = $this->createPermanentLink(array(), $a_goto_additional);
270 if ($goto) {
271 $this->appendBody($this->getLanguageText($this->goto_caption) . ": " .
272 $goto);
273 $this->appendBody("\n\n");
274 }
275
276 if ($find_ref_id) {
277 $this->ref_id = null;
278 }
279 }
280
281 if ($this->reason) {
282 $this->appendBody($this->getLanguageText($this->reason));
283 $this->appendBody("\n\n");
284 }
285
287
288 // signature will append new lines
289 $this->body = trim($this->body);
290
291 if (!$a_append_signature_direct) {
292 $this->getMail()->appendInstallationSignature(true);
293 } else {
295 }
296
297 return true;
298 }
299
308 protected function composeAndSendMail($a_user_id, $a_goto_additional = null, $a_permission = "read")
309 {
310 if ($this->compose($a_user_id, $a_goto_additional, $a_permission)) {
311 parent::sendMail(array($a_user_id), is_numeric($a_user_id));
312 return true;
313 }
314 return false;
315 }
316
326 public function composeAndGetMessage($a_user_id, $a_goto_additional = null, $a_permission = "read", $a_append_signature_direct = false)
327 {
328 if ($this->compose($a_user_id, $a_goto_additional, $a_permission, $a_append_signature_direct)) {
329 return $this->body;
330 }
331 }
332}
An exception for terminatinating execution or to throw for unit testing.
Base class for course/group mail notifications.
getBlockBorder()
Get (ascii) block border.
appendBody($a_body)
Append body text.
initLanguage($a_usr_id)
Init language.
getObjectTitle($a_shorten=false)
createPermanentLink($a_params=array(), $a_append='')
isRefIdAccessible($a_user_id, $a_ref_id, $a_permission="read")
Check if ref id is accessible for user.
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
static _getInstallationSignature()
static getSalutation($a_usr_id, ilLanguage $a_language=null)
static _getAllReferences($a_id)
get all reference ids of object
Wrapper classes for system notifications.
setIntroductionLangId($a_lang_id)
Set introduction lang id.
setReasonLangId($a_lang_id)
Set reason lang id.
addAdditionalInfo($a_lang_id, $a_value, $a_multiline=false, $a_lang_direct=false)
Add additional information.
setSubjectLangId($a_lang_id)
Set subject lang id.
setGotoLangId($a_lang_id)
Set goto lang id.
setChangedByUserId($a_id)
Set changed by user id.
setTaskLangId($a_lang_id)
Set task lang id.
composeAndSendMail($a_user_id, $a_goto_additional=null, $a_permission="read")
Send notification to single recipient.
compose($a_user_id, $a_goto_additional=null, $a_permission="read", $a_append_signature_direct=false)
Compose notification to single recipient.
composeAndGetMessage($a_user_id, $a_goto_additional=null, $a_permission="read", $a_append_signature_direct=false)
Compose notification to single recipient.
sendMail(array $a_user_ids, $a_goto_additional=null, $a_permission="read")
Send notification(s)
setIntroductionDirect($a_text)
Set introduction text.
setSubjectDirect($a_text)
Set subject text.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
language()
Definition: language.php:2