ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilNotificationConfig.php
Go to the documentation of this file.
1 <?php
2 
12  private $type;
13 
21  private $link;
22  private $linktarget = '_self';
23 
24  private $title;
25 
32  private $iconPath;
33 
36 
49  private $disableAfterDelivery = false;
56  private $validForSeconds = 0;
57 
63  private $handlerParams = array();
64 
65  public function __construct($type) {
66  $this->type = $type;
67  }
68 
69  public function getType() {
70  return $this->type;
71  }
72 
73  public function setAutoDisable($value) {
74  $this->disableAfterDelivery = $value;
75  }
76 
77  public function hasDisableAfterDeliverySet() {
78  return (bool) $this->disableAfterDelivery;
79  }
80 
81  public function setLink($link) {
82  $this->link = $link;
83  }
84 
85  public function getLink() {
86  return $this->link;
87  }
88 
89  public function setIconPath($path) {
90  $this->iconPath = $path;
91  }
92 
93  public function getIconPath() {
94  return $this->iconPath;
95  }
96 
109  public function setTitleVar($name, $parameters = array(), $language_module = 'notification') {
110  $this->title = new ilNotificationParameter($name, $parameters, $language_module);
111  }
112 
113  public function getTitleVar() {
114  return $this->title->getName();
115  }
116 
132  public function setShortDescriptionVar($name, $parameters = array(), $language_module = 'notification') {
133  $this->short_description = new ilNotificationParameter($name, $parameters, $language_module);
134  }
135 
136  public function getShortDescriptionVar() {
137  return $this->short_description->getName();
138  }
139 
155  public function setLongDescriptionVar($name, $parameters = array(), $language_module = 'notification') {
156  $this->long_description = new ilNotificationParameter($name, $parameters, $language_module);
157  }
158 
159  public function getLongDescriptionVar() {
160  return $this->long_description->getName();
161  }
162 
163  public function getLanguageParameters() {
164  return array(
165  'title' => $this->title,
166  'longDescription' => $this->long_description,
167  'shortDescription' => $this->short_description,
168  );
169  }
170 
171  public function getLinktarget() {
172  return $this->linktarget;
173  }
174 
175  public function setLinktarget($linktarget) {
176  $this->linktarget = $linktarget;
177  }
178 
179  public function setValidForSeconds($seconds) {
180  $this->validForSeconds = $seconds;
181  }
182 
183  public function getValidForSeconds() {
184  return $this->validForSeconds;
185  }
186 
187  protected function beforeSendToUsers(){
188 
189  }
190 
191  protected function afterSendToUsers(){
192 
193  }
194 
195  protected function beforeSendToListeners(){
196 
197  }
198 
199  protected function afterSendToListeners(){
200 
201  }
202 
208  final public function notifyByUsers(array $recipients, $processAsync = false) {
209  require_once 'Services/Notifications/classes/class.ilNotificationSystem.php';
210  $this->beforeSendToUsers();
211  ilNotificationSystem::sendNotificationToUsers($this, $recipients, $processAsync);
212  $this->afterSendToUsers();
213  }
214 
215 
216  final public function notifyByListeners($ref_id, $processAsync = false) {
217  require_once 'Services/Notifications/classes/class.ilNotificationSystem.php';
218  $this->beforeSendToListeners();
220  $this->afterSendToListeners();
221  }
222 
223  final public function notifyByRoles(array $roles, $processAsync = false) {
224  require_once 'Services/Notifications/classes/class.ilNotificationSystem.php';
225  //$this->beforeSendToListeners();
226  ilNotificationSystem::sendNotificationToRoles($this, $roles, $processAsync);
227  //$this->afterSendToListeners();
228  }
229 
230  public function getUserInstance(ilObjUser $user, $languageVars, $defaultLanguage) {
231  $notificationObject = new ilNotificationObject($this, $user);
232 
233  $title = '';
234  $short = '';
235  $long = '';
236 
237  if ($languageVars[$this->title->getName()]->lang[$user->getLanguage()]) {
238  $title = $languageVars[$this->title->getName()]->lang[$user->getLanguage()];
239  }
240  else if ($languageVars[$this->title->getName()]->lang[$defaultLanguage]) {
241  $title = $languageVars[$this->title->getName()]->lang[$defaultLanguage];
242  }
243  else {
244  $title = $this->title->getName();
245  }
246 
247  if ($languageVars[$this->short_description->getName()]->lang[$user->getLanguage()]) {
248  $short = $languageVars[$this->short_description->getName()]->lang[$user->getLanguage()];
249  }
250  else if ($languageVars[$this->short_description->getName()]->lang[$defaultLanguage]) {
251  $short = $languageVars[$this->short_description->getName()]->lang[$defaultLanguage];
252  }
253  else {
254  $short = $this->short_description->getName();
255  }
256 
257  if ($languageVars[$this->long_description->getName()]->lang[$user->getLanguage()]) {
258  $long = $languageVars[$this->long_description->getName()]->lang[$user->getLanguage()];
259  }
260  else if ($languageVars[$this->long_description->getName()]->lang[$defaultLanguage]) {
261  $long = $languageVars[$this->long_description->getName()]->lang[$defaultLanguage];
262  }
263  else {
264  $long = $this->long_description->getName();
265  }
266 
267  $notificationObject->title = $title;
268  $notificationObject->shortDescription = $short;
269  $notificationObject->longDescription = $long;
270 
271  $notificationObject->iconPath = $this->iconPath;
272 
273  return $notificationObject;
274  }
275 
276  public function setHandlerParam($name, $value) {
277  if (strpos($name, '.')) {
278  $nsParts = explode('.', $name, 2);
279  $ns = $nsParts[0];
280  $field = $nsParts[1];
281  $this->handlerParams[$ns][$field] = $value;
282  }
283  else {
284  $this->handlerParams[''][$name] = $value;
285  }
286  }
287 
288  public function getHandlerParams() {
289  return $this->handlerParams;
290  }
291 
292  public function unsetHandlerParam($name) {
293  unset($this->handlerParams[$name]);
294  }
295 }
296 
304 
310 
314  public $user;
315 
316  public $title;
319  public $link;
320  public $linktarget;
321  public $iconPath;
323 
325 
326  $this->baseNotification = $baseNotification;
327  $this->user = $user;
328 
329  $this->link = $this->baseNotification->getLink();
330  $this->linktarget = $this->baseNotification->getLinktarget();
331  $this->handlerParams = $this->baseNotification->getHandlerParams();
332  }
333 
334  public function __sleep() {
335  return array('title', 'shortDescription', 'longDescription', 'iconPath', 'link', 'linktarget', 'handlerParams');
336  }
337 
338 }
339 
346 
347  private $name;
348  private $parameters = array();
349  private $language_module = array();
350 
351  public function __construct($name, $parameters = array(), $language_module = 'notification') {
352  $this->name = $name;
353  $this->parameters = $parameters;
354  $this->language_module = $language_module;
355  }
356 
357  public function getName() {
358  return $this->name;
359  }
360 
361  public function getParameters() {
362  return $this->parameters;
363  }
364 
365  public function getLanguageModule() {
366  return $this->language_module;
367  }
368 }