ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilForum Class Reference

Class Forum core functions for forum. More...

+ Collaboration diagram for ilForum:

Public Member Functions

 __construct ()
 Constructor @access public. More...
 
 setLanguage ($lng)
 
 setForumId ($a_obj_id)
 set object id which refers to ILIAS obj_id More...
 
 setForumRefId ($a_ref_id)
 set reference id which refers to ILIAS obj_id More...
 
 getForumId ()
 get forum id @access public More...
 
 getForumRefId ()
 get forum ref_id @access public More...
 
 getOrderField ()
 get name of orderField More...
 
 setDbTable ($dbTable)
 set database table More...
 
 getDbTable ()
 get name of database table More...
 
 setMDB2WhereCondition ($query_string, $data_type, $data_value)
 set content for additional condition More...
 
 getMDB2Query ()
 get content of additional condition More...
 
 getMDB2DataValue ()
 get content of additional condition More...
 
 getMDB2DataType ()
 get content of additional condition More...
 
 setPageHits ($pageHits)
 
 getPageHits ()
 get number of max. More...
 
 getOneTopic ()
 get one topic-dataset by WhereCondition More...
 
 getOneThread ()
 get one thread-dataset by WhereCondition More...
 
 getOnePost ($post)
 get one post-dataset More...
 
 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 More...
 
 generateThread (ilForumTopic $thread, $message, $notify, $notify_posts, $status=1, bool $withFirstVisibleEntry=true)
 
 moveThreads ($thread_ids=array(), $src_ref_id=0, $dest_top_frm_fk=0)
 Moves all chosen threads and their posts to a new forum. More...
 
 postCensorship ($message, $pos_pk, $cens=0)
 update dataset in frm_posts with censorship info More...
 
 deletePost ($postIdOrArray, $raiseEvents=true)
 Delete post and sub-posts. More...
 
 getAllThreads ($a_topic_id, array $params=array(), $limit=0, $offset=0)
 
 getUserStatistic ($is_moderator=false)
 
 getFirstPostByThread ($a_thread_id)
 Get first post of thread. More...
 
 getModerators ()
 get all users assigned to local role il_frm_moderator_<frm_ref_id> More...
 
 countUserArticles ($a_user_id)
 get number of articles from given user-ID More...
 
 countActiveUserArticles ($a_user_id)
 
 convertDate ($date)
 converts the date format More...
 
 addPostTree ($a_tree_id, $a_node_id=-1, $a_date='')
 create a new post-tree More...
 
 insertPostNode ($a_node_id, $a_parent_id, $tree_id, $a_date='')
 insert node under parent node @access public More...
 
 getPostDepth ($a_node_id, $tree_id)
 Return depth of an object @access private. More...
 
 getFirstPostNode ($tree_id)
 get data of the first node from frm_posts_tree and frm_posts @access public More...
 
 getPostNode ($post_id)
 get data of given node from frm_posts_tree and frm_posts @access public More...
 
 fetchPostNodeData ($a_row)
 get data of parent node from frm_posts_tree and frm_posts @access private More...
 
 deletePostTree ($a_node)
 delete node and the whole subtree under this node @access public More...
 
 updateVisits ($ID)
 update page hits of given forum- or thread-ID @access public More...
 
 prepareText ($text, $edit=0, $quote_user='', $type='')
 prepares given string @access public More...
 
 __deletePostFiles ($a_ids)
 
 getImportName ()
 
 setImportName ($a_import_name)
 
 enableForumNotification ($user_id)
 Enable a user's notification about new posts in this forum. More...
 
 disableForumNotification ($user_id)
 Disable a user's notification about new posts in this forum. More...
 
 isForumNotificationEnabled ($user_id)
 Check whether a user's notification about new posts in this forum is enabled (result > 0) or not (result == 0) More...
 
 enableThreadNotification ($user_id, $thread_id)
 no usage? ..delete . More...
 
 isThreadNotificationEnabled ($user_id, $thread_id)
 Check whether a user's notification about new posts in a thread is enabled (result > 0) or not (result == 0) More...
 
 mergeThreads ($source_id, $target_id)
 

Static Public Member Functions

static _getLanguageInstanceByUsrId ($usr_id)
 Get the ilLanguage instance for the passed user id. More...
 
static _lookupPostMessage ($a_id)
 
static _getModerators ($a_ref_id)
 get all users assigned to local role il_frm_moderator_<frm_ref_id> (static) More...
 
static _isModerator ($a_ref_id, $a_usr_id)
 checks whether a user is moderator of a given forum object More...
 
static _getThreads ($a_obj_id, $a_sort_mode=self::SORT_DATE)
 Get thread infos of object. More...
 
static _lookupObjIdForForumId ($a_for_id)
 
static updateLastPostByObjId ($a_obj_id)
 

Data Fields

const SORT_TITLE = 1
 
const SORT_DATE = 2
 
const DEFAULT_PAGE_HITS = 30
 
 $lng
 
 $error
 
 $db
 
 $user
 
 $settings
 

Static Protected Attributes

static $moderators_by_ref_id_map = array()
 

Private Member Functions

 setOrderField ($orderField)
 set database field for sorting results More...
 

Private Attributes

 $dbTable
 
 $className = "ilForum"
 
 $orderField
 
 $mdb2Query
 
 $mdb2DataValue
 
 $mdb2DataType
 
 $txtQuote1 = "[quote]"
 
 $txtQuote2 = "[/quote]"
 
 $replQuote1 = '<blockquote class="ilForumQuote">'
 
 $replQuote2 = '</blockquote>'
 
 $pageHits = self::DEFAULT_PAGE_HITS
 
 $id
 

Detailed Description

Class Forum core functions for forum.

Author
Wolfgang Merkens wmerk.nosp@m.ens@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$

Definition at line 13 of file class.ilForum.php.

Constructor & Destructor Documentation

◆ __construct()

ilForum::__construct ( )

Constructor @access public.

Definition at line 73 of file class.ilForum.php.

74 {
75 global $DIC;
76
77 $this->error = $DIC['ilErr'];
78 $this->lng = $DIC->language();
79 $this->db = $DIC->database();
80 $this->user = $DIC->user();
81 $this->settings = $DIC->settings();
82 }
user()
Definition: user.php:4
error($a_errmsg)
set error message @access public
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2

References $DIC, error(), settings(), and user().

+ Here is the call graph for this function:

Member Function Documentation

◆ __deletePostFiles()

ilForum::__deletePostFiles (   $a_ids)

Definition at line 1911 of file class.ilForum.php.

1912 {
1913 if (!is_array($a_ids)) {
1914 return false;
1915 }
1916
1917 $tmp_file_obj = new ilFileDataForum($this->getForumId());
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"]);
1923 }
1924 }
1925 unset($tmp_file_obj);
1926 return true;
1927 }
This class handles all operations on files for the forum object.
getForumId()
get forum id @access public
$files
Definition: metarefresh.php:49

References $files, and getForumId().

Referenced by deletePost().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getLanguageInstanceByUsrId()

static ilForum::_getLanguageInstanceByUsrId (   $usr_id)
static

Get the ilLanguage instance for the passed user id.

Parameters
integer$usr_ida user id
Returns
ilLanguage @access public

Definition at line 100 of file class.ilForum.php.

101 {
102 static $lngCache = array();
103
104 $languageShorthandle = ilObjUser::_lookupLanguage($usr_id);
105
106 // lookup in cache array
107 if (!isset($lngCache[$languageShorthandle])) {
108 $lngCache[$languageShorthandle] = new ilLanguage($languageShorthandle);
109 $lngCache[$languageShorthandle]->loadLanguageModule('forum');
110 }
111
112 return $lngCache[$languageShorthandle];
113 }
language handling
static _lookupLanguage($a_usr_id)

References ilObjUser\_lookupLanguage().

+ Here is the call graph for this function:

◆ _getModerators()

static ilForum::_getModerators (   $a_ref_id)
static

get all users assigned to local role il_frm_moderator_<frm_ref_id> (static)

Parameters
int$a_ref_idreference id
Returns
array user_ids @access public

Definition at line 1405 of file class.ilForum.php.

1406 {
1407 global $DIC;
1408 $rbacreview = $DIC->rbac()->review();
1409
1410 $role_arr = $rbacreview->getRolesOfRoleFolder($a_ref_id);
1411 foreach ($role_arr as $role_id) {
1412 if (ilObject::_lookupTitle($role_id) == 'il_frm_moderator_' . $a_ref_id) {
1413 return $rbacreview->assignedUsers($role_id);
1414 }
1415 }
1416
1417 return array();
1418 }
static _lookupTitle($a_id)
lookup object title

References $DIC, and ilObject\_lookupTitle().

Referenced by _isModerator(), ilForumNotification\checkParentNodeTree(), getModerators(), ilObjForumNotificationDataProvider\getPostActivationRecipients(), ilForumSettingsGUI\showMembers(), and ilForumSettingsGUI\updateUserNotifications().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getThreads()

static ilForum::_getThreads (   $a_obj_id,
  $a_sort_mode = self::SORT_DATE 
)
static

Get thread infos of object.

Parameters
int$a_obj_id
int$a_sort_modeSORT_TITLE or SORT_DATE
Returns
array

Definition at line 2112 of file class.ilForum.php.

2113 {
2114 global $DIC;
2115 $ilDB = $DIC->database();
2116
2117 switch ($a_sort_mode) {
2118 case self::SORT_DATE:
2119 $sort = 'thr_date';
2120 break;
2121
2122 case self::SORT_TITLE:
2123 default:
2124 $sort = 'thr_subject';
2125 break;
2126 }
2127
2128 $res = $ilDB->queryf(
2129 '
2130 SELECT * FROM frm_threads
2131 JOIN frm_data ON top_pk = thr_top_fk
2132 WHERE top_frm_fk = %s
2133 ORDER BY %s',
2134 array('integer', 'text'),
2135 array($a_obj_id, $sort)
2136 );
2137
2138 while ($row = $ilDB->fetchObject($res)) {
2139 $threads[$row->thr_pk] = $row->thr_subject;
2140 }
2141 return $threads ? $threads : array();
2142 }
const SORT_DATE
const SORT_TITLE
$row
foreach($_POST as $key=> $value) $res
global $ilDB

References $DIC, $ilDB, $res, $row, SORT_DATE, and SORT_TITLE.

Referenced by ilObjForumSearchResultTableGUI\parse().

+ Here is the caller graph for this function:

◆ _isModerator()

static ilForum::_isModerator (   $a_ref_id,
  $a_usr_id 
)
static

checks whether a user is moderator of a given forum object

