ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilNotificationGUI.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 require_once './Services/Object/classes/class.ilObjectGUI.php';
5 require_once 'Services/Notifications/classes/class.ilNotificationConfig.php';
6 require_once 'Services/Notifications/classes/class.ilNotificationHandler.php';
7 
16 {
17 
18  private $handler = array();
19 
24  function __construct()
25  {
26  $this->type = "not";
27 
28  require_once 'Services/Notifications/classes/class.ilNotificationSetupHelper.php';
29  }
30 
31  function _forwards()
32  {
33  return array();
34  }
35 
36  function executeCommand()
37  {
38  global $ilCtrl;
39 
40  if(!$ilCtrl->getCmd())
41  return;
42 
43  $cmd = $ilCtrl->getCmd() . 'Object';
44  $this->$cmd();
45 
46  }
47 
48  public function getHandler($type)
49  {
50  return $this->handler[$type];
51  }
52 
53  private function getAvailableTypes($types = array())
54  {
56  }
57 
58  private function getAvailableChannels($types = array())
59  {
61  }
62 
70  public function getOSDNotificationsObject()
71  {
72  global $ilUser;
73 
74  if($ilUser->getId() == ANONYMOUS_USER_ID)
75  {
76  return '{}';
77  }
78 
79  require_once 'Services/Notifications/classes/class.ilNotificationEchoHandler.php';
80  require_once 'Services/Notifications/classes/class.ilNotificationOSDHandler.php';
81 
82  $notifications = ilNotificationOSDHandler::getNotificationsForUser($ilUser->getId(), true, (int)$_REQUEST['max_age']);
83  $result = new stdClass();
84  $result->notifications = $notifications;
85  $result->server_time = time();
86  echo json_encode($result);
87  exit;
88  }
89 
90  public function removeOSDNotificationsObject()
91  {
92  global $ilUser;
93 
94  require_once 'Services/Notifications/classes/class.ilNotificationEchoHandler.php';
95  require_once 'Services/Notifications/classes/class.ilNotificationOSDHandler.php';
96 
98 
99  exit;
100  }
101 
102  public function addHandler($channel, ilNotificationHandler $handler)
103  {
104  if(!array_key_exists($channel, $this->handler) || !is_array($this->handler[$channel]))
105  $this->handler[$channel] = array();
106 
107  $this->handler[$channel][] = $handler;
108  }
109 
110  private function saveCustomizingOptionObject()
111  {
112  global $ilUser;
113 
114  if($_POST['enable_custom_notification_configuration'])
115  {
116  $ilUser->writePref('use_custom_notification_setting', 1);
117  }
118  else
119  {
120  $ilUser->writePref('use_custom_notification_setting', 0);
121  }
122 
123  $this->showSettingsObject();
124  }
125 
126  public function showSettingsObject()
127  {
128  global $tpl, $ilCtrl, $ilUser, $lng;
129 
130  require_once 'Services/Notifications/classes/class.ilNotificationSettingsTable.php';
131  require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
132 
133  $userTypes = ilNotificationDatabaseHandler::loadUserConfig($ilUser->getId());
134 
135  $lng->loadLanguageModule('notification');
136 
137  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
138  $form = new ilPropertyFormGUI();
139  $chk = new ilCheckboxInputGUI($lng->txt('enable_custom_notification_configuration'), 'enable_custom_notification_configuration');
140  $chk->setValue('1');
141  $chk->setChecked($ilUser->getPref('use_custom_notification_setting') == 1);
142  $form->addItem($chk);
143 
144  $form->setFormAction($ilCtrl->getFormAction($this, 'showSettingsObject'));
145  $form->addCommandButton('saveCustomizingOption', $lng->txt('save'));
146  $form->addCommandButton('showSettings', $lng->txt('cancel'));
147 
148  $table = new ilNotificationSettingsTable($this, 'a title', $this->getAvailableChannels(array('set_by_user')), $userTypes);
149 
150  $table->setFormAction($ilCtrl->getFormAction($this, 'saveSettings'));
151  $table->setData($this->getAvailableTypes(array('set_by_user')));
152 
153  if($ilUser->getPref('use_custom_notification_setting') == 1)
154  {
155  $table->addCommandButton('saveSettings', $lng->txt('save'));
156  $table->addCommandButton('showSettings', $lng->txt('cancel'));
157  $table->setEditable(true);
158  }
159  else
160  {
161  $table->setEditable(false);
162  }
163 
164  $tpl->setContent($form->getHtml() . $table->getHTML());
165  }
166 
167  private function saveSettingsObject()
168  {
169  global $ilUser, $ilCtrl;
170  require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
171 
172  ilNotificationDatabaseHandler::setUserConfig($ilUser->getId(), $_REQUEST['notification'] ? $_REQUEST['notification'] : array());
173  $this->showSettingsObject();
174  }
175 
176  function addLocatorItems()
177  {
178  global $ilLocator, $ilCtrl;
179 
180  if(is_object($this->object))
181  {
182  $ilLocator->addItem($this->object->getTitle(), $ilCtrl->getLinkTarget($this, ''), '', $_GET["ref_id"]);
183  }
184  }
185 }