4 require_once
'./Modules/Forum/classes/class.ilForumProperties.php';
5 require_once
'./Modules/Forum/classes/class.ilObjForum.php';
6 require_once
'./Modules/Forum/classes/class.ilForumTopic.php';
7 require_once
'./Modules/Forum/classes/class.ilForumPost.php';
105 static $lngCache =
array();
110 if(!isset($lngCache[$languageShorthandle]))
112 $lngCache[$languageShorthandle] =
new ilLanguage($languageShorthandle);
113 $lngCache[$languageShorthandle]->loadLanguageModule(
'forum');
116 return $lngCache[$languageShorthandle];
127 if (!isset($a_obj_id))
129 $message = get_class($this).
"::setForumId(): No obj_id given!";
130 $this->
ilias->raiseError($message,$this->
ilias->error_obj->WARNING);
133 $this->
id = $a_obj_id;
143 if (!isset($a_ref_id))
145 $message = get_class($this).
"::setForumRefId(): No ref_id given!";
146 $this->
ilias->raiseError($message,$this->
ilias->error_obj->WARNING);
149 $this->ref_id = $a_ref_id;
182 die($this->className .
"::setOrderField(): No orderField given.");
211 die($this->className .
"::setDbTable(): No database table given.");
242 $this->mdb2Query = $query_string;
243 $this->mdb2DataValue = $data_value;
244 $this->mdb2DataType = $data_type;
257 if($this->mdb2Query !=
'')
271 if($this->mdb2DataValue !=
'')
284 if($this->mdb2DataType !=
'')
327 $data_type =
array();
328 $data_value =
array();
330 $query =
'SELECT * FROM frm_data WHERE ';
334 $query .=
''.$this->getMDB2Query().
'';
338 $res = $ilDB->queryf(
$query, $data_type, $data_value);
341 if(is_null(
$row))
return NULL;
343 $row[
"top_name"] = trim(
$row[
"top_name"]);
344 $row[
"top_description"] = nl2br(
$row[
"top_description"]);
356 if(!is_array(
$row) || !count(
$row))
return null;
358 $row[
'top_name'] = trim(
$row[
'top_name']);
359 $row[
'top_description'] = nl2br(
$row[
'top_description']);
374 $data_type =
array();
375 $data_value =
array();
377 $query =
'SELECT * FROM frm_threads WHERE ';
385 $sql_res = $ilDB->queryf(
$query, $data_type, $data_value);
386 $result = $ilDB->fetchAssoc($sql_res);
403 $res = $ilDB->queryf(
' 404 SELECT frm_posts.*, usr_data.lastname FROM frm_posts, usr_data 406 AND pos_display_user_id = usr_id',
413 $row[
"pos_message"] = nl2br(
$row[
"pos_message"]);
422 $res = $ilDB->queryf(
' 423 SELECT * FROM frm_posts WHERE pos_pk = %s',
426 while(
$row = $ilDB->fetchObject(
$res))
428 return $row->pos_message;
448 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)
453 $objNewPost->setForumId($forum_id);
454 $objNewPost->setThreadId($thread_id);
455 $objNewPost->setSubject($subject);
456 $objNewPost->setMessage($message);
457 $objNewPost->setDisplayUserId($display_user_id);
458 $objNewPost->setUserAlias($alias);
459 $objNewPost->setPosAuthorId($author_id);
463 if($frm_settings->getMarkModeratorPosts() == 1)
465 self::_isModerator($this->
getForumRefId(), $author_id) ? $is_moderator = true : $is_moderator =
false;
469 $is_moderator =
false;
471 $objNewPost->setIsAuthorModerator($is_moderator);
475 $objNewPost->setCreateDate(
date(
"Y-m-d H:i:s"));
479 if (strpos($date,
"-") > 0)
481 $objNewPost->setCreateDate($date);
485 $objNewPost->setCreateDate(
date(
"Y-m-d H:i:s", $date));
490 $objNewPost->setPostActivationDate($objNewPost->getCreateDate());
494 $objNewPost->setNotification($notify);
495 $objNewPost->setStatus($status);
496 $objNewPost->insert();
499 if ($parent_pos == 0)
501 $this->
addPostTree($objNewPost->getThreadId(), $objNewPost->getId(), $objNewPost->getCreateDate());
505 $this->
insertPostNode($objNewPost->getId(), $parent_pos, $objNewPost->getThreadId(), $objNewPost->getCreateDate());
509 $lastPost = $objNewPost->getForumId().
"#".$objNewPost->getThreadId().
"#".$objNewPost->getId();
514 SET thr_num_posts = thr_num_posts + 1, 517 array(
'text',
'integer'),
518 array($lastPost, $objNewPost->getThreadId()));
523 SET top_num_posts = top_num_posts + 1, 526 array(
'text',
'integer'),
527 array($lastPost, $objNewPost->getForumId()));
531 $forum_obj->markPostRead($objNewPost->getPosAuthorId(), $objNewPost->getThreadId(), $objNewPost->getId());
536 require_once
'Services/RTE/classes/class.ilRTE.php';
537 include_once(
"./Services/News/classes/class.ilNewsItem.php");
539 $news_item->setContext($forum_obj->getId(),
'frm', $objNewPost->getId(),
'pos');
541 $news_item->setTitle($objNewPost->getSubject());
543 if($objNewPost->getMessage() != strip_tags($objNewPost->getMessage()))
545 $news_item->setContentHtml(
true);
548 $news_item->setUserId($display_user_id);
550 $news_item->create();
553 return $objNewPost->getId();
576 if($notify_posts == 1)
583 SET top_num_threads = top_num_threads + 1 592 $message, 0, $notify,
615 if (is_numeric($src_top_frm_fk) && $src_top_frm_fk > 0 && is_numeric($dest_top_frm_fk) && $dest_top_frm_fk > 0)
626 if ($oldFrmData[
'top_pk'] && $newFrmData[
'top_pk'])
631 foreach ($thread_ids as
$id)
635 $numPosts = $objTmpThread->movePosts($src_top_frm_fk, $oldFrmData[
'top_pk'], $dest_top_frm_fk, $newFrmData[
'top_pk']);
636 if (($last_post_string = $objTmpThread->getLastPostString()) !=
'')
638 $last_post_string = explode(
'#', $last_post_string);
639 $last_post_string[0] = $newFrmData[
'top_pk'];
640 $last_post_string = implode(
'#', $last_post_string);
641 $objTmpThread->setLastPostString($last_post_string);
644 $visits += $objTmpThread->getVisits();
646 $moved_posts += $numPosts;
649 $objTmpThread->setForumId($newFrmData[
'top_pk']);
650 $objTmpThread->update();
652 unset($objTmpThread);
657 $res = $ilDB->queryf(
' 658 SELECT pos_thr_fk, pos_pk 660 WHERE pos_top_fk = %s 661 ORDER BY pos_date DESC',
662 array(
'integer'),
array($oldFrmData[
'top_pk']));
665 $last_post_src = $oldFrmData[
'top_pk'] .
'#' .
$row->pos_thr_fk .
'#' .
$row->pos_pk;
667 $statement = $ilDB->manipulateF(
' 669 SET top_num_posts = top_num_posts - %s, 670 top_num_threads = top_num_threads - %s, 671 visits = visits - %s, 674 array(
'integer',
'integer',
'integer',
'text',
'integer'),
679 $oldFrmData[
'top_pk']));
684 $res = $ilDB->queryf(
' 685 SELECT pos_thr_fk, pos_pk 687 WHERE pos_top_fk = %s 688 ORDER BY pos_date DESC',
689 array(
'integer'),
array($newFrmData[
'top_kp']));
692 $last_post_dest = $newFrmData[
'top_pk'] .
'#' .
$row->pos_thr_fk .
'#' .
$row->pos_pk;
694 $statement = $ilDB->manipulateF(
' 696 SET top_num_posts = top_num_posts + %s, 697 top_num_threads = top_num_threads + %s, 698 visits = visits + %s, 701 array(
'integer',
'integer',
'integer',
'text',
'integer'),
702 array($moved_posts, $moved_threads, $visits, $last_post_dest, $newFrmData[
'top_pk']));
736 $cens_date =
date(
"Y-m-d H:i:s");
740 SET pos_cens_com = %s, 745 array(
'text',
'timestamp',
'integer',
'integer',
'integer'),
746 array($message, $cens_date, $cens,
$GLOBALS[
'DIC'][
'ilUser']->getId(), $pos_pk));
749 include_once(
"./Services/News/classes/class.ilNewsItem.php");
751 "frm", $pos_pk,
"pos");
758 $news_item->setContent(nl2br($this->
prepareText($message, 0)));
759 if($message != strip_tags($message))
761 $news_item->setContentHtml(
true);
765 $news_item->setContentHtml(
false);
768 $news_item->update();
773 $res = $ilDB->queryf(
' 774 SELECT * FROM frm_posts 778 $rec = $ilDB->fetchAssoc(
$res);
782 $news_item->setContent(nl2br($this->
prepareText($rec[
"pos_message"], 0)));
783 if($rec[
"pos_message"] != strip_tags($rec[
"pos_message"]))
785 $news_item->setContentHtml(
true);
789 $news_item->setContentHtml(
false);
792 $news_item->update();
796 require_once
'Modules/Forum/classes/class.ilForumPost.php';
797 $GLOBALS[
'ilAppEventHandler']->raise(
819 include_once
"./Modules/Forum/classes/class.ilObjForum.php";
823 $GLOBALS[
'ilAppEventHandler']->raise(
829 'thread_deleted' => ($p_node[
"parent"] == 0)?
true :
false 838 $draft_ids = $obj_history->deleteHistoryByPostIds($del_id);
841 $obj_draft->deleteDraftsByDraftIds($draft_ids);
844 foreach($del_id as $post_id)
846 ilObjForum::_deleteReadEntries($post_id);
852 $dead_pos = count($del_id);
856 if ($p_node[
"parent"] == 0)
859 include_once
'./Modules/Forum/classes/class.ilObjForum.php';
861 ilObjForum::_deleteAccessEntries($p_node[
'tree']);
864 $dead_thr = $p_node[
"tree"];
866 $statement = $ilDB->manipulateF(
' 867 DELETE FROM frm_threads 872 $statement = $ilDB->manipulateF(
' 874 SET top_num_threads = top_num_threads - 1 875 WHERE top_frm_fk = %s',
879 $posset = $ilDB->queryf(
' 880 SELECT * FROM frm_posts 881 WHERE pos_thr_fk = %s',
884 while ($posrec = $ilDB->fetchAssoc($posset))
886 include_once(
"./Services/News/classes/class.ilNewsItem.php");
888 "frm", $posrec[
"pos_pk"],
"pos");
892 $news_item->delete();
897 include_once
'Services/MediaObjects/classes/class.ilObjMediaObject.php';
899 foreach(
$mobs as $mob)
916 $statement = $ilDB->manipulateF(
' 917 DELETE FROM frm_posts 918 WHERE pos_thr_fk = %s',
926 for ($i = 0; $i < $dead_pos; $i++)
928 $statement = $ilDB->manipulateF(
' 929 DELETE FROM frm_posts 934 include_once(
"./Services/News/classes/class.ilNewsItem.php");
936 "frm", $del_id[$i],
"pos");
940 $news_item->delete();
945 include_once
'Services/MediaObjects/classes/class.ilObjMediaObject.php';
947 foreach(
$mobs as $mob)
963 $statement = $ilDB->manipulateF(
' 965 SET thr_num_posts = thr_num_posts - %s 967 array(
'integer',
'integer'),
968 array($dead_pos, $p_node[
'tree']));
972 $res1 = $ilDB->queryf(
' 973 SELECT * FROM frm_posts 974 WHERE pos_thr_fk = %s 975 ORDER BY pos_date DESC',
978 if ($res1->numRows() == 0)
986 while ($selData = $ilDB->fetchAssoc($res1))
993 $lastPost_thr = $selData[
"pos_top_fk"].
"#".$selData[
"pos_thr_fk"].
"#".$selData[
"pos_pk"];
998 $statement = $ilDB->manipulateF(
' 1000 SET thr_last_post = %s 1002 array(
'text',
'integer'),
array($lastPost_thr, $p_node[
'tree']));
1006 $statement = $ilDB->manipulateF(
' 1008 SET top_num_posts = top_num_posts - %s 1009 WHERE top_frm_fk = %s',
1010 array(
'integer',
'integer'),
array($dead_pos, $this->
id));
1014 $res2 = $ilDB->queryf(
' 1015 SELECT * FROM frm_posts, frm_data 1016 WHERE pos_top_fk = top_pk 1018 ORDER BY pos_date DESC',
1021 if ($res2->numRows() == 0)
1029 while ($selData = $ilDB->fetchAssoc($res2))
1036 $lastPost_top = $selData[
"pos_top_fk"].
"#".$selData[
"pos_thr_fk"].
"#".$selData[
"pos_pk"];
1041 $statement = $ilDB->manipulateF(
' 1043 SET top_last_post = %s 1044 WHERE top_frm_fk = %s',
1045 array(
'text',
'integer'),
array($lastPost_top, $this->
id));
1057 public function getAllThreads($a_topic_id,
array $params =
array(), $limit = 0, $offset = 0)
1066 $frm_overview_setting = (int)$ilSetting::_lookupValue(
'frma',
'forum_overview');
1068 $is_post_activation_enabled = $frm_props->isPostActivationEnabled();
1070 $excluded_ids_condition =
'';
1073 $excluded_ids_condition =
' AND ' . $ilDB->in(
'thr_pk',
$params[
'excluded_ids'],
true,
'integer') .
' ';
1076 if(!in_array(strtolower(
$params[
'order_column']),
array(
'lp_date',
'rating',
'thr_subject',
'num_posts',
'num_visit')))
1078 $params[
'order_column'] =
'post_date';
1080 if(!in_array(strtolower(
$params[
'order_direction']),
array(
'asc',
'desc')))
1082 $params[
'order_direction'] =
'desc';
1085 $cnt_active_pos_query =
'';
1086 $cnt_join_type =
'LEFT';
1087 if($is_post_activation_enabled && !
$params[
'is_moderator'])
1089 $cnt_active_pos_query =
" AND (pos_status = {$ilDB->quote(1, 'integer')} OR pos_author_id = {$ilDB->quote($ilUser->getId(), 'integer')}) ";
1090 $cnt_join_type =
"INNER";
1093 "SELECT COUNT(DISTINCT(thr_pk)) cnt 1095 {$cnt_join_type} JOIN frm_posts 1096 ON pos_thr_fk = thr_pk {$cnt_active_pos_query} 1097 WHERE thr_top_fk = %s {$excluded_ids_condition} 1100 $cntData = $ilDB->fetchAssoc(
$res);
1101 $cnt = (int)$cntData[
'cnt'];
1104 $active_inner_query =
'';
1106 if($is_post_activation_enabled && !
$params[
'is_moderator'])
1108 $active_query =
' AND (pos_status = %s OR pos_author_id = %s) ';
1109 $active_inner_query =
' AND (ipos.pos_status = %s OR ipos.pos_author_id = %s) ';
1110 $having =
' HAVING num_posts > 0';
1115 $data_types =
array();
1117 $optional_fields =
'';
1118 if($frm_props->isIsThreadRatingEnabled())
1120 $optional_fields =
',avg_rating';
1122 if($frm_props->getThreadSorting() == 1)
1124 $optional_fields =
',thread_sorting';
1127 $additional_sort =
'';
1128 if($frm_props->getThreadSorting())
1130 $additional_sort .=
' , thread_sorting ASC ';
1133 if(
$params[
'order_column'] ==
'thr_subject')
1135 $dynamic_columns =
array(
', thr_subject ' .
$params[
'order_direction']);
1137 else if(
$params[
'order_column'] ==
'num_posts')
1139 $dynamic_columns =
array(
', thr_num_posts ' .
$params[
'order_direction']);
1141 else if(
$params[
'order_column'] ==
'num_visit')
1143 $dynamic_columns =
array(
', visits ' .
$params[
'order_direction']);
1147 $dynamic_columns =
array(
', post_date ' .
$params[
'order_direction']);
1150 if($frm_props->isIsThreadRatingEnabled())
1152 $dynamic_columns[] =
' ,avg_rating ' .
$params[
'order_direction'];
1154 if(
'rating' == strtolower(
$params[
'order_column']))
1156 $dynamic_columns = array_reverse($dynamic_columns);
1158 $additional_sort .= implode(
' ', $dynamic_columns);
1160 if(!$ilUser->isAnonymous())
1163 (CASE WHEN COUNT(DISTINCT(notification_id)) > 0 THEN 1 ELSE 0 END) usr_notification_is_enabled, 1164 MAX(pos_date) post_date, 1165 COUNT(DISTINCT(pos_pk)) num_posts, 1166 COUNT(DISTINCT(pos_pk)) - COUNT(DISTINCT(postread.post_id)) num_unread_posts, ";
1172 (SELECT COUNT(DISTINCT(ipos.pos_pk)) 1174 LEFT JOIN frm_user_read iread ON iread.post_id = ipos.pos_pk AND iread.usr_id = %s 1175 LEFT JOIN frm_thread_access iacc ON (iacc.thread_id = ipos.pos_thr_fk AND iacc.usr_id = %s) 1176 WHERE ipos.pos_thr_fk = thr_pk 1178 AND (ipos.pos_update > iacc.access_old_ts 1180 (iacc.access_old IS NULL AND (ipos.pos_update > " . $ilDB->quote(
date(
'Y-m-d H:i:s', NEW_DEADLINE),
'timestamp') .
")) 1183 AND ipos.pos_author_id != %s 1184 AND iread.usr_id IS NULL $active_inner_query 1188 $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 1192 LEFT JOIN frm_notification 1193 ON frm_notification.thread_id = thr_pk 1194 AND frm_notification.user_id = %s 1197 ON pos_thr_fk = thr_pk $active_query 1199 LEFT JOIN frm_user_read postread 1200 ON postread.post_id = pos_pk 1201 AND postread.usr_id = %s";
1203 $query .=
" WHERE thr_top_fk = %s 1204 {$excluded_ids_condition} 1205 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 1208 ORDER BY is_sticky DESC {$additional_sort}, thr_date DESC";
1214 $data_types[] =
'integer';
1215 $data_types[] =
'integer';
1216 $data_types[] =
'integer';
1217 if($is_post_activation_enabled && !
$params[
'is_moderator'])
1219 array_push($data_types,
'integer',
'integer');
1222 $data_types[] =
'integer';
1223 if($is_post_activation_enabled && !
$params[
'is_moderator'])
1225 array_push($data_types,
'integer',
'integer');
1227 $data_types[] =
'integer';
1228 $data_types[] =
'integer';
1233 $data[] = $ilUser->getId();
1234 $data[] = $ilUser->getId();
1235 $data[] = $ilUser->getId();
1236 if($is_post_activation_enabled && !
$params[
'is_moderator'])
1238 array_push(
$data,
'1', $ilUser->getId());
1241 $data[] = $ilUser->getId();
1242 if($is_post_activation_enabled && !
$params[
'is_moderator'])
1244 array_push($data,
'1', $ilUser->getId());
1246 $data[] = $ilUser->getId();
1247 $data[] = $a_topic_id;
1252 0 usr_notification_is_enabled, 1253 MAX(pos_date) post_date, 1254 COUNT(DISTINCT(pos_pk)) num_posts, 1255 COUNT(DISTINCT(pos_pk)) num_unread_posts, 1256 COUNT(DISTINCT(pos_pk)) num_new_posts, 1257 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 1262 ON pos_thr_fk = thr_pk $active_query";
1264 $query .=
" WHERE thr_top_fk = %s 1265 {$excluded_ids_condition} 1266 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 1269 ORDER BY is_sticky DESC {$additional_sort}, thr_date DESC";
1271 if($is_post_activation_enabled && !
$params[
'is_moderator'])
1273 array_push($data_types,
'integer',
'integer');
1275 $data_types[] =
'integer';
1276 if($is_post_activation_enabled && !
$params[
'is_moderator'])
1278 array_push(
$data,
'1', $ilUser->getId());
1280 $data[] = $a_topic_id;
1283 if($limit || $offset)
1285 $ilDB->setLimit($limit, $offset);
1288 while(
$row = $ilDB->fetchAssoc(
$res))
1291 $thread->assignData(
$row);
1292 $threads[] = $thread;
1296 'items' => $threads,
1305 $statistic =
array();
1307 $data_types =
array();
1310 $query =
"SELECT COUNT(f.pos_display_user_id) ranking, u.login, p.value, u.lastname, u.firstname 1312 INNER JOIN frm_posts_tree t 1313 ON f.pos_pk = t.pos_fk 1314 INNER JOIN frm_threads th 1315 ON t.thr_fk = th.thr_pk 1316 INNER JOIN usr_data u 1317 ON u.usr_id = f.pos_display_user_id 1318 INNER JOIN frm_data d 1319 ON d.top_pk = f.pos_top_fk 1320 LEFT JOIN usr_pref p 1321 ON p.usr_id = u.usr_id AND p.keyword = %s 1324 array_push($data_types,
'text');
1325 array_push(
$data,
'public_profile');
1329 $query .=
' AND (pos_status = %s 1331 AND pos_author_id = %s ))';
1333 array_push($data_types,
'integer',
'integer',
'integer');
1334 array_push(
$data,
'1',
'0', $ilUser->getId());
1337 $query .=
' AND d.top_frm_fk = %s 1338 GROUP BY pos_display_user_id, u.login, p.value,u.lastname, u.firstname';
1340 array_push($data_types,
'integer');
1348 while (
$row = $ilDB->fetchAssoc(
$res))
1355 if(!$ilUser->isAnonymous() && in_array(
$row[
'value'],
array(
'y',
'g')) ||
1356 $ilUser->isAnonymous() &&
'g' ==
$row[
'value'])
1358 $lastname =
$row[
'lastname'];
1359 $firstname =
$row[
'firstname'];
1362 $statistic[
$counter][] = $lastname;
1363 $statistic[
$counter][] = $firstname;
1368 return is_array($statistic) ? $statistic :
array();
1383 $res = $ilDB->queryf(
' 1384 SELECT * FROM frm_posts_tree 1386 AND parent_pos = %s',
1387 array(
'integer',
'integer'),
array($a_thread_id,
'0'));
1391 return $row->pos_fk ?
$row->pos_fk : 0;
1416 $role_arr = $rbacreview->getRolesOfRoleFolder($a_ref_id);
1417 foreach($role_arr as $role_id)
1421 return $rbacreview->assignedUsers($role_id);
1438 if(!self::$moderators_by_ref_id_map[$a_ref_id])
1440 self::$moderators_by_ref_id_map[$a_ref_id] = self::_getModerators($a_ref_id);
1442 return in_array($a_usr_id, self::$moderators_by_ref_id_map[$a_ref_id]);
1456 $res = $ilDB->queryf(
' 1457 SELECT * FROM frm_data 1458 INNER JOIN frm_posts ON pos_top_fk = top_pk 1459 WHERE top_frm_fk = %s 1460 AND pos_author_id = %s',
1461 array(
'integer',
'integer'),
1464 return $res->numRows();
1471 $res = $ilDB->queryf(
' 1472 SELECT * FROM frm_data 1473 INNER JOIN frm_posts ON pos_top_fk = top_pk 1474 WHERE top_frm_fk = %s 1475 AND (pos_status = %s 1477 AND pos_author_id = %s 1480 AND pos_author_id = %s',
1481 array(
'integer',
'integer',
'integer',
'integer',
'integer'),
1484 return $res->numRows();
1505 public function addPostTree($a_tree_id, $a_node_id = -1, $a_date =
'')
1509 $a_date = $a_date ? $a_date :
date(
"Y-m-d H:i:s");
1511 if ($a_node_id <= 0)
1513 $a_node_id = $a_tree_id;
1516 $nextId = $ilDB->nextId(
'frm_posts_tree');
1518 $statement = $ilDB->manipulateF(
' 1519 INSERT INTO frm_posts_tree 1529 VALUES(%s, %s, %s, %s, %s, %s, %s, %s )',
1530 array(
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'timestamp'),
1531 array($nextId, $a_tree_id, $a_node_id,
'0',
'1',
'2',
'1', $a_date));
1547 $a_date = $a_date ? $a_date :
date(
"Y-m-d H:i:s");
1550 $sql_res = $ilDB->queryf(
' 1551 SELECT * FROM frm_posts_tree 1554 array(
'integer',
'integer'),
1555 array($a_parent_id, $tree_id));
1557 $res = $ilDB->fetchObject($sql_res);
1565 $statement = $ilDB->manipulateF(
' 1566 UPDATE frm_posts_tree 1578 array(
'integer',
'integer',
'integer'),
1579 array($left, $left, $tree_id));
1581 $depth = $this->
getPostDepth($a_parent_id, $tree_id) + 1;
1584 $nextId = $ilDB->nextId(
'frm_posts_tree');
1585 $statement = $ilDB->manipulateF(
' 1586 INSERT INTO frm_posts_tree 1596 VALUES(%s,%s,%s, %s, %s, %s,%s, %s)',
1597 array(
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'integer',
'timestamp'),
1623 $sql_res = $ilDB->queryf(
' 1624 SELECT depth FROM frm_posts_tree 1627 array(
'integer',
'integer'),
1628 array($a_node_id, $tree_id));
1630 $res = $ilDB->fetchObject($sql_res);
1650 $res = $ilDB->queryf(
' 1651 SELECT * FROM frm_posts, frm_posts_tree 1652 WHERE pos_pk = pos_fk 1655 array(
'integer',
'integer'),
1656 array(
'0', $tree_id));
1673 $res = $ilDB->queryf(
' 1674 SELECT * FROM frm_posts, frm_posts_tree 1675 WHERE pos_pk = pos_fk 1695 require_once(
'./Services/User/classes/class.ilObjUser.php');
1699 $tmp_user =
new ilObjUser($a_row->pos_display_user_id);
1700 $fullname = $tmp_user->getFullname();
1701 $loginname = $tmp_user->getLogin();
1704 $fullname = $fullname ? $fullname : ($a_row->import_name ? $a_row->import_name : $lng->txt(
"unknown"));
1707 "pos_pk" => $a_row->pos_pk,
1708 "child" => $a_row->pos_pk,
1709 "author" => $a_row->pos_display_user_id,
1710 "alias" => $a_row->pos_usr_alias,
1711 "title" => $fullname,
1712 "loginname" => $loginname,
1714 "message" => $a_row->pos_message,
1715 "subject" => $a_row->pos_subject,
1716 "pos_cens_com" => $a_row->pos_cens_com,
1717 "pos_cens" => $a_row->pos_cens,
1719 "date" => $a_row->fpt_date,
1720 "create_date" => $a_row->pos_date,
1721 "update" => $a_row->pos_update,
1722 "update_user" => $a_row->update_user,
1723 "tree" => $a_row->thr_fk,
1724 "parent" => $a_row->parent_pos,
1725 "lft" => $a_row->lft,
1726 "rgt" => $a_row->rgt,
1727 "depth" => $a_row->depth,
1728 "id" => $a_row->fpt_pk,
1729 "notify" => $a_row->notify,
1730 "import_name" => $a_row->import_name,
1731 "pos_status" => $a_row->pos_status
1751 $res = $ilDB->queryf(
' 1752 SELECT * FROM frm_posts_tree 1755 AND parent_pos = %s',
1756 array(
'integer',
'integer',
'integer'),
1757 array($a_node[
'tree'], $a_node[
'pos_pk'], $a_node[
'parent']));
1759 while(
$row = $ilDB->fetchObject(
$res))
1761 $a_node[
"lft"] =
$row->lft;
1762 $a_node[
"rgt"] =
$row->rgt;
1765 $diff = $a_node[
"rgt"] - $a_node[
"lft"] + 1;
1769 SELECT * FROM frm_posts_tree 1770 WHERE lft BETWEEN %s AND %s 1772 array(
'integer',
'integer',
'integer'),
1773 array($a_node[
'lft'], $a_node[
'rgt'], $a_node[
'tree']));
1777 while ($treeData = $ilDB->fetchAssoc(
$result))
1779 $del_id[] = $treeData[
"pos_fk"];
1783 $statement = $ilDB->manipulateF(
' 1784 DELETE FROM frm_posts_tree 1785 WHERE lft BETWEEN %s AND %s 1787 array(
'integer',
'integer',
'integer'),
1788 array($a_node[
'lft'], $a_node[
'rgt'], $a_node[
'tree']));
1792 $statement = $ilDB->manipulateF(
' 1793 UPDATE frm_posts_tree 1805 array(
'integer',
'integer',
'integer',
'integer',
'integer'),
1806 array($a_node[
'lft'], $diff, $a_node[
'lft'], $diff, $a_node[
'tree']));
1822 $checkTime =
time() - (60*60);
1824 if (
$_SESSION[
"frm_visit_".$this->dbTable.
"_".$ID] < $checkTime)
1828 $query =
'UPDATE '.$this->dbTable.
' SET visits = visits + 1 WHERE ';
1830 $data_type =
array();
1831 $data_value =
array();
1839 $res = $ilDB->queryf(
$query, $data_type, $data_value);
1855 if($type ==
'export')
1857 $this->replQuote1 =
"<blockquote class=\"quote\"><hr size=\"1\" color=\"#000000\">";
1858 $this->replQuote2 =
"<hr size=\"1\" color=\"#000000\"/></blockquote>";
1864 $lname = ($quote_user !=
"")
1865 ?
'="'.$quote_user.
'"' 1868 $text =
"[quote$lname]".$text.
"[/quote]";
1873 $startZ = substr_count (
$text,
"[quote");
1874 $endZ = substr_count (
$text,
"[/quote]");
1876 if ($startZ > 0 || $endZ > 0)
1879 if ($startZ > $endZ)
1881 $diff = $startZ - $endZ;
1883 for ($i = 0; $i < $diff; $i++)
1886 else $text .=
"[/quote]";
1889 elseif ($startZ < $endZ)
1891 $diff = $endZ - $startZ;
1893 for ($i = 0; $i < $diff; $i++)
1895 if ($type ==
'export')
$text = $this->txtQuote1.$text;
1896 else $text =
"[quote]".$text;
1902 $text = preg_replace(
1903 '@\[(quote\s*?=\s*?"([^"]*?)"\s*?)\]@i',
1904 $this->replQuote1 .
'<div class="ilForumQuoteHead">' . $lng->txt(
'quote').
' ($2)</div>',
1908 $text = str_replace(
"[quote]",
1909 $this->replQuote1.
'<div class="ilForumQuoteHead">'.$lng->txt(
"quote").
'</div>',
$text);
1911 $text = str_replace(
"[/quote]", $this->replQuote2, $text);
1916 if($type !=
'export')
1920 include_once
'./Services/MathJax/classes/class.ilMathJax.php';
1946 $res = $ilDB->queryf(
' 1947 SELECT frm_data.* FROM frm_data, frm_posts 1949 AND pos_top_fk = top_pk',
1960 if(!is_array($a_ids))
1964 include_once
"./Modules/Forum/classes/class.ilFileDataForum.php";
1967 foreach($a_ids as $pos_id)
1969 $tmp_file_obj->setPosId($pos_id);
1970 $files = $tmp_file_obj->getFilesOfPost();
1973 $tmp_file_obj->unlinkFile($file[
"name"]);
1976 unset($tmp_file_obj);
1982 return $this->import_name;
1986 $this->import_name = $a_import_name;
2003 $res = $ilDB->queryf(
' 2004 SELECT frm_notification.thread_id FROM frm_data, frm_notification, frm_threads 2005 WHERE frm_notification.user_id = %s 2006 AND frm_notification.thread_id = frm_threads.thr_pk 2007 AND frm_threads.thr_top_fk = frm_data.top_pk 2008 AND frm_data.top_frm_fk = %s 2009 GROUP BY frm_notification.thread_id',
2010 array(
'integer',
'integer'),
2011 array($user_id, $this->
id));
2013 if (is_object(
$res) &&
$res->numRows() > 0)
2015 $thread_data =
array();
2016 $thread_data_types =
array();
2018 $query =
' DELETE FROM frm_notification 2020 AND thread_id IN (';
2022 array_push($thread_data, $user_id);
2023 array_push($thread_data_types,
'integer');
2027 while(
$row = $ilDB->fetchAssoc(
$res))
2029 if($counter < $res->numRows())
2032 array_push($thread_data,
$row[
'thread_id']);
2033 array_push($thread_data_types,
'integer');
2039 array_push($thread_data,
$row[
'thread_id']);
2040 array_push($thread_data_types,
'integer');
2046 $statement = $ilDB->manipulateF(
$query, $thread_data_types, $thread_data);
2051 $nextId = $ilDB->nextId(
'frm_notification');
2053 $statement = $ilDB->manipulateF(
' 2054 INSERT INTO frm_notification 2059 VALUES(%s, %s, %s)',
2060 array(
'integer',
'integer',
'integer'),
2061 array($nextId, $user_id, $this->
id));
2078 $statement = $ilDB->manipulateF(
' 2079 DELETE FROM frm_notification 2082 array(
'integer',
'integer'),
2083 array($user_id, $this->
id));
2098 $result = $ilDB->queryf(
'SELECT COUNT(*) cnt FROM frm_notification WHERE user_id = %s AND frm_id = %s',
2099 array(
'integer',
'integer'),
array($user_id, $this->
id));
2101 while($record = $ilDB->fetchAssoc(
$result))
2103 return (
bool)$record[
'cnt'];
2122 $nextId = $ilDB->nextId(
'frm_notification');
2123 $statement = $ilDB->manipulateF(
' 2124 INSERT INTO frm_notification 2129 VALUES (%s, %s, %s)',
2130 array(
'integer',
'integer',
'integer'),
array($nextId, $user_id, $thread_id));
2149 SELECT COUNT(*) cnt FROM frm_notification 2151 AND thread_id = %s',
2152 array(
'integer',
'integer'),
2153 array($user_id, $thread_id));
2156 while($record = $ilDB->fetchAssoc(
$result))
2158 return (
bool)$record[
'cnt'];
2173 public static function _getThreads($a_obj_id,$a_sort_mode = self::SORT_DATE)
2177 switch($a_sort_mode)
2179 case self::SORT_DATE:
2183 case self::SORT_TITLE:
2185 $sort =
'thr_subject';
2189 $res = $ilDB->queryf(
' 2190 SELECT * FROM frm_threads 2191 JOIN frm_data ON top_pk = thr_top_fk 2192 WHERE top_frm_fk = %s 2194 array(
'integer',
'text'),
array($a_obj_id, $sort));
2196 while(
$row = $ilDB->fetchObject(
$res))
2198 $threads[
$row->thr_pk] =
$row->thr_subject;
2200 return $threads ? $threads :
array();
2207 $res = $ilDB->queryf(
' 2208 SELECT top_frm_fk FROM frm_data 2212 if ($fdata = $ilDB->fetchAssoc(
$res))
2214 return $fdata[
"top_frm_fk"];
2224 $res2 = $ilDB->queryf(
' 2225 SELECT pos_top_fk, pos_thr_fk, pos_pk FROM frm_posts, frm_data 2226 WHERE pos_top_fk = top_pk 2228 ORDER BY pos_date DESC',
2231 if ($res2->numRows() == 0)
2239 while ($selData = $ilDB->fetchAssoc($res2))
2246 $lastPost_top = $selData[
"pos_top_fk"].
"#".$selData[
"pos_thr_fk"].
"#".$selData[
"pos_pk"];
2251 $ilDB->update(
'frm_data',
2252 array(
'top_last_post' =>
array(
'text', $lastPost_top)),
2253 array(
'top_frm_fk' =>
array(
'integer', $a_obj_id))
2267 $source_thread_obj =
new ilForumTopic((
int)$source_id);
2270 if($source_thread_obj->getForumId() != $target_thread_obj->getForumId())
2272 throw new ilException(
'not_allowed_to_merge_into_another_forum');
2275 if($source_thread_obj->getCreateDate() > $target_thread_obj->getCreateDate())
2277 $merge_thread_source = $source_thread_obj;
2278 $merge_thread_target = $target_thread_obj;
2282 $merge_thread_source = $target_thread_obj;
2283 $merge_thread_target = $source_thread_obj;
2286 $thread_subject = $target_thread_obj->getSubject();
2289 $targed_was_closed = $merge_thread_target->isClosed();
2291 $merge_thread_source->close();
2293 if($targed_was_closed ==
false)
2295 $merge_thread_target->close();
2298 $source_all_posts = $merge_thread_source->getAllPosts();
2299 $source_root_node = $merge_thread_source->getFirstPostNode();
2300 $target_root_node = $merge_thread_target->getFirstPostNode();
2302 $add_difference = $target_root_node->getRgt();
2305 include_once
'Modules/Forum/classes/class.ilForumPostsTree.php';
2307 $new_target_rgt = ($target_root_node->getRgt() + $source_root_node->getRgt());
2310 $new_target_root = $target_root_node->getId();
2313 foreach($source_all_posts as $post)
2318 $posts_tree_obj->setPosFk($post->pos_pk);
2320 if($post_obj->getParentId() == 0)
2322 $posts_tree_obj->setParentPos($new_target_root);
2325 $posts_tree_obj->setRgt(($post_obj->getRgt() + $add_difference) - 1);
2326 $posts_tree_obj->setLft($target_root_node->getRgt());
2328 $posts_tree_obj->setDepth(($post_obj->getDepth() + 1));
2329 $posts_tree_obj->setSourceThreadId($merge_thread_source->getId());
2331 $posts_tree_obj->setTargetThreadId($merge_thread_target->getId());
2333 $posts_tree_obj->mergeParentPos();
2337 $posts_tree_obj->setRgt(($post_obj->getRgt() + $add_difference) - 1);
2338 $posts_tree_obj->setLft(($post_obj->getLft() + $add_difference) - 1);
2340 $posts_tree_obj->setDepth(($post_obj->getDepth() + 1));
2341 $posts_tree_obj->setSourceThreadId($merge_thread_source->getId());
2343 $posts_tree_obj->setParentPos($post_obj->getParentId());
2344 $posts_tree_obj->setTargetThreadId($merge_thread_target->getId());
2346 $posts_tree_obj->merge();
2351 include_once
'Modules/Forum/classes/class.ilForumPost.php';
2355 include_once
'Modules/Forum/classes/class.ilForumNotification.php';
2359 include_once
'./Modules/Forum/classes/class.ilObjForum.php';
2360 ilObjForum::_deleteAccessEntries($merge_thread_source->getId());
2366 $post_date_source = $merge_thread_source->getLastPost()->getCreateDate();
2367 $post_date_target = $merge_thread_target->getLastPost()->getCreateDate();
2369 $target_last_post = $merge_thread_target->getLastPostString();
2370 $exp = explode(
'#', $target_last_post);
2372 if($post_date_source > $post_date_target)
2374 $exp[2] = $merge_thread_source->getLastPost()->getId();
2378 $exp[2] = $merge_thread_target->getLastPost()->getId();
2380 $new_thr_last_post = implode(
'#', $exp);
2382 $num_posts_source = (int)$merge_thread_source->getNumPosts();
2383 $num_visits_source = (int)$merge_thread_source->getVisits();
2384 $num_posts_target = (int)$merge_thread_target->getNumPosts();
2385 $num_visits_target = (int)$merge_thread_source->getVisits();
2388 $frm_topic_obj->setNumPosts(($num_posts_source + $num_posts_target));
2389 $frm_topic_obj->setVisits(($num_visits_source + $num_visits_target));
2390 $frm_topic_obj->setLastPostString($new_thr_last_post);
2391 $frm_topic_obj->setSubject($thread_subject);
2392 $frm_topic_obj->setId($merge_thread_target->getId());
2394 $frm_topic_obj->updateMergedThread();
2400 if(!$targed_was_closed)
2402 $merge_thread_target->reopen();
2405 $GLOBALS[
'ilAppEventHandler']->raise(
'Modules/Forum',
'mergedThreads',
2406 array(
'source_thread_id' => $merge_thread_source->getId(),
2407 'target_thread_id' => $merge_thread_target->getId())
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.
Base class for ILIAS Exception handling.
getOnePost($post)
get one post-dataset
static _lookupPostMessage($a_id)
static mergeThreads($obj_id, $source_id, $target_id)
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
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.
countUserArticles($a_user_id)
get number of articles from given user-ID
getForumRefId()
get forum ref_id public
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
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 _lookupTitle($a_id)
lookup object title
static updateTargetRootRgt($root_node_id, $rgt)
getFirstPostByThread($a_thread_id)
Get first post of thread.
updateVisits($ID)
update page hits of given forum- or thread-ID public
getUserStatistic($is_moderator=false)
deletePost($post)
delete post and sub-posts
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
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
__deletePostFiles($a_ids)
static getInstance($a_obj_id=0)
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
getModeratorFromPost($pos_pk)
get one post-dataset
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)
enableThreadNotification($user_id, $thread_id)
Enable a user's notification about new posts in a thread.
static updateLastPostByObjId($a_obj_id)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
getOrderField()
get name of orderField
getModerators()
get all users assigned to local role il_frm_moderator_<frm_ref_id>
static formatDate(ilDateTime $date)
Format a date public.
redirection script todo: (a better solution should control the processing via a xml file) ...
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)
Create styles array
The data for the language used.
getMDB2Query()
get content of additional condition
addPostTree($a_tree_id, $a_node_id=-1, $a_date='')
create a new post-tree
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 mergePosts($source_thread_id, $target_thread_id)
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 deleteByThreadId($thr_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)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
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
setImportName($a_import_name)
setOrderField($orderField)
set database field for sorting results
__construct()
Constructor public.
getPostNode($post_id)
get data of given node from frm_posts_tree and frm_posts public