Parameters
int$a_ref_idreference id
int$a_usr_iduser id
Returns
bool @access public

Definition at line 1428 of file class.ilForum.php.

1429 {
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);
1432 }
1433 return in_array($a_usr_id, self::$moderators_by_ref_id_map[$a_ref_id]);
1434 }
static _getModerators($a_ref_id)
get all users assigned to local role il_frm_moderator_<frm_ref_id> (static)

References _getModerators().

Referenced by generatePost(), ilObjForumGUI\renderDraftContent(), ilObjForumGUI\renderPostContent(), and ilForumExportGUI\renderPostHtml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lookupObjIdForForumId()

static ilForum::_lookupObjIdForForumId (   $a_for_id)
static

Definition at line 2144 of file class.ilForum.php.

2145 {
2146 global $DIC;
2147 $ilDB = $DIC->database();
2148
2149 $res = $ilDB->queryf(
2150 '
2151 SELECT top_frm_fk FROM frm_data
2152 WHERE top_pk = %s',
2153 array('integer'),
2154 array($a_for_id)
2155 );
2156
2157 if ($fdata = $ilDB->fetchAssoc($res)) {
2158 return $fdata["top_frm_fk"];
2159 }
2160 return false;
2161 }

References $DIC, $ilDB, and $res.

Referenced by ilForumPostingDraftsBlockGUI\fillDataSection(), ilObjMediaObject\getParentObjectIdForUsage(), ilObjForumGUI\mergeThreadsObject(), and ilForumTopic\movePosts().

+ Here is the caller graph for this function:

◆ _lookupPostMessage()

static ilForum::_lookupPostMessage (   $a_id)
static

Definition at line 387 of file class.ilForum.php.

388 {
389 global $DIC;
390 $ilDB = $DIC->database();
391
392 $res = $ilDB->queryf(
393 '
394 SELECT * FROM frm_posts WHERE pos_pk = %s',
395 array('integer'),
396 array($a_id)
397 );
398
399 while ($row = $ilDB->fetchObject($res)) {
400 return $row->pos_message;
401 }
402 return '';
403 }

References $DIC, $ilDB, $res, and $row.

◆ addPostTree()

ilForum::addPostTree (   $a_tree_id,
  $a_node_id = -1,
  $a_date = '' 
)

create a new post-tree

Parameters
integera_tree_id: id where tree belongs to
integera_node_id: root node of tree (optional; default is tree_id itself)
Returns
boolean true on success @access public

Definition at line 1502 of file class.ilForum.php.

1503 {
1504 $a_date = $a_date ? $a_date : date("Y-m-d H:i:s");
1505
1506 if ($a_node_id <= 0) {
1507 $a_node_id = $a_tree_id;
1508 }
1509
1510 $nextId = $this->db->nextId('frm_posts_tree');
1511
1512 $this->db->manipulateF(
1513 '
1514 INSERT INTO frm_posts_tree
1515 ( fpt_pk,
1516 thr_fk,
1517 pos_fk,
1518 parent_pos,
1519 lft,
1520 rgt,
1521 depth,
1522 fpt_date
1523 )
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)
1527 );
1528
1529 return true;
1530 }

Referenced by generatePost().

+ Here is the caller graph for this function:

◆ convertDate()

ilForum::convertDate (   $date)

converts the date format

Parameters
string$date
Returns
string formatted datetime @access public

Definition at line 1490 of file class.ilForum.php.

1491 {
1493 }
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling

References ilDatePresentation\formatDate(), and IL_CAL_DATETIME.

Referenced by getOnePost().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ countActiveUserArticles()

ilForum::countActiveUserArticles (   $a_user_id)

Definition at line 1461 of file class.ilForum.php.

1462 {
1463 $res = $this->db->queryf(
1464 '
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
1472 OR (pos_status = %s
1473 AND pos_author_id = %s
1474 )
1475 )
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)
1479 );
1480
1481 return $res->numRows();
1482 }

References $res, getForumId(), and user().

+ Here is the call graph for this function:

◆ countUserArticles()

ilForum::countUserArticles (   $a_user_id)

get number of articles from given user-ID

Parameters
integer$user,user-ID
Returns
integer @access public

Definition at line 1443 of file class.ilForum.php.

1444 {
1445 $res = $this->db->queryf(
1446 '
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'),
1455 array($this->getForumId(), $a_user_id)
1456 );
1457
1458 return $res->numRows();
1459 }

References $res, and getForumId().

+ Here is the call graph for this function:

◆ deletePost()

ilForum::deletePost (   $postIdOrArray,
  $raiseEvents = true 
)

Delete post and sub-posts.

Parameters
int|array<string,mixed>$postIdOrArray
bool$raiseEvents
Returns
int|mixed

Definition at line 799 of file class.ilForum.php.

800 {
801 if (is_numeric($postIdOrArray)) {
802 $p_node = $this->getPostNode($postIdOrArray);
803 } else {
804 $p_node = $postIdOrArray;
805 }
806
807 if ($raiseEvents) {
808 $GLOBALS['ilAppEventHandler']->raise(
809 'Modules/Forum',
810 'deletedPost',
811 [
812 'ref_id' => $this->getForumRefId(),
813 'post' => new ilForumPost($p_node['pos_pk']),
814 'thread_deleted' => ($p_node["parent"] == 0) ? true : false
815 ]
816 );
817 }
818
819 // delete tree and get id's of all posts to delete
820 $del_id = $this->deletePostTree($p_node);
821
822 // delete drafts_history
823 $obj_history = new ilForumDraftsHistory();
824 $obj_history->deleteHistoryByPostIds($del_id);
825 // delete all drafts
826 $obj_draft = new ilForumPostDraft();
827 $obj_draft->deleteDraftsByPostIds($del_id);
828
829 // Delete User read entries
830 foreach ($del_id as $post_id) {
832 }
833
834 // DELETE ATTACHMENTS ASSIGNED TO POST
835 $this->__deletePostFiles($del_id);
836
837 $dead_pos = count($del_id);
838 $dead_thr = 0;
839
840 // if deletePost is thread opener ...
841 if ($p_node["parent"] == 0) {
842 // delete thread access data
843 ilObjForum::_deleteAccessEntries($p_node['tree']);
844
845 // delete thread
846 $dead_thr = $p_node["tree"];
847
848 $this->db->manipulateF(
849 '
850 DELETE FROM frm_threads
851 WHERE thr_pk = %s',
852 array('integer'),
853 array($p_node['tree'])
854 );
855
856 // update num_threads
857 $this->db->manipulateF(
858 '
859 UPDATE frm_data
860 SET top_num_threads = top_num_threads - 1
861 WHERE top_frm_fk = %s',
862 array('integer'),
863 array($this->id)
864 );
865
866 // delete all related news
867 $posset = $this->db->queryf(
868 '
869 SELECT * FROM frm_posts
870 WHERE pos_thr_fk = %s',
871 array('integer'),
872 array($p_node['tree'])
873 );
874
875 while ($posrec = $this->db->fetchAssoc($posset)) {
877 $this->id,
878 "frm",
879 $posrec["pos_pk"],
880 "pos"
881 );
882 if ($news_id > 0) {
883 $news_item = new ilNewsItem($news_id);
884 $news_item->delete();
885 }
886
887 try {
888 $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', $posrec['pos_pk']);
889 foreach ($mobs as $mob) {
890 if (ilObjMediaObject::_exists($mob)) {
891 ilObjMediaObject::_removeUsage($mob, 'frm:html', $posrec['pos_pk']);
892 $mob_obj = new ilObjMediaObject($mob);
893 $mob_obj->delete();
894 }
895 }
896 } catch (Exception $e) {
897 }
898 }
899
900 // delete all posts of this thread
901 $this->db->manipulateF(
902 '
903 DELETE FROM frm_posts
904 WHERE pos_thr_fk = %s',
905 array('integer'),
906 array($p_node['tree'])
907 );
908 } else {
909 // delete this post and its sub-posts
910 for ($i = 0; $i < $dead_pos; $i++) {
911 $this->db->manipulateF(
912 '
913 DELETE FROM frm_posts
914 WHERE pos_pk = %s',
915 array('integer'),
916 array($del_id[$i])
917 );
918
919 // delete related news item
921 $this->id,
922 "frm",
923 $del_id[$i],
924 "pos"
925 );
926 if ($news_id > 0) {
927 $news_item = new ilNewsItem($news_id);
928 $news_item->delete();
929 }
930
931 try {
932 $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', $del_id[$i]);
933 foreach ($mobs as $mob) {
934 if (ilObjMediaObject::_exists($mob)) {
935 ilObjMediaObject::_removeUsage($mob, 'frm:html', $del_id[$i]);
936 $mob_obj = new ilObjMediaObject($mob);
937 $mob_obj->delete();
938 }
939 }
940 } catch (Exception $e) {
941 }
942 }
943
944 // update num_posts in frm_threads
945 $this->db->manipulateF(
946 '
947 UPDATE frm_threads
948 SET thr_num_posts = thr_num_posts - %s
949 WHERE thr_pk = %s',
950 array('integer', 'integer'),
951 array($dead_pos, $p_node['tree'])
952 );
953
954 // get latest post of thread and update last_post
955 $res1 = $this->db->queryf(
956 '
957 SELECT * FROM frm_posts
958 WHERE pos_thr_fk = %s
959 ORDER BY pos_date DESC',
960 array('integer'),
961 array($p_node['tree'])
962 );
963
964 if ($res1->numRows() == 0) {
965 $lastPost_thr = "";
966 } else {
967 $z = 0;
968
969 while ($selData = $this->db->fetchAssoc($res1)) {
970 if ($z > 0) {
971 break;
972 }
973
974 $lastPost_thr = $selData["pos_top_fk"] . "#" . $selData["pos_thr_fk"] . "#" . $selData["pos_pk"];
975 $z++;
976 }
977 }
978
979 $this->db->manipulateF(
980 '
981 UPDATE frm_threads
982 SET thr_last_post = %s
983 WHERE thr_pk = %s',
984 array('text', 'integer'),
985 array($lastPost_thr, $p_node['tree'])
986 );
987 }
988
989 // update num_posts in frm_data
990 $this->db->manipulateF(
991 '
992 UPDATE frm_data
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)
997 );
998
999 // get latest post of forum and update last_post
1000 $res2 = $this->db->queryf(
1001 '
1002 SELECT * FROM frm_posts, frm_data
1003 WHERE pos_top_fk = top_pk
1004 AND top_frm_fk = %s
1005 ORDER BY pos_date DESC',
1006 array('integer'),
1007 array($this->id)
1008 );
1009
1010 if ($res2->numRows() == 0) {
1011 $lastPost_top = "";
1012 } else {
1013 $z = 0;
1014
1015 while ($selData = $this->db->fetchAssoc($res2)) {
1016 if ($z > 0) {
1017 break;
1018 }
1019
1020 $lastPost_top = $selData["pos_top_fk"] . "#" . $selData["pos_thr_fk"] . "#" . $selData["pos_pk"];
1021 $z++;
1022 }
1023 }
1024
1025 $this->db->manipulateF(
1026 '
1027 UPDATE frm_data
1028 SET top_last_post = %s
1029 WHERE top_frm_fk = %s',
1030 array('text', 'integer'),
1031 array($lastPost_top, $this->id)
1032 );
1033
1034 return $dead_thr;
1035 }
Class ilForumDraftHistory.
Class ilForumPostDraft.
deletePostTree($a_node)
delete node and the whole subtree under this node @access public
__deletePostFiles($a_ids)
getPostNode($post_id)
get data of given node from frm_posts_tree and frm_posts @access public
getForumRefId()
get forum ref_id @access public
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.
static _deleteReadEntries($a_post_id)
static _deleteAccessEntries($a_thread_id)
Class ilObjMediaObject.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
static _exists($a_id, $a_reference=false, $a_type=null)
checks wether a lm content object with specified id exists or not
$i
Definition: disco.tpl.php:19
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
$mobs

