Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
NotificationManager.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  * Component for handling all Notifications in system.
11  * If need to notify all Notificators about event invoked method Yii::app()->notificationManager->notifyAbout($notification);
12  */
13 class NotificationManager extends CApplicationComponent
14 {
15 
16  public $cacheTime;
17 
18  /**
19  * @var array notificators array
20  */
21  private $_notificators = array();
22 
23  /**
24  * Public setter
25  *
26  * @param array $config configuration array
27  *
28  * @return void
29  */
30  public function setNotificators($config)
31  {
32  foreach ($config as $name => $notificator) {
33  $this->_notificators[$name] = $notificator;
34  }
35  }
36 
37  /**
38  * Public getter
39  *
40  * @return array
41  */
42  public function getNotificators()
43  {
44  return $this->_notificators;
45  }
46 
47  /**
48  * Add notificator
49  *
50  * @param string $name notificator name, if exists will be replaced
51  * @param array|object $notificatorConfig notificator config array or object
52  *
53  * @return void
54  */
55  public function addNotificator($name, $notificatorConfig)
56  {
57  if (is_array($notificatorConfig)) {
58  $notificatorConfig = Yii::createComponent($notificatorConfig);
59  $notificatorConfig->init();
60  $this->_notificators[$name] = $notificatorConfig;
61  } elseif ($notificatorConfig instanceof CComponent) {
62  $this->_notificators[$name] = $notificatorConfig;
63  }
64  }
65 
66  /**
67  * Remove notificator
68  *
69  * @param string $name notificator name
70  *
71  * @return void
72  */
73  public function removeNotificator($name)
74  {
75  unset($this->_notificators[$name]);
76  }
77 
78  /**
79  * Init manager
80  *
81  * @return void
82  */
83  public function init()
84  {
85  foreach ($this->_notificators as $name => $notificator) {
86  $this->addNotificator($name, $notificator);
87  }
88  parent::init();
89  }
90 
91  /**
92  * Method which starts handle $notification by all notificators
93  *
94  * @param Notification $notification occurred notification
95  *
96  * @return void
97  */
98  public function notifyAbout(Notification $notification)
99  {
100  foreach ($this->_notificators as $notificator) {
101  $notificator->notify($notification);
102  }
103  }
104 
105 }