ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSystemNotification.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Mail/classes/class.ilMailNotification.php';
5 
17 {
18  protected $subject_lang_id; // [string]
19  protected $introduction; // [string]
20  protected $introduction_direct; // [string]
21  protected $task; // [string]
22  protected $reason; // [string]
23  protected $additional; // [array]
24  protected $goto_caption; // [string]
25  protected $changed_by; // [int]
26  protected $all_ref_ids; // [array]
27 
33  public function setSubjectLangId($a_lang_id)
34  {
35  $this->subject_lang_id = (string)$a_lang_id;
36  }
37 
43  public function setIntroductionLangId($a_lang_id)
44  {
45  $this->introduction = (string)$a_lang_id;
46  }
47 
53  public function setIntroductionDirect($a_text)
54  {
55  $this->introduction_direct = trim($a_text);
56  }
57 
63  public function setTaskLangId($a_lang_id)
64  {
65  $this->task = (string)$a_lang_id;
66  }
67 
73  public function setReasonLangId($a_lang_id)
74  {
75  $this->reason = (string)$a_lang_id;
76  }
77 
83  public function setGotoLangId($a_lang_id)
84  {
85  $this->goto_caption = (string)$a_lang_id;
86  }
87 
93  public function setChangedByUserId($a_id)
94  {
95  $this->changed_by = (int)$a_id;
96 
97  include_once "Services/User/classes/class.ilUserUtil.php";
98  }
99 
107  public function addAdditionalInfo($a_lang_id, $a_value, $a_multiline = false)
108  {
109  $this->additional[$a_lang_id] = array(trim($a_value), (bool)$a_multiline);
110  }
111 
120  public function sendMail(array $a_user_ids, $a_goto_additional = null, $a_permission = "read")
121  {
122  $this->all_ref_ids = null;
123 
124  // prepare object related info
125  if($this->getObjId())
126  {
127  if(!$this->getRefId())
128  {
129  // try to find ref_id(s)
130  if(!$this->is_in_wsp)
131  {
132  $ref_ids = ilObject::_getAllReferences($this->getObjId());
133  if(sizeof($ref_ids) == 1)
134  {
135  $this->ref_id = array_shift($ref_ids);
136  }
137  else
138  {
139  $this->all_ref_ids = $ref_ids;
140  }
141  }
142  }
143  else if($this->is_in_wsp) // #11680
144  {
145  $this->ref_id = $this->wsp_tree->lookupNodeId($this->getObjId());
146  }
147 
148  // default values
149  if(!$this->goto_caption)
150  {
151  $this->goto_caption = "url";
152  }
153  }
154 
155  $recipient_ids = array();
156  foreach(array_unique($a_user_ids) as $user_id)
157  {
158  // author of change should not get notification
159  if($this->changed_by == $user_id)
160  {
161  continue;
162  }
163 
164  if($this->composeAndSendMail($user_id, $a_goto_additional, $a_permission))
165  {
166  $recipient_ids[] = $user_id;
167  }
168  }
169 
170  return $recipient_ids;
171  }
172 
182  public function compose($a_user_id, $a_goto_additional = null, $a_permission = "read", $a_append_signature_direct = false)
183  {
184  $this->initLanguage($a_user_id);
185  $this->initMail();
186 
187  $this->setSubject(
188  sprintf($this->getLanguageText($this->subject_lang_id), $this->getObjectTitle(true))
189  );
190 
191  $this->setBody(ilMail::getSalutation($a_user_id, $this->getLanguage()));
192  $this->appendBody("\n\n");
193 
194  if($this->introduction)
195  {
196  $this->appendBody($this->getLanguageText($this->introduction));
197  $this->appendBody("\n\n");
198  }
199 
200  if($this->introduction_direct)
201  {
202  $this->appendBody($this->introduction_direct);
203  $this->appendBody("\n\n");
204  }
205 
206  if($this->task)
207  {
208  $this->appendBody($this->getLanguageText($this->task));
209  $this->appendBody("\n\n");
210  }
211 
212  // details table
213  if($this->getObjId())
214  {
215  $this->appendBody($this->getLanguageText("obj_".$this->getObjType()).": ".
216  $this->getObjectTitle()."\n");
217  }
218  if(sizeof($this->additional))
219  {
220  foreach($this->additional as $lang_id => $item)
221  {
222  if(!$item[1])
223  {
224  $this->appendBody($this->getLanguageText($lang_id).": ".
225  $item[0]."\n");
226  }
227  else
228  {
229  $this->appendBody("\n".$this->getLanguageText($lang_id)."\n".
230  $this->getBlockBorder().
231  $item[0]."\n".
232  $this->getBlockBorder()."\n");
233  }
234  }
235  }
236  $this->body = trim($this->body);
237  $this->appendBody("\n\n");
238 
239  if($this->changed_by)
240  {
241  $this->appendBody($this->getLanguageText("system_notification_installation_changed_by").": ".
242  ilUserUtil::getNamePresentation($this->changed_by));
243  $this->appendBody("\n\n");
244  }
245 
246  if($this->getObjId())
247  {
248  // try to find accessible ref_id
249  if(!$this->getRefId() && $this->all_ref_ids)
250  {
251  $find_ref_id = true;
252  foreach($this->all_ref_ids as $ref_id)
253  {
254  if($this->isRefIdAccessible($a_user_id, $ref_id, $a_permission))
255  {
256  $this->ref_id = $ref_id;
257  break;
258  }
259  }
260  }
261 
262  // check if initially given ref_id is accessible for current recipient
263  if($this->getRefId() &&
264  !$find_ref_id &&
265  !$this->isRefIdAccessible($a_user_id, $this->getRefId(), $a_permission))
266  {
267  return false;
268  }
269 
270  $goto = $this->createPermanentLink(array(), $a_goto_additional);
271  if($goto)
272  {
273  $this->appendBody($this->getLanguageText($this->goto_caption).": ".
274  $goto);
275  $this->appendBody("\n\n");
276  }
277 
278  if($find_ref_id)
279  {
280  $this->ref_id = null;
281  }
282  }
283 
284  if($this->reason)
285  {
286  $this->appendBody($this->getLanguageText($this->reason));
287  $this->appendBody("\n\n");
288  }
289 
290  $this->appendBody(ilMail::_getAutoGeneratedMessageString($this->language));
291 
292  // signature will append new lines
293  $this->body = trim($this->body);
294 
295  if(!$a_append_signature_direct)
296  {
297  $this->getMail()->appendInstallationSignature(true);
298  }
299  else
300  {
302  }
303 
304  return true;
305  }
306 
315  protected function composeAndSendMail($a_user_id, $a_goto_additional = null, $a_permission = "read")
316  {
317  if($this->compose($a_user_id, $a_goto_additional, $a_permission))
318  {
319  parent::sendMail(array($a_user_id), array('system'), is_numeric($a_user_id));
320  return true;
321  }
322  return false;
323  }
324 
334  public function composeAndGetMessage($a_user_id, $a_goto_additional = null, $a_permission = "read", $a_append_signature_direct = false)
335  {
336  if($this->compose($a_user_id, $a_goto_additional, $a_permission, $a_append_signature_direct))
337  {
338  return $this->body;
339  }
340  }
341 }
342 
343 ?>