References $GLOBALS, $i, $mobs, __deletePostFiles(), ilObjForum\_deleteAccessEntries(), ilObjForum\_deleteReadEntries(), ilObjMediaObject\_exists(), ilObjMediaObject\_getMobsOfObject(), ilObjMediaObject\_removeUsage(), deletePostTree(), ilNewsItem\getFirstNewsIdForContext(), getForumRefId(), and getPostNode().

Referenced by mergeThreads().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deletePostTree()

ilForum::deletePostTree (   $a_node)

delete node and the whole subtree under this node @access public

Parameters
arraynode_data of a node
Returns
array ID's of deleted posts

Definition at line 1733 of file class.ilForum.php.

1734 {
1735 // GET LEFT AND RIGHT VALUES
1736 $res = $this->db->queryf(
1737 '
1738 SELECT * FROM frm_posts_tree
1739 WHERE thr_fk = %s
1740 AND pos_fk = %s
1741 AND parent_pos = %s',
1742 array('integer', 'integer', 'integer'),
1743 array($a_node['tree'], $a_node['pos_pk'], $a_node['parent'])
1744 );
1745
1746 while ($row = $this->db->fetchObject($res)) {
1747 $a_node["lft"] = $row->lft;
1748 $a_node["rgt"] = $row->rgt;
1749 }
1750
1751 $diff = $a_node["rgt"] - $a_node["lft"] + 1;
1752
1753 // get data of posts
1754 $result = $this->db->queryf(
1755 '
1756 SELECT * FROM frm_posts_tree
1757 WHERE lft BETWEEN %s AND %s
1758 AND thr_fk = %s',
1759 array('integer', 'integer', 'integer'),
1760 array($a_node['lft'], $a_node['rgt'], $a_node['tree'])
1761 );
1762
1763 $del_id = array();
1764
1765 while ($treeData = $this->db->fetchAssoc($result)) {
1766 $del_id[] = $treeData["pos_fk"];
1767 }
1768
1769 // delete subtree
1770 $this->db->manipulateF(
1771 '
1772 DELETE FROM frm_posts_tree
1773 WHERE lft BETWEEN %s AND %s
1774 AND thr_fk = %s',
1775 array('integer', 'integer', 'integer'),
1776 array($a_node['lft'], $a_node['rgt'], $a_node['tree'])
1777 );
1778
1779 // close gaps
1780 $this->db->manipulateF(
1781 '
1782 UPDATE frm_posts_tree
1783 SET lft = CASE
1784 WHEN lft > %s
1785 THEN lft - %s
1786 ELSE lft
1787 END,
1788 rgt = CASE
1789 WHEN rgt > %s
1790 THEN rgt - %s
1791 ELSE rgt
1792 END
1793 WHERE thr_fk = %s',
1794 array('integer', 'integer', 'integer', 'integer', 'integer'),
1795 array($a_node['lft'], $diff, $a_node['lft'], $diff, $a_node['tree'])
1796 );
1797
1798 return $del_id;
1799 }
$result

References $res, $result, and $row.

Referenced by deletePost().

+ Here is the caller graph for this function:

◆ disableForumNotification()

ilForum::disableForumNotification (   $user_id)

Disable a user's notification about new posts in this forum.

Parameters
integeruser_id A user's ID
Returns
bool true @access private

Definition at line 2017 of file class.ilForum.php.

2018 {
2019 $this->db->manipulateF(
2020 '
2021 DELETE FROM frm_notification
2022 WHERE user_id = %s
2023 AND frm_id = %s',
2024 array('integer', 'integer'),
2025 array($user_id, $this->id)
2026 );
2027
2028 return true;
2029 }

◆ enableForumNotification()

ilForum::enableForumNotification (   $user_id)

Enable a user's notification about new posts in this forum.

Parameters
integeruser_id A user's ID
Returns
bool true @access private

Definition at line 1944 of file class.ilForum.php.

1945 {
1946 if (!$this->isForumNotificationEnabled($user_id)) {
1947 /* Remove all notifications of threads that belong to the forum */
1948
1949 $res = $this->db->queryf(
1950 '
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)
1959 );
1960
1961 if (is_object($res) && $res->numRows() > 0) {
1962 $thread_data = array();
1963 $thread_data_types = array();
1964
1965 $query = ' DELETE FROM frm_notification
1966 WHERE user_id = %s
1967 AND thread_id IN (';
1968
1969 array_push($thread_data, $user_id);
1970 array_push($thread_data_types, 'integer');
1971
1972 $counter = 1;
1973
1974 while ($row = $this->db->fetchAssoc($res)) {
1975 if ($counter < $res->numRows()) {
1976 $query .= '%s, ';
1977 array_push($thread_data, $row['thread_id']);
1978 array_push($thread_data_types, 'integer');
1979 }
1980
1981 if ($counter == $res->numRows()) {
1982 $query .= '%s)';
1983 array_push($thread_data, $row['thread_id']);
1984 array_push($thread_data_types, 'integer');
1985 }
1986 $counter++;
1987 }
1988
1989 $this->db->manipulateF($query, $thread_data_types, $thread_data);
1990 }
1991
1992 /* Insert forum notification */
1993
1994 $nextId = $this->db->nextId('frm_notification');
1995
1996 $this->db->manipulateF(
1997 '
1998 INSERT INTO frm_notification
1999 ( notification_id,
2000 user_id,
2001 frm_id
2002 )
2003 VALUES(%s, %s, %s)',
2004 array('integer','integer', 'integer'),
2005 array($nextId, $user_id, $this->id)
2006 );
2007 }
2008 return true;
2009 }
isForumNotificationEnabled($user_id)
Check whether a user's notification about new posts in this forum is enabled (result > 0) or not (res...
$query

References $query, $res, $row, and isForumNotificationEnabled().

+ Here is the call graph for this function:

◆ enableThreadNotification()

ilForum::enableThreadNotification (   $user_id,
  $thread_id 
)

no usage? ..delete .

Enable a user's notification about new posts in a thread

Parameters
integeruser_id A user's ID
integerthread_id ID of the thread
Returns
bool true @access private

Definition at line 2061 of file class.ilForum.php.

2062 {
2063 if (!$this->isThreadNotificationEnabled($user_id, $thread_id)) {
2064 $nextId = $this->db->nextId('frm_notification');
2065 $this->db->manipulateF(
2066 '
2067 INSERT INTO frm_notification
2068 ( notification_id,
2069 user_id,
2070 thread_id
2071 )
2072 VALUES (%s, %s, %s)',
2073 array('integer', 'integer', 'integer'),
2074 array($nextId, $user_id, $thread_id)
2075 );
2076 }
2077
2078 return true;
2079 }
isThreadNotificationEnabled($user_id, $thread_id)
Check whether a user's notification about new posts in a thread is enabled (result > 0) or not (resul...

References isThreadNotificationEnabled().

+ Here is the call graph for this function:

◆ fetchPostNodeData()

ilForum::fetchPostNodeData (   $a_row)

get data of parent node from frm_posts_tree and frm_posts @access private

Parameters
objectdb db result object containing node_data
Returns
array 2-dim (int/str) node_data

Definition at line 1686 of file class.ilForum.php.

1687 {
1688 if (ilObject::_exists($a_row->pos_display_user_id)) {
1689 $tmp_user = new ilObjUser($a_row->pos_display_user_id);
1690 $fullname = $tmp_user->getFullname();
1691 $loginname = $tmp_user->getLogin();
1692 }
1693
1694 $fullname = $fullname ? $fullname : ($a_row->import_name ? $a_row->import_name : $this->lng->txt("unknown"));
1695
1696 $data = array(
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,
1703 "type" => "post",
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,
1708 // "date" => $a_row->date,
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
1722 );
1723
1724 return $data ? $data : array();
1725 }
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
$data
Definition: bench.php:6

References $data, and ilObject\_exists().

Referenced by getFirstPostNode(), and getPostNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generatePost()

ilForum::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

Parameters
int$forum_id
int$thread_id
int$author_id
int$display_user_id
string$message
int$parent_pos
int$notify
string$subject
string$alias
string$datedatetime|timestamp
int$status
int$send_activation_mail
Returns
int new post_id

Definition at line 421 of file class.ilForum.php.

