ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
49 public function __construct($a_is_personal_workspace = false)
50 {
51 global $lng, $ilUser;
52
53 $this->is_in_wsp = (bool)$a_is_personal_workspace;
54
55 $this->setSender(ANONYMOUS_USER_ID);
56 $this->language = ilLanguageFactory::_getLanguage($lng->getDefaultLanguage());
57
58 if($this->is_in_wsp)
59 {
60 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
61 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
62 $this->wsp_tree = new ilWorkspaceTree($ilUser->getId()); // owner of tree is irrelevant
63 $this->wsp_access_handler = new ilWorkspaceAccessHandler($this->wsp_tree);
64 }
65 }
66
72 public function setType($a_type)
73 {
74 $this->type = $a_type;
75 }
76
81 public function getType()
82 {
83 return $this->type;
84 }
85
91 public function setSender($a_usr_id)
92 {
93 $this->sender = $a_usr_id;
94 }
95
100 public function getSender()
101 {
102 return $this->sender;
103 }
104
110 protected function setSubject($a_subject)
111 {
112 return $this->subject = $a_subject;
113 }
114
119 protected function getSubject()
120 {
121 return $this->subject;
122 }
123
129 protected function setBody($a_body)
130 {
131 $this->body = $a_body;
132 }
133
139 protected function appendBody($a_body)
140 {
141 return $this->body .= $a_body;
142 }
143
148 protected function getBody()
149 {
150 return $this->body;
151 }
152
158 public function setRecipients($a_rcp)
159 {
160 $this->recipients = $a_rcp;
161 }
162
167 public function getRecipients()
168 {
169 return $this->recipients;
170 }
171
176 public function setAttachments($a_att)
177 {
178 $this->attachments = $a_att;
179 }
180
185 public function getAttachments()
186 {
187 return (array) $this->attachments;
188 }
189
194 public function setLangModules(array $a_modules)
195 {
196 $this->lang_modules = $a_modules;
197 }
198
203 protected function initLanguage($a_usr_id)
204 {
205 $this->language = $this->getUserLanguage($a_usr_id);
206 }
207
214 public function getUserLanguage($a_usr_id)
215 {
217 $language->loadLanguageModule('mail');
218
219 if(sizeof($this->lang_modules))
220 {
221 foreach($this->lang_modules as $lmod)
222 {
223 $language->loadLanguageModule($lmod);
224 }
225 }
226
227 return $language;
228 }
229
234 protected function initLanguageByIso2Code($a_code = '')
235 {
236 $this->language = ilLanguageFactory::_getLanguage($a_code);
237 $this->language->loadLanguageModule('mail');
238
239 if(sizeof($this->lang_modules))
240 {
241 foreach($this->lang_modules as $lmod)
242 {
243 $this->language->loadLanguageModule($lmod);
244 }
245 }
246 }
247
252 protected function setLanguage($a_language)
253 {
254 $this->language = $a_language;
255 }
256
261 protected function getLanguage()
262 {
263 return $this->language;
264 }
265
271 protected function getLanguageText($a_keyword)
272 {
273 return str_replace('\n', "\n", $this->getLanguage()->txt($a_keyword));
274 }
275
281 public function setRefId($a_id)
282 {
283 if(!$this->is_in_wsp)
284 {
285 $this->ref_id = $a_id;
286 $obj_id = ilObject::_lookupObjId($this->ref_id);
287 }
288 else
289 {
290 $this->ref_id = (int)$a_id;
291 $obj_id = $this->wsp_tree->lookupObjectId($this->getRefId());
292 }
293
294 $this->setObjId($obj_id);
295 }
296
301 public function getRefId()
302 {
303 return $this->ref_id;
304 }
305
310 public function getObjId()
311 {
312 return $this->obj_id;
313 }
314
319 public function setObjId($a_obj_id)
320 {
321 $this->obj_id = $a_obj_id;
322 $this->obj_type = ilObject::_lookupType($this->obj_id);
323 }
324
329 public function getObjType()
330 {
331 return $this->obj_type;
332 }
333
339 public function setAdditionalInformation($a_info)
340 {
341 $this->additional_info = $a_info;
342 }
343
348 public function getAdditionalInformation()
349 {
350 return (array) $this->additional_info;
351 }
352
358 protected function getObjectTitle($a_shorten = false)
359 {
360 if(!$this->getObjId())
361 {
362 return '';
363 }
365 if((bool)$a_shorten)
366 {
367 $txt = ilUtil::shortenText($txt, self::SUBJECT_TITLE_LENGTH,true);
368 }
369 return $txt;
370 }
371
378 public function sendMail($a_rcp,$a_type,$a_parse_recipients = true)
379 {
380 $recipients = array();
381 foreach($a_rcp as $rcp)
382 {
383 if($a_parse_recipients)
384 {
386 }
387 else
388 {
389 $recipients[] = $rcp;
390 }
391 }
392 $recipients = implode(',',$recipients);
393 $error = $this->getMail()->sendMail(
395 '',
396 '',
397 $this->getSubject(),
398 $this->getBody(),
399 $this->getAttachments(),
400 $a_type
401 );
402
403 if(strlen($error))
404 {
405 $GLOBALS['ilLog']->write(__METHOD__.': '.$error);
406 }
407 }
408
413 protected function initMail()
414 {
415 return $this->mail = new ilMail($this->getSender());
416 }
417
422 protected function getMail()
423 {
424 return is_object($this->mail) ? $this->mail : $this->initMail();
425 }
426
431 protected function createPermanentLink($a_params = array(),$a_append = '')
432 {
433 include_once './Services/Link/classes/class.ilLink.php';
434
435 if($this->getRefId())
436 {
437 if(!$this->is_in_wsp)
438 {
439 return ilLink::_getLink($this->ref_id,$this->getObjType(),$a_params,$a_append);
440 }
441 else
442 {
443 return ilWorkspaceAccessHandler::getGotoLink($this->getRefId(), $this->getObjId(), $a_append);
444 }
445 }
446 else
447 {
448 // Return root
449 return ilLink::_getLink(ROOT_FOLDER_ID,'root');
450 }
451 }
452
458 protected function userToString($a_usr_id)
459 {
460 $name = ilObjUser::_lookupName($a_usr_id);
461 return ($name['title'] ? $name['title'].' ' : '').
462 ($name['firstname'] ? $name['firstname'].' ' : '').
463 ($name['lastname'] ? $name['lastname'].' ' : '');
464 }
465
474 protected function isRefIdAccessible($a_user_id, $a_ref_id, $a_permission = "read")
475 {
476 global $ilAccess;
477
478 // no given permission == accessible
479
480 if(!$this->is_in_wsp)
481 {
482 if(trim($a_permission) &&
483 !$ilAccess->checkAccessOfUser($a_user_id, $a_permission, "", $a_ref_id, $this->getObjType()))
484 {
485 return false;
486 }
487 }
488 else
489 {
490 if(trim($a_permission) &&
491 !$this->wsp_access_handler->checkAccessOfUser($this->wsp_tree, $a_user_id, $a_permission, "", $a_ref_id, $this->getObjType()))
492 {
493 return false;
494 }
495 }
496 return true;
497 }
498
503 public function getBlockBorder()
504 {
505 return "----------------------------------------\n";
506 }
507}
508
509?>
static _getLanguageOfUser($a_usr_id)
Get language object of user.
static _getLanguage($a_lang_key='')
Get langauge object.
Base class for course/group mail notifications.
getBlockBorder()
Get (ascii) block border.
appendBody($a_body)
Append body text.
userToString($a_usr_id)
Utility function.
initLanguageByIso2Code($a_code='')
Init language by ISO2 code.
setType($a_type)
Set notification type.
getType()
Get notification type.
setRecipients($a_rcp)
set mail recipients
setAdditionalInformation($a_info)
Additional information for creating notification mails.
getSender()
get sender of mail
__construct($a_is_personal_workspace=false)
Constructor.
getLanguage()
get language object
sendMail($a_rcp, $a_type, $a_parse_recipients=true)
Send Mail.
getUserLanguage($a_usr_id)
Get user language.
getAdditionalInformation()
Get additional information for generating notification mails.
setBody($a_body)
Set mail body.
setObjId($a_obj_id)
set obj id
getSubject()
Get mail subject.
setLanguage($a_language)
A language.
initLanguage($a_usr_id)
Init language.
setSender($a_usr_id)
Set sender of mail.
getRecipients()
get array of recipients
getObjectTitle($a_shorten=false)
Get object title.
setAttachments($a_att)
Set attachments
getLanguageText($a_keyword)
Replace new lines.
setSubject($a_subject)
Set mail subject.
setLangModules(array $a_modules)
Set lang modules.
createPermanentLink($a_params=array(), $a_append='')
Create a permanent link for an object.
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.
_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:10
$GLOBALS['ct_recipient']
global $lng
Definition: privfeed.php:40
global $ilUser
Definition: imgupload.php:15