ILIAS  Release_4_2_x_branch Revision 61807
 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 
17 {
19 
20  private $type = null;
21  private $sender = null;
22 
23  private $mail = null;
24  private $subject = '';
25  private $body = '';
26 
27  protected $language = null;
28 
29  private $recipients = array();
30 
31  private $ref_id = null;
32  private $obj_id = null;
33  private $obj_type = null;
34 
35  private $additional_info = array();
36 
41  public function __construct()
42  {
43  global $lng;
44 
45  $this->setSender(ANONYMOUS_USER_ID);
46  $this->language = ilLanguageFactory::_getLanguage($lng->getDefaultLanguage());
47  }
48 
54  public function setType($a_type)
55  {
56  $this->type = $a_type;
57  }
58 
63  public function getType()
64  {
65  return $this->type;
66  }
67 
73  public function setSender($a_usr_id)
74  {
75  $this->sender = $a_usr_id;
76  }
77 
82  public function getSender()
83  {
84  return $this->sender;
85  }
86 
92  protected function setSubject($a_subject)
93  {
94  return $this->subject = $a_subject;
95  }
96 
101  protected function getSubject()
102  {
103  return $this->subject;
104  }
105 
111  protected function setBody($a_body)
112  {
113  $this->body = $a_body;
114  }
115 
121  protected function appendBody($a_body)
122  {
123  return $this->body .= $a_body;
124  }
125 
130  protected function getBody()
131  {
132  return $this->body;
133  }
134 
140  public function setRecipients($a_rcp)
141  {
142  $this->recipients = $a_rcp;
143  }
144 
149  public function getRecipients()
150  {
151  return $this->recipients;
152  }
153 
158  protected function initLanguage($a_usr_id)
159  {
160  $this->language = ilLanguageFactory::_getLanguageOfUser($a_usr_id);
161  $this->language->loadLanguageModule('mail');
162  }
163 
168  protected function initLanguageByIso2Code($a_code = '')
169  {
170  $this->language = ilLanguageFactory::_getLanguage($a_code);
171  $this->language->loadLanguageModule('mail');
172  }
173 
178  protected function setLanguage($a_language)
179  {
180  $this->language = $a_language;
181  }
182 
187  protected function getLanguage()
188  {
189  return $this->language;
190  }
191 
197  protected function getLanguageText($a_keyword)
198  {
199  return str_replace('\n', "\n", $this->getLanguage()->txt($a_keyword));
200  }
201 
207  public function setRefId($a_id)
208  {
209  $this->ref_id = $a_id;
210  $this->obj_id = ilObject::_lookupObjId($this->ref_id);
211  $this->obj_type = ilObject::_lookupType($this->obj_id);
212  }
213 
218  public function getRefId()
219  {
220  return $this->ref_id;
221  }
222 
227  public function getObjId()
228  {
229  return $this->obj_id;
230  }
231 
236  public function setObjId($a_obj_id)
237  {
238  $this->obj_id = $a_obj_id;
239  }
240 
245  public function getObjType()
246  {
247  return $this->obj_type;
248  }
249 
255  public function setAdditionalInformation($a_info)
256  {
257  $this->additional_info = $a_info;
258  }
259 
264  public function getAdditionalInformation()
265  {
266  return (array) $this->additional_info;
267  }
268 
274  protected function getObjectTitle($a_shorten = false)
275  {
276  if(!$this->getObjId())
277  {
278  return '';
279  }
280  return ilUtil::shortenText(ilObject::_lookupTitle($this->getObjId()), self::SUBJECT_TITLE_LENGTH,true);
281  }
282 
283 
288  public function send()
289  {
290  switch($this->getType())
291  {
292 
293  }
294  }
295 
302  public function sendMail($a_rcp,$a_type,$a_parse_recipients = true)
303  {
304  $recipients = array();
305  foreach($a_rcp as $rcp)
306  {
307  if($a_parse_recipients)
308  {
310  }
311  else
312  {
313  $recipients[] = $rcp;
314  }
315  }
316  $recipients = implode(',',$recipients);
317  $error = $this->getMail()->sendMail(
318  $recipients,
319  '',
320  '',
321  $this->getSubject(),
322  $this->getBody(),
323  array(),
324  $a_type
325  );
326 
327  if(strlen($error))
328  {
329  $GLOBALS['ilLog']->write(__METHOD__.': '.$error);
330  }
331  }
332 
337  protected function initMail()
338  {
339  return $this->mail = new ilMail($this->getSender());
340  }
341 
346  protected function getMail()
347  {
348  return is_object($this->mail) ? $this->mail : $this->initMail();
349  }
350 
355  protected function createPermanentLink($a_params = array(),$a_append = '')
356  {
357  include_once './classes/class.ilLink.php';
358 
359  if($this->getRefId())
360  {
361  return ilLink::_getLink($this->ref_id,$this->getObjType(),$a_params,$a_append);
362  }
363  else
364  {
365  // Return root
366  return ilLink::_getLink(ROOT_FOLDER_ID,'root');
367  }
368  }
369 
370 
376  protected function userToString($a_usr_id)
377  {
378  $name = ilObjUser::_lookupName($a_usr_id);
379  return ($name['title'] ? $name['title'].' ' : '').
380  ($name['firstname'] ? $name['firstname'].' ' : '').
381  ($name['lastname'] ? $name['lastname'].' ' : '');
382  }
383 }
384 ?>