ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilMailNotification.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
5include_once './Services/Language/classes/class.ilLanguageFactory.php';
6include_once './Services/Mail/classes/class.ilMail.php';
7
16abstract class ilMailNotification
17{
19
20 protected $type = null;
21 protected $sender = null;
22
23 protected $mail = null;
24 protected $subject = '';
25 protected $body = '';
26
27 protected $attachments = array();
28
29 protected $language = null;
30 protected $lang_modules = array();
31
32 protected $recipients = array();
33
34 protected $ref_id = null;
35 protected $obj_id = null;
36 protected $obj_type = null;
37
38 protected $additional_info = array();
39
40 protected $is_in_wsp;
41 protected $wsp_tree;
43
47 public function __construct($a_is_personal_workspace = false)
48 {
49 global $DIC;
50
51 $this->is_in_wsp = (bool) $a_is_personal_workspace;
52
53 $this->setSender(ANONYMOUS_USER_ID);
54 $this->language = ilLanguageFactory::_getLanguage($DIC->language()->getDefaultLanguage());
55
56 if ($this->is_in_wsp) {
57 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
58 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
59 $this->wsp_tree = new ilWorkspaceTree($DIC->user()->getId()); // owner of tree is irrelevant
60 $this->wsp_access_handler = new ilWorkspaceAccessHandler($this->wsp_tree);
61 }
62 }
63
68 public function setType($a_type)
69 {
70 $this->type = $a_type;
71 }
72
77 public function getType()
78 {
79 return $this->type;
80 }
81
86 public function setSender($a_usr_id)
87 {
88 $this->sender = $a_usr_id;
89 }
90
95 public function getSender()
96 {
97 return $this->sender;
98 }
99
104 protected function setSubject($a_subject)
105 {
106 return $this->subject = $a_subject;
107 }
108
112 protected function getSubject()
113 {
114 return $this->subject;
115 }
116
120 protected function setBody($a_body)
121 {
122 $this->body = $a_body;
123 }
124
130 protected function appendBody($a_body)
131 {
132 return $this->body .= $a_body;
133 }
134
138 protected function getBody()
139 {
140 return $this->body;
141 }
142
146 public function setRecipients(array $a_rcp)
147 {
148 $this->recipients = $a_rcp;
149 }
150
155 public function getRecipients()
156 {
157 return $this->recipients;
158 }
159
164 public function setAttachments($a_att)
165 {
166 $this->attachments = $a_att;
167 }
168
173 public function getAttachments()
174 {
175 return (array) $this->attachments;
176 }
177
182 public function setLangModules(array $a_modules)
183 {
184 $this->lang_modules = $a_modules;
185 }
186
191 protected function initLanguage($a_usr_id)
192 {
193 $this->language = $this->getUserLanguage($a_usr_id);
194 }
195
202 public function getUserLanguage($a_usr_id)
203 {
205 $language->loadLanguageModule('mail');
206
207 if (sizeof($this->lang_modules)) {
208 foreach ($this->lang_modules as $lmod) {
209 $language->loadLanguageModule($lmod);
210 }
211 }
212
213 return $language;
214 }
215
220 protected function initLanguageByIso2Code($a_code = '')
221 {
223 $this->language->loadLanguageModule('mail');
224
225 if (sizeof($this->lang_modules)) {
226 foreach ($this->lang_modules as $lmod) {
227 $this->language->loadLanguageModule($lmod);
228 }
229 }
230 }
231
235 protected function setLanguage($a_language)
236 {
237 $this->language = $a_language;
238 }
239
243 protected function getLanguage()
244 {
245 return $this->language;
246 }
247
252 protected function getLanguageText($a_keyword)
253 {
254 return str_replace('\n', "\n", $this->getLanguage()->txt($a_keyword));
255 }
256
260 public function setRefId($a_id)
261 {
262 if (!$this->is_in_wsp) {
263 $this->ref_id = $a_id;
264 $obj_id = ilObject::_lookupObjId($this->ref_id);
265 } else {
266 $this->ref_id = (int) $a_id;
267 $obj_id = $this->wsp_tree->lookupObjectId($this->getRefId());
268 }
269
270 $this->setObjId($obj_id);
271 }
272
276 public function getRefId()
277 {
278 return $this->ref_id;
279 }
280
284 public function getObjId()
285 {
286 return $this->obj_id;
287 }
288
292 public function setObjId($a_obj_id)
293 {
294 $this->obj_id = $a_obj_id;
295 $this->obj_type = ilObject::_lookupType($this->obj_id);
296 }
297
302 public function getObjType()
303 {
304 return $this->obj_type;
305 }
306
311 public function setAdditionalInformation(array $a_info)
312 {
313 $this->additional_info = $a_info;
314 }
315
319 public function getAdditionalInformation()
320 {
321 return (array) $this->additional_info;
322 }
323
328 protected function getObjectTitle($a_shorten = false)
329 {
330 if (!$this->getObjId()) {
331 return '';
332 }
334 if ((bool) $a_shorten) {
335 $txt = ilUtil::shortenText($txt, self::SUBJECT_TITLE_LENGTH, true);
336 }
337 return $txt;
338 }
339
344 public function sendMail(array $a_rcp, $a_parse_recipients = true)
345 {
346 $recipients = array();
347 foreach ($a_rcp as $rcp) {
348 if ($a_parse_recipients) {
350 } else {
351 $recipients[] = $rcp;
352 }
353 }
354 $recipients = implode(',', $recipients);
355 $errors = $this->getMail()->enqueue(
357 '',
358 '',
359 $this->getSubject(),
360 $this->getBody(),
361 $this->getAttachments()
362 );
363 // smeyer: 19.5.16 fixed strlen warning, since $error is of type array
364 if (count($errors) > 0) {
365 require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
367 //ilLoggerFactory::getLogger('mail')->error($error);
368 }
369 }
370
374 protected function initMail()
375 {
376 return $this->mail = new ilMail($this->getSender());
377 }
378
382 protected function getMail()
383 {
384 return is_object($this->mail) ? $this->mail : $this->initMail();
385 }
386
392 protected function createPermanentLink($a_params = array(), $a_append = '')
393 {
394 include_once './Services/Link/classes/class.ilLink.php';
395
396 if ($this->getRefId()) {
397 if (!$this->is_in_wsp) {
398 return ilLink::_getLink($this->ref_id, $this->getObjType(), $a_params, $a_append);
399 } else {
400 return ilWorkspaceAccessHandler::getGotoLink($this->getRefId(), $this->getObjId(), $a_append);
401 }
402 } else {
403 // Return root
404 return ilLink::_getLink(ROOT_FOLDER_ID, 'root');
405 }
406 }
407
412 protected function userToString($a_usr_id)
413 {
414 $name = ilObjUser::_lookupName($a_usr_id);
415 return ($name['title'] ? $name['title'] . ' ' : '') .
416 ($name['firstname'] ? $name['firstname'] . ' ' : '') .
417 ($name['lastname'] ? $name['lastname'] . ' ' : '');
418 }
419
428 protected function isRefIdAccessible($a_user_id, $a_ref_id, $a_permission = "read")
429 {
430 global $DIC;
431
432 // no given permission == accessible
433
434 if (!$this->is_in_wsp) {
435 if (trim($a_permission) &&
436 !$DIC->access()->checkAccessOfUser($a_user_id, $a_permission, "", $a_ref_id, $this->getObjType())) {
437 return false;
438 }
439 } else {
440 if (trim($a_permission) &&
441 !$this->wsp_access_handler->checkAccessOfUser($this->wsp_tree, $a_user_id, $a_permission, "", $a_ref_id, $this->getObjType())) {
442 return false;
443 }
444 }
445 return true;
446 }
447
452 public function getBlockBorder()
453 {
454 return "----------------------------------------\n";
455 }
456}
An exception for terminatinating execution or to throw for unit testing.
static _getLanguageOfUser($a_usr_id)
Get language object of user.
static _getLanguage($a_lang_key='')
Get langauge object.
static getLogger($a_component_id)
Get component logger.
Base class for course/group mail notifications.
getBlockBorder()
Get (ascii) block border.
appendBody($a_body)
Append body text.
initLanguageByIso2Code($a_code='')
Init language by ISO2 code.
setType($a_type)
Set notification type.
getType()
Get notification type.
getSender()
get sender of mail
__construct($a_is_personal_workspace=false)
getUserLanguage($a_usr_id)
Get user language.
sendMail(array $a_rcp, $a_parse_recipients=true)
initLanguage($a_usr_id)
Init language.
setSender($a_usr_id)
Set sender of mail.
getRecipients()
get array of recipients
getAttachments()
Get attachments.
getObjectTitle($a_shorten=false)
setAttachments($a_att)
Set attachments.
setLangModules(array $a_modules)
Set lang modules.
createPermanentLink($a_params=array(), $a_append='')
setAdditionalInformation(array $a_info)
Additional information for creating notification mails.
isRefIdAccessible($a_user_id, $a_ref_id, $a_permission="read")
Check if ref id is accessible for user.
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
Access handler for personal workspace.
static getGotoLink($a_node_id, $a_obj_id, $a_additional=null)
Tree handler for personal workspace.
$txt
Definition: error.php:13
language()
Definition: language.php:2
if($format !==null) $name
Definition: metadata.php:230
$errors
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46