ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilObjForum.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Object/classes/class.ilObject.php';
5require_once 'Modules/Forum/classes/class.ilForum.php';
6require_once 'Modules/Forum/classes/class.ilFileDataForum.php';
7require_once 'Modules/Forum/classes/class.ilForumProperties.php';
8
18class ilObjForum extends ilObject
19{
25 public $Forum;
26
27// private $objProperties = null;
28
33 protected static $obj_id_to_forum_id_cache = array();
34
39 protected static $ref_id_to_forum_id_cache = array();
40
45 protected static $forum_statistics_cache = array();
46
51 protected static $forum_last_post_cache = array();
52
59 public function __construct($a_id = 0, $a_call_by_reference = true)
60 {
61 $this->type = 'frm';
62 parent::__construct($a_id, $a_call_by_reference);
63
64 /*
65 * this constant is used for the information if a single post is marked as new
66 * All threads/posts created before this date are never marked as new
67 * Default is 8 weeks
68 *
69 */
70 $new_deadline = time() - 60 * 60 * 24 * 7 * ($this->ilias->getSetting('frm_store_new') ?
71 $this->ilias->getSetting('frm_store_new') :
72 8);
73 define('NEW_DEADLINE', $new_deadline);
74
75 // TODO: needs to rewrite scripts that are using Forum outside this class
76 $this->Forum = new ilForum();
77 }
78
82 public function create()
83 {
84 $id = parent::create();
85
86 require_once 'Modules/Forum/classes/class.ilForumProperties.php';
87 $properties = ilForumProperties::getInstance($this->getId());
88 $properties->setDefaultView(1);
89 $properties->setAnonymisation(0);
90 $properties->setStatisticsStatus(0);
91 $properties->setPostActivation(0);
92 $properties->setThreadSorting(0);
93 $properties->insert();
94
95 $this->createSettings();
96
97 $this->saveData();
98
99 return $id;
100 }
101
105 public function setPermissions($a_ref_id)
106 {
110 global $rbacadmin;
111
112 parent::setPermissions($a_ref_id);
113
114 // ...finally assign moderator role to creator of forum object
115 $roles = array(ilObjForum::_lookupModeratorRole($this->getRefId()));
116 $rbacadmin->assignUser($roles[0], $this->getOwner(), 'n');
117 $this->updateModeratorRole($roles[0]);
118 }
119
123 public function updateModeratorRole($role_id)
124 {
128 global $ilDB;
129
130 $ilDB->manipulate('UPDATE frm_data SET top_mods = ' . $ilDB->quote($role_id, 'integer') . ' WHERE top_frm_fk = ' . $ilDB->quote($this->getId(), 'integer'));
131 }
132
138 function getDiskUsage()
139 {
140 require_once("./Modules/File/classes/class.ilObjFileAccess.php");
141 return ilObjForumAccess::_lookupDiskUsage($this->id);
142 }
143
144 public static function _lookupThreadSubject($a_thread_id)
145 {
150 global $ilDB;
151
152 $res = $ilDB->queryf('
153 SELECT thr_subject FROM frm_threads WHERE thr_pk = %s',
154 array('integer'), array($a_thread_id));
155
156 while($row = $ilDB->fetchObject($res))
157 {
158 return $row->thr_subject;
159 }
160 return '';
161 }
162
163 // METHODS FOR UN-READ STATUS
164 public function getCountUnread($a_usr_id, $a_thread_id = 0)
165 {
166// return $this->_getCountUnread($this->getId(),$a_usr_id,$a_thread_id);
167// }
168//
169// function _getCountUnread($a_frm_id, $a_usr_id,$a_thread_id = 0)
170// {
171
172 $a_frm_id = $this->getId();
173
177 global $ilBench, $ilDB;
178
179 $ilBench->start("Forum", 'getCountRead');
180 if(!$a_thread_id)
181 {
182 // Get topic_id
183 $res = $ilDB->queryf('
184 SELECT top_pk FROM frm_data WHERE top_frm_fk = %s',
185 array('integer'), array($a_frm_id));
186
187
188 while($row = $ilDB->fetchObject($res))
189 {
190 $topic_id = $row->top_pk;
191 }
192
193 // Get number of posts
194 $res = $ilDB->queryf('
195 SELECT COUNT(pos_pk) num_posts FROM frm_posts
196 WHERE pos_top_fk = %s',
197 array('integer'), array($topic_id));
198
199 while($row = $ilDB->fetchObject($res))
200 {
201 $num_posts = $row->num_posts;
202 }
203
204 $res = $ilDB->queryf('
205 SELECT COUNT(post_id) count_read FROM frm_user_read
206 WHERE obj_id = %s
207 AND usr_id = %s',
208 array('integer', 'integer'), array($a_frm_id, $a_usr_id));
209
210 while($row = $ilDB->fetchObject($res))
211 {
212 $count_read = $row->count_read;
213 }
214 $unread = $num_posts - $count_read;
215
216 $ilBench->stop("Forum", 'getCountRead');
217 return $unread > 0 ? $unread : 0;
218 }
219 else
220 {
221 $res = $ilDB->queryf('
222 SELECT COUNT(pos_pk) num_posts FROM frm_posts
223 WHERE pos_thr_fk = %s',
224 array('integer'), array($a_thread_id));
225
226 $row = $ilDB->fetchObject($res);
227 $num_posts = $row->num_posts;
228
229 $res = $ilDB->queryf('
230 SELECT COUNT(post_id) count_read FROM frm_user_read
231 WHERE obj_id = %s
232 AND usr_id = %s
233 AND thread_id = %s',
234 array('integer', 'integer', 'integer'), array($a_frm_id, $a_frm_id, $a_thread_id));
235
236 $row = $ilDB->fetchObject($res);
237 $count_read = $row->count_read;
238
239 $unread = $num_posts - $count_read;
240
241 $ilBench->stop("Forum", 'getCountRead');
242 return $unread > 0 ? $unread : 0;
243 }
244 $ilBench->stop("Forum", 'getCountRead');
245 return false;
246 }
247
248
249 public function markThreadRead($a_usr_id, $a_thread_id)
250 {
254 global $ilDB;
255
256 // Get all post ids
257 $res = $ilDB->queryf('
258 SELECT * FROM frm_posts WHERE pos_thr_fk = %s',
259 array('integer'), array($a_thread_id));
260
261 while($row = $ilDB->fetchObject($res))
262 {
263 $this->markPostRead($a_usr_id, $a_thread_id, $row->pos_pk);
264 }
265 return true;
266 }
267
268 public function markAllThreadsRead($a_usr_id)
269 {
273 global $ilDB;
274
275 $res = $ilDB->queryf('
276 SELECT * FROM frm_data, frm_threads
277 WHERE top_frm_fk = %s
278 AND top_pk = thr_top_fk',
279 array('integer'), array($this->getId()));
280
281 while($row = $ilDB->fetchObject($res))
282 {
283 $this->markThreadRead($a_usr_id, $row->thr_pk);
284 }
285
286 return true;
287 }
288
289
290 public function markPostRead($a_usr_id, $a_thread_id, $a_post_id)
291 {
295 global $ilDB;
296
297 // CHECK IF ENTRY EXISTS
298 $res = $ilDB->queryf('
299 SELECT * FROM frm_user_read
300 WHERE usr_id = %s
301 AND obj_id = %s
302 AND thread_id = %s
303 AND post_id = %s',
304 array('integer', 'integer', 'integer', 'integer'),
305 array($a_usr_id, $this->getId(), $a_thread_id, $a_post_id));
306
307 if($ilDB->numRows($res))
308 {
309 return true;
310 }
311
312 $res = $ilDB->manipulateF('
313 INSERT INTO frm_user_read
314 ( usr_id,
315 obj_id,
316 thread_id,
317 post_id
318 )
319 VALUES (%s,%s,%s,%s)',
320 array('integer', 'integer', 'integer', 'integer'),
321 array($a_usr_id, $this->getId(), $a_thread_id, $a_post_id));
322
323 return true;
324 }
325
326 public function markPostUnread($a_user_id, $a_post_id)
327 {
331 global $ilDB;
332
333 $res = $ilDB->manipulateF('
334 DELETE FROM frm_user_read
335 WHERE usr_id = %s
336 AND post_id = %s',
337 array('integer', 'integer'),
338 array($a_user_id, $a_post_id));
339 }
340
341 public function isRead($a_usr_id, $a_post_id)
342 {
346 global $ilDB;
347
348 $res = $ilDB->queryf('
349 SELECT * FROM frm_user_read
350 WHERE usr_id = %s
351 AND post_id = %s',
352 array('integer', 'integer'),
353 array($a_usr_id, $a_post_id));
354
355 return $ilDB->numRows($res) ? true : false;
356 }
357
358 public function updateLastAccess($a_usr_id, $a_thread_id)
359 {
363 global $ilDB;
364
365 $res = $ilDB->queryf('
366 SELECT * FROM frm_thread_access
367 WHERE usr_id = %s
368 AND obj_id = %s
369 AND thread_id = %s',
370 array('integer', 'integer', 'integer'),
371 array($a_usr_id, $this->getId(), $a_thread_id));
372 $data = $ilDB->fetchAssoc($res);
373
374 $ilDB->replace(
375 'frm_thread_access',
376 array(
377 'usr_id' => array('integer', $a_usr_id),
378 'obj_id' => array('integer', $this->getId()),
379 'thread_id' => array('integer', $a_thread_id)
380 ),
381 array(
382 'access_last' => array('integer', time()),
383 'access_old' => array('integer', isset($data['access_old']) ? $data['access_old'] : 0),
384 'access_old_ts' => array('timestamp', $data['access_old_ts'])
385 )
386 );
387
388 return true;
389 }
390
395 public static function _updateOldAccess($a_usr_id)
396 {
401 global $ilDB, $ilias;
402
403 $ilDB->manipulateF('
404 UPDATE frm_thread_access
405 SET access_old = access_last
406 WHERE usr_id = %s',
407 array('integer'), array($a_usr_id));
408
409 $set = $ilDB->query("SELECT * FROM frm_thread_access " .
410 " WHERE usr_id = " . $ilDB->quote($a_usr_id, "integer")
411 );
412 while($rec = $ilDB->fetchAssoc($set))
413 {
414 $ilDB->manipulate("UPDATE frm_thread_access SET " .
415 " access_old_ts = " . $ilDB->quote(date('Y-m-d H:i:s', $rec["access_old"]), "timestamp") .
416 " WHERE usr_id = " . $ilDB->quote($rec["usr_id"], "integer") .
417 " AND obj_id = " . $ilDB->quote($rec["obj_id"], "integer") .
418 " AND thread_id = " . $ilDB->quote($rec["thread_id"], "integer")
419 );
420 }
421
422 $new_deadline = time() - 60 * 60 * 24 * 7 * ($ilias->getSetting('frm_store_new') ?
423 $ilias->getSetting('frm_store_new') :
424 8);
425
426 $ilDB->manipulateF('
427 DELETE FROM frm_thread_access WHERE access_last < %s',
428 array('integer'), array($new_deadline));
429 }
430
431 function _deleteUser($a_usr_id)
432 {
436 global $ilDB;
437
438 $data = array($a_usr_id);
439
440 $res = $ilDB->manipulateF('
441 DELETE FROM frm_user_read WHERE usr_id = %s',
442 array('integer'), $data
443 );
444
445 $res = $ilDB->manipulateF('
446 DELETE FROM frm_thread_access WHERE usr_id = %s',
447 array('integer'), $data
448 );
449
450 // delete notifications of deleted user
451 $ilDB->manipulateF('
452 DELETE FROM frm_notification WHERE user_id = %s',
453 array('integer'), $data);
454
455 return true;
456 }
457
458
459 function _deleteReadEntries($a_post_id)
460 {
464 global $ilDB;
465
466 $statement = $ilDB->manipulateF('
467 DELETE FROM frm_user_read WHERE post_id = %s',
468 array('integer'), array($a_post_id));
469
470 return true;
471 }
472
473 function _deleteAccessEntries($a_thread_id)
474 {
478 global $ilDB;
479
480 $statement = $ilDB->manipulateF('
481 DELETE FROM frm_thread_access WHERE thread_id = %s',
482 array('integer'), array($a_thread_id));
483
484 return true;
485 }
486
491 function update()
492 {
496 global $ilDB;
497
498 if(parent::update())
499 {
500
501 $statement = $ilDB->manipulateF('
502 UPDATE frm_data
503 SET top_name = %s,
504 top_description = %s,
505 top_update = %s,
506 update_user = %s
507 WHERE top_frm_fk =%s',
508 array('text', 'text', 'timestamp', 'integer', 'integer'),
509 array(
510 $this->getTitle(),
511 $this->getDescription(),
512 date("Y-m-d H:i:s"),
513 (int)$_SESSION["AccountId"],
514 (int)$this->getId()
515 ));
516
517 return true;
518 }
519
520 return false;
521 }
522
529 public function cloneObject($a_target_id, $a_copy_id = 0)
530 {
534 global $ilDB;
535
536 $new_obj = parent::cloneObject($a_target_id, $a_copy_id);
537 $this->cloneAutoGeneratedRoles($new_obj);
538
539 ilForumProperties::getInstance($this->getId())->copy($new_obj->getId());
540 $this->Forum->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($this->getId()));
541 $topData = $this->Forum->getOneTopic();
542
543 $ilDB->update('frm_data', array(
544 'top_name' => array('text', $topData['top_name']),
545 'top_description' => array('text', $topData['top_description']),
546 'top_num_posts' => array('integer', $topData['top_num_posts']),
547 'top_num_threads' => array('integer', $topData['top_num_threads']),
548 'top_last_post' => array('text', $topData['top_last_post']),
549 'top_date' => array('timestamp', $topData['top_date']),
550 'visits' => array('integer', $topData['visits']),
551 'top_update' => array('timestamp', $topData['top_update']),
552 'update_user' => array('integer', $topData['update_user']),
553 'top_usr_id' => array('integer', $topData['top_usr_id'])
554 ), array(
555 'top_frm_fk' => array('integer', $new_obj->getId())
556 ));
557
558 // read options
559 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
560
561 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
562 $options = $cwo->getOptions($this->getRefId());
563
564 $options['threads'] = $this->Forum->_getThreads($this->getId());
565
566 // Generate starting threads
567 include_once('Modules/Forum/classes/class.ilFileDataForum.php');
568
569 $new_frm = $new_obj->Forum;
570 $new_frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($new_obj->getId()));
571
572 $new_frm->setForumId($new_obj->getId());
573 $new_frm->setForumRefId($new_obj->getRefId());
574
575 $new_topic = $new_frm->getOneTopic();
576 foreach($options['threads'] as $thread_id=> $thread_subject)
577 {
578 $this->Forum->setMDB2WhereCondition('thr_pk = %s ', array('integer'), array($thread_id));
579
580 $old_thread = $this->Forum->getOneThread();
581
582 $old_post_id = $this->Forum->getFirstPostByThread($old_thread['thr_pk']);
583 $old_post = $this->Forum->getOnePost($old_post_id);
584
585 // Now create new thread and first post
586
587 $new_post = $new_frm->generateThread(
588 $new_topic['top_pk'],
589 $old_thread['thr_author_id'],
590 $old_thread['thr_display_user_id'],
591 $old_thread['thr_subject'],
592 ilForum::_lookupPostMessage($old_post_id),
593 $old_post['notify'],
594 0,
595 $old_thread['thr_usr_alias'],
596 $old_thread['thr_date']);
597 // Copy attachments
598 $old_forum_files = new ilFileDataForum($this->getId(), $old_post_id);
599 $old_forum_files->ilClone($new_obj->getId(), $new_post);
600 }
601
602 return $new_obj;
603 }
604
611 public function cloneAutoGeneratedRoles($new_obj)
612 {
617 global $ilLog, $rbacadmin;
618
619 $moderator = ilObjForum::_lookupModeratorRole($this->getRefId());
620 $new_moderator = ilObjForum::_lookupModeratorRole($new_obj->getRefId());
621
622 if(!$moderator || !$new_moderator || !$this->getRefId() || !$new_obj->getRefId())
623 {
624 $ilLog->write(__METHOD__ . ' : Error cloning auto generated role: il_frm_moderator');
625 }
626 $rbacadmin->copyRolePermissions($moderator, $this->getRefId(), $new_obj->getRefId(), $new_moderator, true);
627 $ilLog->write(__METHOD__ . ' : Finished copying of role il_frm_moderator.');
628
629 include_once './Modules/Forum/classes/class.ilForumModerators.php';
630 $obj_mods = new ilForumModerators($this->getRefId());
631
632 $old_mods = $obj_mods->getCurrentModerators();
633 foreach($old_mods as $user_id)
634 {
635 // The object owner is already member of the moderator role when this method is called
636 // Since the new static caches are introduced with ILIAS 5.0, a database error occurs if we try to assign the user here.
637 if($this->getOwner() != $user_id)
638 {
639 $rbacadmin->assignUser($new_moderator, $user_id);
640 }
641 }
642 }
643
649 public function delete()
650 {
654 global $ilDB;
655
656 // always call parent delete function first!!
657 if(!parent::delete())
658 {
659 return false;
660 }
661
662 // delete attachments
663 $tmp_file_obj =& new ilFileDataForum($this->getId());
664 $tmp_file_obj->delete();
665 unset($tmp_file_obj);
666
667 $this->Forum->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($this->getId()));
668
669 $topData = $this->Forum->getOneTopic();
670
671 $threads = $this->Forum->getAllThreads($topData['top_pk']);
672 foreach($threads['items'] as $thread)
673 {
674 $thread_ids_to_delete[$thread->getId()] = $thread->getId();
675 }
676
677 // delete tree
678 $ilDB->manipulate('DELETE FROM frm_posts_tree WHERE '. $ilDB->in('thr_fk', $thread_ids_to_delete, false, 'integer'));
679
680 // delete posts
681 $ilDB->manipulate('DELETE FROM frm_posts WHERE '. $ilDB->in('pos_thr_fk', $thread_ids_to_delete, false, 'integer'));
682
683 // delete threads
684 $ilDB->manipulate('DELETE FROM frm_threads WHERE '. $ilDB->in('thr_pk', $thread_ids_to_delete, false, 'integer'));
685
686 $obj_id = array($this->getId());
687 // delete forum
688 $ilDB->manipulateF('DELETE FROM frm_data WHERE top_frm_fk = %s',
689 array('integer'), $obj_id);
690
691 // delete settings
692 $ilDB->manipulateF('DELETE FROM frm_settings WHERE obj_id = %s',
693 array('integer'), $obj_id);
694
695 // delete read infos
696 $ilDB->manipulateF('DELETE FROM frm_user_read WHERE obj_id = %s',
697 array('integer'), $obj_id);
698
699 // delete thread access entries
700 $ilDB->manipulateF('DELETE FROM frm_thread_access WHERE obj_id = %s',
701 array('integer'), $obj_id);
702
703 //delete thread notifications
704 $ilDB->manipulate('DELETE FROM frm_notification WHERE '. $ilDB->in('thread_id', $thread_ids_to_delete, false, 'integer'));
705
706 //delete forum notifications
707 $ilDB->manipulateF('DELETE FROM frm_notification WHERE frm_id = %s', array('integer'), $obj_id);
708
709 return true;
710 }
711
717 public function initDefaultRoles()
718 {
719 include_once './Services/AccessControl/classes/class.ilObjRole.php';
721 'il_frm_moderator_'.$this->getRefId(),
722 "Moderator of forum obj_no.".$this->getId(),
723 'il_frm_moderator',
724 $this->getRefId()
725 );
726 return array();
727 }
728
736 public static function _lookupModeratorRole($a_ref_id)
737 {
741 global $ilDB;
742
743 $mod_title = 'il_frm_moderator_' . $a_ref_id;
744
745 $res = $ilDB->queryf('
746 SELECT * FROM object_data WHERE title = %s',
747 array('text'), array($mod_title));
748
749 while($row = $ilDB->fetchObject($res))
750 {
751 return $row->obj_id;
752 }
753 return 0;
754 }
755
756
757 public function createSettings()
758 {
759 // news settings (public notifications yes/no)
760 include_once("./Services/News/classes/class.ilNewsItem.php");
761 $default_visibility = ilNewsItem::_getDefaultVisibilityForRefId($_GET["ref_id"]);
762 if($default_visibility == "public")
763 {
764 ilBlockSetting::_write("news", "public_notifications", 1, 0, $this->getId());
765 }
766
767 return true;
768 }
769
770 public function saveData($a_roles = array())
771 {
776 global $ilUser, $ilDB;
777
778 $nextId = $ilDB->nextId('frm_data');
779
780 $top_data = array(
781 'top_frm_fk' => $this->getId(),
782 'top_name' => $this->getTitle(),
783 'top_description' => $this->getDescription(),
784 'top_num_posts' => 0,
785 'top_num_threads' => 0,
786 'top_last_post' => NULL,
787 'top_mods' => !is_numeric($a_roles[0]) ? 0 : $a_roles[0],
788 'top_usr_id' => $ilUser->getId(),
789 'top_date' => ilUtil::now()
790 );
791
792 $ilDB->manipulateF('
793 INSERT INTO frm_data
794 (
795 top_pk,
796 top_frm_fk,
797 top_name,
798 top_description,
799 top_num_posts,
800 top_num_threads,
801 top_last_post,
802 top_mods,
803 top_date,
804 top_usr_id
805 )
806 VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
807 array('integer', 'integer', 'text', 'text', 'integer', 'integer', 'text', 'integer', 'timestamp', 'integer'),
808 array(
809 $nextId,
810 $top_data['top_frm_fk'],
811 $top_data['top_name'],
812 $top_data['top_description'],
813 $top_data['top_num_posts'],
814 $top_data['top_num_threads'],
815 $top_data['top_last_post'],
816 $top_data['top_mods'],
817 $top_data['top_date'],
818 $top_data['top_usr_id']
819 ));
820 }
821
822 public function setThreadSorting($a_thr_pk, $a_sorting_value)
823 {
824 global $ilDB;
825
826 $ilDB->update('frm_threads',
827 array('thread_sorting' => array('integer',$a_sorting_value)),
828 array('thr_pk' => array('integer', $a_thr_pk)));
829 }
830
831
837 public static function lookupForumIdByObjId($obj_id)
838 {
839 if(array_key_exists($obj_id, self::$obj_id_to_forum_id_cache))
840 {
841 return (int)self::$obj_id_to_forum_id_cache[$obj_id];
842 }
843
844 self::preloadForumIdsByObjIds(array($obj_id));
845
846 return (int)self::$obj_id_to_forum_id_cache[$obj_id];
847 }
848
854 public static function lookupForumIdByRefId($ref_id)
855 {
856 if(array_key_exists($ref_id, self::$ref_id_to_forum_id_cache))
857 {
858 return (int)self::$ref_id_to_forum_id_cache[$ref_id];
859 }
860
861 self::preloadForumIdsByRefIds(array($ref_id));
862
863 return (int)self::$ref_id_to_forum_id_cache[$ref_id];
864 }
865
870 public static function preloadForumIdsByObjIds(array $obj_ids)
871 {
875 global $ilDB;
876
877 if(count($obj_ids) == 1)
878 {
879 $in = " objr.obj_id = " . $ilDB->quote(current($obj_ids), 'integer') . " ";
880 }
881 else
882 {
883 $in = $ilDB->in('objr.obj_id', $obj_ids, false, 'integer');
884 }
885 $query = "
886 SELECT frmd.top_pk, objr.ref_id, objr.obj_id
887 FROM object_reference objr
888 INNER JOIN frm_data frmd ON frmd.top_frm_fk = objr.obj_id
889 WHERE $in
890 ";
891 $res = $ilDB->query($query);
892
893 // Prepare cache array
894 foreach($obj_ids as $obj_id)
895 {
896 self::$obj_id_to_forum_id_cache[$obj_id] = null;
897 }
898
899 while($row = $ilDB->fetchAssoc($res))
900 {
901 self::$obj_id_to_forum_id_cache[$row['obj_id']] = $row['top_pk'];
902 self::$ref_id_to_forum_id_cache[$row['ref_id']] = $row['top_pk'];
903 }
904 }
905
910 public static function preloadForumIdsByRefIds(array $ref_ids)
911 {
915 global $ilDB;
916
917 if(count($ref_ids) == 1)
918 {
919 $in = " objr.ref_id = " . $ilDB->quote(current($ref_ids), 'integer') . " ";
920 }
921 else
922 {
923 $in = $ilDB->in('objr.ref_id', $ref_ids, false, 'integer');
924 }
925 $query = "
926 SELECT frmd.top_pk, objr.ref_id, objr.obj_id
927 FROM object_reference objr
928 INNER JOIN frm_data frmd ON frmd.top_frm_fk = objr.obj_id
929 WHERE $in
930 ";
931 $res = $ilDB->query($query);
932
933 // Prepare cache array
934 foreach($ref_ids as $ref_id)
935 {
936 self::$ref_id_to_forum_id_cache[$ref_id] = null;
937 }
938
939 while($row = $ilDB->fetchAssoc($res))
940 {
941 self::$obj_id_to_forum_id_cache[$row['obj_id']] = $row['top_pk'];
942 self::$ref_id_to_forum_id_cache[$row['ref_id']] = $row['top_pk'];
943 }
944 }
945
951 public static function lookupStatisticsByRefId($ref_id)
952 {
959 global $ilAccess, $ilUser, $ilDB, $ilSetting;
960
961 if(isset(self::$forum_statistics_cache[$ref_id]))
962 {
963 return self::$forum_statistics_cache[$ref_id];
964 }
965
966 $statistics = array(
967 'num_posts' => 0,
968 'num_unread_posts' => 0,
969 'num_new_posts' => 0
970 );
971
973 if(!$forumId)
974 {
975 self::$forum_statistics_cache[$ref_id] = $statistics;
976 return self::$forum_statistics_cache[$ref_id];
977 }
978
980 $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
981
982 $act_clause = '';
983
984 if($is_post_activation_enabled && !$ilAccess->checkAccess('moderate_frm', '', $ref_id))
985 {
986 $act_clause .= " AND (frm_posts.pos_status = " . $ilDB->quote(1, "integer") . " OR frm_posts.pos_author_id = " . $ilDB->quote($ilUser->getId(), "integer") . ") ";
987 }
988
989 $new_deadline = date('Y-m-d H:i:s', time() - 60 * 60 * 24 * 7 * ($ilSetting->get('frm_store_new') ? $ilSetting->get('frm_store_new') : 8));
990
991 if(!$ilUser->isAnonymous())
992 {
993 $query = "
994 (SELECT COUNT(frm_posts.pos_pk) cnt
995 FROM frm_posts
996 INNER JOIN frm_threads ON frm_posts.pos_thr_fk = frm_threads.thr_pk
997 WHERE frm_threads.thr_top_fk = %s $act_clause)
998
999 UNION ALL
1000
1001 (SELECT COUNT(DISTINCT(frm_user_read.post_id)) cnt
1002 FROM frm_user_read
1003 INNER JOIN frm_posts ON frm_user_read.post_id = frm_posts.pos_pk
1004 INNER JOIN frm_threads ON frm_threads.thr_pk = frm_posts.pos_thr_fk
1005 WHERE frm_user_read.usr_id = %s AND frm_posts.pos_top_fk = %s $act_clause)
1006 ";
1007
1008 $types = array('integer', 'integer', 'integer');
1009 $values = array($forumId, $ilUser->getId(), $forumId);
1010
1011 $forum_overview_setting = (int)$ilSetting::_lookupValue('frma', 'forum_overview');
1012 if($forum_overview_setting == ilForumProperties::FORUM_OVERVIEW_WITH_NEW_POSTS)
1013 {
1014 $news_types = array('integer', 'integer', 'integer', 'timestamp', 'integer');
1015 $news_values = array($ilUser->getId(), $ilUser->getId(), $forumId, $new_deadline, $ilUser->getId());
1016
1017 $query .= "
1018 UNION ALL
1019
1020 (SELECT COUNT(frm_posts.pos_pk) cnt
1021 FROM frm_posts
1022 LEFT JOIN frm_user_read ON (post_id = frm_posts.pos_pk AND frm_user_read.usr_id = %s)
1023 LEFT JOIN frm_thread_access ON (frm_thread_access.thread_id = frm_posts.pos_thr_fk AND frm_thread_access.usr_id = %s)
1024 WHERE frm_posts.pos_top_fk = %s
1025 AND ( (frm_posts.pos_update > frm_thread_access.access_old_ts)
1026 OR (frm_thread_access.access_old IS NULL AND frm_posts.pos_update > %s)
1027 )
1028 AND frm_posts.pos_author_id != %s
1029 AND frm_user_read.usr_id IS NULL $act_clause)";
1030
1031 $types = array_merge($types, $news_types);
1032 $values = array_merge($values, $news_values);
1033 }
1034
1035 $mapping = array_keys($statistics);
1036 $res = $ilDB->queryF(
1037 $query,
1038 $types,
1039 $values
1040 );
1041 for($i = 0; $i <= 2; $i++)
1042 {
1043 $row = $ilDB->fetchAssoc($res);
1044
1045 $statistics[$mapping[$i]] = (int)$row['cnt'];
1046
1047 if($i == 1)
1048 {
1049 // unread = all - read
1050 $statistics[$mapping[$i]] = $statistics[$mapping[$i - 1]] - $statistics[$mapping[$i]];
1051 }
1052 }
1053 }
1054 else
1055 {
1056 $query = "
1057 SELECT COUNT(frm_posts.pos_pk) cnt
1058 FROM frm_posts
1059 INNER JOIN frm_threads ON frm_posts.pos_thr_fk = frm_threads.thr_pk
1060 WHERE frm_threads.thr_top_fk = %s $act_clause
1061 ";
1062 $types = array('integer');
1063 $values = array($forumId);
1064 $res = $ilDB->queryF(
1065 $query,
1066 $types,
1067 $values
1068 );
1069 $row = $ilDB->fetchAssoc($res);
1070
1071 $statistics = array(
1072 'num_posts' => $row['cnt'],
1073 'num_unread_posts' => $row['cnt'],
1074 'num_new_posts' => $row['cnt']
1075 );
1076 }
1077
1078 self::$forum_statistics_cache[$ref_id] = $statistics;
1079
1080 return self::$forum_statistics_cache[$ref_id];
1081 }
1082
1088 public static function lookupLastPostByRefId($ref_id)
1089 {
1095 global $ilAccess, $ilUser, $ilDB;
1096
1097 if(isset(self::$forum_last_post_cache[$ref_id]))
1098 {
1099 return self::$forum_last_post_cache[$ref_id];
1100 }
1101
1103 if(!$forumId)
1104 {
1105 self::$forum_last_post_cache[$ref_id] = array();
1106 return self::$forum_last_post_cache[$ref_id];
1107 }
1108
1109 $act_clause = '';
1110 if(!$ilAccess->checkAccess('moderate_frm', '', $ref_id))
1111 {
1112 $act_clause .= " AND (frm_posts.pos_status = " . $ilDB->quote(1, "integer") . " OR frm_posts.pos_author_id = " . $ilDB->quote($ilUser->getId(), "integer") . ") ";
1113 }
1114
1115 $ilDB->setLimit(1, 0);
1116 $query = "
1117 SELECT *
1118 FROM frm_posts
1119 WHERE pos_top_fk = %s $act_clause
1120 ORDER BY pos_date DESC
1121 ";
1122 $res = $ilDB->queryF(
1123 $query,
1124 array('integer'),
1125 array($forumId)
1126 );
1127
1128 $data = $ilDB->fetchAssoc($res);
1129
1130 self::$forum_last_post_cache[$ref_id] = is_array($data) ? $data : array();
1131
1132 return self::$forum_last_post_cache[$ref_id];
1133 }
1134
1141 public static function getUserIdsOfLastPostsByRefIdAndThreadIds($ref_id, array $thread_ids)
1142 {
1148 global $ilUser, $ilAccess, $ilDB;
1149
1150 $act_clause = '';
1151 $act_inner_clause = '';
1152 if(!$ilAccess->checkAccess('moderate_frm', '', $ref_id))
1153 {
1154 $act_clause .= " AND (t1.pos_status = " . $ilDB->quote(1, "integer") . " OR t1.pos_author_id = " . $ilDB->quote($ilUser->getId(), "integer") . ") ";
1155 $act_inner_clause .= " AND (t3.pos_status = " . $ilDB->quote(1, "integer") . " OR t3.pos_author_id = " . $ilDB->quote($ilUser->getId(), "integer") . ") ";
1156 }
1157
1158 $in = $ilDB->in("t1.pos_thr_fk", $thread_ids, false, 'integer');
1159 $inner_in = $ilDB->in("t3.pos_thr_fk", $thread_ids, false, 'integer');
1160//@todo fix this query 'group by ... '
1161 $query = "
1162 SELECT t1.pos_display_user_id, t1.update_user
1163 FROM frm_posts t1
1164 INNER JOIN (
1165 SELECT t3.pos_thr_fk, MAX(t3.pos_date) pos_date
1166 FROM frm_posts t3
1167 WHERE $inner_in $act_inner_clause
1168 GROUP BY t3.pos_thr_fk
1169 ) t2 ON t2.pos_thr_fk = t1.pos_thr_fk AND t2.pos_date = t1.pos_date
1170 WHERE $in $act_clause
1171 GROUP BY t1.pos_thr_fk, t1.pos_display_user_id, t1.update_user
1172 ";
1174 $usr_ids = array();
1175
1176 $res = $ilDB->query($query);
1177 while($row = $ilDB->fetchAssoc($res))
1178 {
1179 if((int)$row['pos_display_user_id'])
1180 {
1181 $usr_ids[] = (int)$row['pos_display_user_id'];
1182 }
1183 if((int)$row['update_user'])
1184 {
1185 $usr_ids[] = (int)$row['update_user'];
1186 }
1187 }
1188
1189 return array_unique($usr_ids);
1190 }
1191
1192 public static function mergeForumUserRead($merge_source_thread_id, $merge_target_thread_id)
1193 {
1194 global $ilDB;
1195
1196 $ilDB->update('frm_user_read',
1197 array('thread_id' => array('integer', $merge_target_thread_id)),
1198 array('thread_id' => array('integer',$merge_source_thread_id)));
1199 }
1200}
$_GET["client_id"]
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
This class handles all operations on files for the forum object.
Class ilForumModerators.
static getInstance($a_obj_id=0)
Class Forum core functions for forum.
_lookupPostMessage($a_id)
static _getDefaultVisibilityForRefId($a_ref_id)
Get default visibility for reference id.
Class ilObjForum.
static $obj_id_to_forum_id_cache
__construct($a_id=0, $a_call_by_reference=true)
Constructor @access public.
static $forum_last_post_cache
initDefaultRoles()
init default roles settings @access public
static $forum_statistics_cache
setThreadSorting($a_thr_pk, $a_sorting_value)
getDiskUsage()
Gets the disk usage of the object in bytes.
static lookupForumIdByRefId($ref_id)
static $ref_id_to_forum_id_cache
static mergeForumUserRead($merge_source_thread_id, $merge_target_thread_id)
static lookupForumIdByObjId($obj_id)
static createDefaultRole($a_title, $a_description, $a_tpl_name, $a_ref_id)
Class ilObject Basic functions for all objects.
getOwner()
get object owner
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone object permissions, put in tree ...
update()
update object in db
static _lookupObjectId($a_ref_id)
lookup object id
setPermissions($a_parent_ref)
set permissions of object
getRefId()
get reference id @access public
getDescription()
get object description
getId()
get object id @access public
getTitle()
get object title @access public
static now()
Return current timestamp in Y-m-d H:i:s format.
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
global $ilBench
Definition: ilias.php:18
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:40
global $ilDB
if(!is_array($argv)) $options
global $ilUser
Definition: imgupload.php:15