19 declare(strict_types=1);
39 private \ILIAS\DI\RBACServices
$rbac;
42 public function __construct(
int $a_id = 0,
bool $a_call_by_reference =
true)
49 $this->
rbac = $DIC->rbac();
50 $this->
logger = $DIC->logger()->root();
53 $weeks = self::NEWS_NEW_CONSIDERATION_WEEKS;
57 $new_deadline = time() - 60 * 60 * 24 * 7 * $weeks;
58 $settings->set(
'frm_new_deadline', (
string) $new_deadline);
65 $id = parent::create();
69 $properties->setAnonymisation(
false);
70 $properties->setStatisticsStatus(
false);
71 $properties->setPostActivation(
false);
72 $properties->setThreadSorting(0);
73 $properties->insert();
86 parent::setPermissions($parent_ref_id);
88 $roles = [self::_lookupModeratorRole($this->
getRefId())];
89 $this->
rbac->admin()->assignUser($roles[0], $this->
getOwner());
95 $this->db->manipulate(
'UPDATE frm_data SET top_mods = ' . $this->db->quote(
98 ) .
' WHERE top_frm_fk = ' . $this->db->quote($this->
getId(),
'integer'));
105 $ilDB = $DIC->database();
107 $res =
$ilDB->queryF(
'SELECT thr_subject FROM frm_threads WHERE thr_pk = %s', [
'integer'], [$a_thread_id]);
108 while ($row =
$ilDB->fetchObject(
$res)) {
109 return $row->thr_subject ??
'';
115 public function getCountUnread(
int $a_usr_id,
int $a_thread_id = 0,
bool $ignoreRoot =
false):
int 117 $a_frm_id = $this->
getId();
122 if ($a_thread_id === 0) {
123 $res = $this->db->queryF(
'SELECT top_pk FROM frm_data WHERE top_frm_fk = %s', [
'integer'], [$a_frm_id]);
124 while ($row = $this->db->fetchObject(
$res)) {
125 $topic_id = (
int) $row->top_pk;
128 $res = $this->db->queryF(
130 SELECT COUNT(pos_pk) num_posts 132 LEFT JOIN frm_posts_tree ON frm_posts_tree.pos_fk = pos_pk 133 WHERE pos_top_fk = %s' . ($ignoreRoot ?
' AND parent_pos != 0 ' :
''),
138 while ($row = $this->db->fetchObject(
$res)) {
139 $num_posts = (
int) $row->num_posts;
142 $res = $this->db->queryF(
143 'SELECT COUNT(post_id) count_read FROM frm_user_read WHERE obj_id = %s AND usr_id = %s',
144 [
'integer',
'integer'],
145 [$a_frm_id, $a_usr_id]
148 while ($row = $this->db->fetchObject(
$res)) {
149 $count_read = (
int) $row->count_read;
152 $res = $this->db->queryF(
154 SELECT COUNT(pos_pk) num_posts FROM frm_posts 155 LEFT JOIN frm_posts_tree ON frm_posts_tree.pos_fk = pos_pk 156 WHERE pos_thr_fk = %s' . ($ignoreRoot ?
' AND parent_pos != 0 ' :
''),
161 $row = $this->db->fetchObject(
$res);
162 $num_posts = (
int) $row->num_posts;
164 $res = $this->db->queryF(
166 SELECT COUNT(post_id) count_read FROM frm_user_read 170 [
'integer',
'integer',
'integer'],
171 [$a_frm_id, $a_frm_id, $a_thread_id]
174 $row = $this->db->fetchObject(
$res);
175 $count_read = (
int) $row->count_read;
177 $unread = $num_posts - $count_read;
179 return max($unread, 0);
184 $res = $this->db->queryF(
'SELECT pos_pk FROM frm_posts WHERE pos_thr_fk = %s', [
'integer'], [$a_thread_id]);
185 while ($row = $this->db->fetchObject(
$res)) {
186 $this->
markPostRead($a_usr_id, $a_thread_id, (
int) $row->pos_pk);
194 $res = $this->db->queryF(
195 'SELECT thr_pk FROM frm_data, frm_threads WHERE top_frm_fk = %s AND top_pk = thr_top_fk',
200 while ($row = $this->db->fetchObject(
$res)) {
205 public function markPostRead(
int $a_usr_id,
int $a_thread_id,
int $a_post_id): void
207 $res = $this->db->queryF(
209 SELECT thread_id FROM frm_user_read 214 [
'integer',
'integer',
'integer',
'integer'],
215 [$a_usr_id, $this->
getId(), $a_thread_id, $a_post_id]
218 if (!$this->db->numRows(
$res)) {
219 $this->db->manipulateF(
221 INSERT INTO frm_user_read 227 VALUES (%s,%s,%s,%s)',
228 [
'integer',
'integer',
'integer',
'integer'],
229 [$a_usr_id, $this->
getId(), $a_thread_id, $a_post_id]
236 $this->db->manipulateF(
237 'DELETE FROM frm_user_read WHERE usr_id = %s AND post_id = %s',
238 [
'integer',
'integer'],
239 [$a_user_id, $a_post_id]
243 public function isRead($a_usr_id, $a_post_id): bool
245 $res = $this->db->queryF(
246 'SELECT * FROM frm_user_read WHERE usr_id = %s AND post_id = %s',
247 [
'integer',
'integer'],
248 [$a_usr_id, $a_post_id]
251 return (
bool) $this->db->numRows(
$res);
256 $res = $this->db->queryF(
257 'SELECT * FROM frm_thread_access WHERE usr_id = %s AND obj_id = %s AND thread_id = %s',
258 [
'integer',
'integer',
'integer'],
259 [$a_usr_id, $this->
getId(), $a_thread_id]
263 if (is_array(
$data)) {
267 'usr_id' => [
'integer', $a_usr_id],
268 'obj_id' => [
'integer', $this->
getId()],
269 'thread_id' => [
'integer', $a_thread_id]
272 'access_last' => [
'integer', time()],
273 'access_old' => [
'integer', (
int) (
$data[
'access_old'] ?? 0)],
274 'access_old_ts' => [
'timestamp',
$data[
'access_old_ts']]
284 $ilDB = $DIC->database();
287 'UPDATE frm_thread_access SET access_old = access_last WHERE usr_id = %s',
293 'SELECT * FROM frm_thread_access WHERE usr_id = ' .
$ilDB->quote($a_usr_id,
'integer')
297 "UPDATE frm_thread_access SET " .
298 " access_old_ts = " .
$ilDB->quote(date(
'Y-m-d H:i:s', (
int) $row[
"access_old"]),
"timestamp") .
299 " WHERE usr_id = " .
$ilDB->quote((
int) $row[
"usr_id"],
"integer") .
300 " AND obj_id = " .
$ilDB->quote((
int) $row[
"obj_id"],
"integer") .
301 " AND thread_id = " .
$ilDB->quote((
int) $row[
"thread_id"],
"integer")
305 $weeks = self::NEWS_NEW_CONSIDERATION_WEEKS;
306 if ($DIC->settings()->get(
'frm_store_new')) {
307 $weeks = (
int) $DIC->settings()->get(
'frm_store_new');
309 $new_deadline = time() - 60 * 60 * 24 * 7 * $weeks;
311 $ilDB->manipulateF(
'DELETE FROM frm_thread_access WHERE access_last < %s', [
'integer'], [$new_deadline]);
320 $DIC->database()->manipulateF(
'DELETE FROM frm_user_read WHERE usr_id = %s', [
'integer'],
$data);
321 $DIC->database()->manipulateF(
'DELETE FROM frm_thread_access WHERE usr_id = %s', [
'integer'],
$data);
322 $DIC->database()->manipulateF(
'DELETE FROM frm_notification WHERE user_id = %s', [
'integer'],
$data);
329 $DIC->database()->manipulateF(
'DELETE FROM frm_user_read WHERE post_id = %s', [
'integer'], [$a_post_id]);
336 $DIC->database()->manipulateF(
'DELETE FROM frm_thread_access WHERE thread_id = %s', [
'integer'], [$a_thread_id]);
341 $this->db->manipulateF(
342 'UPDATE frm_data SET update_user = %s WHERE top_frm_fk = %s',
343 [
'integer',
'integer'],
344 [$usr_id, $this->
getId()],
350 if (parent::update()) {
351 $this->db->manipulateF(
352 'UPDATE frm_data SET top_name = %s, top_description = %s, top_update = %s, update_user = %s WHERE top_frm_fk = %s',
353 [
'text',
'text',
'timestamp',
'integer',
'integer'],
358 $this->
user->getId(),
369 public function cloneObject(
int $target_id,
int $copy_id = 0,
bool $omit_tree =
false): ?
ilObject 372 $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
376 $this->Forum->setMDB2WhereCondition(
'top_frm_fk = %s ', [
'integer'], [$this->
getId()]);
377 $topData = $this->Forum->getOneTopic();
379 $this->db->update(
'frm_data', [
380 'top_name' => [
'text', $topData->getTopName()],
381 'top_description' => [
'text', $topData->getTopDescription()],
382 'top_num_posts' => [
'integer', $topData->getTopNumPosts()],
383 'top_num_threads' => [
'integer', $topData->getTopNumThreads()],
384 'top_last_post' => [
'text', $topData->getTopLastPost()],
385 'top_date' => [
'timestamp', $topData->getTopDate()],
386 'visits' => [
'integer', $topData->getVisits()],
387 'top_update' => [
'timestamp', $topData->getTopUpdate()],
388 'update_user' => [
'integer', $topData->getUpdateUser()],
389 'top_usr_id' => [
'integer', $topData->getTopUsrId()]
391 'top_frm_fk' => [
'integer', $new_obj->getId()]
395 $options = $cwo->getOptions($this->
getRefId());
397 $options[
'threads'] = $this->Forum::getSortedThreadSubjects($this->
getId());
399 $new_frm = $new_obj->Forum;
400 $new_frm->setMDB2WhereCondition(
'top_frm_fk = %s ', [
'integer'], [$new_obj->getId()]);
402 $new_frm->setForumId($new_obj->getId());
403 $new_frm->setForumRefId($new_obj->getRefId());
405 $new_topic = $new_frm->getOneTopic();
406 foreach ($options[
'threads'] as $thread_id => $thread_subject) {
407 $this->Forum->setMDB2WhereCondition(
'thr_pk = %s ', [
'integer'], [$thread_id]);
409 $old_thread = $this->Forum->getOneThread();
411 $old_post_id = $this->Forum->getRootPostIdByThread($old_thread->getId());
414 $newThread->setSticky($old_thread->isSticky());
415 $newThread->setForumId($new_topic->getTopPk());
416 $newThread->setThrAuthorId($old_thread->getThrAuthorId());
417 $newThread->setDisplayUserId($old_thread->getDisplayUserId());
418 $newThread->setSubject($old_thread->getSubject());
419 $newThread->setUserAlias($old_thread->getUserAlias());
420 $newThread->setCreateDate($old_thread->getCreateDate());
423 $top_pos = $old_thread->getFirstVisiblePostNode();
428 $newPostId = $new_frm->generateThread(
430 $top_pos->getMessage(),
431 $top_pos->isNotificationEnabled(),
434 (bool) ($old_thread->getNumPosts() - 1)
438 $old_forum_files->
ilClone($new_obj->getId(), $newPostId);
442 $targetRefId = $new_obj->getRefId();
445 $sourceRefId > 0 && $targetRefId > 0 &&
446 $this->tree->getParentId($sourceRefId) === $this->tree->getParentId($targetRefId)
448 $grpRefId = $this->tree->checkForParentType($targetRefId,
'grp');
449 $crsRefId = $this->tree->checkForParentType($targetRefId,
'crs');
451 if ($grpRefId > 0 || $crsRefId > 0) {
453 $notifications->cloneFromSource($sourceRefId);
459 foreach ($translations as $language) {
461 $copiedXML = $originalPageObject->copyXmlContent();
464 $duplicatePageObject->setId($new_obj->getId());
465 $duplicatePageObject->setParentId($new_obj->getId());
466 $duplicatePageObject->setLanguage($language);
467 $duplicatePageObject->setXMLContent($copiedXML);
468 $duplicatePageObject->createFromXML();
474 if (!$cwo->isRootNode($this->getRefId())) {
477 $new_obj->setOfflineStatus(
true);
486 $src_moderator_role_id = self::_lookupModeratorRole($this->
getRefId());
487 $new_moderator_role_id = self::_lookupModeratorRole($new_obj->getRefId());
490 0 === $src_moderator_role_id ||
491 0 === $new_moderator_role_id ||
493 0 === $new_obj->getRefId()
495 $this->
logger->write(__METHOD__ .
' : Error cloning auto generated role: il_frm_moderator');
498 $this->
rbac->admin()->copyRolePermissions(
499 $src_moderator_role_id,
501 $new_obj->getRefId(),
502 $new_moderator_role_id,
506 $this->
logger->write(__METHOD__ .
' : Finished copying of role il_frm_moderator.');
509 $src_moderator_usr_ids = $moderators->getCurrentModerators();
510 foreach ($src_moderator_usr_ids as $usr_id) {
513 if ($this->
getOwner() !== $usr_id) {
514 $this->
rbac->admin()->assignUser($new_moderator_role_id, $usr_id);
519 public function delete():
bool 521 $this->Forum->setForumId($this->
getId());
523 if (!parent::delete()) {
529 $originalPageObject->delete();
533 $tmp_file_obj->delete();
535 $this->Forum->setMDB2WhereCondition(
'top_frm_fk = %s ', [
'integer'], [$this->
getId()]);
537 $topData = $this->Forum->getOneTopic();
539 $threads = $this->Forum->getAllThreads($topData->getTopPk(), [
540 'is_moderator' =>
true,
542 $thread_ids_to_delete = [];
543 foreach ($threads[
'items'] as $thread) {
544 $thread_ids_to_delete[$thread->getId()] = $thread->getId();
547 $this->db->manipulate(
'DELETE FROM frm_posts_tree WHERE ' . $this->db->in(
549 $thread_ids_to_delete,
553 $this->db->manipulate(
'DELETE FROM frm_posts WHERE ' . $this->db->in(
555 $thread_ids_to_delete,
559 $this->db->manipulate(
'DELETE FROM frm_threads WHERE ' . $this->db->in(
561 $thread_ids_to_delete,
566 $obj_id = [$this->
getId()];
568 $this->db->manipulateF(
'DELETE FROM frm_data WHERE top_frm_fk = %s', [
'integer'], $obj_id);
569 $this->db->manipulateF(
'DELETE FROM frm_settings WHERE obj_id = %s', [
'integer'], $obj_id);
570 $this->db->manipulateF(
'DELETE FROM frm_user_read WHERE obj_id = %s', [
'integer'], $obj_id);
571 $this->db->manipulateF(
'DELETE FROM frm_thread_access WHERE obj_id = %s', [
'integer'], $obj_id);
572 $this->db->manipulate(
'DELETE FROM frm_notification WHERE ' . $this->db->in(
574 $thread_ids_to_delete,
578 $this->db->manipulateF(
'DELETE FROM frm_notification WHERE frm_id = %s', [
'integer'], $obj_id);
579 $this->db->manipulateF(
'DELETE FROM frm_posts_deleted WHERE obj_id = %s', [
'integer'], $obj_id);
587 $res = $this->db->queryF(
588 'SELECT draft_id FROM frm_posts_drafts WHERE forum_id = %s',
594 while ($row = $this->db->fetchAssoc(
$res)) {
595 $draft_ids[] = (
int) $row[
'draft_id'];
598 if (count($draft_ids) > 0) {
600 $historyObj->deleteHistoryByDraftIds($draft_ids);
603 $draftObj->deleteDraftsByDraftIds($draft_ids);
610 'il_frm_moderator_' . $this->
getRefId(),
611 "Moderator of forum obj_no." . $this->
getId(),
621 $ilDB = $DIC->database();
623 $mod_title =
'il_frm_moderator_' . $a_ref_id;
625 $res =
$ilDB->queryF(
'SELECT obj_id FROM object_data WHERE title = %s', [
'text'], [$mod_title]);
626 while ($row =
$ilDB->fetchObject(
$res)) {
627 return (
int) $row->obj_id;
638 if ($DIC->http()->wrapper()->query()->has(
'ref_id')) {
639 $ref_id = $DIC->http()->wrapper()->query()->retrieve(
641 $DIC->refinery()->kindlyTo()->int()
647 if ($default_visibility ===
'public') {
654 $nextId = $this->db->nextId(
'frm_data');
657 'top_frm_fk' => $this->
getId(),
660 'top_num_posts' => 0,
661 'top_num_threads' => 0,
662 'top_last_post' => null,
664 'top_usr_id' => $this->
user->getId(),
668 $this->db->manipulateF(
683 VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
698 $top_data[
'top_frm_fk'],
699 $top_data[
'top_name'],
700 $top_data[
'top_description'],
701 $top_data[
'top_num_posts'],
702 $top_data[
'top_num_threads'],
703 $top_data[
'top_last_post'],
704 $top_data[
'top_mods'],
705 $top_data[
'top_date'],
706 $top_data[
'top_usr_id']
715 [
'thread_sorting' => [
'integer', $a_sorting_value]],
716 [
'thr_pk' => [
'integer', $a_thr_pk]]
722 if (array_key_exists($obj_id, self::$obj_id_to_forum_id_cache)) {
723 return self::$obj_id_to_forum_id_cache[$obj_id];
726 self::preloadForumIdsByObjIds([$obj_id]);
728 return self::$obj_id_to_forum_id_cache[$obj_id];
733 if (array_key_exists($ref_id, self::$ref_id_to_forum_id_cache)) {
734 return self::$ref_id_to_forum_id_cache[
$ref_id];
737 self::preloadForumIdsByRefIds([$ref_id]);
739 return self::$ref_id_to_forum_id_cache[
$ref_id];
749 $ilDB = $DIC->database();
751 if (count($obj_ids) === 1) {
752 $in =
' objr.obj_id = ' .
$ilDB->quote(current($obj_ids),
'integer') .
' ';
754 $in =
$ilDB->in(
'objr.obj_id', $obj_ids,
false,
'integer');
757 SELECT frmd.top_pk, objr.ref_id, objr.obj_id 758 FROM object_reference objr 759 INNER JOIN frm_data frmd ON frmd.top_frm_fk = objr.obj_id 765 foreach ($obj_ids as $obj_id) {
766 self::$obj_id_to_forum_id_cache[$obj_id] = 0;
770 self::$obj_id_to_forum_id_cache[(
int) $row[
'obj_id']] = (
int) $row[
'top_pk'];
771 self::$ref_id_to_forum_id_cache[(
int) $row[
'ref_id']] = (
int) $row[
'top_pk'];
782 $ilDB = $DIC->database();
784 if (count($ref_ids) === 1) {
785 $in =
" objr.ref_id = " .
$ilDB->quote(current($ref_ids),
'integer') .
" ";
787 $in =
$ilDB->in(
'objr.ref_id', $ref_ids,
false,
'integer');
790 SELECT frmd.top_pk, objr.ref_id, objr.obj_id 791 FROM object_reference objr 792 INNER JOIN frm_data frmd ON frmd.top_frm_fk = objr.obj_id 798 foreach ($ref_ids as
$ref_id) {
799 if (!array_key_exists($ref_id, self::$ref_id_to_forum_id_cache)) {
800 self::$ref_id_to_forum_id_cache[
$ref_id] = 0;
805 self::$obj_id_to_forum_id_cache[(
int) $row[
'obj_id']] = (
int) $row[
'top_pk'];
806 self::$ref_id_to_forum_id_cache[(
int) $row[
'ref_id']] = (
int) $row[
'top_pk'];
818 $ilAccess = $DIC->access();
820 $ilDB = $DIC->database();
823 if (isset(self::$forum_statistics_cache[$ref_id])) {
824 return self::$forum_statistics_cache[
$ref_id];
829 'num_unread_posts' => 0,
833 $forumId = self::lookupForumIdByRefId($ref_id);
835 self::$forum_statistics_cache[
$ref_id] = $statistics;
836 return self::$forum_statistics_cache[
$ref_id];
840 $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
844 if ($is_post_activation_enabled && !$ilAccess->checkAccess(
'moderate_frm',
'', $ref_id)) {
845 $act_clause .=
' AND (frm_posts.pos_status = ' .
$ilDB->quote(
848 ) .
' OR frm_posts.pos_author_id = ' .
$ilDB->quote(
$ilUser->getId(),
'integer') .
') ';
851 $weeks = self::NEWS_NEW_CONSIDERATION_WEEKS;
857 ->setTimestamp(time() - 60 * 60 * 24 * 7 * $weeks)
858 ->format(
'Y-m-d H:i:s');
862 (SELECT COUNT(frm_posts.pos_pk) cnt 864 INNER JOIN frm_posts_tree tree1 865 ON tree1.pos_fk = frm_posts.pos_pk 866 AND tree1.parent_pos != 0 867 INNER JOIN frm_threads ON frm_posts.pos_thr_fk = frm_threads.thr_pk 868 WHERE frm_threads.thr_top_fk = %s $act_clause) 872 (SELECT COUNT(DISTINCT(frm_user_read.post_id)) cnt 874 INNER JOIN frm_posts ON frm_user_read.post_id = frm_posts.pos_pk 875 INNER JOIN frm_posts_tree tree1 876 ON tree1.pos_fk = frm_posts.pos_pk 877 AND tree1.parent_pos != 0 878 INNER JOIN frm_threads ON frm_threads.thr_pk = frm_posts.pos_thr_fk 879 WHERE frm_user_read.usr_id = %s AND frm_posts.pos_top_fk = %s $act_clause) 882 $types = [
'integer',
'integer',
'integer'];
883 $values = [$forumId,
$ilUser->getId(), $forumId];
887 $news_types = [
'integer',
'integer',
'integer',
'timestamp',
'integer'];
893 (SELECT COUNT(frm_posts.pos_pk) cnt 895 INNER JOIN frm_posts_tree tree1 896 ON tree1.pos_fk = frm_posts.pos_pk 897 AND tree1.parent_pos != 0 898 LEFT JOIN frm_user_read ON (post_id = frm_posts.pos_pk AND frm_user_read.usr_id = %s) 899 LEFT JOIN frm_thread_access ON (frm_thread_access.thread_id = frm_posts.pos_thr_fk AND frm_thread_access.usr_id = %s) 900 WHERE frm_posts.pos_top_fk = %s 901 AND ( (frm_posts.pos_update > frm_thread_access.access_old_ts) 902 OR (frm_thread_access.access_old IS NULL AND frm_posts.pos_update > %s) 904 AND frm_posts.pos_author_id != %s 905 AND frm_user_read.usr_id IS NULL $act_clause)";
907 $types = array_merge($types, $news_types);
908 $values = array_merge($values, $news_values);
911 $mapping = array_keys($statistics);
917 for (
$i = 0;
$i <= 2;
$i++) {
920 $statistics[$mapping[
$i]] = (
int) ((is_array($row) ? $row[
'cnt'] : 0));
924 $statistics[$mapping[
$i]] = $statistics[$mapping[
$i - 1]] - $statistics[$mapping[
$i]];
929 SELECT COUNT(frm_posts.pos_pk) cnt 931 INNER JOIN frm_posts_tree tree1 932 ON tree1.pos_fk = frm_posts.pos_pk 933 AND tree1.parent_pos != 0 934 INNER JOIN frm_threads ON frm_posts.pos_thr_fk = frm_threads.thr_pk 935 WHERE frm_threads.thr_top_fk = %s $act_clause 937 $types = [
'integer'];
938 $values = [$forumId];
947 'num_posts' => (
int) $row[
'cnt'],
948 'num_unread_posts' => (
int) $row[
'cnt'],
949 'num_new_posts' => (
int) $row[
'cnt']
953 self::$forum_statistics_cache[
$ref_id] = $statistics;
955 return self::$forum_statistics_cache[
$ref_id];
962 $ilAccess = $DIC->access();
964 $ilDB = $DIC->database();
966 if (array_key_exists($ref_id, self::$forum_last_post_cache)) {
967 return self::$forum_last_post_cache[
$ref_id];
970 $forumId = self::lookupForumIdByRefId($ref_id);
972 self::$forum_last_post_cache[
$ref_id] = null;
973 return self::$forum_last_post_cache[
$ref_id];
977 if (!$ilAccess->checkAccess(
'moderate_frm',
'', $ref_id)) {
978 $act_clause .=
' AND (frm_posts.pos_status = ' .
$ilDB->quote(
981 ) .
' OR frm_posts.pos_author_id = ' .
$ilDB->quote(
$ilUser->getId(),
'integer') .
') ';
984 $ilDB->setLimit(1, 0);
988 INNER JOIN frm_posts_tree tree1 989 ON tree1.pos_fk = frm_posts.pos_pk 990 AND tree1.parent_pos != 0 991 WHERE pos_top_fk = %s $act_clause 992 ORDER BY pos_date DESC 1002 self::$forum_last_post_cache[
$ref_id] = null;
1003 return self::$forum_last_post_cache[
$ref_id];
1007 $casted_data[
'pos_pk'] = (
int)
$data[
'pos_pk'];
1008 $casted_data[
'pos_top_fk'] = (
int)
$data[
'pos_top_fk'];
1009 $casted_data[
'pos_thr_fk'] = (
int)
$data[
'pos_thr_fk'];
1010 $casted_data[
'pos_usr_alias'] = (string)
$data[
'pos_usr_alias'];
1011 $casted_data[
'pos_subject'] = (string)
$data[
'pos_subject'];
1012 $casted_data[
'pos_date'] = (string)
$data[
'pos_date'];
1013 $casted_data[
'pos_update'] = (string)
$data[
'pos_update'];
1014 $casted_data[
'update_user'] = (
int)
$data[
'update_user'];
1015 $casted_data[
'pos_cens'] = (
int)
$data[
'pos_cens'];
1016 $casted_data[
'pos_cens_com'] = (string)
$data[
'pos_cens_com'];
1017 $casted_data[
'notify'] = (
int)
$data[
'notify'];
1018 $casted_data[
'import_name'] = (string)
$data[
'import_name'];
1019 $casted_data[
'pos_status'] = (
int)
$data[
'pos_status'];
1020 $casted_data[
'pos_message'] = (string)
$data[
'pos_message'];
1021 $casted_data[
'pos_author_id'] = (
int)
$data[
'pos_author_id'];
1022 $casted_data[
'pos_display_user_id'] = (
int)
$data[
'pos_display_user_id'];
1023 $casted_data[
'is_author_moderator'] = (
int)
$data[
'is_author_moderator'];
1024 $casted_data[
'pos_cens_date'] = (string)
$data[
'pos_cens_date'];
1025 $casted_data[
'pos_activation_date'] = (string)
$data[
'pos_activation_date'];
1027 self::$forum_last_post_cache[
$ref_id] = $casted_data;
1029 return self::$forum_last_post_cache[
$ref_id];
1041 $ilAccess = $DIC->access();
1043 $ilDB = $DIC->database();
1046 $act_inner_clause =
'';
1047 if (!$ilAccess->checkAccess(
'moderate_frm',
'', $ref_id)) {
1048 $act_clause .=
" AND (t1.pos_status = " .
$ilDB->quote(
1051 ) .
" OR t1.pos_author_id = " .
$ilDB->quote(
$ilUser->getId(),
"integer") .
") ";
1052 $act_inner_clause .=
" AND (t3.pos_status = " .
$ilDB->quote(
1055 ) .
" OR t3.pos_author_id = " .
$ilDB->quote(
$ilUser->getId(),
"integer") .
") ";
1058 $in =
$ilDB->in(
"t1.pos_thr_fk", $thread_ids,
false,
'integer');
1059 $inner_in =
$ilDB->in(
"t3.pos_thr_fk", $thread_ids,
false,
'integer');
1062 SELECT t1.pos_display_user_id, t1.update_user 1064 INNER JOIN frm_posts_tree tree1 ON tree1.pos_fk = t1.pos_pk AND tree1.parent_pos != 0 1066 SELECT t3.pos_thr_fk, MAX(t3.pos_date) pos_date 1068 INNER JOIN frm_posts_tree tree2 ON tree2.pos_fk = t3.pos_pk AND tree2.parent_pos != 0 1069 WHERE $inner_in $act_inner_clause 1070 GROUP BY t3.pos_thr_fk 1071 ) t2 ON t2.pos_thr_fk = t1.pos_thr_fk AND t2.pos_date = t1.pos_date 1072 WHERE $in $act_clause 1073 GROUP BY t1.pos_thr_fk, t1.pos_display_user_id, t1.update_user 1079 while ($row =
$ilDB->fetchAssoc(
$res)) {
1080 if ((
int) $row[
'pos_display_user_id']) {
1081 $usr_ids[] = (
int) $row[
'pos_display_user_id'];
1083 if ((
int) $row[
'update_user']) {
1084 $usr_ids[] = (
int) $row[
'update_user'];
1088 return array_unique($usr_ids);
1091 public static function mergeForumUserRead(
int $merge_source_thread_id,
int $merge_target_thread_id): void
1095 $DIC->database()->update(
1097 [
'thread_id' => [
'integer', $merge_target_thread_id]],
1098 [
'thread_id' => [
'integer', $merge_source_thread_id]]
1104 $res = $this->db->query(
1105 'SELECT COUNT(is_sticky) num_sticky FROM frm_threads 1106 INNER JOIN frm_data ON top_pk = thr_top_fk 1107 WHERE frm_data.top_frm_fk = ' . $this->db->quote($this->getId(),
'integer') .
' 1108 AND is_sticky = ' . $this->db->quote(1,
'integer')
1110 if ($row = $this->db->fetchAssoc(
$res)) {
1111 return (
int) $row[
'num_sticky'];
1124 $sql =
'SELECT DISTINCT page_id FROM page_object WHERE parent_id = %s AND parent_type = %s';
1125 $res = $this->db->queryF(
1127 [
'integer',
'text'],
1131 while ($row = $this->db->fetchAssoc(
$res)) {
1132 $pageObjIds[] = (
int) $row[
'page_id'];
__construct(int $a_id=0, bool $a_call_by_reference=true)
static mergeForumUserRead(int $merge_source_thread_id, int $merge_target_thread_id)
Class Forum core functions for forum.
static _lookupThreadSubject(int $a_thread_id)
static array $forum_statistics_cache
static _getDefaultVisibilityForRefId(int $a_ref_id)
Get default visibility for reference id.
static lookupForumIdByObjId(int $obj_id)
const NEWS_NEW_CONSIDERATION_WEEKS
static _lookupModeratorRole(int $a_ref_id)
updateModeratorRole(int $role_id)
static _deleteAccessEntries(int $a_thread_id)
static getUserIdsOfLastPostsByRefIdAndThreadIds(int $ref_id, array $thread_ids)
ILIAS DI RBACServices $rbac
deleteDraftsByForumId(int $forum_id)
static createDefaultRole(string $a_title, string $a_description, string $a_tpl_name, int $a_ref_id)
static preloadForumIdsByObjIds(array $obj_ids)
static lookupTranslations(string $a_parent_type, int $a_id)
Lookup translations.
static lookupForumIdByRefId(int $ref_id)
static now()
Return current timestamp in Y-m-d H:i:s format.
markAllThreadsRead(int $a_usr_id)
static _deleteReadEntries(int $a_post_id)
Class ilForumDraftHistory.
static getInstance(int $a_obj_id=0)
static _lookupValue(string $a_module, string $a_keyword)
static _deleteUser(int $a_usr_id)
updateMoficationUserId(int $usr_id)
static lookupStatisticsByRefId(int $ref_id)
static _updateOldAccess(int $a_usr_id)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
static _write(string $a_type, string $a_setting, string $a_value, int $a_user=0, int $a_block_id=0)
Write setting to database.
static _lookupObjectId(int $ref_id)
setThreadSorting(int $a_thr_pk, int $a_sorting_value)
static array $obj_id_to_forum_id_cache
setOfflineStatus(bool $status)
static array $forum_last_post_cache
updateLastAccess(int $a_usr_id, int $a_thread_id)
getCountUnread(int $a_usr_id, int $a_thread_id=0, bool $ignoreRoot=false)
const FORUM_OVERVIEW_WITH_NEW_POSTS
static array $ref_id_to_forum_id_cache
static lookupLastPostByRefId(int $ref_id)
isRead($a_usr_id, $a_post_id)
__construct(Container $dic, ilPlugin $plugin)
This class handles all operations on files for the forum object.
static _getInstance(int $a_copy_id)
markPostUnread(int $a_user_id, int $a_post_id)
setPermissions(int $parent_ref_id)
markThreadRead(int $a_usr_id, int $a_thread_id)
static preloadForumIdsByRefIds(array $ref_ids)
markPostRead(int $a_usr_id, int $a_thread_id, int $a_post_id)
cloneAutoGeneratedRoles(self $new_obj)
ilClone(int $a_new_obj_id, int $a_new_pos_id)