ILIAS  Release_4_2_x_branch Revision 61807
 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 '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 
59  public function getOSDNotificationsObject() {
60  global $ilUser;
61 
62  if ($ilUser->getId() == ANONYMOUS_USER_ID) {
63  return '{}';
64  }
65 
66  $GLOBALS['WEB_ACCESS_WITHOUT_SESSION'] = true;
67 
68  require_once 'Services/Notifications/classes/class.ilNotificationEchoHandler.php';
69  require_once 'Services/Notifications/classes/class.ilNotificationOSDHandler.php';
70 
71  $notifications = ilNotificationOSDHandler::getNotificationsForUser($ilUser->getId(), true, (int)$_REQUEST['max_age']);
72  $result = new stdClass();
73  $result->notifications = $notifications;
74  $result->server_time = time();
75  echo json_encode($result);
76  exit;
77  }
78 
79  public function removeOSDNotificationsObject() {
80  global $ilUser;
81 
82  $GLOBALS['WEB_ACCESS_WITHOUT_SESSION'] = true;
83 
84  require_once 'Services/Notifications/classes/class.ilNotificationEchoHandler.php';
85  require_once 'Services/Notifications/classes/class.ilNotificationOSDHandler.php';
86 
88 
89  exit;
90  }
91 
92  public function addHandler($channel, ilNotificationHandler $handler) {
93  if (!array_key_exists($channel, $this->handler) || !is_array($this->handler[$channel]))
94  $this->handler[$channel] = array();
95 
96  $this->handler[$channel][] = $handler;
97  }
98 
99  private function saveCustomizingOptionObject() {
100  global $ilUser;
101 
102  if ($_POST['enable_custom_notification_configuration']) {
103  $ilUser->writePref('use_custom_notification_setting', 1);
104  }
105  else {
106  $ilUser->writePref('use_custom_notification_setting', 0);
107  }
108 
109 
110  $this->showSettingsObject();
111  }
112 
113  public function showSettingsObject() {
114  global $tpl, $ilCtrl, $ilUser, $lng;
115 
116  require_once 'Services/Notifications/classes/class.ilNotificationSettingsTable.php';
117  require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
118 
119  $userTypes = ilNotificationDatabaseHandler::loadUserConfig($ilUser->getId());
120 
121  $lng->loadLanguageModule('notification');
122 
123  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
124  $form = new ilPropertyFormGUI();
125  $chk = new ilCheckboxInputGUI($lng->txt('enable_custom_notification_configuration'), 'enable_custom_notification_configuration');
126  $chk->setValue('1');
127  $chk->setChecked($ilUser->getPref('use_custom_notification_setting') == 1);
128  $form->addItem($chk);
129 
130  $form->setFormAction($ilCtrl->getFormAction($this, 'showSettingsObject'));
131  $form->addCommandButton('saveCustomizingOption', $lng->txt('save'));
132  $form->addCommandButton('showSettings', $lng->txt('cancel'));
133 
134  $table = new ilNotificationSettingsTable($this, 'a title', $this->getAvailableChannels(array('set_by_user')), $userTypes);
135 
136  $table->setFormAction($ilCtrl->getFormAction($this, 'saveSettings'));
137  $table->setData($this->getAvailableTypes(array('set_by_user')));
138 
139  if ($ilUser->getPref('use_custom_notification_setting') == 1) {
140  $table->addCommandButton('saveSettings', $lng->txt('save'));
141  $table->addCommandButton('showSettings', $lng->txt('cancel'));
142  $table->setEditable(true);
143  }
144  else {
145  $table->setEditable(false);
146  }
147 
148  $tpl->setContent($form->getHtml() . $table->getHTML());
149  }
150 
151  private function saveSettingsObject() {
152  global $ilUser, $ilCtrl;
153  require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
154 
155  ilNotificationDatabaseHandler::setUserConfig($ilUser->getId(), $_REQUEST['notification'] ? $_REQUEST['notification'] : array());
156  $this->showSettingsObject();
157  }
158 
159  function addLocatorItems() {
160  global $ilLocator, $ilCtrl;
161 
162  if (is_object($this->object)) {
163  $ilLocator->addItem($this->object->getTitle(), $ilCtrl->getLinkTarget($this, ''), '', $_GET["ref_id"]);
164  }
165  }
166 
167 } // END class.ilObjFileGUI
168 ?>