ILIAS  Release_4_1_x_branch Revision 61804
 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 $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 
159  protected function initLanguage($a_usr_id)
160  {
161  $this->language = ilLanguageFactory::_getLanguageOfUser($a_usr_id);
162  $this->language->loadLanguageModule('mail');
163  }
164 
170  protected function setLanguage($a_language)
171  {
172  $this->language = $a_language;
173  }
174 
179  protected function getLanguage()
180  {
181  return $this->language;
182  }
183 
189  protected function getLanguageText($a_keyword)
190  {
191  return str_replace('\n', "\n", $this->getLanguage()->txt($a_keyword));
192  }
193 
199  public function setRefId($a_id)
200  {
201  $this->ref_id = $a_id;
202  $this->obj_id = ilObject::_lookupObjId($this->ref_id);
203  $this->obj_type = ilObject::_lookupType($this->obj_id);
204  }
205 
210  public function getRefId()
211  {
212  return $this->ref_id;
213  }
214 
219  public function getObjId()
220  {
221  return $this->obj_id;
222  }
223 
228  public function setObjId($a_obj_id)
229  {
230  $this->obj_id = $a_obj_id;
231  }
232 
237  public function getObjType()
238  {
239  return $this->obj_type;
240  }
241 
247  public function setAdditionalInformation($a_info)
248  {
249  $this->additional_info = $a_info;
250  }
251 
256  public function getAdditionalInformation()
257  {
258  return (array) $this->additional_info;
259  }
260 
266  protected function getObjectTitle($a_shorten = false)
267  {
268  if(!$this->getObjId())
269  {
270  return '';
271  }
272  return ilUtil::shortenText(ilObject::_lookupTitle($this->getObjId()), self::SUBJECT_TITLE_LENGTH,true);
273  }
274 
275 
280  public function send()
281  {
282  switch($this->getType())
283  {
284 
285  }
286  }
287 
294  public function sendMail($a_rcp,$a_type,$a_parse_recipients = true)
295  {
296  $recipients = array();
297  foreach($a_rcp as $rcp)
298  {
299  if($a_parse_recipients)
300  {
302  }
303  else
304  {
305  $recipients[] = $rcp;
306  }
307  }
308  $recipients = implode(',',$recipients);
309  $error = $this->getMail()->sendMail(
310  $recipients,
311  '',
312  '',
313  $this->getSubject(),
314  $this->getBody(),
315  array(),
316  $a_type
317  );
318 
319  if(strlen($error))
320  {
321  $GLOBALS['ilLog']->write(__METHOD__.': '.$error);
322  }
323  }
324 
329  protected function initMail()
330  {
331  return $this->mail = new ilMail($this->getSender());
332  }
333 
338  protected function getMail()
339  {
340  return is_object($this->mail) ? $this->mail : $this->initMail();
341  }
342 
347  protected function createPermanentLink($a_params = array(),$a_append = '')
348  {
349  include_once './classes/class.ilLink.php';
350 
351  if($this->getRefId())
352  {
353  return ilLink::_getLink($this->ref_id,$this->getObjType(),$a_params,$a_append);
354  }
355  else
356  {
357  // Return root
358  return ilLink::_getLink(ROOT_FOLDER_ID,'root');
359  }
360  }
361 
362 
368  protected function userToString($a_usr_id)
369  {
370  $name = ilObjUser::_lookupName($a_usr_id);
371  return ($name['title'] ? $name['title'].' ' : '').
372  ($name['firstname'] ? $name['firstname'].' ' : '').
373  ($name['lastname'] ? $name['lastname'].' ' : '');
374  }
375 }
376 ?>