422 {
423 $objNewPost = new ilForumPost();
424 $objNewPost->setForumId($forum_id);
425 $objNewPost->setThreadId($thread_id);
426 $objNewPost->setSubject($subject);
427 $objNewPost->setMessage($message);
428 $objNewPost->setDisplayUserId($display_user_id);
429 $objNewPost->setUserAlias($alias);
430 $objNewPost->setPosAuthorId($author_id);
431
432 $frm_settings = ilForumProperties::getInstance($this->getForumId());
433
434 if ($frm_settings->getMarkModeratorPosts() == 1) {
435 self::_isModerator($this->getForumRefId(), $author_id) ? $is_moderator = true : $is_moderator = false;
436 } else {
437 $is_moderator = false;
438 }
439 $objNewPost->setIsAuthorModerator($is_moderator);
440
441 if ($date == "") {
442 $objNewPost->setCreateDate(date("Y-m-d H:i:s"));
443 } else {
444 if (strpos($date, "-") > 0) { // in mysql format
445 $objNewPost->setCreateDate($date);
446 } else { // a timestamp
447 $objNewPost->setCreateDate(date("Y-m-d H:i:s", $date));
448 }
449 }
450 if ($status == 1) {
451 $objNewPost->setPostActivationDate($objNewPost->getCreateDate());
452 }
453
454 $objNewPost->setImportName($this->getImportName());
455 $objNewPost->setNotification($notify);
456 $objNewPost->setStatus($status);
457 $objNewPost->insert();
458
459 // entry in tree-table
460 if ($parent_pos == 0) {
461 $this->addPostTree($objNewPost->getThreadId(), $objNewPost->getId(), $objNewPost->getCreateDate());
462 } else {
463 $this->insertPostNode($objNewPost->getId(), $parent_pos, $objNewPost->getThreadId(), $objNewPost->getCreateDate());
464 }
465
466 // string last post
467 $lastPost = $objNewPost->getForumId() . "#" . $objNewPost->getThreadId() . "#" . $objNewPost->getId();
468
469 // update thread
470 $this->db->manipulateF(
471 '
472 UPDATE frm_threads
473 SET thr_num_posts = thr_num_posts + 1,
474 thr_last_post = %s
475 WHERE thr_pk = %s',
476 array('text', 'integer'),
477 array($lastPost, $objNewPost->getThreadId())
478 );
479
480 // update forum
481 $this->db->manipulateF(
482 '
483 UPDATE frm_data
484 SET top_num_posts = top_num_posts + 1,
485 top_last_post = %s
486 WHERE top_pk = %s',
487 array('text', 'integer'),
488 array($lastPost, $objNewPost->getForumId())
489 );
490
491 // MARK READ
493 $forum_obj->markPostRead($objNewPost->getPosAuthorId(), $objNewPost->getThreadId(), $objNewPost->getId());
494
495 // Add Notification to news
496 if ($status && $parent_pos > 0) {
497 $news_item = new ilNewsItem();
498 $news_item->setContext($forum_obj->getId(), 'frm', $objNewPost->getId(), 'pos');
499 $news_item->setPriority(NEWS_NOTICE);
500 $news_item->setTitle($objNewPost->getSubject());
501 $news_item->setContent(ilRTE::_replaceMediaObjectImageSrc($this->prepareText($objNewPost->getMessage(), 0), 1));
502 if ($objNewPost->getMessage() != strip_tags($objNewPost->getMessage())) {
503 $news_item->setContentHtml(true);
504 }
505
506 $news_item->setUserId($display_user_id);
507 $news_item->setVisibility(NEWS_USERS);
508 $news_item->create();
509 }
510
511 return $objNewPost->getId();
512 }
const NEWS_USERS
const NEWS_NOTICE
static getInstance($a_obj_id=0)
addPostTree($a_tree_id, $a_node_id=-1, $a_date='')
create a new post-tree
static _isModerator($a_ref_id, $a_usr_id)
checks whether a user is moderator of a given forum object
prepareText($text, $edit=0, $quote_user='', $type='')
prepares given string @access public
insertPostNode($a_node_id, $a_parent_id, $tree_id, $a_date='')
insert node under parent node @access public
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
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...
catch(Exception $e) $message

References $message, _isModerator(), ilRTE\_replaceMediaObjectImageSrc(), addPostTree(), getForumId(), getForumRefId(), getImportName(), ilForumProperties\getInstance(), ilObjectFactory\getInstanceByRefId(), insertPostNode(), NEWS_NOTICE, NEWS_USERS, and prepareText().

Referenced by generateThread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generateThread()

ilForum::generateThread ( ilForumTopic  $thread,
  $message,
  $notify,
  $notify_posts,
  $status = 1,
bool  $withFirstVisibleEntry = true 
)
Parameters
ilForumTopic$thread
string$message
int$notify
int$notify_posts
int$status
bool$withFirstVisibleEntry
Returns
int The id of the new posting, created implicitly when creating new threads

Definition at line 523 of file class.ilForum.php.

530 {
531 if (!$thread->getCreateDate()) {
532 $thread->setCreateDate(date('Y-m-d H:i:s'));
533 }
534
535 $thread->setImportName($this->getImportName());
536 $thread->insert();
537
538 if ($notify_posts == 1) {
539 $thread->enableNotification($thread->getThrAuthorId());
540 }
541
542 $this->db->manipulateF(
543 '
544 UPDATE frm_data
545 SET top_num_threads = top_num_threads + 1
546 WHERE top_pk = %s',
547 array('integer'),
548 array($thread->getForumId())
549 );
550
551 $rootNodeId = $this->generatePost(
552 $thread->getForumId(),
553 $thread->getId(),
554 $thread->getThrAuthorId(),
555 $thread->getDisplayUserId(),
556 '',
557 0,
558 0,
559 $thread->getSubject(),
560 $thread->getUserAlias(),
561 $thread->getCreateDate(),
562 1,
563 0
564 );
565
566 if (!$withFirstVisibleEntry) {
567 return $rootNodeId;
568 }
569
570 return $this->generatePost(
571 $thread->getForumId(),
572 $thread->getId(),
573 $thread->getThrAuthorId(),
574 $thread->getDisplayUserId(),
575 $message,
576 $rootNodeId,
577 $notify,
578 $thread->getSubject(),
579 $thread->getUserAlias(),
580 $thread->getCreateDate(),
581 $status,
582 0
583 );
584 }
insert()
Inserts the object data into database.
setImportName($a_import_name)
enableNotification($a_user_id)
Enable a user's notification about new posts in a thread.
setCreateDate($a_createdate)
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

References $message, ilForumTopic\enableNotification(), generatePost(), ilForumTopic\getCreateDate(), ilForumTopic\getDisplayUserId(), ilForumTopic\getForumId(), ilForumTopic\getId(), getImportName(), ilForumTopic\getSubject(), ilForumTopic\getThrAuthorId(), ilForumTopic\getUserAlias(), ilForumTopic\insert(), ilForumTopic\setCreateDate(), and ilForumTopic\setImportName().

+ Here is the call graph for this function:

◆ getAllThreads()

ilForum::getAllThreads (   $a_topic_id,
array  $params = array(),
  $limit = 0,
  $offset = 0 
)
Parameters
$a_topic_id
array$params
int$limit
int$offset
Returns
array

Definition at line 1044 of file class.ilForum.php.

1045 {
1046 $frm_overview_setting = (int) $this->settings->get('forum_overview');
1047 $frm_props = ilForumProperties::getInstance($this->getForumId());
1048 $is_post_activation_enabled = $frm_props->isPostActivationEnabled();
1049
1050 $user_id = $this->user->getId();
1051
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') . ' ';
1055 }
1056
1057 if (!in_array(strtolower($params['order_column']), array('lp_date', 'rating', 'thr_subject', 'num_posts', 'num_visit'))) {
1058 $params['order_column'] = 'post_date';
1059 }
1060 if (!in_array(strtolower($params['order_direction']), array('asc', 'desc'))) {
1061 $params['order_direction'] = 'desc';
1062 }
1063
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";
1069 }
1070 $query =
1071 "SELECT COUNT(DISTINCT(thr_pk)) cnt
1072 FROM frm_threads
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}
1076 ";
1077 $res = $this->db->queryF($query, array('integer'), array($a_topic_id));
1078 $cntData = $this->db->fetchAssoc($res);
1079 $cnt = (int) $cntData['cnt'];
1080
1081 $active_query = '';
1082 $active_inner_query = '';
1083 $having = '';
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';
1088 }
1089
1090 $threads = array();
1091 $data = array();
1092 $data_types = array();
1093
1094 $optional_fields = '';
1095 if ($frm_props->isIsThreadRatingEnabled()) {
1096 $optional_fields = ',avg_rating';
1097 }
1098 if ($frm_props->getThreadSorting() == 1) {
1099 $optional_fields = ',thread_sorting';
1100 }
1101
1102 $additional_sort = '';
1103 if ($frm_props->getThreadSorting()) {
1104 $additional_sort .= ' , thread_sorting ASC ';
1105 }
1106
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']);
1113 } else {
1114 $dynamic_columns = array(', post_date ' . $params['order_direction']);
1115 }
1116
1117 if ($frm_props->isIsThreadRatingEnabled()) {
1118 $dynamic_columns[] = ' ,avg_rating ' . $params['order_direction'];
1119 }
1120 if ('rating' == strtolower($params['order_column'])) {
1121 $dynamic_columns = array_reverse($dynamic_columns);
1122 }
1123 $additional_sort .= implode(' ', $dynamic_columns);
1124
1125 if (!$this->user->isAnonymous()) {
1126 $query = "SELECT
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, ";
1131
1132 // new posts query
1133 if ($frm_overview_setting == ilForumProperties::FORUM_OVERVIEW_WITH_NEW_POSTS) {
1134 $query .= "
1135 (SELECT COUNT(DISTINCT(ipos.pos_pk))
1136 FROM frm_posts ipos
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
1144 OR
1145 (iacc.access_old IS NULL AND (ipos.pos_update > " . $this->db->quote(date('Y-m-d H:i:s', NEW_DEADLINE), 'timestamp') . "))
1146 )
1147
1148 AND ipos.pos_author_id != %s
1149 AND iread.usr_id IS NULL $active_inner_query
1150 ) num_new_posts, ";
1151 }
1152
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
1154 {$optional_fields}
1155 FROM frm_threads
1156
1157 LEFT JOIN frm_notification
1158 ON frm_notification.thread_id = thr_pk
1159 AND frm_notification.user_id = %s
1160
1161 LEFT JOIN frm_posts
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";
1168
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
1172 {$optional_fields}
1173 {$having}
1174 ORDER BY is_sticky DESC {$additional_sort}, thr_date DESC";
1175
1176
1177 // data_types for new posts query and $active_inner_query
1178 if ($frm_overview_setting == ilForumProperties::FORUM_OVERVIEW_WITH_NEW_POSTS) {
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');
1184 }
1185 }
1186 $data_types[] = 'integer';
1187 if ($is_post_activation_enabled && !$params['is_moderator']) {
1188 array_push($data_types, 'integer', 'integer');
1189 }
1190 $data_types[] = 'integer';
1191 $data_types[] = 'integer';
1192
1193 // data_values for new posts query and $active_inner_query
1194 if ($frm_overview_setting == ilForumProperties::FORUM_OVERVIEW_WITH_NEW_POSTS) {
1195 $data[] = $user_id;
1196 $data[] = $user_id;
1197 $data[] = $user_id;
1198 if ($is_post_activation_enabled && !$params['is_moderator']) {
1199 array_push($data, '1', $user_id);
1200 }
1201 }
1202 $data[] = $user_id;
1203 if ($is_post_activation_enabled && !$params['is_moderator']) {
1204 array_push($data, '1', $user_id);
1205 }
1206 $data[] = $user_id;
1207 $data[] = $a_topic_id;
1208 } else {
1209 $query = "SELECT
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
1216 {$optional_fields}
1217 FROM frm_threads
1218
1219 LEFT JOIN frm_posts
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
1223 ";
1224
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
1228 {$optional_fields}
1229 {$having}
1230 ORDER BY is_sticky DESC {$additional_sort}, thr_date DESC";
1231
1232 if ($is_post_activation_enabled && !$params['is_moderator']) {
1233 array_push($data_types, 'integer', 'integer');
1234 }
1235 $data_types[] = 'integer';
1236 if ($is_post_activation_enabled && !$params['is_moderator']) {
1237 array_push($data, '1', $user_id);
1238 }
1239 $data[] = $a_topic_id;
1240 }
1241
1242 if ($limit || $offset) {
1243 $this->db->setLimit($limit, $offset);
1244 }
1245 $res = $this->db->queryF($query, $data_types, $data);
1246
1247 $threadIds = [];
1248 while ($row = $this->db->fetchAssoc($res)) {
1249 $thread = new ilForumTopic($row['thr_pk'], $params['is_moderator'], true);
1250 $thread->assignData($row);
1251 $threads[$row['thr_pk']] = $thread;
1252 $threadIds[] = $row['thr_pk'];
1253 }
1254
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')
1262 );
1263 }
1264
1265 $post_res = $this->db->query(
1266 '
1267 SELECT frm_posts.*
1268 FROM frm_posts
1269 INNER JOIN (
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 . '
1274 GROUP BY pos_thr_fk
1275 ) opost ON frm_posts.pos_thr_fk = opost.pos_thr_fk AND frm_posts.pos_date = opost.i_pos_date'
1276 );
1277
1278 while ($post_row = $this->db->fetchAssoc($post_res)) {
1279 $tmp_obj = new ilForumPost($post_row['pos_pk'], $params['is_moderator'], true);
1280
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']);
1287
1288 $threads[$post_row['pos_thr_fk']]->setLastPostForThreadOverview($tmp_obj);
1289 }
1290
1291 return array(
1292 'items' => $threads,
1293 'cnt' => $cnt
1294 );
1295 }

