ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  private $type = null;
21  private $sender = null;
22 
23  private $mail = null;
24  private $subject = '';
25  private $body = '';
26 
27  private $attachments = array();
28 
29  protected $language = null;
30 
31  private $recipients = array();
32 
33  private $ref_id = null;
34  private $obj_id = null;
35  private $obj_type = null;
36 
37  private $additional_info = array();
38 
43  public function __construct()
44  {
45  global $lng;
46 
47  $this->setSender(ANONYMOUS_USER_ID);
48  $this->language = ilLanguageFactory::_getLanguage($lng->getDefaultLanguage());
49  }
50 
56  public function setType($a_type)
57  {
58  $this->type = $a_type;
59  }
60 
65  public function getType()
66  {
67  return $this->type;
68  }
69 
75  public function setSender($a_usr_id)
76  {
77  $this->sender = $a_usr_id;
78  }
79 
84  public function getSender()
85  {
86  return $this->sender;
87  }
88 
94  protected function setSubject($a_subject)
95  {
96  return $this->subject = $a_subject;
97  }
98 
103  protected function getSubject()
104  {
105  return $this->subject;
106  }
107 
113  protected function setBody($a_body)
114  {
115  $this->body = $a_body;
116  }
117 
123  protected function appendBody($a_body)
124  {
125  return $this->body .= $a_body;
126  }
127 
132  protected function getBody()
133  {
134  return $this->body;
135  }
136 
142  public function setRecipients($a_rcp)
143  {
144  $this->recipients = $a_rcp;
145  }
146 
151  public function getRecipients()
152  {
153  return $this->recipients;
154  }
155 
156  public function setAttachments($a_att)
157  {
158  $this->attachments = $a_att;
159  }
160 
161  public function getAttachments()
162  {
163  return (array) $this->attachments;
164  }
165 
170  protected function initLanguage($a_usr_id)
171  {
172  $this->language = ilLanguageFactory::_getLanguageOfUser($a_usr_id);
173  $this->language->loadLanguageModule('mail');
174  }
175 
180  protected function initLanguageByIso2Code($a_code = '')
181  {
182  $this->language = ilLanguageFactory::_getLanguage($a_code);
183  $this->language->loadLanguageModule('mail');
184  }
185 
190  protected function setLanguage($a_language)
191  {
192  $this->language = $a_language;
193  }
194 
199  protected function getLanguage()
200  {
201  return $this->language;
202  }
203 
209  protected function getLanguageText($a_keyword)
210  {
211  return str_replace('\n', "\n", $this->getLanguage()->txt($a_keyword));
212  }
213 
219  public function setRefId($a_id)
220  {
221  $this->ref_id = $a_id;
222  $this->obj_id = ilObject::_lookupObjId($this->ref_id);
223  $this->obj_type = ilObject::_lookupType($this->obj_id);
224  }
225 
230  public function getRefId()
231  {
232  return $this->ref_id;
233  }
234 
239  public function getObjId()
240  {
241  return $this->obj_id;
242  }
243 
248  public function setObjId($a_obj_id)
249  {
250  $this->obj_id = $a_obj_id;
251  }
252 
257  public function getObjType()
258  {
259  return $this->obj_type;
260  }
261 
267  public function setAdditionalInformation($a_info)
268  {
269  $this->additional_info = $a_info;
270  }
271 
276  public function getAdditionalInformation()
277  {
278  return (array) $this->additional_info;
279  }
280 
286  protected function getObjectTitle($a_shorten = false)
287  {
288  if(!$this->getObjId())
289  {
290  return '';
291  }
292  return ilUtil::shortenText(ilObject::_lookupTitle($this->getObjId()), self::SUBJECT_TITLE_LENGTH,true);
293  }
294 
295 
300  public function send()
301  {
302  switch($this->getType())
303  {
304 
305  }
306  }
307 
314  public function sendMail($a_rcp,$a_type,$a_parse_recipients = true)
315  {
316  $recipients = array();
317  foreach($a_rcp as $rcp)
318  {
319  if($a_parse_recipients)
320  {
322  }
323  else
324  {
325  $recipients[] = $rcp;
326  }
327  }
328  $recipients = implode(',',$recipients);
329  $error = $this->getMail()->sendMail(
330  $recipients,
331  '',
332  '',
333  $this->getSubject(),
334  $this->getBody(),
335  $this->getAttachments(),
336  $a_type
337  );
338 
339  if(strlen($error))
340  {
341  $GLOBALS['ilLog']->write(__METHOD__.': '.$error);
342  }
343  }
344 
349  protected function initMail()
350  {
351  return $this->mail = new ilMail($this->getSender());
352  }
353 
358  protected function getMail()
359  {
360  return is_object($this->mail) ? $this->mail : $this->initMail();
361  }
362 
367  protected function createPermanentLink($a_params = array(),$a_append = '')
368  {
369  include_once './Services/Link/classes/class.ilLink.php';
370 
371  if($this->getRefId())
372  {
373  return ilLink::_getLink($this->ref_id,$this->getObjType(),$a_params,$a_append);
374  }
375  else
376  {
377  // Return root
378  return ilLink::_getLink(ROOT_FOLDER_ID,'root');
379  }
380  }
381 
382 
388  protected function userToString($a_usr_id)
389  {
390  $name = ilObjUser::_lookupName($a_usr_id);
391  return ($name['title'] ? $name['title'].' ' : '').
392  ($name['firstname'] ? $name['firstname'].' ' : '').
393  ($name['lastname'] ? $name['lastname'].' ' : '');
394  }
395 }
396 ?>