ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
5 include_once './Services/Language/classes/class.ilLanguageFactory.php';
6 include_once './Services/Mail/classes/class.ilMail.php';
7 
16 abstract 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(
371  $recipients,
372  '',
373  '',
374  $this->getSubject(),
375  $this->getBody(),
376  $this->getAttachments(),
377  $a_type
378  );
379  // smeyer: 19.5.16 fixed strlen warning, since $error is of type array
380  if($error)
381  {
382  require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
384  //ilLoggerFactory::getLogger('mail')->error($error);
385  }
386  }
387 
391  protected function initMail()
392  {
393  return $this->mail = new ilMail($this->getSender());
394  }
395 
399  protected function getMail()
400  {
401  return is_object($this->mail) ? $this->mail : $this->initMail();
402  }
403 
409  protected function createPermanentLink($a_params = array(),$a_append = '')
410  {
411  include_once './Services/Link/classes/class.ilLink.php';
412 
413  if($this->getRefId())
414  {
415  if(!$this->is_in_wsp)
416  {
417  return ilLink::_getLink($this->ref_id,$this->getObjType(),$a_params,$a_append);
418  }
419  else
420  {
421  return ilWorkspaceAccessHandler::getGotoLink($this->getRefId(), $this->getObjId(), $a_append);
422  }
423  }
424  else
425  {
426  // Return root
427  return ilLink::_getLink(ROOT_FOLDER_ID,'root');
428  }
429  }
430 
435  protected function userToString($a_usr_id)
436  {
437  $name = ilObjUser::_lookupName($a_usr_id);
438  return ($name['title'] ? $name['title'].' ' : '').
439  ($name['firstname'] ? $name['firstname'].' ' : '').
440  ($name['lastname'] ? $name['lastname'].' ' : '');
441  }
442 
451  protected function isRefIdAccessible($a_user_id, $a_ref_id, $a_permission = "read")
452  {
453  global $ilAccess;
454 
455  // no given permission == accessible
456 
457  if(!$this->is_in_wsp)
458  {
459  if(trim($a_permission) &&
460  !$ilAccess->checkAccessOfUser($a_user_id, $a_permission, "", $a_ref_id, $this->getObjType()))
461  {
462  return false;
463  }
464  }
465  else
466  {
467  if(trim($a_permission) &&
468  !$this->wsp_access_handler->checkAccessOfUser($this->wsp_tree, $a_user_id, $a_permission, "", $a_ref_id, $this->getObjType()))
469  {
470  return false;
471  }
472  }
473  return true;
474  }
475 
480  public function getBlockBorder()
481  {
482  return "----------------------------------------\n";
483  }
484 }
485 
486 ?>
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
$error
Definition: Error.php:17
getType()
Get notification type.
initLanguageByIso2Code($a_code='')
Init language by ISO2 code.
setSender($a_usr_id)
Set sender of mail.
initLanguage($a_usr_id)
Init language.
setAttachments($a_att)
Set attachments.
isRefIdAccessible($a_user_id, $a_ref_id, $a_permission="read")
Check if ref id is accessible for user.
Access handler for personal workspace.
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
static _lookupTitle($a_id)
lookup object title
mail($to, $subject, $message, $additional_headers=null, $additional_parameters=null)
Tree handler for personal workspace.
$a_type
Definition: workflow.php:93
__construct($a_is_personal_workspace=false)
static _getLanguage($a_lang_key='')
Get langauge object.
Base class for course/group mail notifications.
setType($a_type)
Set notification type.
static getGotoLink($a_node_id, $a_obj_id, $a_additional=null)
setLangModules(array $a_modules)
Set lang modules.
This class handles base functions for mail handling.
static _lookupObjId($a_id)
getObjectTitle($a_shorten=false)
getAttachments()
Get attachments.
$ilUser
Definition: imgupload.php:18
getObjType()
Get object type.
$txt
Definition: error.php:12
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
sendMail(array $a_rcp, $a_type, $a_parse_recipients=true)
static _getLanguageOfUser($a_usr_id)
Get language object of user.
getRecipients()
get array of recipients
getBlockBorder()
Get (ascii) block border.
createPermanentLink($a_params=array(), $a_append='')
getSender()
get sender of mail
global $lng
Definition: privfeed.php:17
appendBody($a_body)
Append body text.
static getLogger($a_component_id)
Get component logger.
getUserLanguage($a_usr_id)
Get user language.
setAdditionalInformation(array $a_info)
Additional information for creating notification mails.