References $data, PHPMailer\PHPMailer\$params, $query, $res, $row, ilForumProperties\FORUM_OVERVIEW_WITH_NEW_POSTS, getForumId(), ilForumProperties\getInstance(), settings(), and user().

+ Here is the call graph for this function:

◆ getDbTable()

ilForum::getDbTable ( )

get name of database table

Returns
string name of database table
See also
$dbTable @access User interface

Definition at line 212 of file class.ilForum.php.

213 {
214 return $this->dbTable;
215 }

References $dbTable.

◆ getFirstPostByThread()

ilForum::getFirstPostByThread (   $a_thread_id)

Get first post of thread.

@access public

Parameters
intthread id
Returns

Definition at line 1371 of file class.ilForum.php.

1372 {
1373 $res = $this->db->queryf(
1374 '
1375 SELECT * FROM frm_posts_tree
1376 WHERE thr_fk = %s
1377 AND parent_pos = %s',
1378 array('integer', 'integer'),
1379 array($a_thread_id, '0')
1380 );
1381
1382 $row = $this->db->fetchObject($res);
1383
1384 return $row->pos_fk ? $row->pos_fk : 0;
1385 }

References $res, and $row.

◆ getFirstPostNode()

ilForum::getFirstPostNode (   $tree_id)

get data of the first node from frm_posts_tree and frm_posts @access public

Parameters
integertree id
Returns
object db result object

Definition at line 1641 of file class.ilForum.php.

1642 {
1643 $res = $this->db->queryf(
1644 '
1645 SELECT * FROM frm_posts, frm_posts_tree
1646 WHERE pos_pk = pos_fk
1647 AND parent_pos = %s
1648 AND thr_fk = %s',
1649 array('integer', 'integer'),
1650 array('0', $tree_id)
1651 );
1652
1653 $row = $this->db->fetchObject($res);
1654
1655 return $this->fetchPostNodeData($row);
1656 }
fetchPostNodeData($a_row)
get data of parent node from frm_posts_tree and frm_posts @access private

References $res, $row, and fetchPostNodeData().

+ Here is the call graph for this function:

◆ getForumId()

ilForum::getForumId ( )

get forum id @access public

Returns
integer object id of forum

Definition at line 150 of file class.ilForum.php.

151 {
152 return $this->id;
153 }

References $id.

Referenced by __deletePostFiles(), countActiveUserArticles(), countUserArticles(), generatePost(), getAllThreads(), and getUserStatistic().

+ Here is the caller graph for this function:

◆ getForumRefId()

ilForum::getForumRefId ( )

get forum ref_id @access public

Returns
integer reference id of forum

Definition at line 160 of file class.ilForum.php.

161 {
162 return $this->ref_id;
163 }

Referenced by deletePost(), generatePost(), getModerators(), and postCensorship().

+ Here is the caller graph for this function:

◆ getImportName()

ilForum::getImportName ( )

Definition at line 1929 of file class.ilForum.php.

1930 {
1931 return $this->import_name;
1932 }

Referenced by generatePost(), and generateThread().

+ Here is the caller graph for this function:

◆ getMDB2DataType()

ilForum::getMDB2DataType ( )

get content of additional condition

Returns
array

Definition at line 260 of file class.ilForum.php.

261 {
262 if ($this->mdb2DataType != '') {
263 return $this->mdb2DataType;
264 }
265 }

References $mdb2DataType.

Referenced by getOneThread(), getOneTopic(), and updateVisits().

+ Here is the caller graph for this function:

◆ getMDB2DataValue()

ilForum::getMDB2DataValue ( )

get content of additional condition

Returns
array

Definition at line 249 of file class.ilForum.php.

250 {
251 if ($this->mdb2DataValue != '') {
253 }
254 }

References $mdb2DataValue.

Referenced by getOneThread(), getOneTopic(), and updateVisits().

+ Here is the caller graph for this function:

◆ getMDB2Query()

ilForum::getMDB2Query ( )

get content of additional condition

Returns
string

Definition at line 238 of file class.ilForum.php.

239 {
240 if ($this->mdb2Query != '') {
241 return $this->mdb2Query;
242 }
243 }

References $mdb2Query.

Referenced by getOneThread(), getOneTopic(), and updateVisits().

+ Here is the caller graph for this function:

◆ getModerators()

ilForum::getModerators ( )

get all users assigned to local role il_frm_moderator_<frm_ref_id>

Returns
array user_ids @access public

Definition at line 1393 of file class.ilForum.php.

1394 {
1395 return self::_getModerators($this->getForumRefId());
1396 }

References _getModerators(), and getForumRefId().

+ Here is the call graph for this function:

◆ getOnePost()

ilForum::getOnePost (   $post)

get one post-dataset

Parameters
integerpost id
Returns
array result dataset of the post @access public

Definition at line 368 of file class.ilForum.php.

369 {
370 $res = $this->db->queryf(
371 '
372 SELECT frm_posts.*, usr_data.lastname FROM frm_posts, usr_data
373 WHERE pos_pk = %s
374 AND pos_display_user_id = usr_id',
375 array('integer'),
376 array($post)
377 );
378
379 $row = $this->db->fetchAssoc($res);
380
381 $row["pos_date"] = $this->convertDate($row["pos_date"]);
382 $row["pos_message"] = nl2br($row["pos_message"]);
383
384 return $row;
385 }
convertDate($date)
converts the date format
$post
Definition: post.php:34

References $post, $res, $row, and convertDate().

+ Here is the call graph for this function:

◆ getOneThread()

ilForum::getOneThread ( )

get one thread-dataset by WhereCondition

Returns
array $result dataset of the thread @access public

Definition at line 342 of file class.ilForum.php.

343 {
344 $data_type = array();
345 $data_value = array();
346
347 $query = 'SELECT * FROM frm_threads WHERE ';
348
349 if ($this->getMDB2Query() != '' && $this->getMDB2DataType() != '' && $this->getMDB2DataValue() != '') {
350 $query .= $this->getMDB2Query();
351 $data_type = $data_type + $this->getMDB2DataType();
352 $data_value = $data_value + $this->getMDB2DataValue();
353
354 $sql_res = $this->db->queryf($query, $data_type, $data_value);
355 $result = $this->db->fetchAssoc($sql_res);
356 $result["thr_subject"] = trim($result["thr_subject"]);
357 }
358
359 return $result;
360 }
getMDB2Query()
get content of additional condition
getMDB2DataType()
get content of additional condition
getMDB2DataValue()
get content of additional condition

References $query, $result, getMDB2DataType(), getMDB2DataValue(), and getMDB2Query().

+ Here is the call graph for this function:

◆ getOneTopic()

ilForum::getOneTopic ( )

get one topic-dataset by WhereCondition

Returns
array $result dataset of the topic @access public

Definition at line 297 of file class.ilForum.php.

298 {
299 $data_type = array();
300 $data_value = array();
301
302 $query = 'SELECT * FROM frm_data WHERE ';
303
304 if ($this->getMDB2Query() != '' && $this->getMDB2DataType() != '' && $this->getMDB2DataValue() != '') {
305 $query .= '' . $this->getMDB2Query() . '';
306 $data_type = $data_type + $this->getMDB2DataType();
307 $data_value = $data_value + $this->getMDB2DataValue();
308
309 $res = $this->db->queryf($query, $data_type, $data_value);
310 $row = $this->db->fetchAssoc($res);
311
312 if (is_null($row)) {
313 return null;
314 }
315
316 $row["top_name"] = trim($row["top_name"]);
317 $row["top_description"] = nl2br($row["top_description"]);
318
319 return $row;
320 } else {
321 $query .= '1 = 1';
322
323 $res = $this->db->query($query);
324 $row = $this->db->fetchAssoc($res);
325
326 if (!is_array($row) || !count($row)) {
327 return null;
328 }
329
330 $row['top_name'] = trim($row['top_name']);
331 $row['top_description'] = nl2br($row['top_description']);
332
333 return $row;
334 }
335 }

References $query, $res, $row, getMDB2DataType(), getMDB2DataValue(), and getMDB2Query().

Referenced by moveThreads().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOrderField()

ilForum::getOrderField ( )

get name of orderField

Returns
string name of orderField
See also
$orderField @access User interface

Definition at line 186 of file class.ilForum.php.

187 {
188 return $this->orderField;
189 }

References $orderField.

◆ getPageHits()

