ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $introduction; // [string]
20 protected $introduction_direct; // [string]
21 protected $task; // [string]
22 protected $reason; // [string]
23 protected $additional; // [array]
24 protected $goto_caption; // [string]
25 protected $changed_by; // [int]
26 protected $all_ref_ids; // [array]
27
33 public function setSubjectLangId($a_lang_id)
34 {
35 $this->subject_lang_id = (string)$a_lang_id;
36 }
37
43 public function setIntroductionLangId($a_lang_id)
44 {
45 $this->introduction = (string)$a_lang_id;
46 }
47
53 public function setIntroductionDirect($a_text)
54 {
55 $this->introduction_direct = trim($a_text);
56 }
57
63 public function setTaskLangId($a_lang_id)
64 {
65 $this->task = (string)$a_lang_id;
66 }
67
73 public function setReasonLangId($a_lang_id)
74 {
75 $this->reason = (string)$a_lang_id;
76 }
77
83 public function setGotoLangId($a_lang_id)
84 {
85 $this->goto_caption = (string)$a_lang_id;
86 }
87
93 public function setChangedByUserId($a_id)
94 {
95 $this->changed_by = (int)$a_id;
96
97 include_once "Services/User/classes/class.ilUserUtil.php";
98 }
99
108 public function addAdditionalInfo($a_lang_id, $a_value, $a_multiline = false, $a_lang_direct = false)
109 {
110 $this->additional[$a_lang_id] = array(trim($a_value), (bool)$a_multiline, (bool)$a_lang_direct);
111 }
112
121 public function sendMail(array $a_user_ids, $a_goto_additional = null, $a_permission = "read")
122 {
123 $this->all_ref_ids = null;
124
125 // prepare object related info
126 if($this->getObjId())
127 {
128 if(!$this->getRefId())
129 {
130 // try to find ref_id(s)
131 if(!$this->is_in_wsp)
132 {
133 $ref_ids = ilObject::_getAllReferences($this->getObjId());
134 if(sizeof($ref_ids) == 1)
135 {
136 $this->ref_id = array_shift($ref_ids);
137 }
138 else
139 {
140 $this->all_ref_ids = $ref_ids;
141 }
142 }
143 }
144 else if($this->is_in_wsp) // #11680
145 {
146 $this->ref_id = $this->wsp_tree->lookupNodeId($this->getObjId());
147 }
148
149 // default values
150 if(!$this->goto_caption)
151 {
152 $this->goto_caption = "url";
153 }
154 }
155
156 $recipient_ids = array();
157 foreach(array_unique($a_user_ids) as $user_id)
158 {
159 // author of change should not get notification
160 if($this->changed_by == $user_id)
161 {
162 continue;
163 }
164
165 if($this->composeAndSendMail($user_id, $a_goto_additional, $a_permission))
166 {
167 $recipient_ids[] = $user_id;
168 }
169 }
170
171 return $recipient_ids;
172 }
173
183 public function compose($a_user_id, $a_goto_additional = null, $a_permission = "read", $a_append_signature_direct = false)
184 {
185 $this->initLanguage($a_user_id);
186 $this->initMail();
187
188 $this->setSubject(
189 sprintf($this->getLanguageText($this->subject_lang_id), $this->getObjectTitle(true))
190 );
191
192 $this->setBody(ilMail::getSalutation($a_user_id, $this->getLanguage()));
193 $this->appendBody("\n\n");
194
195 if($this->introduction)
196 {
197 $this->appendBody($this->getLanguageText($this->introduction));
198 $this->appendBody("\n\n");
199 }
200
201 if($this->introduction_direct)
202 {
203 $this->appendBody($this->introduction_direct);
204 $this->appendBody("\n\n");
205 }
206
207 if($this->task)
208 {
209 $this->appendBody($this->getLanguageText($this->task));
210 $this->appendBody("\n\n");
211 }
212
213 // details table
214 if($this->getObjId())
215 {
216 $this->appendBody($this->getLanguageText("obj_".$this->getObjType()).": ".
217 $this->getObjectTitle()."\n");
218 }
219 if(sizeof($this->additional))
220 {
221 foreach($this->additional as $lang_id => $item)
222 {
223 $caption = "";
224 if($lang_id)
225 {
226 $caption = (!$item[2])
227 ? $this->getLanguageText($lang_id)
228 : $lang_id;
229 }
230 if(!$item[1])
231 {
232 if($caption)
233 {
234 $caption .= ": ";
235 }
236 $this->appendBody($caption.$item[0]."\n");
237 }
238 else
239 {
240 if($caption)
241 {
242 $caption .= "\n";
243 }
244 $this->appendBody("\n".$caption.
245 $this->getBlockBorder().
246 $item[0]."\n".
247 $this->getBlockBorder()."\n");
248 }
249 }
250 }
251 $this->body = trim($this->body);
252 $this->appendBody("\n\n");
253
254 if($this->changed_by)
255 {
256 $this->appendBody($this->getLanguageText("system_notification_installation_changed_by").": ".
257 ilUserUtil::getNamePresentation($this->changed_by));
258 $this->appendBody("\n\n");
259 }
260
261 if($this->getObjId())
262 {
263 // try to find accessible ref_id
264 if(!$this->getRefId() && $this->all_ref_ids)
265 {
266 $find_ref_id = true;
267 foreach($this->all_ref_ids as $ref_id)
268 {
269 if($this->isRefIdAccessible($a_user_id, $ref_id, $a_permission))
270 {
271 $this->ref_id = $ref_id;
272 break;
273 }
274 }
275 }
276
277 // check if initially given ref_id is accessible for current recipient
278 if($this->getRefId() &&
279 !$find_ref_id &&
280 !$this->isRefIdAccessible($a_user_id, $this->getRefId(), $a_permission))
281 {
282 return false;
283 }
284
285 $goto = $this->createPermanentLink(array(), $a_goto_additional);
286 if($goto)
287 {
288 $this->appendBody($this->getLanguageText($this->goto_caption).": ".
289 $goto);
290 $this->appendBody("\n\n");
291 }
292
293 if($find_ref_id)
294 {
295 $this->ref_id = null;
296 }
297 }
298
299 if($this->reason)
300 {
301 $this->appendBody($this->getLanguageText($this->reason));
302 $this->appendBody("\n\n");
303 }
304
305 $this->appendBody(ilMail::_getAutoGeneratedMessageString($this->language));
306
307 // signature will append new lines
308 $this->body = trim($this->body);
309
310 if(!$a_append_signature_direct)
311 {
312 $this->getMail()->appendInstallationSignature(true);
313 }
314 else
315 {
317 }
318
319 return true;
320 }
321
330 protected function composeAndSendMail($a_user_id, $a_goto_additional = null, $a_permission = "read")
331 {
332 if($this->compose($a_user_id, $a_goto_additional, $a_permission))
333 {
334 parent::sendMail(array($a_user_id), array('system'), is_numeric($a_user_id));
335 return true;
336 }
337 return false;
338 }
339
349 public function composeAndGetMessage($a_user_id, $a_goto_additional = null, $a_permission = "read", $a_append_signature_direct = false)
350 {
351 if($this->compose($a_user_id, $a_goto_additional, $a_permission, $a_append_signature_direct))
352 {
353 return $this->body;
354 }
355 }
356}
357
358?>
Base class for course/group mail notifications.
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 getSalutation($a_usr_id, $a_language=null)
Get salutation.
static _getInstallationSignature()
Static getter for the installation signature.
static _getAutoGeneratedMessageString($lang=null)
get auto generated info string
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.
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)
Default behaviour is: