ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilForumNotification.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once './Modules/Forum/classes/class.ilObjForum.php';
5
6
16{
17 protected static $node_data_cache = array();
18
20 private $user_id;
21 private $forum_id;
22 private $thread_id;
23 private $admin_force;
24 private $user_toggle;
25
26 private $ref_id;
27
28
29
34 public function __construct($ref_id)
35 {
36 global $ilObjDataCache,$lng,$ilias;
37
38 $this->lng = $lng;
39 $this->ilias = $ilias;
40 $this->ref_id = $ref_id;
41 $this->forum_id = $ilObjDataCache->lookupObjId($ref_id);
42
43 }
44
45 public function setNotificationId($a_notification_id)
46 {
47 $this->notification_id = $a_notification_id;
48 }
49 public function getNotificationId()
50 {
52 }
53 public function setUserId($a_user_id)
54 {
55 $this->user_id = $a_user_id;
56 }
57 public function getUserId()
58 {
59 return $this->user_id;
60 }
61
62 public function setForumId($a_forum_id)
63 {
64 $this->forum_id = $a_forum_id;
65 }
66 public function getForumId()
67 {
68 return $this->forum_id;
69 }
70
71 public function setThreadId($a_thread_id)
72 {
73 $this->thread_id = $a_thread_id;
74 }
75 public function getThreadId()
76 {
77 return $this->thread_id;
78 }
79
80
81 public function setAdminForce($a_admin_force)
82 {
83 $this->admin_force = $a_admin_force;
84 }
85 public function getAdminForce()
86 {
87 return $this->admin_force;
88 }
89
90
91 public function setUserToggle($a_user_toggle)
92 {
93 $this->user_toggle = $a_user_toggle;
94 }
95 public function getUserToggle()
96 {
97 return $this->user_toggle;
98 }
99
100 public function setForumRefId($a_ref_id)
101 {
102 $this->ref_id = $a_ref_id;
103 }
104 public function getForumRefId()
105 {
106 return $this->ref_id;
107 }
108
109 //user_id of who sets the setting to notify members
110 public function setUserIdNoti($a_user_id_noti)
111 {
112 $this->user_id_noti = $a_user_id_noti;
113 }
114 //user_id of who sets the setting to notify members
115 public function getUserIdNoti()
116 {
117 return $this->user_id_noti;
118 }
119
120 public function isAdminForceNotification()
121 {
122 global $ilDB;
123
124 $res = $ilDB->queryF('
125 SELECT admin_force_noti FROM frm_notification
126 WHERE user_id = %s
127 AND frm_id = %s
128 AND user_id_noti > %s ',
129 array('integer','integer', 'integer'),
130 array($this->getUserId(), $this->getForumId(), 0));
131
132 while($row = $ilDB->fetchAssoc($res))
133 {
134 return $row['admin_force_noti'];
135 }
136 }
137 public function isUserToggleNotification()
138 {
139 global $ilDB;
140
141 $res = $ilDB->queryF('
142 SELECT user_toggle_noti FROM frm_notification
143 WHERE user_id = %s
144 AND frm_id = %s
145 AND user_id_noti > %s',
146 array('integer', 'integer', 'integer'),
147 array($this->getUserId(), $this->getForumId(), 0 ));
148
149 while($row = $ilDB->fetchAssoc($res))
150 {
151 return $row['user_toggle_noti'];
152 }
153
154 }
155
156 public function insertAdminForce()
157 {
158 global $ilDB, $ilUser;
159
160 $next_id = $ilDB->nextId('frm_notification');
161 $res = $ilDB->manipulateF('
162 INSERT INTO frm_notification
163 (notification_id, user_id, frm_id, admin_force_noti, user_toggle_noti, user_id_noti)
164 VALUES(%s,%s,%s,%s,%s,%s)',
165 array('integer', 'integer', 'integer', 'integer', 'integer', 'integer'),
166 array($next_id, $this->getUserId(), $this->getForumId(), $this->getAdminForce(), $this->getUserToggle(), $ilUser->getId()));
167
168 }
169 public function deleteAdminForce()
170 {
171 global $ilDB;
172
173 $res = $ilDB->manipulateF('
174 DELETE FROM frm_notification
175 WHERE user_id = %s
176 AND frm_id = %s
177 AND admin_force_noti = %s
178 AND user_id_noti > %s' ,
179 array('integer', 'integer','integer', 'integer'),
180 array($this->getUserId(), $this->getForumId(), 1, 0));
181 }
182
183 public function deleteUserToggle()
184 {
185 global $ilDB, $ilUser;
186
187 $res = $ilDB->manipulateF('
188 DELETE FROM frm_notification
189 WHERE user_id = %s
190 AND frm_id = %s
191 AND admin_force_noti = %s
192 AND user_toggle_noti = %s
193 AND user_id_noti > %s' ,
194 array('integer', 'integer','integer','integer', 'integer'),
195 array($this->getUserId(),$this->getForumId(),1,1, 0 ));
196
197 }
198
199 public function updateUserToggle()
200 {
201 global $ilDB;
202
203 $res = $ilDB->manipulateF('
204 UPDATE frm_notification
205 SET user_toggle_noti = %s
206 WHERE user_id = %s
207 AND frm_id = %s
208 AND admin_force_noti = %s',
209 array('integer','integer','integer','integer'),
210 array($this->getUserToggle(), $this->getUserId(),$this->getForumId(), 1));
211 }
212
213 /* If a new member enters a Course or a Group, this function checks
214 * if this CRS/GRP contains a forum and a notification setting set by admin or moderator
215 * and inserts the new member into frm_notification
216 * */
217 public static function checkForumsExistsInsert($ref_id, $user_id = 0)
218 {
219 global $ilUser;
220
221 include_once 'Modules/Forum/classes/class.ilForumProperties.php';
222
223 $node_data = self::getCachedNodeData($ref_id);
224
225 foreach($node_data as $data)
226 {
227 //check frm_properties if frm_noti is enabled
228 $frm_noti = new ilForumNotification($data['ref_id']);
229 if($user_id != 0)
230 {
231 $frm_noti->setUserId($user_id);
232 }
233 else $frm_noti->setUserId($ilUser->getId());
234
236 $frm_noti->setAdminForce($admin_force);
237
239 if($user_toggle) $frm_noti->setAdminForce(1);
240
241 if($admin_force == 1 || $user_toggle == 1)
242 {
243 $frm_noti->setUserToggle($user_toggle);
244 $frm_noti->setForumId($data['obj_id']);
245 if($frm_noti->existsNotification() == false)
246 {
247 $frm_noti->insertAdminForce();
248 }
249 }
250 }
251 }
252
253 public static function checkForumsExistsDelete($ref_id, $user_id = 0)
254 {
255 global $ilUser;
256
257 $node_data = self::getCachedNodeData($ref_id);
258
259 include_once 'Modules/Forum/classes/class.ilForumModerators.php';
260
261 foreach($node_data as $data)
262 {
263 //check frm_properties if frm_noti is enabled
264 $frm_noti = new ilForumNotification($data['ref_id']);
265 $objFrmMods = new ilForumModerators($data['ref_id']);
266 $moderator_ids = $objFrmMods->getCurrentModerators();
267
268 if($user_id != 0)
269 {
270 $frm_noti->setUserId($user_id);
271 }
272 else $frm_noti->setUserId($ilUser->getId());
273
274 $frm_noti->setForumId($data['obj_id']);
275 if(!in_array($frm_noti->getUserId(), $moderator_ids))
276 {
277 $frm_noti->deleteAdminForce();
278 }
279 }
280 }
281
285 public static function getCachedNodeData($ref_id)
286 {
287 if(!array_key_exists($ref_id, self::$node_data_cache))
288 {
289 global $tree;
290 self::$node_data_cache[$ref_id] = $tree->getChildsByType($ref_id, 'frm');
291 }
292
293 return self::$node_data_cache[$ref_id];
294 }
295
296 public static function _isParentNodeGrpCrs($a_ref_id)
297 {
298 global $tree;
299
300 $parent_ref_id = $tree->getParentId($a_ref_id);
301 $parent_obj = ilObjectFactory::getInstanceByRefId($parent_ref_id);
302
303 if($parent_obj->getType() == 'crs' || $parent_obj->getType() == 'grp')
304 return $parent_obj->getType();
305 else return false;
306 }
307
308
309 public static function _clearForcedForumNotifications($a_parameter)
310 {
311 global $ilDB, $ilObjDataCache;
312
313 if(!$a_parameter['tree'] == 'tree')
314 {
315 return;
316 }
317
318 $ref_id = $a_parameter['source_id'];
320
321 if($is_parent)
322 {
323 $forum_id = $ilObjDataCache->lookupObjId($ref_id);
324
325 $ilDB->manipulateF('
326 DELETE FROM frm_notification
327 WHERE frm_id = %s
328 AND admin_force_noti = %s',
329 array('integer','integer'),
330 array($forum_id, 1));
331 }
332 }
333
334 public static function checkParentNodeTree($ref_id)
335 {
336 global $tree;
337
338 $parent_ref_id = $tree->getParentId($ref_id);
339 $parent_obj = ilObjectFactory::getInstanceByRefId($parent_ref_id);
340
341 if($parent_obj->getType() == 'crs')
342 {
343 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
344 $oParticipants = ilCourseParticipants::_getInstanceByObjId($parent_obj->getId());
345 }
346 else if($parent_obj->getType() == 'grp')
347 {
348 include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
349 $oParticipants = ilGroupParticipants::_getInstanceByObjId($parent_obj->getId());
350 }
351
352 $result = array();
353 if($parent_obj->getType() == 'crs' || $parent_obj->getType() == 'grp')
354 {
355 $moderator_ids = self::_getModerators($ref_id);
356 $admin_ids = $oParticipants->getAdmins();
357 $tutor_ids = $oParticipants->getTutors();
358
359 $result = array_unique(array_merge($moderator_ids,$admin_ids,$tutor_ids));
360 }
361 return $result;
362 }
363
371 public function _getModerators($a_ref_id)
372 {
373 global $rbacreview;
374
375 $role_arr = $rbacreview->getRolesOfRoleFolder($a_ref_id);
376
377 foreach ($role_arr as $role_id)
378 {
379 //$roleObj = $this->ilias->obj_factory->getInstanceByObjId($role_id);
380 $title = ilObject::_lookupTitle($role_id);
381 if ($title == "il_frm_moderator_".$a_ref_id)
382 {
383 #return $rbacreview->assignedUsers($roleObj->getId());
384 return $title = $rbacreview->assignedUsers($role_id);
385 }
386 }
387
388 return array();
389 }
390
391 public function update()
392 {
393 global $ilDB;
394
395 $res = $ilDB->manipulateF('
396 UPDATE frm_notification
397 SET admin_force_noti = %s,
398 user_toggle_noti = %s
399 WHERE user_id = %s
400 AND frm_id = %s',
401 array('integer','integer','integer','integer'),
402 array($this->getAdminForce(), $this->getUserToggle(), $this->getUserId(), $this->getForumId()));
403 }
404
406 {
407 global $ilDB;
408
409 $res = $ilDB->manipulateF('
410 DELETE FROM frm_notification
411 WHERE frm_id = %s
412 AND user_id_noti > %s',
413 array('integer', 'integer'),
414 array($this->getForumId(), 0));
415 }
416
417 public function read()
418 {
419 global $ilDB;
420 $result = array();
421
422 $query = $ilDB->queryF('
423 SELECT * FROM frm_notification WHERE
424 frm_id = %s',
425 array('integer'),
426 array($this->getForumId()));
427
428 while($row = $ilDB->fetchAssoc($query))
429 {
430 $result[$row['user_id']] = $row;
431 }
432 return $result;
433 }
434
435 public static function mergeThreadNotificiations($merge_source_thread_id, $merge_target_thread_id)
436 {
437 // check notifications etc..
438 global $ilDB;
439
440 $res = $ilDB->queryF('SELECT notification_id, user_id FROM frm_notification
441 WHERE frm_id = %s
442 AND thread_id = %s
443 ORDER BY user_id ASC',
444 array('integer', 'integer'), array(0, $merge_source_thread_id));
445
446 $res_2 = $ilDB->queryF('SELECT user_id FROM frm_notification
447 WHERE frm_id = %s
448 AND thread_id = %s
449 ORDER BY user_id ASC',
450 array('integer', 'integer'), array(0, $merge_target_thread_id));
451
452 $users_already_notified = $ilDB->fetchAssoc($res_2);
453 while($row = $ilDB->fetchAssoc($res))
454 {
455 if(in_array($row['user_id'], $users_already_notified))
456 {
457 // delete source notification because already exists for target_id
458 $ilDB->manipulatef('DELETE FROM frm_notification WHERE notification_id = %s',
459 array('integer'), array($row['notification_id']));
460 }
461 else
462 {
463 // update source notification
464 $ilDB->update('frm_notification',
465 array('thread_id' => array('integer', $merge_target_thread_id)),
466 array('thread_id' => array('integer', $merge_source_thread_id)
467 ));
468 }
469 }
470 }
471
475 public function existsNotification()
476 {
477 global $ilDB;
478
479 $res = $ilDB->queryF('
480 SELECT * FROM frm_notification
481 WHERE user_id = %s
482 AND frm_id = %s
483 AND admin_force_noti = %s',
484 array('integer', 'integer', 'integer'),
485 array($this->getUserId(), $this->getForumId(), $this->getAdminForce()));
486
487 if($row = $ilDB->numRows($res) > 0)
488 {
489 return true;
490 }
491 return false;
492 }
493
494} // END class.ilForumNotification
$result
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Class ilForumModerators.
Class ilForumNotification.
__construct($ref_id)
Constructor @access public.
setNotificationId($a_notification_id)
static checkForumsExistsDelete($ref_id, $user_id=0)
static _clearForcedForumNotifications($a_parameter)
_getModerators($a_ref_id)
get all users assigned to local role il_frm_moderator_<frm_ref_id> (static)
static checkForumsExistsInsert($ref_id, $user_id=0)
static mergeThreadNotificiations($merge_source_thread_id, $merge_target_thread_id)
static _isParentNodeGrpCrs($a_ref_id)
static _isUserToggleNoti($a_obj_id)
static _isAdminForceNoti($a_obj_id)
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupTitle($a_id)
lookup object title
$data
redirection script todo: (a better solution should control the processing via a xml file)
global $lng
Definition: privfeed.php:40
global $ilDB
global $ilUser
Definition: imgupload.php:15