ilForum::getPageHits ( )

get number of max.

visible datasets

Returns
integer $pageHits
See also
$pageHits @access User interface

Definition at line 287 of file class.ilForum.php.

288 {
289 return $this->pageHits;
290 }

References $pageHits.

◆ getPostDepth()

ilForum::getPostDepth (   $a_node_id,
  $tree_id 
)

Return depth of an object @access private.

Parameters
integernode_id of parent's node_id
integernode_id of parent's node parent_id
Returns
integer depth of node

Definition at line 1615 of file class.ilForum.php.

1616 {
1617 if ($tree_id) {
1618 $sql_res = $this->db->queryf(
1619 '
1620 SELECT depth FROM frm_posts_tree
1621 WHERE pos_fk = %s
1622 AND thr_fk = %s',
1623 array('integer', 'integer'),
1624 array($a_node_id, $tree_id)
1625 );
1626
1627 $res = $this->db->fetchObject($sql_res);
1628
1629 return $res->depth;
1630 } else {
1631 return 0;
1632 }
1633 }

References $res.

Referenced by insertPostNode().

+ Here is the caller graph for this function:

◆ getPostNode()

ilForum::getPostNode (   $post_id)

get data of given node from frm_posts_tree and frm_posts @access public

Parameters
integerpost_id
Returns
array<string, mixed>

Definition at line 1664 of file class.ilForum.php.

1665 {
1666 $res = $this->db->queryf(
1667 '
1668 SELECT * FROM frm_posts, frm_posts_tree
1669 WHERE pos_pk = pos_fk
1670 AND pos_pk = %s',
1671 array('integer'),
1672 array($post_id)
1673 );
1674
1675 $row = $this->db->fetchObject($res);
1676
1677 return $this->fetchPostNodeData($row);
1678 }

References $res, $row, and fetchPostNodeData().

Referenced by deletePost(), and mergeThreads().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserStatistic()

ilForum::getUserStatistic (   $is_moderator = false)
Parameters
bool$is_moderator
Returns
array

Definition at line 1301 of file class.ilForum.php.

1302 {
1303 $statistic = array();
1304
1305 $data_types = array();
1306 $data = array();
1307
1308 $query = "SELECT COUNT(f.pos_display_user_id) ranking, u.login, p.value, u.lastname, u.firstname
1309 FROM frm_posts f
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";
1321
1322 array_push($data_types, 'text');
1323 array_push($data, 'public_profile');
1324
1325 if (!$is_moderator) {
1326 $query .= ' AND (pos_status = %s
1327 OR (pos_status = %s
1328 AND pos_author_id = %s ))';
1329
1330 array_push($data_types, 'integer', 'integer', 'integer');
1331 array_push($data, '1', '0', $this->user->getId());
1332 }
1333
1334 $query .= ' AND d.top_frm_fk = %s
1335 GROUP BY pos_display_user_id, u.login, p.value,u.lastname, u.firstname';
1336
1337 array_push($data_types, 'integer');
1338 array_push($data, $this->getForumId());
1339
1340 $res = $this->db->queryf($query, $data_types, $data);
1341
1342 $counter = 0;
1343 while ($row = $this->db->fetchAssoc($res)) {
1344 $statistic[$counter][] = $row['ranking'];
1345 $statistic[$counter][] = $row['login'];
1346
1347 $lastname = '';
1348 $firstname = '';
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'];
1353 }
1354
1355 $statistic[$counter][] = $lastname;
1356 $statistic[$counter][] = $firstname;
1357
1358 ++$counter;
1359 }
1360
1361 return is_array($statistic) ? $statistic : array();
1362 }

References $data, $query, $res, $row, getForumId(), and user().

+ Here is the call graph for this function:

◆ insertPostNode()

ilForum::insertPostNode (   $a_node_id,
  $a_parent_id,
  $tree_id,
  $a_date = '' 
)

insert node under parent node @access public

Parameters
integernode_id
integertree_id
integerparent_id (optional)

Definition at line 1539 of file class.ilForum.php.

1540 {
1541 $a_date = $a_date ? $a_date : date("Y-m-d H:i:s");
1542
1543 // get left value
1544 $sql_res = $this->db->queryf(
1545 '
1546 SELECT * FROM frm_posts_tree
1547 WHERE pos_fk = %s
1548 AND thr_fk = %s',
1549 array('integer', 'integer'),
1550 array($a_parent_id, $tree_id)
1551 );
1552
1553 $res = $this->db->fetchObject($sql_res);
1554
1555 $left = $res->lft;
1556
1557 $lft = $left + 1;
1558 $rgt = $left + 2;
1559
1560 // spread tree
1561 $this->db->manipulateF(
1562 '
1563 UPDATE frm_posts_tree
1564 SET lft = CASE
1565 WHEN lft > %s
1566 THEN lft + 2
1567 ELSE lft
1568 END,
1569 rgt = CASE
1570 WHEN rgt > %s
1571 THEN rgt + 2
1572 ELSE rgt
1573 END
1574 WHERE thr_fk = %s',
1575 array('integer', 'integer', 'integer'),
1576 array($left, $left, $tree_id)
1577 );
1578
1579 $depth = $this->getPostDepth($a_parent_id, $tree_id) + 1;
1580
1581 // insert node
1582 $nextId = $this->db->nextId('frm_posts_tree');
1583 $this->db->manipulateF(
1584 '
1585 INSERT INTO frm_posts_tree
1586 ( fpt_pk,
1587 thr_fk,
1588 pos_fk,
1589 parent_pos,
1590 lft,
1591 rgt,
1592 depth,
1593 fpt_date
1594 )
1595 VALUES(%s,%s,%s, %s, %s, %s,%s, %s)',
1596 array('integer','integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'timestamp'),
1597 array( $nextId,
1598 $tree_id,
1599 $a_node_id,
1600 $a_parent_id,
1601 $lft,
1602 $rgt,
1603 $depth,
1604 $a_date)
1605 );
1606 }
getPostDepth($a_node_id, $tree_id)
Return depth of an object @access private.

References $res, and getPostDepth().

Referenced by generatePost().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isForumNotificationEnabled()

ilForum::isForumNotificationEnabled (   $user_id)

Check whether a user's notification about new posts in this forum is enabled (result > 0) or not (result == 0)

Parameters
integeruser_id A user's ID
Returns
integer Result

Definition at line 2036 of file class.ilForum.php.

2037 {
2038 $result = $this->db->queryf(
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)
2042 );
2043
2044 while ($record = $this->db->fetchAssoc($result)) {
2045 return (bool) $record['cnt'];
2046 }
2047
2048 return false;
2049 }

References $result.

Referenced by enableForumNotification().

+ Here is the caller graph for this function:

◆ isThreadNotificationEnabled()

ilForum::isThreadNotificationEnabled (   $user_id,
  $thread_id 
)

Check whether a user's notification about new posts in a thread is enabled (result > 0) or not (result == 0)

Parameters
integeruser_id A user's ID
integerthread_id ID of the thread
Returns
integer Result

Definition at line 2087 of file class.ilForum.php.

2088 {
2089 $result = $this->db->queryf(
2090 '
2091 SELECT COUNT(*) cnt FROM frm_notification
2092 WHERE user_id = %s
2093 AND thread_id = %s',
2094 array('integer', 'integer'),
2095 array($user_id, $thread_id)
2096 );
2097
2098
2099 while ($record = $this->db->fetchAssoc($result)) {
2100 return (bool) $record['cnt'];
2101 }
2102
2103 return false;
2104 }

References $result.

Referenced by enableThreadNotification().

+ Here is the caller graph for this function:

◆ mergeThreads()

ilForum::mergeThreads (   $source_id,
  $target_id 
)
Parameters
int$source_id
int$target_id
Exceptions
ilException

Definition at line 2206 of file class.ilForum.php.

2207 {
2208 // selected source and target objects
2209 $sourceThread = new \ilForumTopic((int) $source_id);
2210 $targetThread = new \ilForumTopic((int) $target_id);
2211
2212 if ($sourceThread->getForumId() != $targetThread->getForumId()) {
2213 throw new \ilException('not_allowed_to_merge_into_another_forum');
2214 }
2215
2216 // use the "older" thread as target
2217 if ($sourceThread->getCreateDate() > $targetThread->getCreateDate()) {
2218 $sourceThreadForMerge = $sourceThread;
2219 $targetThreadForMerge = $targetThread;
2220 } else {
2221 $sourceThreadForMerge = $targetThread;
2222 $targetThreadForMerge = $sourceThread;
2223 }
2224
2225 $threadSubject = $targetThreadForMerge->getSubject();
2226
2227 $targetWasClosedBeforeMerge = (bool) $targetThreadForMerge->isClosed();
2228 $sourceThreadForMerge->close();
2229
2230 if (false === $targetWasClosedBeforeMerge) {
2231 $targetThreadForMerge->close();
2232 }
2233
2234 $allSourcePostings = $sourceThreadForMerge->getAllPosts();
2235 $sourceThreadRootNode = $sourceThreadForMerge->getFirstPostNode();
2236 $targetThreadRootNode = $targetThreadForMerge->getFirstPostNode();
2237
2238 $sourceThreadRootArray = $this->getPostNode($sourceThreadRootNode->getId());
2239
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');
2245
2246 $ilAtomQuery->addQueryCallable(static function (ilDBInterface $ilDB) use (
2247 $targetThreadForMerge,
2248 $sourceThreadForMerge,
2249 $targetThreadRootNode,
2250 $sourceThreadRootNode,
2251 $allSourcePostings
2252 ) {
2253 $targetRootNodeRgt = $targetThreadRootNode->getRgt();
2254 $targetRootNodeId = $targetThreadRootNode->getId();
2255
2256 // update target root node rgt: Ignore the root node itself from the source (= -2)
2258 $targetThreadRootNode->getId(),
2259 ($targetThreadRootNode->getRgt() + $sourceThreadRootNode->getRgt() - 2)
2260 );
2261
2262 // get source post tree and update posts tree
2263 foreach ($allSourcePostings as $post) {
2264 $post_obj = new ilForumPost($post->pos_pk);
2265
2266 if ((int) $post_obj->getId() === (int) $sourceThreadRootNode->getId()) {
2267 // Ignore the source root node (MUST be deleted later)
2268 continue;
2269 }
2270
2271 $tree = new \ilForumPostsTree();
2272 $tree->setPosFk($post->pos_pk);
2273
2274 if ((int) $post_obj->getParentId() === (int) $sourceThreadRootNode->getId()) {
2275 $tree->setParentPos($targetRootNodeId);
2276 } else {
2277 $tree->setParentPos($post_obj->getParentId());
2278 }
2279
2280 $tree->setLft(($post_obj->getLft() + $targetRootNodeRgt) - 2);
2281 $tree->setRgt(($post_obj->getRgt() + $targetRootNodeRgt) - 2);
2282
2283 $tree->setDepth($post_obj->getDepth());
2284 $tree->setTargetThreadId($targetThreadForMerge->getId());
2285 $tree->setSourceThreadId($sourceThreadForMerge->getId());
2286
2287 $tree->merge();
2288 }
2289
2290 // update frm_posts pos_thr_fk = target_thr_id
2292 (int) $sourceThreadForMerge->getId(),
2293 (int) $targetThreadForMerge->getId(),
2294 [(int) $sourceThreadRootNode->getId(),]
2295 );
2296 });
2297 $ilAtomQuery->run();
2298
2299 // check notifications
2300 \ilForumNotification::mergeThreadNotificiations($sourceThreadForMerge->getId(), $targetThreadForMerge->getId());
2301
2302 // delete frm_thread_access entries
2303 \ilObjForum::_deleteAccessEntries($sourceThreadForMerge->getId());
2304
2305 // update frm_user_read
2306 \ilObjForum::mergeForumUserRead($sourceThreadForMerge->getId(), $targetThreadForMerge->getId());
2307
2308 // update visits, thr_num_posts, last_post, subject
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);
2314 }
2315
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();
2323
2324 if (!$targetWasClosedBeforeMerge) {
2325 $targetThreadForMerge->reopen();
2326 }
2327
2328 // raise event for updating existing drafts
2329 $GLOBALS['ilAppEventHandler']->raise(
2330 'Modules/Forum',
2331 'mergedThreads',
2332 [
2333 'source_thread_id' => $sourceThreadForMerge->getId(),
2334 'target_thread_id' => $targetThreadForMerge->getId()
2335 ]
2336 );
2337
2338 $this->deletePost($sourceThreadRootArray, false);
2339 }
static mergeThreadNotificiations($merge_source_thread_id, $merge_target_thread_id)
static mergePosts(int $sourceThreadId, int $targetThreadId, array $excludedPostIds=[])
static updateTargetRootRgt($root_node_id, $rgt)
deletePost($postIdOrArray, $raiseEvents=true)
Delete post and sub-posts.
static mergeForumUserRead($merge_source_thread_id, $merge_target_thread_id)
$target_id
Definition: goto.php:49
Interface ilDBInterface.

