ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $lng, $ilUser;
50
51 $this->is_in_wsp = (bool)$a_is_personal_workspace;
52
53 $this->setSender(ANONYMOUS_USER_ID);
54 $this->language = ilLanguageFactory::_getLanguage($lng->getDefaultLanguage());
55
56 if($this->is_in_wsp)
57 {
58 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
59 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
60 $this->wsp_tree = new ilWorkspaceTree($ilUser->getId()); // owner of tree is irrelevant
61 $this->wsp_access_handler = new ilWorkspaceAccessHandler($this->wsp_tree);
62 }
63 }
64
69 public function setType($a_type)
70 {
71 $this->type = $a_type;
72 }
73
78 public function getType()
79 {
80 return $this->type;
81 }
82
87 public function setSender($a_usr_id)
88 {
89 $this->sender = $a_usr_id;
90 }
91
96 public function getSender()
97 {
98 return $this->sender;
99 }
100
105 protected function setSubject($a_subject)
106 {
107 return $this->subject = $a_subject;
108 }
109
113 protected function getSubject()
114 {
115 return $this->subject;
116 }
117
121 protected function setBody($a_body)
122 {
123 $this->body = $a_body;
124 }
125
131 protected function appendBody($a_body)
132 {
133 return $this->body .= $a_body;
134 }
135
139 protected function getBody()
140 {
141 return $this->body;
142 }
143
147 public function setRecipients(array $a_rcp)
148 {
149 $this->recipients = $a_rcp;
150 }
151
156 public function getRecipients()
157 {
158 return $this->recipients;
159 }
160
165 public function setAttachments($a_att)
166 {
167 $this->attachments = $a_att;
168 }
169
174 public function getAttachments()
175 {
176 return (array) $this->attachments;
177 }
178
183 public function setLangModules(array $a_modules)
184 {
185 $this->lang_modules = $a_modules;
186 }
187
192 protected function initLanguage($a_usr_id)
193 {
194 $this->language = $this->getUserLanguage($a_usr_id);
195 }
196
203 public function getUserLanguage($a_usr_id)
204 {
206 $language->loadLanguageModule('mail');
207
208 if(sizeof($this->lang_modules))
209 {
210 foreach($this->lang_modules as $lmod)
211 {
212 $language->loadLanguageModule($lmod);
213 }
214 }
215
216 return $language;
217 }
218
223 protected function initLanguageByIso2Code($a_code = '')
224 {
225 $this->language = ilLanguageFactory::_getLanguage($a_code);
226 $this->language->loadLanguageModule('mail');
227
228 if(sizeof($this->lang_modules))
229 {
230 foreach($this->lang_modules as $lmod)
231 {
232 $this->language->loadLanguageModule($lmod);
233 }
234 }
235 }
236
240 protected function setLanguage($a_language)
241 {
242 $this->language = $a_language;
243 }
244
248 protected function getLanguage()
249 {
250 return $this->language;
251 }
252
257 protected function getLanguageText($a_keyword)
258 {
259 return str_replace('\n', "\n", $this->getLanguage()->txt($a_keyword));
260 }
261
265 public function setRefId($a_id)
266 {
267 if(!$this->is_in_wsp)
268 {
269 $this->ref_id = $a_id;
270 $obj_id = ilObject::_lookupObjId($this->ref_id);
271 }
272 else
273 {
274 $this->ref_id = (int)$a_id;
275 $obj_id = $this->wsp_tree->lookupObjectId($this->getRefId());
276 }
277
278 $this->setObjId($obj_id);
279 }
280
284 public function getRefId()
285 {
286 return $this->ref_id;
287 }
288
292 public function getObjId()
293 {
294 return $this->obj_id;
295 }
296
300 public function setObjId($a_obj_id)
301 {
302 $this->obj_id = $a_obj_id;
303 $this->obj_type = ilObject::_lookupType($this->obj_id);
304 }
305
310 public function getObjType()
311 {
312 return $this->obj_type;
313 }
314
319 public function setAdditionalInformation(array $a_info)
320 {
321 $this->additional_info = $a_info;
322 }
323
327 public function getAdditionalInformation()
328 {
329 return (array) $this->additional_info;
330 }
331
336 protected function getObjectTitle($a_shorten = false)
337 {
338 if(!$this->getObjId())
339 {
340 return '';
341 }
343 if((bool)$a_shorten)
344 {
345 $txt = ilUtil::shortenText($txt, self::SUBJECT_TITLE_LENGTH,true);
346 }
347 return $txt;
348 }
349
355 public function sendMail(array $a_rcp, $a_type, $a_parse_recipients = true)
356 {
357 $recipients = array();
358 foreach($a_rcp as $rcp)
359 {
360 if($a_parse_recipients)
361 {
363 }
364 else
365 {
366 $recipients[] = $rcp;
367 }
368 }
369 $recipients = implode(',',$recipients);
370 $error = $this->getMail()->sendMail(
372 '',
373 '',
374 $this->getSubject(),
375 $this->getBody(),
376 $this->getAttachments(),
377 $a_type
378 );
379
380 if(strlen($error))
381 {
382 require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
383 ilLoggerFactory::getLogger('mail')->error($error);
384 }
385 }
386
390 protected function initMail()
391 {
392 return $this->mail = new ilMail($this->getSender());
393 }
394
398 protected function getMail()
399 {
400 return is_object($this->mail) ? $this->mail : $this->initMail();
401 }
402
408 protected function createPermanentLink($a_params = array(),$a_append = '')
409 {
410 include_once './Services/Link/classes/class.ilLink.php';
411
412 if($this->getRefId())
413 {
414 if(!$this->is_in_wsp)
415 {
416 return ilLink::_getLink($this->ref_id,$this->getObjType(),$a_params,$a_append);
417 }
418 else
419 {
420 return ilWorkspaceAccessHandler::getGotoLink($this->getRefId(), $this->getObjId(), $a_append);
421 }
422 }
423 else
424 {
425 // Return root
426 return ilLink::_getLink(ROOT_FOLDER_ID,'root');
427 }
428 }
429
434 protected function userToString($a_usr_id)
435 {
436 $name = ilObjUser::_lookupName($a_usr_id);
437 return ($name['title'] ? $name['title'].' ' : '').
438 ($name['firstname'] ? $name['firstname'].' ' : '').
439 ($name['lastname'] ? $name['lastname'].' ' : '');
440 }
441
450 protected function isRefIdAccessible($a_user_id, $a_ref_id, $a_permission = "read")
451 {
452 global $ilAccess;
453
454 // no given permission == accessible
455
456 if(!$this->is_in_wsp)
457 {
458 if(trim($a_permission) &&
459 !$ilAccess->checkAccessOfUser($a_user_id, $a_permission, "", $a_ref_id, $this->getObjType()))
460 {
461 return false;
462 }
463 }
464 else
465 {
466 if(trim($a_permission) &&
467 !$this->wsp_access_handler->checkAccessOfUser($this->wsp_tree, $a_user_id, $a_permission, "", $a_ref_id, $this->getObjType()))
468 {
469 return false;
470 }
471 }
472 return true;
473 }
474
479 public function getBlockBorder()
480 {
481 return "----------------------------------------\n";
482 }
483}
484
485?>
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.
sendMail(array $a_rcp, $a_type, $a_parse_recipients=true)
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.
initLanguage($a_usr_id)
Init language.
setSender($a_usr_id)
Set sender of mail.
getRecipients()
get array of recipients
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.
Class Mail this class handles base functions for mail handling.
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:12
global $lng
Definition: privfeed.php:40
global $ilUser
Definition: imgupload.php:15