77 $this->error = $DIC[
'ilErr'];
78 $this->lng = $DIC->language();
79 $this->db = $DIC->database();
80 $this->
user = $DIC->user();
102 static $lngCache = array();
107 if (!isset($lngCache[$languageShorthandle])) {
108 $lngCache[$languageShorthandle] =
new ilLanguage($languageShorthandle);
109 $lngCache[$languageShorthandle]->loadLanguageModule(
'forum');
112 return $lngCache[$languageShorthandle];
122 if (!isset($a_obj_id)) {
123 $message = get_class($this) .
"::setForumId(): No obj_id given!";
124 $this->error->raiseError(
$message, $this->error->WARNING);
127 $this->
id = $a_obj_id;
137 if (!isset($a_ref_id)) {
138 $message = get_class($this) .
"::setForumRefId(): No ref_id given!";
139 $this->error->raiseError(
$message, $this->error->WARNING);
142 $this->ref_id = $a_ref_id;
162 return $this->ref_id;
174 die($this->className .
"::setOrderField(): No orderField given.");
200 die($this->className .
"::setDbTable(): No database table given.");
227 $this->mdb2Query = $query_string;
228 $this->mdb2DataValue = $data_value;
229 $this->mdb2DataType = $data_type;
240 if ($this->mdb2Query !=
'') {
251 if ($this->mdb2DataValue !=
'') {
262 if ($this->mdb2DataType !=
'') {
299 $data_type = array();
300 $data_value = array();
302 $query =
'SELECT * FROM frm_data WHERE ';
309 $res = $this->db->queryf(
$query, $data_type, $data_value);
316 $row[
"top_name"] = trim(
$row[
"top_name"]);
317 $row[
"top_description"] = nl2br(
$row[
"top_description"]);
326 if (!is_array(
$row) || !count(
$row)) {
330 $row[
'top_name'] = trim(
$row[
'top_name']);
331 $row[
'top_description'] = nl2br(
$row[
'top_description']);
344 $data_type = array();
345 $data_value = array();
347 $query =
'SELECT * FROM frm_threads WHERE ';
354 $sql_res = $this->db->queryf(
$query, $data_type, $data_value);
355 $result = $this->db->fetchAssoc($sql_res);
370 $res = $this->db->queryf(
372 SELECT frm_posts.*, usr_data.lastname FROM frm_posts, usr_data 374 AND pos_display_user_id = usr_id',
382 $row[
"pos_message"] = nl2br(
$row[
"pos_message"]);
390 $ilDB = $DIC->database();
394 SELECT * FROM frm_posts WHERE pos_pk = %s',
400 return $row->pos_message;
421 public function generatePost($forum_id, $thread_id, $author_id, $display_user_id,
$message, $parent_pos, $notify, $subject =
'', $alias =
'', $date =
'', $status = 1, $send_activation_mail = 0)
424 $objNewPost->setForumId($forum_id);
425 $objNewPost->setThreadId($thread_id);
426 $objNewPost->setSubject($subject);
428 $objNewPost->setDisplayUserId($display_user_id);
429 $objNewPost->setUserAlias($alias);
430 $objNewPost->setPosAuthorId($author_id);
434 if ($frm_settings->getMarkModeratorPosts() == 1) {
435 self::_isModerator($this->
getForumRefId(), $author_id) ? $is_moderator = true : $is_moderator =
false;
437 $is_moderator =
false;
439 $objNewPost->setIsAuthorModerator($is_moderator);
442 $objNewPost->setCreateDate(date(
"Y-m-d H:i:s"));
444 if (strpos($date,
"-") > 0) {
445 $objNewPost->setCreateDate($date);
447 $objNewPost->setCreateDate(date(
"Y-m-d H:i:s", $date));
451 $objNewPost->setPostActivationDate($objNewPost->getCreateDate());
455 $objNewPost->setNotification($notify);
456 $objNewPost->setStatus($status);
457 $objNewPost->insert();
460 if ($parent_pos == 0) {
461 $this->
addPostTree($objNewPost->getThreadId(), $objNewPost->getId(), $objNewPost->getCreateDate());
463 $this->
insertPostNode($objNewPost->getId(), $parent_pos, $objNewPost->getThreadId(), $objNewPost->getCreateDate());
467 $lastPost = $objNewPost->getForumId() .
"#" . $objNewPost->getThreadId() .
"#" . $objNewPost->getId();
470 $this->db->manipulateF(
473 SET thr_num_posts = thr_num_posts + 1, 476 array(
'text',
'integer'),
477 array($lastPost, $objNewPost->getThreadId())
481 $this->db->manipulateF(
484 SET top_num_posts = top_num_posts + 1, 487 array(
'text',
'integer'),
488 array($lastPost, $objNewPost->getForumId())
493 $forum_obj->markPostRead($objNewPost->getPosAuthorId(), $objNewPost->getThreadId(), $objNewPost->getId());
496 if ($status && $parent_pos > 0) {
498 $news_item->setContext($forum_obj->getId(),
'frm', $objNewPost->getId(),
'pos');
500 $news_item->setTitle($objNewPost->getSubject());
502 if ($objNewPost->getMessage() != strip_tags($objNewPost->getMessage())) {
503 $news_item->setContentHtml(
true);
506 $news_item->setUserId($display_user_id);
508 $news_item->create();
511 return $objNewPost->getId();
529 bool $withFirstVisibleEntry =
true 538 if ($notify_posts == 1) {
542 $this->db->manipulateF(
545 SET top_num_threads = top_num_threads + 1 566 if (!$withFirstVisibleEntry) {
595 public function moveThreads($thread_ids = array(), $src_ref_id = 0, $dest_top_frm_fk = 0)
599 $errorMessages = array();
601 if (is_numeric($src_top_frm_fk) && $src_top_frm_fk > 0 && is_numeric($dest_top_frm_fk) && $dest_top_frm_fk > 0) {
610 if ($oldFrmData[
'top_pk'] && $newFrmData[
'top_pk']) {
615 foreach ($thread_ids as
$id) {
619 $numPosts = $objTmpThread->movePosts(
621 $oldFrmData[
'top_pk'],
623 $newFrmData[
'top_pk']
626 if (($last_post_string = $objTmpThread->getLastPostString()) !=
'') {
627 $last_post_string = explode(
'#', $last_post_string);
628 $last_post_string[0] = $newFrmData[
'top_pk'];
629 $last_post_string = implode(
'#', $last_post_string);
630 $objTmpThread->setLastPostString($last_post_string);
633 $visits += $objTmpThread->getVisits();
635 $moved_posts += $numPosts;
638 $objTmpThread->setForumId($newFrmData[
'top_pk']);
639 $objTmpThread->update();
641 unset($objTmpThread);
643 $errorMessages[] = sprintf($this->lng->txt(
'frm_move_invalid_file_type'), $objTmpThread->getSubject());
648 if ($moved_threads > 0 || $moved_posts > 0 || $visits > 0) {
650 $this->db->setLimit(1);
651 $res = $this->db->queryf(
653 SELECT pos_thr_fk, pos_pk 655 WHERE pos_top_fk = %s 656 ORDER BY pos_date DESC',
658 array($oldFrmData[
'top_pk'])
661 $row = $this->db->fetchObject(
$res);
662 $last_post_src = $oldFrmData[
'top_pk'] .
'#' .
$row->pos_thr_fk .
'#' .
$row->pos_pk;
664 $this->db->manipulateF(
667 SET top_num_posts = top_num_posts - %s, 668 top_num_threads = top_num_threads - %s, 669 visits = visits - %s, 672 array(
'integer',
'integer',
'integer',
'text',
'integer'),
677 $oldFrmData[
'top_pk'])
681 $this->db->setLimit(1);
682 $res = $this->db->queryf(
684 SELECT pos_thr_fk, pos_pk 686 WHERE pos_top_fk = %s 687 ORDER BY pos_date DESC',
689 array($newFrmData[
'top_kp'])
692 $row = $this->db->fetchObject(
$res);
693 $last_post_dest = $newFrmData[
'top_pk'] .
'#' .
$row->pos_thr_fk .
'#' .
$row->pos_pk;
695 $this->db->manipulateF(
698 SET top_num_posts = top_num_posts + %s, 699 top_num_threads = top_num_threads + %s, 700 visits = visits + %s, 703 array(
'integer',
'integer',
'integer',
'text',
'integer'),
704 array($moved_posts, $moved_threads, $visits, $last_post_dest, $newFrmData[
'top_pk'])
709 return $errorMessages;
723 $cens_date = date(
"Y-m-d H:i:s");
725 $this->db->manipulateF(
728 SET pos_cens_com = %s, 733 array(
'text',
'timestamp',
'integer',
'integer',
'integer'),
734 array(
$message, $cens_date, $cens,
$GLOBALS[
'DIC'][
'ilUser']->getId(), $pos_pk)
750 $news_item->setContentHtml(
true);
752 $news_item->setContentHtml(
false);
755 $news_item->update();
758 $res = $this->db->queryf(
760 SELECT * FROM frm_posts 766 $rec = $this->db->fetchAssoc(
$res);
770 $news_item->setContent(nl2br($this->
prepareText($rec[
"pos_message"], 0)));
771 if ($rec[
"pos_message"] != strip_tags($rec[
"pos_message"])) {
772 $news_item->setContentHtml(
true);
774 $news_item->setContentHtml(
false);
777 $news_item->update();
781 $GLOBALS[
'ilAppEventHandler']->raise(
799 public function deletePost($postIdOrArray, $raiseEvents =
true)
801 if (is_numeric($postIdOrArray)) {
804 $p_node = $postIdOrArray;
808 $GLOBALS[
'ilAppEventHandler']->raise(
814 'thread_deleted' => ($p_node[
"parent"] == 0) ?
true :
false 824 $obj_history->deleteHistoryByPostIds($del_id);
827 $obj_draft->deleteDraftsByPostIds($del_id);
830 foreach ($del_id as $post_id) {
837 $dead_pos = count($del_id);
841 if ($p_node[
"parent"] == 0) {
846 $dead_thr = $p_node[
"tree"];
848 $this->db->manipulateF(
850 DELETE FROM frm_threads 853 array($p_node[
'tree'])
857 $this->db->manipulateF(
860 SET top_num_threads = top_num_threads - 1 861 WHERE top_frm_fk = %s',
867 $posset = $this->db->queryf(
869 SELECT * FROM frm_posts 870 WHERE pos_thr_fk = %s',
872 array($p_node[
'tree'])
875 while ($posrec = $this->db->fetchAssoc($posset)) {
884 $news_item->delete();
889 foreach (
$mobs as $mob) {
901 $this->db->manipulateF(
903 DELETE FROM frm_posts 904 WHERE pos_thr_fk = %s',
906 array($p_node[
'tree'])
910 for (
$i = 0;
$i < $dead_pos;
$i++) {
911 $this->db->manipulateF(
913 DELETE FROM frm_posts 928 $news_item->delete();
933 foreach (
$mobs as $mob) {
945 $this->db->manipulateF(
948 SET thr_num_posts = thr_num_posts - %s 950 array(
'integer',
'integer'),
951 array($dead_pos, $p_node[
'tree'])
955 $res1 = $this->db->queryf(
957 SELECT * FROM frm_posts 958 WHERE pos_thr_fk = %s 959 ORDER BY pos_date DESC',
961 array($p_node[
'tree'])
964 if ($res1->numRows() == 0) {
969 while ($selData = $this->db->fetchAssoc($res1)) {
974 $lastPost_thr = $selData[
"pos_top_fk"] .
"#" . $selData[
"pos_thr_fk"] .
"#" . $selData[
"pos_pk"];
979 $this->db->manipulateF(
982 SET thr_last_post = %s 984 array(
'text',
'integer'),
985 array($lastPost_thr, $p_node[
'tree'])
990 $this->db->manipulateF(
993 SET top_num_posts = top_num_posts - %s 994 WHERE top_frm_fk = %s',
995 array(
'integer',
'integer'),
996 array($dead_pos, $this->
id)
1000 $res2 = $this->db->queryf(
1002 SELECT * FROM frm_posts, frm_data 1003 WHERE pos_top_fk = top_pk 1005 ORDER BY pos_date DESC',
1010 if ($res2->numRows() == 0) {
1015 while ($selData = $this->db->fetchAssoc($res2)) {
1020 $lastPost_top = $selData[
"pos_top_fk"] .
"#" . $selData[
"pos_thr_fk"] .
"#" . $selData[
"pos_pk"];
1025 $this->db->manipulateF(
1028 SET top_last_post = %s 1029 WHERE top_frm_fk = %s',
1030 array(
'text',
'integer'),
1031 array($lastPost_top, $this->
id)
1046 $frm_overview_setting = (int) $this->
settings->get(
'forum_overview');
1048 $is_post_activation_enabled = $frm_props->isPostActivationEnabled();
1050 $user_id = $this->
user->getId();
1052 $excluded_ids_condition =
'';
1053 if (isset(
$params[
'excluded_ids']) && is_array(
$params[
'excluded_ids']) &&
$params[
'excluded_ids']) {
1054 $excluded_ids_condition =
' AND ' . $this->db->in(
'thr_pk',
$params[
'excluded_ids'],
true,
'integer') .
' ';
1057 if (!in_array(strtolower(
$params[
'order_column']), array(
'lp_date',
'rating',
'thr_subject',
'num_posts',
'num_visit'))) {
1058 $params[
'order_column'] =
'post_date';
1060 if (!in_array(strtolower(
$params[
'order_direction']), array(
'asc',
'desc'))) {
1061 $params[
'order_direction'] =
'desc';
1064 $cnt_active_pos_query =
'';
1065 $cnt_join_type =
'LEFT';
1066 if ($is_post_activation_enabled && !
$params[
'is_moderator']) {
1067 $cnt_active_pos_query =
" AND (pos_status = {$this->db->quote(1, 'integer')} OR pos_author_id = {$this->db->quote($user_id, 'integer')}) ";
1068 $cnt_join_type =
"INNER";
1071 "SELECT COUNT(DISTINCT(thr_pk)) cnt 1073 {$cnt_join_type} JOIN frm_posts 1074 ON pos_thr_fk = thr_pk {$cnt_active_pos_query} 1075 WHERE thr_top_fk = %s {$excluded_ids_condition} 1077 $res = $this->db->queryF(
$query, array(
'integer'), array($a_topic_id));
1078 $cntData = $this->db->fetchAssoc(
$res);
1079 $cnt = (int) $cntData[
'cnt'];
1082 $active_inner_query =
'';
1084 if ($is_post_activation_enabled && !
$params[
'is_moderator']) {
1085 $active_query =
' AND (pos_status = %s OR pos_author_id = %s) ';
1086 $active_inner_query =
' AND (ipos.pos_status = %s OR ipos.pos_author_id = %s) ';
1087 $having =
' HAVING num_posts > 0';
1092 $data_types = array();
1094 $optional_fields =
'';
1095 if ($frm_props->isIsThreadRatingEnabled()) {
1096 $optional_fields =
',avg_rating';
1098 if ($frm_props->getThreadSorting() == 1) {
1099 $optional_fields =
',thread_sorting';
1102 $additional_sort =
'';
1103 if ($frm_props->getThreadSorting()) {
1104 $additional_sort .=
' , thread_sorting ASC ';
1107 if (
$params[
'order_column'] ==
'thr_subject') {
1108 $dynamic_columns = array(
', thr_subject ' .
$params[
'order_direction']);
1109 } elseif (
$params[
'order_column'] ==
'num_posts') {
1110 $dynamic_columns = array(
', thr_num_posts ' .
$params[
'order_direction']);
1111 } elseif (
$params[
'order_column'] ==
'num_visit') {
1112 $dynamic_columns = array(
', visits ' .
$params[
'order_direction']);
1114 $dynamic_columns = array(
', post_date ' .
$params[
'order_direction']);
1117 if ($frm_props->isIsThreadRatingEnabled()) {
1118 $dynamic_columns[] =
' ,avg_rating ' .
$params[
'order_direction'];
1120 if (
'rating' == strtolower(
$params[
'order_column'])) {
1121 $dynamic_columns = array_reverse($dynamic_columns);
1123 $additional_sort .= implode(
' ', $dynamic_columns);
1125 if (!$this->
user->isAnonymous()) {
1127 (CASE WHEN COUNT(DISTINCT(notification_id)) > 0 THEN 1 ELSE 0 END) usr_notification_is_enabled, 1128 MAX(pos_date) post_date, 1129 SUM(tree1.parent_pos != 0) num_posts, 1130 SUM(tree1.parent_pos != 0) - SUM(tree1.parent_pos != 0 AND postread.post_id IS NOT NULL) num_unread_posts, ";
1135 (SELECT COUNT(DISTINCT(ipos.pos_pk)) 1137 INNER JOIN frm_posts_tree treenew 1138 ON treenew.pos_fk = ipos.pos_pk 1139 LEFT JOIN frm_user_read iread ON iread.post_id = ipos.pos_pk AND iread.usr_id = %s 1140 LEFT JOIN frm_thread_access iacc ON (iacc.thread_id = ipos.pos_thr_fk AND iacc.usr_id = %s) 1141 WHERE ipos.pos_thr_fk = thr_pk 1142 AND treenew.parent_pos != 0 1143 AND (ipos.pos_update > iacc.access_old_ts 1145 (iacc.access_old IS NULL AND (ipos.pos_update > " . $this->db->quote(date(
'Y-m-d H:i:s', NEW_DEADLINE),
'timestamp') .
")) 1148 AND ipos.pos_author_id != %s 1149 AND iread.usr_id IS NULL $active_inner_query 1153 $query .=
" thr_pk, thr_top_fk, thr_subject, thr_author_id, thr_display_user_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed 1157 LEFT JOIN frm_notification 1158 ON frm_notification.thread_id = thr_pk 1159 AND frm_notification.user_id = %s 1162 ON pos_thr_fk = thr_pk $active_query 1163 LEFT JOIN frm_posts_tree tree1 1164 ON tree1.pos_fk = frm_posts.pos_pk 1165 LEFT JOIN frm_user_read postread 1166 ON postread.post_id = pos_pk 1167 AND postread.usr_id = %s";
1169 $query .=
" WHERE thr_top_fk = %s 1170 {$excluded_ids_condition} 1171 GROUP BY thr_pk, thr_top_fk, thr_subject, thr_author_id, thr_display_user_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed 1174 ORDER BY is_sticky DESC {$additional_sort}, thr_date DESC";
1179 $data_types[] =
'integer';
1180 $data_types[] =
'integer';
1181 $data_types[] =
'integer';
1182 if ($is_post_activation_enabled && !
$params[
'is_moderator']) {
1183 array_push($data_types,
'integer',
'integer');
1186 $data_types[] =
'integer';
1187 if ($is_post_activation_enabled && !
$params[
'is_moderator']) {
1188 array_push($data_types,
'integer',
'integer');
1190 $data_types[] =
'integer';
1191 $data_types[] =
'integer';
1198 if ($is_post_activation_enabled && !
$params[
'is_moderator']) {
1199 array_push(
$data,
'1', $user_id);
1203 if ($is_post_activation_enabled && !
$params[
'is_moderator']) {
1204 array_push(
$data,
'1', $user_id);
1207 $data[] = $a_topic_id;
1210 0 usr_notification_is_enabled, 1211 MAX(pos_date) post_date, 1212 COUNT(DISTINCT(pos_pk)) num_posts, 1213 COUNT(DISTINCT(pos_pk)) num_unread_posts, 1214 COUNT(DISTINCT(pos_pk)) num_new_posts, 1215 thr_pk, thr_top_fk, thr_subject, thr_author_id, thr_display_user_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed 1220 ON pos_thr_fk = thr_pk $active_query 1221 LEFT JOIN frm_posts_tree tree1 1222 ON tree1.pos_fk = frm_posts.pos_pk 1225 $query .=
" WHERE thr_top_fk = %s 1226 {$excluded_ids_condition} 1227 GROUP BY thr_pk, thr_top_fk, thr_subject, thr_author_id, thr_display_user_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed 1230 ORDER BY is_sticky DESC {$additional_sort}, thr_date DESC";
1232 if ($is_post_activation_enabled && !
$params[
'is_moderator']) {
1233 array_push($data_types,
'integer',
'integer');
1235 $data_types[] =
'integer';
1236 if ($is_post_activation_enabled && !
$params[
'is_moderator']) {
1237 array_push(
$data,
'1', $user_id);
1239 $data[] = $a_topic_id;
1242 if ($limit || $offset) {
1243 $this->db->setLimit($limit, $offset);
1248 while (
$row = $this->db->fetchAssoc(
$res)) {
1250 $thread->assignData(
$row);
1251 $threads[
$row[
'thr_pk']] = $thread;
1252 $threadIds[] = $row[
'thr_pk'];
1255 $inner_last_active_post_condition =
"";
1256 if ($is_post_activation_enabled && !
$params[
'is_moderator']) {
1257 $inner_last_active_post_condition = sprintf(
1258 " AND (iposts.pos_status = %s OR (iposts.pos_status = %s AND iposts.pos_author_id = %s)) ",
1259 $this->db->quote(1,
'integer'),
1260 $this->db->quote(0,
'integer'),
1261 $this->db->quote($this->
user->getId(),
'integer')
1265 $post_res = $this->db->query(
1270 SELECT pos_thr_fk, MAX(iposts.pos_date) i_pos_date 1271 FROM frm_posts iposts 1272 WHERE ' . $this->db->in(
'iposts.pos_thr_fk', $threadIds,
false,
'integer') .
' 1273 ' . $inner_last_active_post_condition .
' 1275 ) opost ON frm_posts.pos_thr_fk = opost.pos_thr_fk AND frm_posts.pos_date = opost.i_pos_date' 1278 while ($post_row = $this->db->fetchAssoc($post_res)) {
1281 $tmp_obj->setPosAuthorId($post_row[
'pos_author_id']);
1282 $tmp_obj->setDisplayUserId($post_row[
'pos_display_user_id']);
1283 $tmp_obj->setUserAlias($post_row[
'pos_usr_alias']);
1284 $tmp_obj->setImportName($post_row[
'import_name']);
1285 $tmp_obj->setId($post_row[
'pos_pk']);
1286 $tmp_obj->setCreateDate($post_row[
'pos_date']);
1288 $threads[$post_row[
'pos_thr_fk']]->setLastPostForThreadOverview($tmp_obj);
1292 'items' => $threads,
1303 $statistic = array();
1305 $data_types = array();
1308 $query =
"SELECT COUNT(f.pos_display_user_id) ranking, u.login, p.value, u.lastname, u.firstname 1310 INNER JOIN frm_posts_tree t 1311 ON f.pos_pk = t.pos_fk 1312 INNER JOIN frm_threads th 1313 ON t.thr_fk = th.thr_pk 1314 INNER JOIN usr_data u 1315 ON u.usr_id = f.pos_display_user_id 1316 INNER JOIN frm_data d 1317 ON d.top_pk = f.pos_top_fk 1318 LEFT JOIN usr_pref p 1319 ON p.usr_id = u.usr_id AND p.keyword = %s 1320 WHERE 1 = 1 AND t.parent_pos != 0";
1322 array_push($data_types,
'text');
1323 array_push(
$data,
'public_profile');
1325 if (!$is_moderator) {
1326 $query .=
' AND (pos_status = %s 1328 AND pos_author_id = %s ))';
1330 array_push($data_types,
'integer',
'integer',
'integer');
1331 array_push(
$data,
'1',
'0', $this->
user->getId());
1334 $query .=
' AND d.top_frm_fk = %s 1335 GROUP BY pos_display_user_id, u.login, p.value,u.lastname, u.firstname';
1337 array_push($data_types,
'integer');
1343 while (
$row = $this->db->fetchAssoc(
$res)) {
1344 $statistic[$counter][] =
$row[
'ranking'];
1345 $statistic[$counter][] =
$row[
'login'];
1349 if (!$this->
user->isAnonymous() && in_array(
$row[
'value'], array(
'y',
'g')) ||
1350 $this->
user->isAnonymous() &&
'g' ==
$row[
'value']) {
1351 $lastname =
$row[
'lastname'];
1352 $firstname =
$row[
'firstname'];
1355 $statistic[$counter][] = $lastname;
1356 $statistic[$counter][] = $firstname;
1361 return is_array($statistic) ? $statistic : array();
1373 $res = $this->db->queryf(
1375 SELECT * FROM frm_posts_tree 1377 AND parent_pos = %s',
1378 array(
'integer',
'integer'),
1379 array($a_thread_id,
'0')
1382 $row = $this->db->fetchObject(
$res);
1384 return $row->pos_fk ?
$row->pos_fk : 0;
1408 $rbacreview = $DIC->rbac()->review();
1410 $role_arr = $rbacreview->getRolesOfRoleFolder($a_ref_id);
1411 foreach ($role_arr as $role_id) {
1413 return $rbacreview->assignedUsers($role_id);
1430 if (!self::$moderators_by_ref_id_map[$a_ref_id]) {
1431 self::$moderators_by_ref_id_map[$a_ref_id] = self::_getModerators($a_ref_id);
1433 return in_array($a_usr_id, self::$moderators_by_ref_id_map[$a_ref_id]);
1445 $res = $this->db->queryf(
1447 SELECT * FROM frm_data 1448 INNER JOIN frm_posts ON pos_top_fk = top_pk 1449 INNER JOIN frm_posts_tree tree1 1450 ON tree1.pos_fk = frm_posts.pos_pk 1451 AND tree1.parent_pos != 0 1452 WHERE top_frm_fk = %s 1453 AND pos_author_id = %s',
1454 array(
'integer',
'integer'),
1458 return $res->numRows();
1463 $res = $this->db->queryf(
1465 SELECT * FROM frm_data 1466 INNER JOIN frm_posts ON pos_top_fk = top_pk 1467 INNER JOIN frm_posts_tree tree1 1468 ON tree1.pos_fk = frm_posts.pos_pk 1469 AND tree1.parent_pos != 0 1470 WHERE top_frm_fk = %s 1471 AND (pos_status = %s 1473 AND pos_author_id = %s 1476 AND pos_author_id = %s',
1477 array(
'integer',
'integer',
'integer',
'integer',
'integer'),
1478 array($this->
getForumId(),
'1',
'0', $this->
user->getId(), $a_user_id)
1481 return $res->numRows();
1502 public function addPostTree($a_tree_id, $a_node_id = -1, $a_date =
'')
1504 $a_date = $a_date ? $a_date : date(
"Y-m-d H:i:s");
1506 if ($a_node_id <= 0) {
1507 $a_node_id = $a_tree_id;
1510 $nextId = $this->db->nextId(
'frm_posts_tree');
1512 $this->db->manipulateF(
1514 INSERT INTO frm_posts_tree 1524 VALUES(%s, %s, %s, %s, %s, %s, %s, %s )',
1525 array(
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'timestamp'),
1526 array($nextId, $a_tree_id, $a_node_id,
'0',
'1',
'2',
'1', $a_date)
1541 $a_date = $a_date ? $a_date : date(
"Y-m-d H:i:s");
1544 $sql_res = $this->db->queryf(
1546 SELECT * FROM frm_posts_tree 1549 array(
'integer',
'integer'),
1550 array($a_parent_id, $tree_id)
1553 $res = $this->db->fetchObject($sql_res);
1561 $this->db->manipulateF(
1563 UPDATE frm_posts_tree 1575 array(
'integer',
'integer',
'integer'),
1576 array($left, $left, $tree_id)
1579 $depth = $this->
getPostDepth($a_parent_id, $tree_id) + 1;
1582 $nextId = $this->db->nextId(
'frm_posts_tree');
1583 $this->db->manipulateF(
1585 INSERT INTO frm_posts_tree 1595 VALUES(%s,%s,%s, %s, %s, %s,%s, %s)',
1596 array(
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'timestamp'),
1618 $sql_res = $this->db->queryf(
1620 SELECT depth FROM frm_posts_tree 1623 array(
'integer',
'integer'),
1624 array($a_node_id, $tree_id)
1627 $res = $this->db->fetchObject($sql_res);
1643 $res = $this->db->queryf(
1645 SELECT * FROM frm_posts, frm_posts_tree 1646 WHERE pos_pk = pos_fk 1649 array(
'integer',
'integer'),
1650 array(
'0', $tree_id)
1653 $row = $this->db->fetchObject(
$res);
1666 $res = $this->db->queryf(
1668 SELECT * FROM frm_posts, frm_posts_tree 1669 WHERE pos_pk = pos_fk 1675 $row = $this->db->fetchObject(
$res);
1689 $tmp_user =
new ilObjUser($a_row->pos_display_user_id);
1690 $fullname = $tmp_user->getFullname();
1691 $loginname = $tmp_user->getLogin();
1694 $fullname = $fullname ? $fullname : ($a_row->import_name ? $a_row->import_name : $this->lng->txt(
"unknown"));
1697 "pos_pk" => $a_row->pos_pk,
1698 "child" => $a_row->pos_pk,
1699 "author" => $a_row->pos_display_user_id,
1700 "alias" => $a_row->pos_usr_alias,
1701 "title" => $fullname,
1702 "loginname" => $loginname,
1704 "message" => $a_row->pos_message,
1705 "subject" => $a_row->pos_subject,
1706 "pos_cens_com" => $a_row->pos_cens_com,
1707 "pos_cens" => $a_row->pos_cens,
1709 "date" => $a_row->fpt_date,
1710 "create_date" => $a_row->pos_date,
1711 "update" => $a_row->pos_update,
1712 "update_user" => $a_row->update_user,
1713 "tree" => $a_row->thr_fk,
1714 "parent" => $a_row->parent_pos,
1715 "lft" => $a_row->lft,
1716 "rgt" => $a_row->rgt,
1717 "depth" => $a_row->depth,
1718 "id" => $a_row->fpt_pk,
1719 "notify" => $a_row->notify,
1720 "import_name" => $a_row->import_name,
1721 "pos_status" => $a_row->pos_status
1736 $res = $this->db->queryf(
1738 SELECT * FROM frm_posts_tree 1741 AND parent_pos = %s',
1742 array(
'integer',
'integer',
'integer'),
1743 array($a_node[
'tree'], $a_node[
'pos_pk'], $a_node[
'parent'])
1746 while (
$row = $this->db->fetchObject(
$res)) {
1747 $a_node[
"lft"] =
$row->lft;
1748 $a_node[
"rgt"] =
$row->rgt;
1751 $diff = $a_node[
"rgt"] - $a_node[
"lft"] + 1;
1756 SELECT * FROM frm_posts_tree 1757 WHERE lft BETWEEN %s AND %s 1759 array(
'integer',
'integer',
'integer'),
1760 array($a_node[
'lft'], $a_node[
'rgt'], $a_node[
'tree'])
1765 while ($treeData = $this->db->fetchAssoc(
$result)) {
1766 $del_id[] = $treeData[
"pos_fk"];
1770 $this->db->manipulateF(
1772 DELETE FROM frm_posts_tree 1773 WHERE lft BETWEEN %s AND %s 1775 array(
'integer',
'integer',
'integer'),
1776 array($a_node[
'lft'], $a_node[
'rgt'], $a_node[
'tree'])
1780 $this->db->manipulateF(
1782 UPDATE frm_posts_tree 1794 array(
'integer',
'integer',
'integer',
'integer',
'integer'),
1795 array($a_node[
'lft'], $diff, $a_node[
'lft'], $diff, $a_node[
'tree'])
1808 $checkTime = time() - (60 * 60);
1810 if (
$_SESSION[
"frm_visit_" . $this->dbTable .
"_" . $ID] < $checkTime) {
1811 $_SESSION[
"frm_visit_" . $this->dbTable .
"_" . $ID] = time();
1812 $query =
'UPDATE ' . $this->dbTable .
' SET visits = visits + 1 WHERE ';
1814 $data_type = array();
1815 $data_value = array();
1822 $res = $this->db->queryf(
$query, $data_type, $data_value);
1836 if (
$type ==
'export') {
1837 $this->replQuote1 =
"<blockquote class=\"quote\"><hr size=\"1\" color=\"#000000\">";
1838 $this->replQuote2 =
"<hr size=\"1\" color=\"#000000\"/></blockquote>";
1843 $lname = ($quote_user !=
"")
1844 ?
'="' . $quote_user .
'"' 1847 $text =
"[quote$lname]" .
$text .
"[/quote]";
1850 $startZ = substr_count(
$text,
"[quote");
1851 $endZ = substr_count(
$text,
"[/quote]");
1853 if ($startZ > 0 || $endZ > 0) {
1855 if ($startZ > $endZ) {
1856 $diff = $startZ - $endZ;
1858 for (
$i = 0;
$i < $diff;
$i++) {
1859 if (
$type ==
'export') {
1862 $text .=
"[/quote]";
1865 } elseif ($startZ < $endZ) {
1866 $diff = $endZ - $startZ;
1868 for (
$i = 0;
$i < $diff;
$i++) {
1869 if (
$type ==
'export') {
1878 $text = preg_replace(
1879 '@\[(quote\s*?=\s*?"([^"]*?)"\s*?)\]@i',
1880 $this->replQuote1 .
'<div class="ilForumQuoteHead">' . $this->lng->txt(
'quote') .
' ($2)</div>',
1884 $text = str_replace(
1886 $this->replQuote1 .
'<div class="ilForumQuoteHead">' . $this->lng->txt(
"quote") .
'</div>',
1890 $text = str_replace(
"[/quote]", $this->replQuote2, $text);
1895 if (
$type !=
'export') {
1913 if (!is_array($a_ids)) {
1918 foreach ($a_ids as $pos_id) {
1919 $tmp_file_obj->setPosId($pos_id);
1920 $files = $tmp_file_obj->getFilesOfPost();
1921 foreach (
$files as $file) {
1922 $tmp_file_obj->unlinkFile($file[
"name"]);
1925 unset($tmp_file_obj);
1931 return $this->import_name;
1935 $this->import_name = $a_import_name;
1949 $res = $this->db->queryf(
1951 SELECT frm_notification.thread_id FROM frm_data, frm_notification, frm_threads 1952 WHERE frm_notification.user_id = %s 1953 AND frm_notification.thread_id = frm_threads.thr_pk 1954 AND frm_threads.thr_top_fk = frm_data.top_pk 1955 AND frm_data.top_frm_fk = %s 1956 GROUP BY frm_notification.thread_id',
1957 array(
'integer',
'integer'),
1958 array($user_id, $this->
id)
1961 if (is_object(
$res) &&
$res->numRows() > 0) {
1962 $thread_data = array();
1963 $thread_data_types = array();
1965 $query =
' DELETE FROM frm_notification 1967 AND thread_id IN (';
1969 array_push($thread_data, $user_id);
1970 array_push($thread_data_types,
'integer');
1974 while (
$row = $this->db->fetchAssoc(
$res)) {
1975 if ($counter < $res->numRows()) {
1977 array_push($thread_data,
$row[
'thread_id']);
1978 array_push($thread_data_types,
'integer');
1981 if ($counter ==
$res->numRows()) {
1983 array_push($thread_data,
$row[
'thread_id']);
1984 array_push($thread_data_types,
'integer');
1989 $this->db->manipulateF(
$query, $thread_data_types, $thread_data);
1994 $nextId = $this->db->nextId(
'frm_notification');
1996 $this->db->manipulateF(
1998 INSERT INTO frm_notification 2003 VALUES(%s, %s, %s)',
2004 array(
'integer',
'integer',
'integer'),
2005 array($nextId, $user_id, $this->
id)
2019 $this->db->manipulateF(
2021 DELETE FROM frm_notification 2024 array(
'integer',
'integer'),
2025 array($user_id, $this->
id)
2039 'SELECT COUNT(*) cnt FROM frm_notification WHERE user_id = %s AND frm_id = %s',
2040 array(
'integer',
'integer'),
2041 array($user_id, $this->
id)
2044 while ($record = $this->db->fetchAssoc(
$result)) {
2045 return (
bool) $record[
'cnt'];
2064 $nextId = $this->db->nextId(
'frm_notification');
2065 $this->db->manipulateF(
2067 INSERT INTO frm_notification 2072 VALUES (%s, %s, %s)',
2073 array(
'integer',
'integer',
'integer'),
2074 array($nextId, $user_id, $thread_id)
2091 SELECT COUNT(*) cnt FROM frm_notification 2093 AND thread_id = %s',
2094 array(
'integer',
'integer'),
2095 array($user_id, $thread_id)
2099 while ($record = $this->db->fetchAssoc(
$result)) {
2100 return (
bool) $record[
'cnt'];
2112 public static function _getThreads($a_obj_id, $a_sort_mode = self::SORT_DATE)
2115 $ilDB = $DIC->database();
2117 switch ($a_sort_mode) {
2118 case self::SORT_DATE:
2122 case self::SORT_TITLE:
2124 $sort =
'thr_subject';
2130 SELECT * FROM frm_threads 2131 JOIN frm_data ON top_pk = thr_top_fk 2132 WHERE top_frm_fk = %s 2134 array(
'integer',
'text'),
2135 array($a_obj_id, $sort)
2139 $threads[
$row->thr_pk] =
$row->thr_subject;
2141 return $threads ? $threads : array();
2147 $ilDB = $DIC->database();
2151 SELECT top_frm_fk FROM frm_data 2158 return $fdata[
"top_frm_fk"];
2166 $ilDB = $DIC->database();
2169 $res2 =
$ilDB->queryf(
2171 SELECT pos_top_fk, pos_thr_fk, pos_pk FROM frm_posts, frm_data 2172 WHERE pos_top_fk = top_pk 2174 ORDER BY pos_date DESC',
2179 if ($res2->numRows() == 0) {
2184 while ($selData =
$ilDB->fetchAssoc($res2)) {
2189 $lastPost_top = $selData[
"pos_top_fk"] .
"#" . $selData[
"pos_thr_fk"] .
"#" . $selData[
"pos_pk"];
2196 array(
'top_last_post' => array(
'text', $lastPost_top)),
2197 array(
'top_frm_fk' => array(
'integer', $a_obj_id))
2209 $sourceThread = new \ilForumTopic((
int) $source_id);
2210 $targetThread = new \ilForumTopic((
int)
$target_id);
2212 if ($sourceThread->getForumId() != $targetThread->getForumId()) {
2213 throw new \ilException(
'not_allowed_to_merge_into_another_forum');
2217 if ($sourceThread->getCreateDate() > $targetThread->getCreateDate()) {
2218 $sourceThreadForMerge = $sourceThread;
2219 $targetThreadForMerge = $targetThread;
2221 $sourceThreadForMerge = $targetThread;
2222 $targetThreadForMerge = $sourceThread;
2225 $threadSubject = $targetThreadForMerge->getSubject();
2227 $targetWasClosedBeforeMerge = (bool) $targetThreadForMerge->isClosed();
2228 $sourceThreadForMerge->close();
2230 if (
false === $targetWasClosedBeforeMerge) {
2231 $targetThreadForMerge->close();
2234 $allSourcePostings = $sourceThreadForMerge->getAllPosts();
2235 $sourceThreadRootNode = $sourceThreadForMerge->getFirstPostNode();
2236 $targetThreadRootNode = $targetThreadForMerge->getFirstPostNode();
2238 $sourceThreadRootArray = $this->
getPostNode($sourceThreadRootNode->getId());
2240 $ilAtomQuery = $this->db->buildAtomQuery();
2241 $ilAtomQuery->addTableLock(
'frm_posts');
2242 $ilAtomQuery->addTableLock(
'frm_posts_tree');
2243 $ilAtomQuery->addTableLock(
'frm_threads');
2244 $ilAtomQuery->addTableLock(
'frm_data');
2247 $targetThreadForMerge,
2248 $sourceThreadForMerge,
2249 $targetThreadRootNode,
2250 $sourceThreadRootNode,
2253 $targetRootNodeRgt = $targetThreadRootNode->getRgt();
2254 $targetRootNodeId = $targetThreadRootNode->getId();
2258 $targetThreadRootNode->getId(),
2259 ($targetThreadRootNode->getRgt() + $sourceThreadRootNode->getRgt() - 2)
2263 foreach ($allSourcePostings as
$post) {
2266 if ((
int) $post_obj->getId() === (int) $sourceThreadRootNode->getId()) {
2271 $tree = new \ilForumPostsTree();
2272 $tree->setPosFk($post->pos_pk);
2274 if ((
int) $post_obj->getParentId() === (int) $sourceThreadRootNode->getId()) {
2275 $tree->setParentPos($targetRootNodeId);
2277 $tree->setParentPos($post_obj->getParentId());
2280 $tree->setLft(($post_obj->getLft() + $targetRootNodeRgt) - 2);
2281 $tree->setRgt(($post_obj->getRgt() + $targetRootNodeRgt) - 2);
2283 $tree->setDepth($post_obj->getDepth());
2284 $tree->setTargetThreadId($targetThreadForMerge->getId());
2285 $tree->setSourceThreadId($sourceThreadForMerge->getId());
2292 (
int) $sourceThreadForMerge->getId(),
2293 (int) $targetThreadForMerge->getId(),
2294 [(int) $sourceThreadRootNode->getId(),]
2297 $ilAtomQuery->run();
2309 $lastPostString = $targetThreadForMerge->getLastPostString();
2310 $exp = explode(
'#', $lastPostString);
2311 if (array_key_exists(2, $exp)) {
2312 $exp[2] = $targetThreadForMerge->getLastPost()->getId();
2313 $lastPostString = implode(
'#', $exp);
2316 $frm_topic_obj = new \ilForumTopic(0,
false,
true);
2317 $frm_topic_obj->setNumPosts((
int) $sourceThreadForMerge->getNumPosts() + (int) $targetThreadForMerge->getNumPosts());
2318 $frm_topic_obj->setVisits((
int) $sourceThreadForMerge->getVisits() + (int) $targetThreadForMerge->getVisits());
2319 $frm_topic_obj->setLastPostString($lastPostString);
2320 $frm_topic_obj->setSubject($threadSubject);
2321 $frm_topic_obj->setId($targetThreadForMerge->getId());
2322 $frm_topic_obj->updateMergedThread();
2324 if (!$targetWasClosedBeforeMerge) {
2325 $targetThreadForMerge->reopen();
2329 $GLOBALS[
'ilAppEventHandler']->raise(
2333 'source_thread_id' => $sourceThreadForMerge->getId(),
2334 'target_thread_id' => $targetThreadForMerge->getId()
2338 $this->
deletePost($sourceThreadRootArray,
false);
getAllThreads($a_topic_id, array $params=array(), $limit=0, $offset=0)
insert()
Inserts the object data into database.
static _isModerator($a_ref_id, $a_usr_id)
checks whether a user is moderator of a given forum object
static mergeForumUserRead($merge_source_thread_id, $merge_target_thread_id)
setForumId($a_obj_id)
set object id which refers to ILIAS obj_id
static _lookupObjIdForForumId($a_for_id)
Class Forum core functions for forum.
getOnePost($post)
get one post-dataset
deletePost($postIdOrArray, $raiseEvents=true)
Delete post and sub-posts.
static _lookupPostMessage($a_id)
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
countUserArticles($a_user_id)
get number of articles from given user-ID
getForumRefId()
get forum ref_id public
disableForumNotification($user_id)
Disable a user's notification about new posts in this forum.
postCensorship($message, $pos_pk, $cens=0)
update dataset in frm_posts with censorship info
getMDB2DataType()
get content of additional condition
getPostDepth($a_node_id, $tree_id)
Return depth of an object private.
insertPostNode($a_node_id, $a_parent_id, $tree_id, $a_date='')
insert node under parent node public
static mergePosts(int $sourceThreadId, int $targetThreadId, array $excludedPostIds=[])
static _lookupTitle($a_id)
lookup object title
static updateTargetRootRgt($root_node_id, $rgt)
getFirstPostByThread($a_thread_id)
Get first post of thread.
mergeThreads($source_id, $target_id)
updateVisits($ID)
update page hits of given forum- or thread-ID public
getUserStatistic($is_moderator=false)
getFirstPostNode($tree_id)
get data of the first node from frm_posts_tree and frm_posts public
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
fetchPostNodeData($a_row)
get data of parent node from frm_posts_tree and frm_posts private
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
enableForumNotification($user_id)
Enable a user's notification about new posts in this forum.
static mergeThreadNotificiations($merge_source_thread_id, $merge_target_thread_id)
Class ilForumDraftHistory.
setCreateDate($a_createdate)
static _lookupObjectId($a_ref_id)
lookup object id
setImportName($a_import_name)
setDbTable($dbTable)
set database table
static _deleteReadEntries($a_post_id)
__deletePostFiles($a_ids)
static getInstance($a_obj_id=0)
catch(Exception $e) $message
generatePost($forum_id, $thread_id, $author_id, $display_user_id, $message, $parent_pos, $notify, $subject='', $alias='', $date='', $status=1, $send_activation_mail=0)
generate new dataset in frm_posts
setMDB2WhereCondition($query_string, $data_type, $data_value)
set content for additional condition
foreach($_POST as $key=> $value) $res
getOneThread()
get one thread-dataset by WhereCondition
prepareText($text, $edit=0, $quote_user='', $type='')
prepares given string public
generateThread(ilForumTopic $thread, $message, $notify, $notify_posts, $status=1, bool $withFirstVisibleEntry=true)
enableThreadNotification($user_id, $thread_id)
no usage? ..delete .
static updateLastPostByObjId($a_obj_id)
getOrderField()
get name of orderField
getModerators()
get all users assigned to local role il_frm_moderator_<frm_ref_id>
deletePostTree($a_node)
delete node and the whole subtree under this node public
getForumId()
get forum id public
isForumNotificationEnabled($user_id)
Check whether a user's notification about new posts in this forum is enabled (result > 0) or not (res...
convertDate($date)
converts the date format
static _getThreads($a_obj_id, $a_sort_mode=self::SORT_DATE)
Get thread infos of object.
getOneTopic()
get one topic-dataset by WhereCondition
countActiveUserArticles($a_user_id)
getMDB2Query()
get content of additional condition
addPostTree($a_tree_id, $a_node_id=-1, $a_date='')
create a new post-tree
static _deleteAccessEntries($a_thread_id)
isThreadNotificationEnabled($user_id, $thread_id)
Check whether a user's notification about new posts in a thread is enabled (result > 0) or not (resul...
const FORUM_OVERVIEW_WITH_NEW_POSTS
static getFirstNewsIdForContext( $a_context_obj_id, $a_context_obj_type, $a_context_sub_obj_id="", $a_context_sub_obj_type="")
Get first new id of news set related to a certain context.
moveThreads($thread_ids=array(), $src_ref_id=0, $dest_top_frm_fk=0)
Moves all chosen threads and their posts to a new forum.
static _lookupLanguage($a_usr_id)
static getInstance()
Singleton: get instance.
This class handles all operations on files for the forum object.
static $moderators_by_ref_id_map
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
getDbTable()
get name of database table
static _getModerators($a_ref_id)
get all users assigned to local role il_frm_moderator_<frm_ref_id> (static)
static _getLanguageInstanceByUsrId($usr_id)
Get the ilLanguage instance for the passed user id.
getMDB2DataValue()
get content of additional condition
getPageHits()
get number of max.
enableNotification($a_user_id)
Enable a user's notification about new posts in a thread.
setForumRefId($a_ref_id)
set reference id which refers to ILIAS obj_id
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
setImportName($a_import_name)
setOrderField($orderField)
set database field for sorting results
Class to report exception.
__construct()
Constructor public.
getPostNode($post_id)
get data of given node from frm_posts_tree and frm_posts public