References $GLOBALS, $ilDB, $post, $target_id, $tree, ilObjForum\_deleteAccessEntries(), deletePost(), getPostNode(), ilObjForum\mergeForumUserRead(), ilForumPost\mergePosts(), ilForumNotification\mergeThreadNotificiations(), and ilForumPostsTree\updateTargetRootRgt().

+ Here is the call graph for this function:

◆ moveThreads()

ilForum::moveThreads (   $thread_ids = array(),
  $src_ref_id = 0,
  $dest_top_frm_fk = 0 
)

Moves all chosen threads and their posts to a new forum.

Parameters
arraychosen thread pks
integerobject id of src forum
integerobject id of dest forum @access public
Returns
array

Definition at line 595 of file class.ilForum.php.

596 {
597 $src_top_frm_fk = ilObject::_lookupObjectId($src_ref_id);
598
599 $errorMessages = array();
600
601 if (is_numeric($src_top_frm_fk) && $src_top_frm_fk > 0 && is_numeric($dest_top_frm_fk) && $dest_top_frm_fk > 0) {
602 $this->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($src_top_frm_fk));
603
604 $oldFrmData = $this->getOneTopic();
605
606 $this->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($dest_top_frm_fk));
607
608 $newFrmData = $this->getOneTopic();
609
610 if ($oldFrmData['top_pk'] && $newFrmData['top_pk']) {
611 $moved_posts = 0;
612 $moved_threads = 0;
613 $visits = 0;
614
615 foreach ($thread_ids as $id) {
616 $objTmpThread = new ilForumTopic($id);
617
618 try {
619 $numPosts = $objTmpThread->movePosts(
620 $src_top_frm_fk,
621 $oldFrmData['top_pk'],
622 $dest_top_frm_fk,
623 $newFrmData['top_pk']
624 );
625
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);
631 }
632
633 $visits += $objTmpThread->getVisits();
634
635 $moved_posts += $numPosts;
636 ++$moved_threads;
637
638 $objTmpThread->setForumId($newFrmData['top_pk']);
639 $objTmpThread->update();
640
641 unset($objTmpThread);
642 } catch (\ilFileUtilsException $exception) {
643 $errorMessages[] = sprintf($this->lng->txt('frm_move_invalid_file_type'), $objTmpThread->getSubject());
644 continue;
645 }
646 }
647
648 if ($moved_threads > 0 || $moved_posts > 0 || $visits > 0) {
649 // update frm_data source forum
650 $this->db->setLimit(1);
651 $res = $this->db->queryf(
652 '
653 SELECT pos_thr_fk, pos_pk
654 FROM frm_posts
655 WHERE pos_top_fk = %s
656 ORDER BY pos_date DESC',
657 array('integer'),
658 array($oldFrmData['top_pk'])
659 );
660
661 $row = $this->db->fetchObject($res);
662 $last_post_src = $oldFrmData['top_pk'] . '#' . $row->pos_thr_fk . '#' . $row->pos_pk;
663
664 $this->db->manipulateF(
665 '
666 UPDATE frm_data
667 SET top_num_posts = top_num_posts - %s,
668 top_num_threads = top_num_threads - %s,
669 visits = visits - %s,
670 top_last_post = %s
671 WHERE top_pk = %s',
672 array('integer', 'integer', 'integer', 'text', 'integer'),
673 array( $moved_posts,
674 $moved_threads,
675 $visits,
676 $last_post_src,
677 $oldFrmData['top_pk'])
678 );
679
680 // update frm_data destination forum
681 $this->db->setLimit(1);
682 $res = $this->db->queryf(
683 '
684 SELECT pos_thr_fk, pos_pk
685 FROM frm_posts
686 WHERE pos_top_fk = %s
687 ORDER BY pos_date DESC',
688 array('integer'),
689 array($newFrmData['top_kp'])
690 );
691
692 $row = $this->db->fetchObject($res);
693 $last_post_dest = $newFrmData['top_pk'] . '#' . $row->pos_thr_fk . '#' . $row->pos_pk;
694
695 $this->db->manipulateF(
696 '
697 UPDATE frm_data
698 SET top_num_posts = top_num_posts + %s,
699 top_num_threads = top_num_threads + %s,
700 visits = visits + %s,
701 top_last_post = %s
702 WHERE top_pk = %s',
703 array('integer', 'integer', 'integer', 'text', 'integer'),
704 array($moved_posts, $moved_threads, $visits, $last_post_dest, $newFrmData['top_pk'])
705 );
706 }
707 }
708
709 return $errorMessages;
710 }
711 }
Class to report exception.
getOneTopic()
get one topic-dataset by WhereCondition
setMDB2WhereCondition($query_string, $data_type, $data_value)
set content for additional condition
static _lookupObjectId($a_ref_id)
lookup object id

References $id, $res, $row, ilObject\_lookupObjectId(), getOneTopic(), and setMDB2WhereCondition().

+ Here is the call graph for this function:

◆ postCensorship()

ilForum::postCensorship (   $message,
  $pos_pk,
  $cens = 0 
)

update dataset in frm_posts with censorship info

Parameters
stringmessage
integerpos_pk
Returns
boolean @access public

Definition at line 721 of file class.ilForum.php.

722 {
723 $cens_date = date("Y-m-d H:i:s");
724
725 $this->db->manipulateF(
726 '
727 UPDATE frm_posts
728 SET pos_cens_com = %s,
729 pos_cens_date = %s,
730 pos_cens = %s,
731 update_user = %s
732 WHERE pos_pk = %s',
733 array('text', 'timestamp', 'integer', 'integer', 'integer'),
734 array($message, $cens_date, $cens, $GLOBALS['DIC']['ilUser']->getId(), $pos_pk)
735 );
736
737 // Change news item accordingly
739 $this->id,
740 "frm",
741 $pos_pk,
742 "pos"
743 );
744 if ($news_id > 0) {
745 if ($cens > 0) { // censor
746 $news_item = new ilNewsItem($news_id);
747 //$news_item->setTitle($subject);
748 $news_item->setContent(nl2br($this->prepareText($message, 0)));
749 if ($message != strip_tags($message)) {
750 $news_item->setContentHtml(true);
751 } else {
752 $news_item->setContentHtml(false);
753 }
754
755 $news_item->update();
756 } else { // revoke censorship
757 // get original message
758 $res = $this->db->queryf(
759 '
760 SELECT * FROM frm_posts
761 WHERE pos_pk = %s',
762 array('integer'),
763 array($pos_pk)
764 );
765
766 $rec = $this->db->fetchAssoc($res);
767
768 $news_item = new ilNewsItem($news_id);
769 //$news_item->setTitle($subject);
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);
773 } else {
774 $news_item->setContentHtml(false);
775 }
776
777 $news_item->update();
778 }
779 }
780
781 $GLOBALS['ilAppEventHandler']->raise(
782 'Modules/Forum',
783 'censoredPost',
784 array(
785 'ref_id' => $this->getForumRefId(),
786 'post' => new ilForumPost($pos_pk)
787 )
788 );
789
790 return true;
791 }

References $GLOBALS, $message, $res, ilNewsItem\getFirstNewsIdForContext(), getForumRefId(), and prepareText().

+ Here is the call graph for this function:

◆ prepareText()

ilForum::prepareText (   $text,
  $edit = 0,
  $quote_user = '',
  $type = '' 
)

prepares given string @access public

Parameters
string
integer
Returns
string

Definition at line 1834 of file class.ilForum.php.

