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