ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilNotificationConfig.php
Go to the documentation of this file.
1 <?php
2 
7 {
8  const TTL_LONG = 1800;
9  const TTL_SHORT = 120;
10 
11  const DEFAULT_TTS = 5;
12 
17  private $type;
18 
25  private $link;
26  private $linktarget = '_self';
27 
28  private $title;
29 
35  private $iconPath;
36 
39 
50  private $disableAfterDelivery = false;
56  private $validForSeconds = 0;
57 
62  protected $visibleForSeconds = 0;
63 
68  private $handlerParams = array();
69 
70  public function __construct($type)
71  {
72  $this->type = $type;
73  }
74 
75  public function getType()
76  {
77  return $this->type;
78  }
79 
80  public function setAutoDisable($value)
81  {
82  $this->disableAfterDelivery = $value;
83  }
84 
85  public function hasDisableAfterDeliverySet()
86  {
87  return (bool) $this->disableAfterDelivery;
88  }
89 
90  public function setLink($link)
91  {
92  $this->link = $link;
93  }
94 
95  public function getLink()
96  {
97  return $this->link;
98  }
99 
100  public function setIconPath($path)
101  {
102  $this->iconPath = $path;
103  }
104 
105  public function getIconPath()
106  {
107  return $this->iconPath;
108  }
109 
120  public function setTitleVar($name, $parameters = array(), $language_module = 'notification')
121  {
122  $this->title = new ilNotificationParameter($name, $parameters, $language_module);
123  }
124 
125  public function getTitleVar()
126  {
127  return $this->title->getName();
128  }
129 
142  public function setShortDescriptionVar($name, $parameters = array(), $language_module = 'notification')
143  {
144  $this->short_description = new ilNotificationParameter($name, $parameters, $language_module);
145  }
146 
147  public function getShortDescriptionVar()
148  {
149  return $this->short_description->getName();
150  }
151 
164  public function setLongDescriptionVar($name, $parameters = array(), $language_module = 'notification')
165  {
166  $this->long_description = new ilNotificationParameter($name, $parameters, $language_module);
167  }
168 
169  public function getLongDescriptionVar()
170  {
171  return $this->long_description->getName();
172  }
173 
174  public function getLanguageParameters()
175  {
176  return array(
177  'title' => $this->title,
178  'longDescription' => $this->long_description,
179  'shortDescription' => $this->short_description,
180  );
181  }
182 
183  public function getLinktarget()
184  {
185  return $this->linktarget;
186  }
187 
188  public function setLinktarget($linktarget)
189  {
190  $this->linktarget = $linktarget;
191  }
192 
193  public function setValidForSeconds($seconds)
194  {
195  $this->validForSeconds = $seconds;
196  }
197 
198  public function getValidForSeconds()
199  {
200  return $this->validForSeconds;
201  }
202 
206  public function getVisibleForSeconds()
207  {
209  }
210 
215  {
216  $this->visibleForSeconds = $visibleForSeconds;
217  }
218 
219  protected function beforeSendToUsers()
220  {
221  }
222 
223  protected function afterSendToUsers()
224  {
225  }
226 
227  protected function beforeSendToListeners()
228  {
229  }
230 
231  protected function afterSendToListeners()
232  {
233  }
234 
239  final public function notifyByUsers(array $recipients, $processAsync = false)
240  {
241  require_once 'Services/Notifications/classes/class.ilNotificationSystem.php';
242  $this->beforeSendToUsers();
243  ilNotificationSystem::sendNotificationToUsers($this, $recipients, $processAsync);
244  $this->afterSendToUsers();
245  }
246 
247  final public function notifyByListeners($ref_id, $processAsync = false)
248  {
249  require_once 'Services/Notifications/classes/class.ilNotificationSystem.php';
250  $this->beforeSendToListeners();
251  ilNotificationSystem::sendNotificationToListeners($this, $ref_id, $processAsync);
252  $this->afterSendToListeners();
253  }
254 
255  final public function notifyByRoles(array $roles, $processAsync = false)
256  {
257  require_once 'Services/Notifications/classes/class.ilNotificationSystem.php';
258  //$this->beforeSendToListeners();
259  ilNotificationSystem::sendNotificationToRoles($this, $roles, $processAsync);
260  //$this->afterSendToListeners();
261  }
262 
263  public function getUserInstance(ilObjUser $user, $languageVars, $defaultLanguage)
264  {
265  $notificationObject = new ilNotificationObject($this, $user);
266 
267  $title = '';
268  $short = '';
269  $long = '';
270 
271  if ($languageVars[$this->title->getName()]->lang[$user->getLanguage()]) {
272  $title = $languageVars[$this->title->getName()]->lang[$user->getLanguage()];
273  } elseif ($languageVars[$this->title->getName()]->lang[$defaultLanguage]) {
274  $title = $languageVars[$this->title->getName()]->lang[$defaultLanguage];
275  } else {
276  $title = $this->title->getName();
277  }
278 
279  if ($languageVars[$this->short_description->getName()]->lang[$user->getLanguage()]) {
280  $short = $languageVars[$this->short_description->getName()]->lang[$user->getLanguage()];
281  } elseif ($languageVars[$this->short_description->getName()]->lang[$defaultLanguage]) {
282  $short = $languageVars[$this->short_description->getName()]->lang[$defaultLanguage];
283  } else {
284  $short = $this->short_description->getName();
285  }
286 
287  if ($languageVars[$this->long_description->getName()]->lang[$user->getLanguage()]) {
288  $long = $languageVars[$this->long_description->getName()]->lang[$user->getLanguage()];
289  } elseif ($languageVars[$this->long_description->getName()]->lang[$defaultLanguage]) {
290  $long = $languageVars[$this->long_description->getName()]->lang[$defaultLanguage];
291  } else {
292  $long = $this->long_description->getName();
293  }
294 
295  $notificationObject->title = $title;
296  $notificationObject->shortDescription = $short;
297  $notificationObject->longDescription = $long;
298 
299  $notificationObject->iconPath = $this->iconPath;
300 
301  return $notificationObject;
302  }
303 
304  public function setHandlerParam($name, $value)
305  {
306  if (strpos($name, '.')) {
307  $nsParts = explode('.', $name, 2);
308  $ns = $nsParts[0];
309  $field = $nsParts[1];
310  $this->handlerParams[$ns][$field] = $value;
311  } else {
312  $this->handlerParams[''][$name] = $value;
313  }
314  }
315 
316  public function getHandlerParams()
317  {
318  return $this->handlerParams;
319  }
320 
321  public function unsetHandlerParam($name)
322  {
323  unset($this->handlerParams[$name]);
324  }
325 }
326 
333 {
334 
339 
343  public $user;
344 
345  public $title;
348  public $link;
349  public $linktarget;
350  public $iconPath;
352 
353  public function __construct(ilNotificationConfig $baseNotification, ilObjUser $user)
354  {
355  $this->baseNotification = $baseNotification;
356  $this->user = $user;
357 
358  $this->link = $this->baseNotification->getLink();
359  $this->linktarget = $this->baseNotification->getLinktarget();
360  $this->handlerParams = $this->baseNotification->getHandlerParams();
361  }
362 
363  public function __sleep()
364  {
365  return array('title', 'shortDescription', 'longDescription', 'iconPath', 'link', 'linktarget', 'handlerParams');
366  }
367 }
368 
374 {
375  private $name;
376  private $parameters = array();
377  private $language_module = array();
378 
379  public function __construct($name, $parameters = array(), $language_module = 'notification')
380  {
381  $this->name = $name;
382  $this->parameters = $parameters;
383  $this->language_module = $language_module;
384  }
385 
386  public function getName()
387  {
388  return $this->name;
389  }
390 
391  public function getParameters()
392  {
393  return $this->parameters;
394  }
395 
396  public function getLanguageModule()
397  {
398  return $this->language_module;
399  }
400 }
setShortDescriptionVar($name, $parameters=array(), $language_module='notification')
Sets the name of the language variable to use as short description text.
setTitleVar($name, $parameters=array(), $language_module='notification')
Sets the name of the language variable to use as title.
A concrete notification based on the ilNotificationConfiguration and returned by ilNotificationConfig...
description of a localized parameter this information is used locate translations while processing no...
static sendNotificationToUsers(ilNotificationConfig $notification, $users, $processAsync=false)
user()
Definition: user.php:4
__construct($name, $parameters=array(), $language_module='notification')
Describes a notification and provides methods for publishing this notification.
notifyByUsers(array $recipients, $processAsync=false)
sends this notification to a list of users
if($format !==null) $name
Definition: metadata.php:146
Create styles array
The data for the language used.
notifyByRoles(array $roles, $processAsync=false)
notifyByListeners($ref_id, $processAsync=false)
__construct(ilNotificationConfig $baseNotification, ilObjUser $user)
setVisibleForSeconds($visibleForSeconds)
static sendNotificationToRoles(ilNotificationConfig $notification, array $roles, $processAsync=false)
static sendNotificationToListeners(ilNotificationConfig $notification, $ref_id, $processAsync=false)
getUserInstance(ilObjUser $user, $languageVars, $defaultLanguage)
getLanguage()
returns a 2char-language-string public
setLongDescriptionVar($name, $parameters=array(), $language_module='notification')
Sets the name of the language variable to use as long description text.