1835 {
1836 if ($type == 'export') {
1837 $this->replQuote1 = "<blockquote class=\"quote\"><hr size=\"1\" color=\"#000000\">";
1838 $this->replQuote2 = "<hr size=\"1\" color=\"#000000\"/></blockquote>";
1839 }
1840
1841 if ($edit == 1) {
1842 // add login name of quoted users
1843 $lname = ($quote_user != "")
1844 ? '="' . $quote_user . '"'
1845 : "";
1846
1847 $text = "[quote$lname]" . $text . "[/quote]";
1848 } else {
1849 // check for quotation
1850 $startZ = substr_count($text, "[quote"); // also count [quote="..."]
1851 $endZ = substr_count($text, "[/quote]");
1852
1853 if ($startZ > 0 || $endZ > 0) {
1854 // add missing opening and closing tags
1855 if ($startZ > $endZ) {
1856 $diff = $startZ - $endZ;
1857
1858 for ($i = 0; $i < $diff; $i++) {
1859 if ($type == 'export') {
1861 } else {
1862 $text .= "[/quote]";
1863 }
1864 }
1865 } elseif ($startZ < $endZ) {
1866 $diff = $endZ - $startZ;
1867
1868 for ($i = 0; $i < $diff; $i++) {
1869 if ($type == 'export') {
1870 $text = $this->txtQuote1 . $text;
1871 } else {
1872 $text = "[quote]" . $text;
1873 }
1874 }
1875 }
1876
1877 if ($edit == 0) {
1878 $text = preg_replace(
1879 '@\[(quote\s*?=\s*?"([^"]*?)"\s*?)\]@i',
1880 $this->replQuote1 . '<div class="ilForumQuoteHead">' . $this->lng->txt('quote') . ' ($2)</div>',
1881 $text
1882 );
1883
1884 $text = str_replace(
1885 "[quote]",
1886 $this->replQuote1 . '<div class="ilForumQuoteHead">' . $this->lng->txt("quote") . '</div>',
1887 $text
1888 );
1889
1890 $text = str_replace("[/quote]", $this->replQuote2, $text);
1891 }
1892 }
1893 }
1894
1895 if ($type != 'export') {
1896 if ($edit == 0) {
1897 $text = ilMathJax::getInstance()->insertLatexImages($text, "<span class\=\"latex\">", "<\/span>");
1898 $text = ilMathJax::getInstance()->insertLatexImages($text, "\[tex\]", "\[\/tex\]");
1899 }
1900
1901 // workaround for preventing template engine
1902 // from hiding text that is enclosed
1903 // in curly brackets (e.g. "{a}")
1904 $text = str_replace("{", "&#123;", $text);
1905 $text = str_replace("}", "&#125;", $text);
1906 }
1907
1908 return $text;
1909 }
static getInstance()
Singleton: get instance.
$type
$text
Definition: errorreport.php:18

References $i, $text, $txtQuote2, $type, and ilMathJax\getInstance().

Referenced by generatePost(), and postCensorship().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDbTable()

ilForum::setDbTable (   $dbTable)

set database table

Parameters
string$dbTabledatabase table
See also
$dbTable @access User interface

Definition at line 197 of file class.ilForum.php.

198 {
199 if ($dbTable == "") {
200 die($this->className . "::setDbTable(): No database table given.");
201 } else {
202 $this->dbTable = $dbTable;
203 }
204 }

References $dbTable.

◆ setForumId()

ilForum::setForumId (   $a_obj_id)

set object id which refers to ILIAS obj_id

Parameters
integerobject id @access public

Definition at line 120 of file class.ilForum.php.

121 {
122 if (!isset($a_obj_id)) {
123 $message = get_class($this) . "::setForumId(): No obj_id given!";
124 $this->error->raiseError($message, $this->error->WARNING);
125 }
126
127 $this->id = $a_obj_id;
128 }

References $message, and error().

+ Here is the call graph for this function:

◆ setForumRefId()

ilForum::setForumRefId (   $a_ref_id)

set reference id which refers to ILIAS obj_id

Parameters
integerobject id @access public

Definition at line 135 of file class.ilForum.php.

136 {
137 if (!isset($a_ref_id)) {
138 $message = get_class($this) . "::setForumRefId(): No ref_id given!";
139 $this->error->raiseError($message, $this->error->WARNING);
140 }
141
142 $this->ref_id = $a_ref_id;
143 }

References $message, and error().

+ Here is the call graph for this function:

◆ setImportName()

ilForum::setImportName (   $a_import_name)

Definition at line 1933 of file class.ilForum.php.

1934 {
1935 $this->import_name = $a_import_name;
1936 }

◆ setLanguage()

ilForum::setLanguage (   $lng)

Definition at line 85 of file class.ilForum.php.

86 {
87 $this->lng = $lng;
88 }

References $lng.

◆ setMDB2WhereCondition()

ilForum::setMDB2WhereCondition (   $query_string,
  $data_type,
  $data_value 
)

set content for additional condition

Parameters
string$query_string
array$data_type
array$data_value
Returns
bool

Definition at line 225 of file class.ilForum.php.

226 {
227 $this->mdb2Query = $query_string;
228 $this->mdb2DataValue = $data_value;
229 $this->mdb2DataType = $data_type;
230
231 return true;
232 }

Referenced by moveThreads().

+ Here is the caller graph for this function:

◆ setOrderField()

ilForum::setOrderField (   $orderField)
private

set database field for sorting results

Parameters
string$orderFielddatabase field for sorting
See also
$orderField @access private

Definition at line 171 of file class.ilForum.php.

172 {
173 if ($orderField == "") {
174 die($this->className . "::setOrderField(): No orderField given.");
175 } else {
176 $this->orderField = $orderField;
177 }
178 }

References $orderField.

◆ setPageHits()

ilForum::setPageHits (   $pageHits)
Parameters
int$pageHits
Returns
bool

Definition at line 271 of file class.ilForum.php.

272 {
273 if ($pageHits < 1 || !is_numeric($pageHits)) {
274 $pageHits = 1;
275 }
276
277 $this->pageHits = (int) $pageHits;
278 return true;
279 }

References $pageHits.

◆ updateLastPostByObjId()

static ilForum::updateLastPostByObjId (   $a_obj_id)
static

Definition at line 2163 of file class.ilForum.php.

2164 {
2165 global $DIC;
2166 $ilDB = $DIC->database();
2167 // get latest post of forum and update last_post
2168 $ilDB->setLimit(1);
2169 $res2 = $ilDB->queryf(
2170 '
2171 SELECT pos_top_fk, pos_thr_fk, pos_pk FROM frm_posts, frm_data
2172 WHERE pos_top_fk = top_pk
2173 AND top_frm_fk = %s
2174 ORDER BY pos_date DESC',
2175 array('integer'),
2176 array($a_obj_id)
2177 );
2178
2179 if ($res2->numRows() == 0) {
2180 $lastPost_top = "";
2181 } else {
2182 $z = 0;
2183
2184 while ($selData = $ilDB->fetchAssoc($res2)) {
2185 if ($z > 0) {
2186 break;
2187 }
2188
2189 $lastPost_top = $selData["pos_top_fk"] . "#" . $selData["pos_thr_fk"] . "#" . $selData["pos_pk"];
2190 $z++;
2191 }
2192 }
2193
2194 $ilDB->update(
2195 'frm_data',
2196 array('top_last_post' => array('text', $lastPost_top)),
2197 array('top_frm_fk' => array('integer', $a_obj_id))
2198 );
2199 }

References $DIC, and $ilDB.

◆ updateVisits()

ilForum::updateVisits (   $ID)

update page hits of given forum- or thread-ID @access public

Parameters
integer

Definition at line 1806 of file class.ilForum.php.

1807 {
1808 $checkTime = time() - (60 * 60);
1809
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 ';
1813
1814 $data_type = array();
1815 $data_value = array();
1816
1817 if ($this->getMDB2Query() != '' && $this->getMDB2DataType() != '' && $this->getMDB2DataValue() != '') {
1818 $query .= $this->getMDB2Query();
1819 $data_type = $data_type + $this->getMDB2DataType();
1820 $data_value = $data_value + $this->getMDB2DataValue();
1821
1822 $res = $this->db->queryf($query, $data_type, $data_value);
1823 }
1824 }
1825 }
$_SESSION["AccountId"]

References $_SESSION, $query, $res, getMDB2DataType(), getMDB2DataValue(), and getMDB2Query().

+ Here is the call graph for this function:

Field Documentation

◆ $className

ilForum::$className = "ilForum"
private

Definition at line 44 of file class.ilForum.php.

◆ $db

ilForum::$db

Definition at line 27 of file class.ilForum.php.

◆ $dbTable

ilForum::$dbTable
private

Definition at line 37 of file class.ilForum.php.

Referenced by getDbTable(), and setDbTable().

◆ $error

ilForum::$error

Definition at line 26 of file class.ilForum.php.

◆ $id

ilForum::$id
private

Definition at line 67 of file class.ilForum.php.

Referenced by getForumId(), and moveThreads().

◆ $lng

ilForum::$lng

Definition at line 25 of file class.ilForum.php.

Referenced by setLanguage().

◆ $mdb2DataType

ilForum::$mdb2DataType
private

Definition at line 56 of file class.ilForum.php.

Referenced by getMDB2DataType().

◆ $mdb2DataValue

ilForum::$mdb2DataValue
private

Definition at line 55 of file class.ilForum.php.

Referenced by getMDB2DataValue().

◆ $mdb2Query

ilForum::$mdb2Query
private

Definition at line 54 of file class.ilForum.php.

Referenced by getMDB2Query().

◆ $moderators_by_ref_id_map

ilForum::$moderators_by_ref_id_map = array()
staticprotected

Definition at line 23 of file class.ilForum.php.

◆ $orderField

ilForum::$orderField
private

Definition at line 52 of file class.ilForum.php.

Referenced by getOrderField(), and setOrderField().

◆ $pageHits

ilForum::$pageHits = self::DEFAULT_PAGE_HITS
private

Definition at line 64 of file class.ilForum.php.

Referenced by getPageHits(), and setPageHits().

◆ $replQuote1

ilForum::$replQuote1 = '<blockquote class="ilForumQuote">'
private

Definition at line 60 of file class.ilForum.php.

◆ $replQuote2

ilForum::$replQuote2 = '</blockquote>'
private

Definition at line 61 of file class.ilForum.php.

◆ $settings

ilForum::$settings

Definition at line 29 of file class.ilForum.php.

◆ $txtQuote1

ilForum::$txtQuote1 = "[quote]"
private

Definition at line 58 of file class.ilForum.php.

◆ $txtQuote2

ilForum::$txtQuote2 = "[/quote]"
private

Definition at line 59 of file class.ilForum.php.

Referenced by prepareText().

◆ $user

ilForum::$user

Definition at line 28 of file class.ilForum.php.

◆ DEFAULT_PAGE_HITS

const ilForum::DEFAULT_PAGE_HITS = 30

Definition at line 18 of file class.ilForum.php.

◆ SORT_DATE

const ilForum::SORT_DATE = 2

Definition at line 16 of file class.ilForum.php.

Referenced by _getThreads().

◆ SORT_TITLE

const ilForum::SORT_TITLE = 1

Definition at line 15 of file class.ilForum.php.

Referenced by _getThreads().


The documentation for this class was generated from the following file: