ILIAS  Release_4_0_x_branch Revision 61816
 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  $this->setSender(ANONYMOUS_USER_ID);
44  $this->language = ilLanguageFactory::_getLanguage('en');
45  }
46 
52  public function setType($a_type)
53  {
54  $this->type = $a_type;
55  }
56 
61  public function getType()
62  {
63  return $this->type;
64  }
65 
71  public function setSender($a_usr_id)
72  {
73  $this->sender = $a_usr_id;
74  }
75 
80  public function getSender()
81  {
82  return $this->sender;
83  }
84 
90  protected function setSubject($a_subject)
91  {
92  return $this->subject = $a_subject;
93  }
94 
99  protected function getSubject()
100  {
101  return $this->subject;
102  }
103 
109  protected function setBody($a_body)
110  {
111  $this->body = $a_body;
112  }
113 
119  protected function appendBody($a_body)
120  {
121  return $this->body .= $a_body;
122  }
123 
128  protected function getBody()
129  {
130  return $this->body;
131  }
132 
138  public function setRecipients($a_rcp)
139  {
140  $this->recipients = $a_rcp;
141  }
142 
147  public function getRecipients()
148  {
149  return $this->recipients;
150  }
151 
157  protected function initLanguage($a_usr_id)
158  {
159  $this->language = ilLanguageFactory::_getLanguageOfUser($a_usr_id);
160  $this->language->loadLanguageModule('mail');
161  }
162 
167  protected function getLanguage()
168  {
169  return $this->language;
170  }
171 
177  protected function getLanguageText($a_keyword)
178  {
179  return str_replace('\n', "\n", $this->getLanguage()->txt($a_keyword));
180  }
181 
187  public function setRefId($a_id)
188  {
189  $this->ref_id = $a_id;
190  $this->obj_id = ilObject::_lookupObjId($this->ref_id);
191  $this->obj_type = ilObject::_lookupType($this->obj_id);
192  }
193 
198  public function getRefId()
199  {
200  return $this->ref_id;
201  }
202 
207  public function getObjId()
208  {
209  return $this->obj_id;
210  }
211 
216  public function getObjType()
217  {
218  return $this->obj_type;
219  }
220 
226  public function setAdditionalInformation($a_info)
227  {
228  $this->additional_info = $a_info;
229  }
230 
235  public function getAdditionalInformation()
236  {
237  return (array) $this->additional_info;
238  }
239 
245  protected function getObjectTitle($a_shorten = false)
246  {
247  if(!$this->getObjId())
248  {
249  return '';
250  }
251  return ilUtil::shortenText(ilObject::_lookupTitle($this->getObjId()), self::SUBJECT_TITLE_LENGTH,true);
252  }
253 
254 
259  public function send()
260  {
261  switch($this->getType())
262  {
263 
264  }
265  }
266 
273  public function sendMail($a_rcp,$a_type)
274  {
275  $recipients = array();
276  foreach($a_rcp as $rcp)
277  {
279  }
280  $recipients = implode(',',$recipients);
281  $error = $this->getMail()->sendMail(
282  $recipients,
283  '',
284  '',
285  $this->getSubject(),
286  $this->getBody(),
287  array(),
288  $a_type
289  );
290 
291  if(strlen($error))
292  {
293  $GLOBALS['ilLog']->write(__METHOD__.': '.$error);
294  }
295  }
296 
301  protected function initMail()
302  {
303  return $this->mail = new ilMail($this->getSender());
304  }
305 
310  protected function getMail()
311  {
312  return is_object($this->mail) ? $this->mail : $this->initMail();
313  }
314 
319  protected function createPermanentLink()
320  {
321  include_once './classes/class.ilLink.php';
322 
323  if($this->getRefId())
324  {
325  return ilLink::_getLink($this->ref_id,$this->getObjType());
326  }
327  else
328  {
329  // Return root
330  return ilLink::_getLink(ROOT_FOLDER_ID,'root');
331  }
332  }
333 
339  protected function userToString($a_usr_id)
340  {
341  $name = ilObjUser::_lookupName($a_usr_id);
342  return ($name['title'] ? $name['title'].' ' : '').
343  ($name['firstname'] ? $name['firstname'].' ' : '').
344  ($name['lastname'] ? $name['lastname'].' ' : '');
345  }
346 }
347 ?>