ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilForum Class Reference

Class Forum core functions for forum. More...

+ Collaboration diagram for ilForum:

Public Member Functions

 __construct ()
 
 setForumId (int $a_obj_id)
 
 setForumRefId (int $a_ref_id)
 
 getForumId ()
 
 getForumRefId ()
 
 setDbTable (string $dbTable)
 
 getDbTable ()
 
 setMDB2WhereCondition (string $query_string, array $data_type, array $data_value)
 
 getMDB2Query ()
 
 getMDB2DataValue ()
 
 getMDB2DataType ()
 
 setPageHits (int $pageHits)
 
 getPageHits ()
 
 getOneTopic ()
 
 getOneThread ()
 
 generateThread (ilForumTopic $thread, string $message, bool $notify, bool $notify_posts, bool $status=true, bool $withFirstVisibleEntry=true)
 
 moveThreads (array $thread_ids, ilObjForum $src_forum, int $target_obj_id)
 
 postCensorship (ilObjForum $forum, string $message, int $pos_pk, int $cens=0)
 
 deletePost ($postIdOrRecord, bool $raiseEvents=true)
 
 getAllThreads (int $a_topic_id, array $params=[], int $limit=0, int $offset=0)
 
 getNumberOfPublishedUserPostings (int $usr_id, bool $post_activation_required)
 
 getUserStatistics (bool $post_activation_required)
 
 getRootPostIdByThread (int $a_thread_id)
 
 getModerators ()
 
 countUserArticles (int $a_user_id)
 
 countActiveUserArticles (int $a_user_id)
 
 convertDate (string $date)
 
 addPostTree (int $a_tree_id, int $a_node_id=-1, string $a_date='')
 
 insertPostNode (int $a_node_id, int $a_parent_id, int $tree_id, string $a_date='')
 insert node under parent node More...
 
 getPostDepth (int $a_node_id, int $tree_id)
 
 getFirstPostNode (int $tree_id)
 
 getPostNode (int $post_id)
 
 fetchPostNodeData (stdClass $a_row)
 
 deletePostTree (array $a_node)
 
 updateVisits (int $ID)
 
 prepareText (string $text, int $edit=0, string $quote_user='', string $type='')
 
 getImportName ()
 
 setImportName (string $a_import_name)
 
 enableForumNotification (int $user_id)
 
 disableForumNotification (int $user_id)
 
 isForumNotificationEnabled (int $user_id)
 
 isThreadNotificationEnabled (int $user_id, int $thread_id)
 
 mergeThreads (int $source_id, int $target_id)
 

Static Public Member Functions

static _getModerators (int $a_ref_id)
 
static _isModerator (int $a_ref_id, int $a_usr_id)
 
static getSortedThreadSubjects (int $a_obj_id, int $a_sort_mode=self::SORT_DATE)
 
static _lookupObjIdForForumId (int $a_for_id)
 

Data Fields

ilLanguage $lng
 
ilErrorHandling $error
 
ilDBInterface $db
 
ilObjUser $user
 
ilSetting $settings
 

Static Protected Attributes

static array $moderators_by_ref_id_map = []
 

Private Member Functions

 deletePostFiles (array $a_ids)
 

Private Attributes

const SORT_TITLE = 1
 
const SORT_DATE = 2
 
const DEFAULT_PAGE_HITS = 30
 
ilAppEventHandler $event
 
string $dbTable
 
string $className = 'ilForum'
 
string $mdb2Query = ''
 
array $mdb2DataValue = []
 
array $mdb2DataType = []
 
string $txtQuote1 = "[quote]"
 
string $txtQuote2 = "[/quote]"
 
string $replQuote1 = '<blockquote class="ilForumQuote">'
 
string $replQuote2 = '</blockquote>'
 
int $pageHits = self::DEFAULT_PAGE_HITS
 
int $id
 
int $ref_id
 
string $import_name = ''
 

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

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

Constructor & Destructor Documentation

◆ __construct()

ilForum::__construct ( )

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

References $DIC, ILIAS\Repository\lng(), ILIAS\Repository\settings(), and ILIAS\Repository\user().

57  {
58  global $DIC;
59 
60  $this->error = $DIC['ilErr'];
61  $this->lng = $DIC->language();
62  $this->db = $DIC->database();
63  $this->user = $DIC->user();
64  $this->settings = $DIC->settings();
65  $this->event = $DIC->event();
66  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ _getModerators()

static ilForum::_getModerators ( int  $a_ref_id)
static
Parameters
int$a_ref_id
Returns
int[]

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

References $DIC, and ilObject\_lookupTitle().

Referenced by ilForumNotificationDataProvider\getPostActivationRecipients(), ilForumSettingsGUI\saveEventsForUser(), ilForumSettingsGUI\showMembers(), and ilForumSettingsGUI\updateUserNotifications().

1130  : array
1131  {
1132  global $DIC;
1133 
1134  $rbacreview = $DIC->rbac()->review();
1135 
1136  $role_arr = $rbacreview->getRolesOfRoleFolder($a_ref_id);
1137  foreach ($role_arr as $role_id) {
1138  if (ilObject::_lookupTitle($role_id) === 'il_frm_moderator_' . $a_ref_id) {
1139  return array_map('intval', $rbacreview->assignedUsers($role_id));
1140  }
1141  }
1142 
1143  return [];
1144  }
global $DIC
Definition: feed.php:28
static _lookupTitle(int $obj_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _isModerator()

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

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

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

1146  : bool
1147  {
1148  if (!isset(self::$moderators_by_ref_id_map[$a_ref_id])) {
1149  self::$moderators_by_ref_id_map[$a_ref_id] = self::_getModerators($a_ref_id);
1150  }
1151 
1152  return in_array($a_usr_id, self::$moderators_by_ref_id_map[$a_ref_id], true);
1153  }
+ Here is the caller graph for this function:

◆ _lookupObjIdForForumId()

static ilForum::_lookupObjIdForForumId ( int  $a_for_id)
static

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

References $DIC, and $res.

Referenced by ilObjMediaObject\getParentObjectIdForUsage(), ilForumDraftsDerivedTaskProvider\getTasks(), ilObjForumGUI\mergeThreadsObject(), and ilForumTopic\movePosts().

1695  : int
1696  {
1697  global $DIC;
1698 
1699  $res = $DIC->database()->queryF('SELECT top_frm_fk FROM frm_data WHERE top_pk = %s', ['integer'], [$a_for_id]);
1700  if ($row = $DIC->database()->fetchAssoc($res)) {
1701  return (int) $row['top_frm_fk'];
1702  }
1703 
1704  return 0;
1705  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ addPostTree()

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

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

Referenced by getOneThread().

1191  : bool
1192  {
1193  $a_date = $a_date ?: date('Y-m-d H:i:s');
1194 
1195  if ($a_node_id <= 0) {
1196  $a_node_id = $a_tree_id;
1197  }
1198 
1199  $nextId = $this->db->nextId('frm_posts_tree');
1200 
1201  $this->db->manipulateF(
1202  '
1203  INSERT INTO frm_posts_tree
1204  ( fpt_pk,
1205  thr_fk,
1206  pos_fk,
1207  parent_pos,
1208  lft,
1209  rgt,
1210  depth,
1211  fpt_date
1212  )
1213  VALUES(%s, %s, %s, %s, %s, %s, %s, %s )',
1214  ['integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'timestamp'],
1215  [$nextId, $a_tree_id, $a_node_id, 0, 1, 2, 1, $a_date]
1216  );
1217 
1218  return true;
1219  }
+ Here is the caller graph for this function:

◆ convertDate()

ilForum::convertDate ( string  $date)

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

References ilDatePresentation\formatDate(), and IL_CAL_DATETIME.

1186  : string
1187  {
1189  }
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
+ Here is the call graph for this function:

◆ countActiveUserArticles()

ilForum::countActiveUserArticles ( int  $a_user_id)

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

References $res, getForumId(), and ILIAS\Repository\user().

1170  : int
1171  {
1172  $res = $this->db->queryF(
1173  'SELECT * FROM frm_data
1174  INNER JOIN frm_posts ON pos_top_fk = top_pk
1175  INNER JOIN frm_posts_tree tree1 ON tree1.pos_fk = frm_posts.pos_pk AND tree1.parent_pos != 0
1176  WHERE top_frm_fk = %s
1177  AND (pos_status = %s OR (pos_status = %s AND pos_author_id = %s))
1178  AND pos_author_id = %s',
1179  ['integer', 'integer', 'integer', 'integer', 'integer'],
1180  [$this->getForumId(), 1, 0, $this->user->getId(), $a_user_id]
1181  );
1182 
1183  return $res->numRows();
1184  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:

◆ countUserArticles()

ilForum::countUserArticles ( int  $a_user_id)

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

References $res, and getForumId().

1155  : int
1156  {
1157  $res = $this->db->queryF(
1158  'SELECT * FROM frm_data
1159  INNER JOIN frm_posts ON pos_top_fk = top_pk
1160  INNER JOIN frm_posts_tree tree1 ON tree1.pos_fk = frm_posts.pos_pk AND tree1.parent_pos != 0
1161  WHERE top_frm_fk = %s
1162  AND pos_author_id = %s',
1163  ['integer', 'integer'],
1164  [$this->getForumId(), $a_user_id]
1165  );
1166 
1167  return $res->numRows();
1168  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:

◆ deletePost()

ilForum::deletePost (   $postIdOrRecord,
bool  $raiseEvents = true 
)
Parameters
int|array<string,mixed>$postIdOrRecord
bool$raiseEvents
Returns
int

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

References Vendor\Package\$e, $i, $mobs, $post, $query, $res, ilObjForum\_deleteAccessEntries(), ilObjForum\_deleteReadEntries(), ilObjMediaObject\_exists(), ilObjMediaObject\_getMobsOfObject(), ilObjMediaObject\_removeUsage(), deletePostFiles(), deletePostTree(), ilNewsItem\getFirstNewsIdForContext(), getForumId(), getForumRefId(), getPostNode(), and ILIAS\Repository\int().

Referenced by mergeThreads().

533  : int
534  {
535  if (is_numeric($postIdOrRecord)) {
536  $p_node = $this->getPostNode($postIdOrRecord);
537  } else {
538  $p_node = $postIdOrRecord;
539  }
540 
541  $post = new ilForumPost((int) $p_node['pos_pk']);
542  if ($raiseEvents) {
543  $is_deleted_thread = ($p_node["parent"] == 0) ? true : false;
544  $num_visible_active_posts = 0;
545  if ($is_deleted_thread) {
546  $query = '
547  SELECT COUNT(*) AS cnt
548  FROM frm_posts
549  INNER JOIN frm_posts_tree ON pos_pk = pos_fk
550  WHERE frm_posts_tree.parent_pos != 0
551  AND pos_thr_fk = ' . $this->db->quote($p_node['pos_thr_fk'], 'integer') . '
552  AND pos_status = ' . $this->db->quote(1, 'integer');
553  $res = $this->db->query($query);
554  $row = $this->db->fetchAssoc($res);
555  $num_visible_active_posts = (int) ($row['cnt'] ?? 0);
556  }
557 
558  $this->event->raise(
559  'Modules/Forum',
560  'beforePostDeletion',
561  [
562  'obj_id' => $this->getForumId(),
563  'ref_id' => $this->getForumRefId(),
564  'post' => $post,
565  'thread_deleted' => $is_deleted_thread,
566  'num_visible_active_posts' => $num_visible_active_posts
567  ]
568  );
569  }
570 
571  $affected_user_ids[] = $post->getPosAuthorId();
572  $deleted_post_ids = $this->deletePostTree($p_node);
573 
574  $obj_history = new ilForumDraftsHistory();
575  $obj_history->deleteHistoryByPostIds($deleted_post_ids);
576 
577  $obj_draft = new ilForumPostDraft();
578  $obj_draft->deleteDraftsByPostIds($deleted_post_ids);
579 
580  foreach ($deleted_post_ids as $post_id) {
582  }
583 
584  $this->deletePostFiles($deleted_post_ids);
585 
586  $dead_pos = count($deleted_post_ids);
587  $dead_thr = 0;
588 
589  if ((int) $p_node['parent'] === 0) {
590  ilObjForum::_deleteAccessEntries((int) $p_node['tree']);
591 
592  $dead_thr = (int) $p_node['tree'];
593 
594  $this->db->manipulateF('DELETE FROM frm_threads WHERE thr_pk = %s', ['integer'], [$dead_thr]);
595  $this->db->manipulateF(
596  'UPDATE frm_data SET top_num_threads = top_num_threads - 1 WHERE top_frm_fk = %s',
597  ['integer'],
598  [$this->id]
599  );
600 
601  $posset = $this->db->queryF('SELECT * FROM frm_posts WHERE pos_thr_fk = %s', ['integer'], [$dead_thr]);
602  while ($posrec = $this->db->fetchAssoc($posset)) {
604  $this->id,
605  'frm',
606  (int) $posrec['pos_pk'],
607  'pos'
608  );
609  if ($news_id > 0) {
610  $news_item = new ilNewsItem($news_id);
611  $news_item->delete();
612  }
613 
614  try {
615  $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', (int) $posrec['pos_pk']);
616  foreach ($mobs as $mob) {
617  if (ilObjMediaObject::_exists($mob)) {
618  ilObjMediaObject::_removeUsage($mob, 'frm:html', (int) $posrec['pos_pk']);
619  $mob_obj = new ilObjMediaObject($mob);
620  $mob_obj->delete();
621  }
622  }
623  } catch (Exception $e) {
624  }
625  $affected_user_ids[] = (int) $posrec['pos_author_id'];
626  }
627 
628  $this->db->manipulateF('DELETE FROM frm_posts WHERE pos_thr_fk = %s', ['integer'], [$p_node['tree']]);
629  } else {
630  for ($i = 0; $i < $dead_pos; $i++) {
631  $this->db->manipulateF('DELETE FROM frm_posts WHERE pos_pk = %s', ['integer'], [$deleted_post_ids[$i]]);
632 
634  $this->id,
635  'frm',
636  $deleted_post_ids[$i],
637  'pos'
638  );
639  if ($news_id > 0) {
640  $news_item = new ilNewsItem($news_id);
641  $news_item->delete();
642  }
643 
644  try {
645  $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', $deleted_post_ids[$i]);
646  foreach ($mobs as $mob) {
647  if (ilObjMediaObject::_exists($mob)) {
648  ilObjMediaObject::_removeUsage($mob, 'frm:html', $deleted_post_ids[$i]);
649  $mob_obj = new ilObjMediaObject($mob);
650  $mob_obj->delete();
651  }
652  }
653  } catch (Exception $e) {
654  }
655  }
656 
657  $this->db->manipulateF(
658  'UPDATE frm_threads SET thr_num_posts = thr_num_posts - %s WHERE thr_pk = %s',
659  ['integer', 'integer'],
660  [$dead_pos, $p_node['tree']]
661  );
662 
663  $res1 = $this->db->queryF(
664  'SELECT * FROM frm_posts WHERE pos_thr_fk = %s ORDER BY pos_date DESC',
665  ['integer'],
666  [$p_node['tree']]
667  );
668 
669  $lastPost_thr = '';
670  if ($res1->numRows() > 0) {
671  $z = 0;
672 
673  while ($selData = $this->db->fetchAssoc($res1)) {
674  if ($z > 0) {
675  break;
676  }
677 
678  $lastPost_thr = $selData['pos_top_fk'] . '#' . $selData['pos_thr_fk'] . '#' . $selData['pos_pk'];
679  $z++;
680  }
681  }
682 
683  $this->db->manipulateF(
684  'UPDATE frm_threads SET thr_last_post = %s WHERE thr_pk = %s',
685  ['text', 'integer'],
686  [$lastPost_thr, $p_node['tree']]
687  );
688  }
689 
690  $this->db->manipulateF(
691  'UPDATE frm_data SET top_num_posts = top_num_posts - %s WHERE top_frm_fk = %s',
692  ['integer', 'integer'],
693  [$dead_pos, $this->id]
694  );
695 
696  $res2 = $this->db->queryF(
697  'SELECT * FROM frm_posts, frm_data WHERE pos_top_fk = top_pk AND top_frm_fk = %s ORDER BY pos_date DESC',
698  ['integer'],
699  [$this->id]
700  );
701 
702  $lastPost_top = '';
703  if ($res2->numRows() > 0) {
704  $z = 0;
705 
706  while ($selData = $this->db->fetchAssoc($res2)) {
707  if ($z > 0) {
708  break;
709  }
710 
711  $lastPost_top = $selData['pos_top_fk'] . '#' . $selData['pos_thr_fk'] . '#' . $selData['pos_pk'];
712  $z++;
713  }
714  }
715 
716  $this->db->manipulateF(
717  'UPDATE frm_data SET top_last_post = %s WHERE top_frm_fk = %s',
718  ['text', 'integer'],
719  [$lastPost_top, $this->id]
720  );
721 
722  if ($raiseEvents) {
723  $this->event->raise(
724  'Modules/Forum',
725  'afterPostDeletion',
726  [
727  'obj_id' => $this->getForumId(),
728  'ref_id' => $this->getForumRefId(),
729  'user_ids' => $affected_user_ids
730  ]
731  );
732  }
733 
734  return $dead_thr;
735  }
Class ilForumPostDraft.
$res
Definition: ltiservices.php:69
getPostNode(int $post_id)
$mobs
Definition: imgupload.php:70
static _deleteAccessEntries(int $a_thread_id)
deletePostFiles(array $a_ids)
static _deleteReadEntries(int $a_post_id)
Class ilForumDraftHistory.
$query
static _exists(int $id, bool $reference=false, ?string $type=null)
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
static _removeUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Remove usage of mob in another container.
A news item can be created by different sources.
static getFirstNewsIdForContext(int $a_context_obj_id, string $a_context_obj_type, int $a_context_sub_obj_id=0, string $a_context_sub_obj_type="")
Get first new id of news set related to a certain context.
$post
Definition: ltitoken.php:49
deletePostTree(array $a_node)
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deletePostFiles()

ilForum::deletePostFiles ( array  $a_ids)
private
Parameters
int[]$a_ids

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

References getForumId().

Referenced by deletePost().

1543  : void
1544  {
1545  $forumFiles = new ilFileDataForum($this->getForumId());
1546  foreach ($a_ids as $pos_id) {
1547  $forumFiles->setPosId($pos_id);
1548  $files = $forumFiles->getFilesOfPost();
1549  foreach ($files as $file) {
1550  $forumFiles->unlinkFile($file['name']);
1551  }
1552  }
1553  }
This class handles all operations on files for the forum object.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deletePostTree()

ilForum::deletePostTree ( array  $a_node)
Parameters
array$a_node
Returns
int[] An list of deleted post ids

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

References $res, and ILIAS\Repository\int().

Referenced by deletePost().

1389  : array
1390  {
1391  $res = $this->db->queryF(
1392  'SELECT lft, rgt FROM frm_posts_tree WHERE thr_fk = %s AND pos_fk = %s AND parent_pos = %s',
1393  ['integer', 'integer', 'integer'],
1394  [$a_node['tree'], $a_node['pos_pk'], $a_node['parent']]
1395  );
1396 
1397  while ($row = $this->db->fetchObject($res)) {
1398  $a_node['lft'] = (int) $row->lft;
1399  $a_node['rgt'] = (int) $row->rgt;
1400  }
1401 
1402  $diff = $a_node['rgt'] - $a_node['lft'] + 1;
1403 
1404  $res = $this->db->queryF(
1405  'SELECT pos_fk FROM frm_posts_tree WHERE lft BETWEEN %s AND %s AND thr_fk = %s',
1406  ['integer', 'integer', 'integer'],
1407  [$a_node['lft'], $a_node['rgt'], $a_node['tree']]
1408  );
1409 
1410  $deleted_post_ids = [];
1411  while ($treeData = $this->db->fetchAssoc($res)) {
1412  $deleted_post_ids[] = (int) $treeData['pos_fk'];
1413  }
1414 
1415  $this->db->manipulateF(
1416  'DELETE FROM frm_posts_tree WHERE lft BETWEEN %s AND %s AND thr_fk = %s',
1417  ['integer', 'integer', 'integer'],
1418  [$a_node['lft'], $a_node['rgt'], $a_node['tree']]
1419  );
1420 
1421  $this->db->manipulateF(
1422  '
1423  UPDATE frm_posts_tree
1424  SET lft = CASE
1425  WHEN lft > %s
1426  THEN lft - %s
1427  ELSE lft
1428  END,
1429  rgt = CASE
1430  WHEN rgt > %s
1431  THEN rgt - %s
1432  ELSE rgt
1433  END
1434  WHERE thr_fk = %s',
1435  ['integer', 'integer', 'integer', 'integer', 'integer'],
1436  [$a_node['lft'], $diff, $a_node['lft'], $diff, $a_node['tree']]
1437  );
1438 
1439  return $deleted_post_ids;
1440  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ disableForumNotification()

ilForum::disableForumNotification ( int  $user_id)

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

1620  : bool
1621  {
1622  $this->db->manipulateF(
1623  'DELETE FROM frm_notification WHERE user_id = %s AND frm_id = %s',
1624  ['integer', 'integer'],
1625  [$user_id, $this->id]
1626  );
1627 
1628  return true;
1629  }

◆ enableForumNotification()

ilForum::enableForumNotification ( int  $user_id)

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

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

1565  : bool
1566  {
1567  if (!$this->isForumNotificationEnabled($user_id)) {
1568  /* Remove all notifications of threads that belong to the forum */
1569  $res = $this->db->queryF(
1570  '
1571  SELECT frm_notification.thread_id FROM frm_data, frm_notification, frm_threads
1572  WHERE frm_notification.user_id = %s
1573  AND frm_notification.thread_id = frm_threads.thr_pk
1574  AND frm_threads.thr_top_fk = frm_data.top_pk
1575  AND frm_data.top_frm_fk = %s
1576  GROUP BY frm_notification.thread_id',
1577  ['integer', 'integer'],
1578  [$user_id, $this->id]
1579  );
1580 
1581  if ($res->numRows() > 0) {
1582  $thread_data = [];
1583  $thread_data_types = [];
1584 
1585  $query = ' DELETE FROM frm_notification WHERE user_id = %s AND thread_id IN (';
1586  $thread_data[] = $user_id;
1587  $thread_data_types[] = 'integer';
1588 
1589  $counter = 1;
1590  while ($row = $this->db->fetchAssoc($res)) {
1591  if ($counter < $res->numRows()) {
1592  $query .= '%s, ';
1593  $thread_data[] = $row['thread_id'];
1594  $thread_data_types[] = 'integer';
1595  }
1596 
1597  if ($counter === $res->numRows()) {
1598  $query .= '%s)';
1599  $thread_data[] = $row['thread_id'];
1600  $thread_data_types[] = 'integer';
1601  }
1602  $counter++;
1603  }
1604 
1605  $this->db->manipulateF($query, $thread_data_types, $thread_data);
1606  }
1607 
1608  /* Insert forum notification */
1609  $nextId = $this->db->nextId('frm_notification');
1610  $this->db->manipulateF(
1611  'INSERT INTO frm_notification (notification_id, user_id, frm_id) VALUES(%s, %s, %s)',
1612  ['integer', 'integer', 'integer'],
1613  [$nextId, $user_id, $this->id]
1614  );
1615  }
1616 
1617  return true;
1618  }
isForumNotificationEnabled(int $user_id)
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:

◆ fetchPostNodeData()

ilForum::fetchPostNodeData ( stdClass  $a_row)

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

References ilObject\_exists(), ILIAS\Repository\int(), and ILIAS\Repository\lng().

Referenced by getFirstPostNode(), and getPostNode().

1338  : array
1339  {
1340  $fullname = '';
1341  $loginname = '';
1342 
1343  if (ilObject::_exists((int) $a_row->pos_display_user_id)) {
1344  $tmp_user = new ilObjUser((int) $a_row->pos_display_user_id);
1345  $fullname = $tmp_user->getFullname();
1346  $loginname = $tmp_user->getLogin();
1347  }
1348 
1349  if ($fullname === '') {
1350  $fullname = $this->lng->txt('unknown');
1351  if ($a_row->import_name) {
1352  $fullname = $a_row->import_name;
1353  }
1354  }
1355 
1356  return [
1357  'type' => 'post',
1358  'pos_pk' => (int) $a_row->pos_pk,
1359  'pos_thr_fk' => (int) $a_row->pos_thr_fk,
1360  'child' => (int) $a_row->pos_pk,
1361  'author' => (int) $a_row->pos_display_user_id,
1362  'alias' => (string) $a_row->pos_usr_alias,
1363  'title' => $fullname,
1364  'loginname' => $loginname,
1365  'message' => (string) $a_row->pos_message,
1366  'subject' => (string) $a_row->pos_subject,
1367  'pos_cens_com' => (string) $a_row->pos_cens_com,
1368  'pos_cens' => (int) $a_row->pos_cens,
1369  'date' => $a_row->fpt_date,
1370  'create_date' => $a_row->pos_date,
1371  'update' => $a_row->pos_update,
1372  'update_user' => (int) $a_row->update_user,
1373  'tree' => (int) $a_row->thr_fk,
1374  'parent' => (int) $a_row->parent_pos,
1375  'lft' => (int) $a_row->lft,
1376  'rgt' => (int) $a_row->rgt,
1377  'depth' => (int) $a_row->depth,
1378  'id' => (int) $a_row->fpt_pk,
1379  'notify' => (int) $a_row->notify,
1380  'import_name' => $a_row->import_name,
1381  'pos_status' => (int) $a_row->pos_status
1382  ];
1383  }
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generateThread()

ilForum::generateThread ( ilForumTopic  $thread,
string  $message,
bool  $notify,
bool  $notify_posts,
bool  $status = true,
bool  $withFirstVisibleEntry = true 
)

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

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

292  : int {
293  if (!$thread->getCreateDate()) {
294  $thread->setCreateDate(date('Y-m-d H:i:s'));
295  }
296 
297  $thread->setImportName($this->getImportName());
298  $thread->insert();
299 
300  if ($notify_posts) {
301  $thread->enableNotification($thread->getThrAuthorId());
302  }
303 
304  $this->db->manipulateF(
305  'UPDATE frm_data SET top_num_threads = top_num_threads + 1 WHERE top_pk = %s',
306  ['integer'],
307  [$thread->getForumId()]
308  );
309 
310  $rootNodeId = $this->generatePost(
311  $thread->getForumId(),
312  $thread->getId(),
313  $thread->getThrAuthorId(),
314  $thread->getDisplayUserId(),
315  '',
316  0,
317  false,
318  $thread->getSubject(),
319  $thread->getUserAlias(),
320  $thread->getCreateDate(),
321  true,
322  false
323  );
324 
325  if (!$withFirstVisibleEntry) {
326  return $rootNodeId;
327  }
328 
329  return $this->generatePost(
330  $thread->getForumId(),
331  $thread->getId(),
332  $thread->getThrAuthorId(),
333  $thread->getDisplayUserId(),
334  $message,
335  $rootNodeId,
336  $notify,
337  $thread->getSubject(),
338  $thread->getUserAlias(),
339  $thread->getCreateDate(),
340  $status,
341  false
342  );
343  }
setCreateDate(?string $a_createdate)
enableNotification(int $a_user_id)
setImportName(?string $a_import_name)
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ getAllThreads()

ilForum::getAllThreads ( int  $a_topic_id,
array  $params = [],
int  $limit = 0,
int  $offset = 0 
)
Parameters
int$a_topic_id
array$params
int$limit
int$offset
Returns
array{cnt: int, items: array<int, ilForumTopic>}

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

References $data, $params, $query, $res, ilForumProperties\FORUM_OVERVIEW_WITH_NEW_POSTS, getForumId(), ilForumProperties\getInstance(), ILIAS\Repository\int(), ilObjForum\NEWS_NEW_CONSIDERATION_WEEKS, ILIAS\Repository\settings(), and ILIAS\Repository\user().

744  : array
745  {
746  $frm_overview_setting = (int) (new ilSetting('frma'))->get(
747  'forum_overview',
749  );
750  $frm_props = ilForumProperties::getInstance($this->getForumId());
751  $is_post_activation_enabled = $frm_props->isPostActivationEnabled();
752 
753  $user_id = $this->user->getId();
754 
755  $excluded_ids_condition = '';
756  if (isset($params['excluded_ids']) && is_array($params['excluded_ids']) && $params['excluded_ids']) {
757  $excluded_ids_condition = ' AND ' . $this->db->in('thr_pk', $params['excluded_ids'], true, 'integer') . ' ';
758  }
759 
760  if (!isset($params['order_column']) || !in_array(
761  strtolower($params['order_column']),
762  ['lp_date', 'rating', 'thr_subject', 'num_posts', 'num_visit']
763  )) {
764  $params['order_column'] = 'post_date';
765  }
766  if (!isset($params['order_direction']) || !in_array(strtolower($params['order_direction']), ['asc', 'desc'])) {
767  $params['order_direction'] = 'desc';
768  }
769 
770  $cnt_active_pos_query = '';
771  $cnt_join_type = 'LEFT';
772  if ($is_post_activation_enabled && !$params['is_moderator']) {
773  $cnt_active_pos_query = " AND (pos_status = {$this->db->quote(1, 'integer')} OR pos_author_id = {$this->db->quote($user_id, 'integer')}) ";
774  $cnt_join_type = "INNER";
775  }
776  $query =
777  "SELECT COUNT(DISTINCT(thr_pk)) cnt
778  FROM frm_threads
779  $cnt_join_type JOIN frm_posts
780  ON pos_thr_fk = thr_pk $cnt_active_pos_query
781  WHERE thr_top_fk = %s $excluded_ids_condition
782  ";
783  $res = $this->db->queryF($query, ['integer'], [$a_topic_id]);
784  $cntData = $this->db->fetchAssoc($res);
785  $cnt = (int) $cntData['cnt'];
786 
787  $active_query = '';
788  $active_inner_query = '';
789  $having = '';
790  if ($is_post_activation_enabled && !$params['is_moderator']) {
791  $active_query = ' AND (pos_status = %s OR pos_author_id = %s) ';
792  $active_inner_query = ' AND (ipos.pos_status = %s OR ipos.pos_author_id = %s) ';
793  $having = ' HAVING num_posts > 0';
794  }
795 
796  $threads = [];
797  $data = [];
798  $data_types = [];
799 
800  $optional_fields = '';
801  if ($frm_props->isIsThreadRatingEnabled()) {
802  $optional_fields = ',avg_rating';
803  }
804  if ($frm_props->getThreadSorting() === 1) {
805  $optional_fields = ',thread_sorting';
806  }
807 
808  $additional_sort = '';
809  if ($frm_props->getThreadSorting()) {
810  $additional_sort .= ' , thread_sorting ASC ';
811  }
812 
813  if ($params['order_column'] === 'thr_subject') {
814  $dynamic_columns = [', thr_subject ' . $params['order_direction']];
815  } elseif ($params['order_column'] === 'num_posts') {
816  $dynamic_columns = [', num_posts ' . $params['order_direction']];
817  } elseif ($params['order_column'] === 'num_visit') {
818  $dynamic_columns = [', visits ' . $params['order_direction']];
819  } else {
820  $dynamic_columns = [', post_date ' . $params['order_direction']];
821  }
822 
823  if ($frm_props->isIsThreadRatingEnabled()) {
824  $dynamic_columns[] = ' ,avg_rating ' . $params['order_direction'];
825  }
826  if ('rating' === strtolower($params['order_column'])) {
827  $dynamic_columns = array_reverse($dynamic_columns);
828  }
829  $additional_sort .= implode(' ', $dynamic_columns);
830 
831  $new_deadline_condition = $this->db->quote(date(
832  'Y-m-d H:i:s',
833  (int) $this->settings->get(
834  'frm_new_deadline',
835  (string) (time() - 60 * 60 * 24 * 7 * ilObjForum::NEWS_NEW_CONSIDERATION_WEEKS)
836  )
837  ), 'timestamp');
838 
839  if (!$this->user->isAnonymous()) {
840  $query = "SELECT
841  (CASE WHEN COUNT(DISTINCT(notification_id)) > 0 THEN 1 ELSE 0 END) usr_notification_is_enabled,
842  MAX(pos_date) post_date,
843  SUM(tree1.parent_pos != 0) num_posts,
844  SUM(tree1.parent_pos != 0) - SUM(tree1.parent_pos != 0 AND postread.post_id IS NOT NULL) num_unread_posts, ";
845 
846  // new posts query
847  if ($frm_overview_setting === ilForumProperties::FORUM_OVERVIEW_WITH_NEW_POSTS) {
848  $query .= "
849  (SELECT COUNT(DISTINCT(ipos.pos_pk))
850  FROM frm_posts ipos
851  INNER JOIN frm_posts_tree treenew
852  ON treenew.pos_fk = ipos.pos_pk
853  LEFT JOIN frm_user_read iread ON iread.post_id = ipos.pos_pk AND iread.usr_id = %s
854  LEFT JOIN frm_thread_access iacc ON (iacc.thread_id = ipos.pos_thr_fk AND iacc.usr_id = %s)
855  WHERE ipos.pos_thr_fk = thr_pk
856  AND treenew.parent_pos != 0
857  AND (ipos.pos_update > iacc.access_old_ts
858  OR
859  (iacc.access_old IS NULL AND (ipos.pos_update > " . $new_deadline_condition . "))
860  )
861 
862  AND ipos.pos_author_id != %s
863  AND iread.usr_id IS NULL $active_inner_query
864  ) num_new_posts, ";
865  }
866 
867  $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
868  $optional_fields
869  FROM frm_threads
870 
871  LEFT JOIN frm_notification
872  ON frm_notification.thread_id = thr_pk
873  AND frm_notification.user_id = %s
874 
875  LEFT JOIN frm_posts
876  ON pos_thr_fk = thr_pk $active_query
877  LEFT JOIN frm_posts_tree tree1
878  ON tree1.pos_fk = frm_posts.pos_pk
879  LEFT JOIN frm_user_read postread
880  ON postread.post_id = pos_pk
881  AND postread.usr_id = %s";
882 
883  $query .= " WHERE thr_top_fk = %s
884  $excluded_ids_condition
885  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
886  $optional_fields
887  $having
888  ORDER BY is_sticky DESC $additional_sort, thr_date DESC";
889 
890  // data_types for new posts query and $active_inner_query
891  if ($frm_overview_setting === ilForumProperties::FORUM_OVERVIEW_WITH_NEW_POSTS) {
892  $data_types[] = 'integer';
893  $data_types[] = 'integer';
894  $data_types[] = 'integer';
895  if ($is_post_activation_enabled && !$params['is_moderator']) {
896  array_push($data_types, 'integer', 'integer');
897  }
898  }
899  $data_types[] = 'integer';
900  if ($is_post_activation_enabled && !$params['is_moderator']) {
901  array_push($data_types, 'integer', 'integer');
902  }
903  $data_types[] = 'integer';
904  $data_types[] = 'integer';
905 
906  // data_values for new posts query and $active_inner_query
907  if ($frm_overview_setting === ilForumProperties::FORUM_OVERVIEW_WITH_NEW_POSTS) {
908  $data[] = $user_id;
909  $data[] = $user_id;
910  $data[] = $user_id;
911  if ($is_post_activation_enabled && !$params['is_moderator']) {
912  array_push($data, 1, $user_id);
913  }
914  }
915  $data[] = $user_id;
916  if ($is_post_activation_enabled && !$params['is_moderator']) {
917  array_push($data, 1, $user_id);
918  }
919  $data[] = $user_id;
920  } else {
921  $query = "SELECT
922  0 usr_notification_is_enabled,
923  MAX(pos_date) post_date,
924  COUNT(DISTINCT(tree1.pos_fk)) num_posts,
925  COUNT(DISTINCT(tree1.pos_fk)) num_unread_posts,
926  COUNT(DISTINCT(tree1.pos_fk)) num_new_posts,
927  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
928  $optional_fields
929  FROM frm_threads
930 
931  LEFT JOIN frm_posts
932  ON pos_thr_fk = thr_pk $active_query
933  LEFT JOIN frm_posts_tree tree1
934  ON tree1.pos_fk = frm_posts.pos_pk AND tree1.parent_pos != 0
935  ";
936 
937  $query .= " WHERE thr_top_fk = %s
938  $excluded_ids_condition
939  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
940  $optional_fields
941  $having
942  ORDER BY is_sticky DESC $additional_sort, thr_date DESC";
943 
944  if ($is_post_activation_enabled && !$params['is_moderator']) {
945  array_push($data_types, 'integer', 'integer');
946  }
947  $data_types[] = 'integer';
948  if ($is_post_activation_enabled && !$params['is_moderator']) {
949  array_push($data, 1, $user_id);
950  }
951  }
952  $data[] = $a_topic_id;
953 
954  if ($limit || $offset) {
955  $this->db->setLimit($limit, $offset);
956  }
957 
958  $threadIds = [];
959  $res = $this->db->queryF($query, $data_types, $data);
960  while ($row = $this->db->fetchAssoc($res)) {
961  $thread = new ilForumTopic((int) $row['thr_pk'], (bool) $params['is_moderator'], true);
962  $thread->assignData($row);
963  $threads[(int) $row['thr_pk']] = $thread;
964  $threadIds[] = (int) $row['thr_pk'];
965  }
966 
967  $inner_last_active_post_condition = '';
968  if ($is_post_activation_enabled && !$params['is_moderator']) {
969  $inner_last_active_post_condition = sprintf(
970  ' AND (iposts.pos_status = %s OR (iposts.pos_status = %s AND iposts.pos_author_id = %s)) ',
971  $this->db->quote(1, 'integer'),
972  $this->db->quote(0, 'integer'),
973  $this->db->quote($this->user->getId(), 'integer')
974  );
975  }
976 
977  $post_res = $this->db->query(
978  'SELECT frm_posts.*
979  FROM frm_posts
980  INNER JOIN (
981  SELECT pos_thr_fk, MAX(iposts.pos_date) i_pos_date
982  FROM frm_posts iposts
983  WHERE ' . $this->db->in('iposts.pos_thr_fk', $threadIds, false, 'integer') . '
984  ' . $inner_last_active_post_condition . '
985  GROUP BY pos_thr_fk
986  ) opost ON frm_posts.pos_thr_fk = opost.pos_thr_fk AND frm_posts.pos_date = opost.i_pos_date'
987  );
988  while ($post_row = $this->db->fetchAssoc($post_res)) {
989  $tmp_obj = new ilForumPost((int) $post_row['pos_pk'], (bool) $params['is_moderator'], true);
990  $tmp_obj->setPosAuthorId((int) $post_row['pos_author_id']);
991  $tmp_obj->setDisplayUserId((int) $post_row['pos_display_user_id']);
992  $tmp_obj->setUserAlias((string) $post_row['pos_usr_alias']);
993  $tmp_obj->setImportName((string) $post_row['import_name']);
994  $tmp_obj->setId((int) $post_row['pos_pk']);
995  $tmp_obj->setCreateDate((string) $post_row['pos_date']);
996 
997  $threads[(int) $post_row['pos_thr_fk']]->setLastPostForThreadOverview($tmp_obj);
998  }
999 
1000  return [
1001  'items' => $threads,
1002  'cnt' => $cnt
1003  ];
1004  }
$res
Definition: ltiservices.php:69
const NEWS_NEW_CONSIDERATION_WEEKS
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
static getInstance(int $a_obj_id=0)
$query
+ Here is the call graph for this function:

◆ getDbTable()

ilForum::getDbTable ( )

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

References $dbTable.

97  : string
98  {
99  return $this->dbTable;
100  }
string $dbTable

◆ getFirstPostNode()

ilForum::getFirstPostNode ( int  $tree_id)

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

References $res, and fetchPostNodeData().

1308  : array
1309  {
1310  $res = $this->db->queryF(
1311  'SELECT * FROM frm_posts, frm_posts_tree WHERE pos_pk = pos_fk AND parent_pos = %s AND thr_fk = %s',
1312  ['integer', 'integer'],
1313  [0, $tree_id]
1314  );
1315 
1316  if ($row = $this->db->fetchObject($res)) {
1317  return $this->fetchPostNodeData($row);
1318  }
1319 
1320  return [];
1321  }
$res
Definition: ltiservices.php:69
fetchPostNodeData(stdClass $a_row)
+ Here is the call graph for this function:

◆ getForumId()

ilForum::getForumId ( )

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

References $id.

Referenced by countActiveUserArticles(), countUserArticles(), deletePost(), deletePostFiles(), getAllThreads(), getNumberOfPublishedUserPostings(), getOneThread(), getUserStatistics(), and mergeThreads().

78  : int
79  {
80  return $this->id;
81  }
+ Here is the caller graph for this function:

◆ getForumRefId()

ilForum::getForumRefId ( )

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

References $ref_id.

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

83  : int
84  {
85  return $this->ref_id;
86  }
+ Here is the caller graph for this function:

◆ getImportName()

ilForum::getImportName ( )

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

References $import_name.

Referenced by generateThread(), and getOneThread().

1555  : string
1556  {
1557  return $this->import_name;
1558  }
string $import_name
+ Here is the caller graph for this function:

◆ getMDB2DataType()

ilForum::getMDB2DataType ( )

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

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

121  : array
122  {
123  return $this->mdb2DataType ?: [];
124  }
+ Here is the caller graph for this function:

◆ getMDB2DataValue()

ilForum::getMDB2DataValue ( )

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

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

116  : array
117  {
118  return $this->mdb2DataValue ?: [];
119  }
+ Here is the caller graph for this function:

◆ getMDB2Query()

ilForum::getMDB2Query ( )

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

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

111  : string
112  {
113  return $this->mdb2Query ?: '';
114  }
+ Here is the caller graph for this function:

◆ getModerators()

ilForum::getModerators ( )
Returns
int[]

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

References getForumRefId().

1121  : array
1122  {
1123  return self::_getModerators($this->getForumRefId());
1124  }
+ Here is the call graph for this function:

◆ getNumberOfPublishedUserPostings()

ilForum::getNumberOfPublishedUserPostings ( int  $usr_id,
bool  $post_activation_required 
)

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

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

1006  : int
1007  {
1008  $query = '
1009  SELECT
1010  SUM(IF(f.pos_cens = %s, 1, 0)) cnt
1011  FROM frm_posts f
1012  INNER JOIN frm_posts_tree t ON f.pos_pk = t.pos_fk AND t.parent_pos != %s
1013  INNER JOIN frm_threads th ON t.thr_fk = th.thr_pk
1014  INNER JOIN frm_data d ON d.top_pk = f.pos_top_fk AND d.top_frm_fk = %s
1015  WHERE f.pos_author_id = %s
1016  ';
1017 
1018  if ($post_activation_required) {
1019  $query .= ' AND f.pos_status = ' . $this->db->quote(1, 'integer');
1020  }
1021 
1022  $res = $this->db->queryF(
1023  $query,
1024  ['integer', 'integer', 'integer', 'integer'],
1025  [0, 0, $this->getForumId(), $usr_id]
1026  );
1027  $row = $this->db->fetchAssoc($res);
1028  if (is_array($row)) {
1029  return (int) $row['cnt'];
1030  }
1031 
1032  return 0;
1033  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:

◆ getOneThread()

ilForum::getOneThread ( )

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

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

165  : ilForumTopic
166  {
167  $data_type = [];
168  $data_value = [];
169 
170  $query = 'SELECT * FROM frm_threads WHERE ';
171  if ($this->getMDB2Query() !== '' && $this->getMDB2DataType() !== [] && $this->getMDB2DataValue() !== []) {
172  $query .= ' ' . $this->getMDB2Query() . ' ';
173  $data_type += $this->getMDB2DataType();
174  $data_value += $this->getMDB2DataValue();
175  } else {
176  $query .= '1 = 1';
177  }
178 
179  $sql_res = $this->db->queryF($query, $data_type, $data_value);
180  $result = $this->db->fetchAssoc($sql_res);
181  $result['thr_subject'] = trim((string) ($result['thr_subject'] ?? ''));
182 
183  $thread_obj = new ilForumTopic();
184  $thread_obj->assignData($result);
185 
186  return $thread_obj;
187  }
$query
getMDB2DataValue()
+ Here is the call graph for this function:

◆ getOneTopic()

ilForum::getOneTopic ( )

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

References $query, $res, ForumDto\getEmptyInstance(), ForumDto\getInstanceFromArray(), getMDB2DataType(), getMDB2DataValue(), and getMDB2Query().

Referenced by moveThreads().

141  : ForumDto
142  {
143  $data_type = [];
144  $data_value = [];
145 
146  $query = 'SELECT * FROM frm_data WHERE ';
147  if ($this->getMDB2Query() !== '' && $this->getMDB2DataType() !== [] && $this->getMDB2DataValue() !== []) {
148  $query .= ' ' . $this->getMDB2Query() . ' ';
149  $data_type += $this->getMDB2DataType();
150  $data_value += $this->getMDB2DataValue();
151  } else {
152  $query .= '1 = 1';
153  }
154 
155  $res = $this->db->queryF($query, $data_type, $data_value);
156  $row = $this->db->fetchAssoc($res);
157 
158  if (!is_array($row) || $row === []) {
160  }
161 
162  return ForumDto::getInstanceFromArray($row);
163  }
$res
Definition: ltiservices.php:69
static getInstanceFromArray(array $record)
static getEmptyInstance()
$query
getMDB2DataValue()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPageHits()

ilForum::getPageHits ( )

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

References $pageHits.

136  : int
137  {
138  return $this->pageHits;
139  }
int $pageHits

◆ getPostDepth()

ilForum::getPostDepth ( int  $a_node_id,
int  $tree_id 
)

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

References $res.

Referenced by insertPostNode().

1290  : int
1291  {
1292  if ($tree_id) {
1293  $res = $this->db->queryF(
1294  'SELECT depth FROM frm_posts_tree WHERE pos_fk = %s AND thr_fk = %s',
1295  ['integer', 'integer'],
1296  [$a_node_id, $tree_id]
1297  );
1298 
1299  $row = $this->db->fetchObject($res);
1300  if ($row instanceof stdClass) {
1301  return (int) $row->depth;
1302  }
1303  }
1304 
1305  return 0;
1306  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ getPostNode()

ilForum::getPostNode ( int  $post_id)

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

References $res, and fetchPostNodeData().

Referenced by deletePost(), and mergeThreads().

1323  : array
1324  {
1325  $res = $this->db->queryF(
1326  'SELECT * FROM frm_posts, frm_posts_tree WHERE pos_pk = pos_fk AND pos_pk = %s',
1327  ['integer'],
1328  [$post_id]
1329  );
1330 
1331  if ($row = $this->db->fetchObject($res)) {
1332  return $this->fetchPostNodeData($row);
1333  }
1334 
1335  return [];
1336  }
$res
Definition: ltiservices.php:69
fetchPostNodeData(stdClass $a_row)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRootPostIdByThread()

ilForum::getRootPostIdByThread ( int  $a_thread_id)

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

References $res.

1102  : int
1103  {
1104  $res = $this->db->queryF(
1105  'SELECT pos_fk FROM frm_posts_tree WHERE thr_fk = %s AND parent_pos = %s',
1106  ['integer', 'integer'],
1107  [$a_thread_id, 0]
1108  );
1109 
1110  $row = $this->db->fetchObject($res);
1111  if ($row instanceof stdClass) {
1112  return (int) $row->pos_fk;
1113  }
1114 
1115  return 0;
1116  }
$res
Definition: ltiservices.php:69

◆ getSortedThreadSubjects()

static ilForum::getSortedThreadSubjects ( int  $a_obj_id,
int  $a_sort_mode = self::SORT_DATE 
)
static
Parameters
int$a_obj_id
int$a_sort_mode
Returns
array<int, string>

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

References $DIC, $res, and ILIAS\Repository\int().

Referenced by ilObjForumSearchResultTableGUI\parse().

1666  : array
1667  {
1668  global $DIC;
1669 
1670  switch ($a_sort_mode) {
1671  case self::SORT_DATE:
1672  $sort = 'thr_date';
1673  break;
1674 
1675  case self::SORT_TITLE:
1676  default:
1677  $sort = 'thr_subject';
1678  break;
1679  }
1680 
1681  $res = $DIC->database()->queryF(
1682  'SELECT thr_pk, thr_subject FROM frm_threads INNER JOIN frm_data ON top_pk = thr_top_fk WHERE top_frm_fk = %s ORDER BY %s',
1683  ['integer', 'text'],
1684  [$a_obj_id, $sort]
1685  );
1686 
1687  $threads = [];
1688  while ($row = $DIC->database()->fetchObject($res)) {
1689  $threads[(int) $row->thr_pk] = $row->thr_subject;
1690  }
1691 
1692  return $threads;
1693  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserStatistics()

ilForum::getUserStatistics ( bool  $post_activation_required)
Parameters
bool$post_activation_required
Returns
array{usr_id: int, pos_author_id: int, firstname: string, lastname: string, login: string, public_profile: string, num_postings: int}[]

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

References $data, $query, $res, getForumId(), ILIAS\Repository\int(), ilPersonalProfileMode\PROFILE_ENABLED_GLOBAL, ilPersonalProfileMode\PROFILE_ENABLED_LOGGED_IN_USERS, and ILIAS\Repository\user().

1039  : array
1040  {
1041  $statistic = [];
1042  $data_types = [];
1043  $data = [];
1044 
1045  $query = '
1046  SELECT
1047  u.login, u.lastname, u.firstname, f.pos_author_id, u.usr_id,
1048  p.value public_profile,
1049  SUM(IF(f.pos_cens = %s, 1, 0)) num_postings
1050  FROM frm_posts f
1051  INNER JOIN frm_posts_tree t ON f.pos_pk = t.pos_fk
1052  INNER JOIN frm_threads th ON t.thr_fk = th.thr_pk
1053  INNER JOIN usr_data u ON u.usr_id = f.pos_author_id
1054  INNER JOIN frm_data d ON d.top_pk = f.pos_top_fk
1055  LEFT JOIN usr_pref p ON p.usr_id = u.usr_id AND p.keyword = %s
1056  WHERE t.parent_pos != %s
1057  ';
1058 
1059  $data_types[] = 'integer';
1060  $data_types[] = 'text';
1061  $data_types[] = 'integer';
1062  $data[] = 0;
1063  $data[] = 'public_profile';
1064  $data[] = 0;
1065 
1066  if ($post_activation_required) {
1067  $query .= ' AND pos_status = %s';
1068  $data_types[] = 'integer';
1069  $data[] = 1;
1070  }
1071 
1072  $query .= '
1073  AND d.top_frm_fk = %s
1074  GROUP BY u.login, p.value,u.lastname, u.firstname, f.pos_author_id
1075  ';
1076 
1077  $data_types[] = 'integer';
1078  $data[] = $this->getForumId();
1079 
1080  $res = $this->db->queryF($query, $data_types, $data);
1081  while ($row = $this->db->fetchAssoc($res)) {
1082  if (
1083  !in_array($row['public_profile'], [
1086  || ($this->user->isAnonymous() && $row['public_profile'] !== ilPersonalProfileMode::PROFILE_ENABLED_GLOBAL)
1087  ) {
1088  $row['lastname'] = '';
1089  $row['firstname'] = '';
1090  }
1091 
1092  $row['usr_id'] = (int) $row['usr_id'];
1093  $row['pos_author_id'] = (int) $row['pos_author_id'];
1094  $row['num_postings'] = (int) $row['num_postings'];
1095 
1096  $statistic[] = $row;
1097  }
1098 
1099  return $statistic;
1100  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:

◆ insertPostNode()

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

insert node under parent node

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

References $res, getPostDepth(), and ILIAS\Repository\int().

Referenced by getOneThread().

1224  : void
1225  {
1226  $a_date = $a_date ?: date('Y-m-d H:i:s');
1227  $left = 1;
1228 
1229  $res = $this->db->queryF(
1230  'SELECT lft FROM frm_posts_tree WHERE pos_fk = %s AND thr_fk = %s',
1231  ['integer', 'integer'],
1232  [$a_parent_id, $tree_id]
1233  );
1234  $row = $this->db->fetchObject($res);
1235  if ($row instanceof stdClass) {
1236  $left = (int) $row->lft;
1237  }
1238 
1239  $lft = $left + 1;
1240  $rgt = $left + 2;
1241 
1242  $this->db->manipulateF(
1243  '
1244  UPDATE frm_posts_tree
1245  SET lft = CASE
1246  WHEN lft > %s
1247  THEN lft + 2
1248  ELSE lft
1249  END,
1250  rgt = CASE
1251  WHEN rgt > %s
1252  THEN rgt + 2
1253  ELSE rgt
1254  END
1255  WHERE thr_fk = %s',
1256  ['integer', 'integer', 'integer'],
1257  [$left, $left, $tree_id]
1258  );
1259 
1260  $depth = $this->getPostDepth($a_parent_id, $tree_id) + 1;
1261 
1262  $nextId = $this->db->nextId('frm_posts_tree');
1263  $this->db->manipulateF(
1264  '
1265  INSERT INTO frm_posts_tree
1266  ( fpt_pk,
1267  thr_fk,
1268  pos_fk,
1269  parent_pos,
1270  lft,
1271  rgt,
1272  depth,
1273  fpt_date
1274  )
1275  VALUES(%s,%s,%s, %s, %s, %s,%s, %s)',
1276  ['integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'timestamp'],
1277  [
1278  $nextId,
1279  $tree_id,
1280  $a_node_id,
1281  $a_parent_id,
1282  $lft,
1283  $rgt,
1284  $depth,
1285  $a_date
1286  ]
1287  );
1288  }
$res
Definition: ltiservices.php:69
getPostDepth(int $a_node_id, int $tree_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isForumNotificationEnabled()

ilForum::isForumNotificationEnabled ( int  $user_id)

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

References $res.

Referenced by enableForumNotification().

1631  : bool
1632  {
1633  $res = $this->db->queryF(
1634  'SELECT COUNT(*) cnt FROM frm_notification WHERE user_id = %s AND frm_id = %s',
1635  ['integer', 'integer'],
1636  [$user_id, $this->id]
1637  );
1638 
1639  if ($row = $this->db->fetchAssoc($res)) {
1640  return (int) $row['cnt'] > 0;
1641  }
1642 
1643  return false;
1644  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ isThreadNotificationEnabled()

ilForum::isThreadNotificationEnabled ( int  $user_id,
int  $thread_id 
)

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

References $res.

1646  : bool
1647  {
1648  $res = $this->db->queryF(
1649  'SELECT COUNT(*) cnt FROM frm_notification WHERE user_id = %s AND thread_id = %s',
1650  ['integer', 'integer'],
1651  [$user_id, $thread_id]
1652  );
1653 
1654  if ($row = $this->db->fetchAssoc($res)) {
1655  return (int) $row['cnt'] > 0;
1656  }
1657 
1658  return false;
1659  }
$res
Definition: ltiservices.php:69

◆ mergeThreads()

ilForum::mergeThreads ( int  $source_id,
int  $target_id 
)

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

References Vendor\Package\$e, $ilDB, ilObjForum\_deleteAccessEntries(), deletePost(), getForumId(), getPostNode(), ilObjForum\mergeForumUserRead(), ilForumPost\mergePosts(), ilForumNotification\mergeThreadNotifications(), and ilForumPostsTree\updateTargetRootRgt().

1707  : void
1708  {
1709  // selected source and target objects
1710  $sourceThread = new ilForumTopic($source_id);
1711  $targetThread = new ilForumTopic($target_id);
1712 
1713  if ($sourceThread->getForumId() !== $targetThread->getForumId()) {
1714  throw new ilException('not_allowed_to_merge_into_another_forum');
1715  }
1716 
1717  // use the 'older' thread as target
1718  if ($sourceThread->getCreateDate() > $targetThread->getCreateDate()) {
1719  $sourceThreadForMerge = $sourceThread;
1720  $targetThreadForMerge = $targetThread;
1721  } else {
1722  $sourceThreadForMerge = $targetThread;
1723  $targetThreadForMerge = $sourceThread;
1724  }
1725 
1726  $threadSubject = $targetThreadForMerge->getSubject();
1727 
1728  $targetWasClosedBeforeMerge = $targetThreadForMerge->isClosed();
1729  $sourceThreadForMerge->close();
1730 
1731  if (false === $targetWasClosedBeforeMerge) {
1732  $targetThreadForMerge->close();
1733  }
1734 
1735  $allSourcePostings = $sourceThreadForMerge->getAllPostIds();
1736  $sourceThreadRootNode = $sourceThreadForMerge->getPostRootNode();
1737  $targetThreadRootNode = $targetThreadForMerge->getPostRootNode();
1738 
1739  $sourceThreadRootArray = $this->getPostNode($sourceThreadRootNode->getId());
1740 
1741  $ilAtomQuery = $this->db->buildAtomQuery();
1742  $ilAtomQuery->addTableLock('frm_posts');
1743  $ilAtomQuery->addTableLock('frm_posts_tree');
1744  $ilAtomQuery->addTableLock('frm_threads');
1745  $ilAtomQuery->addTableLock('frm_data');
1746 
1747  $ilAtomQuery->addQueryCallable(static function (ilDBInterface $ilDB) use (
1748  $targetThreadForMerge,
1749  $sourceThreadForMerge,
1750  $targetThreadRootNode,
1751  $sourceThreadRootNode,
1752  $allSourcePostings
1753  ) {
1754  $targetRootNodeRgt = $targetThreadRootNode->getRgt();
1755  $targetRootNodeId = $targetThreadRootNode->getId();
1756 
1757  // update target root node rgt: Ignore the root node itself from the source (= -2)
1759  $targetThreadRootNode->getId(),
1760  ($targetThreadRootNode->getRgt() + $sourceThreadRootNode->getRgt() - 2)
1761  );
1762 
1763  // get source post tree and update posts tree
1764  foreach ($allSourcePostings as $pos_pk) {
1765  $post_obj = new ilForumPost($pos_pk);
1766 
1767  if ($post_obj->getId() === $sourceThreadRootNode->getId()) {
1768  // Ignore the source root node (MUST be deleted later)
1769  continue;
1770  }
1771 
1772  $tree = new ilForumPostsTree();
1773  $tree->setPosFk($pos_pk);
1774 
1775  if ($post_obj->getParentId() === $sourceThreadRootNode->getId()) {
1776  $tree->setParentPos($targetRootNodeId);
1777  } else {
1778  $tree->setParentPos($post_obj->getParentId());
1779  }
1780 
1781  $tree->setLft(($post_obj->getLft() + $targetRootNodeRgt) - 2);
1782  $tree->setRgt(($post_obj->getRgt() + $targetRootNodeRgt) - 2);
1783 
1784  $tree->setDepth($post_obj->getDepth());
1785  $tree->setTargetThreadId($targetThreadForMerge->getId());
1786  $tree->setSourceThreadId($sourceThreadForMerge->getId());
1787 
1788  $tree->merge();
1789  }
1790 
1792  $sourceThreadForMerge->getId(),
1793  $targetThreadForMerge->getId(),
1794  [$sourceThreadRootNode->getId()]
1795  );
1796  });
1797  $ilAtomQuery->run();
1798 
1799  ilForumNotification::mergeThreadNotifications($sourceThreadForMerge->getId(), $targetThreadForMerge->getId());
1800  ilObjForum::_deleteAccessEntries($sourceThreadForMerge->getId());
1801  ilObjForum::mergeForumUserRead($sourceThreadForMerge->getId(), $targetThreadForMerge->getId());
1802 
1803  $lastPostString = $targetThreadForMerge->getLastPostString();
1804  $exp = explode('#', $lastPostString);
1805  if (array_key_exists(2, $exp)) {
1806  try {
1807  $exp[2] = $targetThreadForMerge->getLastPost()->getId();
1808  $lastPostString = implode('#', $exp);
1809  } catch (OutOfBoundsException $e) {
1810  $lastPostString = null;
1811  }
1812  }
1813 
1814  $frm_topic_obj = new ilForumTopic(0, false, true);
1815  $frm_topic_obj->setNumPosts($sourceThreadForMerge->getNumPosts() + $targetThreadForMerge->getNumPosts());
1816  $frm_topic_obj->setVisits($sourceThreadForMerge->getVisits() + $targetThreadForMerge->getVisits());
1817  $frm_topic_obj->setLastPostString($lastPostString);
1818  $frm_topic_obj->setSubject($threadSubject);
1819  $frm_topic_obj->setId($targetThreadForMerge->getId());
1820  $frm_topic_obj->updateMergedThread();
1821 
1822  if (!$targetWasClosedBeforeMerge) {
1823  $targetThreadForMerge->reopen();
1824  }
1825 
1826  $this->event->raise(
1827  'Modules/Forum',
1828  'mergedThreads',
1829  [
1830  'obj_id' => $this->getForumId(),
1831  'source_thread_id' => $sourceThreadForMerge->getId(),
1832  'target_thread_id' => $targetThreadForMerge->getId()
1833  ]
1834  );
1835 
1836  $this->deletePost($sourceThreadRootArray, false);
1837  }
getPostNode(int $post_id)
static mergeForumUserRead(int $merge_source_thread_id, int $merge_target_thread_id)
static _deleteAccessEntries(int $a_thread_id)
$target_id
Definition: goto.php:52
static mergePosts(int $sourceThreadId, int $targetThreadId, array $excludedPostIds=[])
static updateTargetRootRgt(int $root_node_id, int $rgt)
deletePost($postIdOrRecord, bool $raiseEvents=true)
static mergeThreadNotifications($merge_source_thread_id, $merge_target_thread_id)
+ Here is the call graph for this function:

◆ moveThreads()

ilForum::moveThreads ( array  $thread_ids,
ilObjForum  $src_forum,
int  $target_obj_id 
)
Parameters
int[]$thread_ids
ilObjForum$src_forum
int$target_obj_id
Returns
string[] A list of error message strings

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

References $res, ilObject\getId(), getOneTopic(), ILIAS\Repository\lng(), and setMDB2WhereCondition().

351  : array
352  {
353  $errorMessages = [];
354 
355  if (!($target_obj_id > 0) || !($src_forum->getId() > 0)) {
356  return $errorMessages;
357  }
358 
359  $this->setMDB2WhereCondition('top_frm_fk = %s ', ['integer'], [$src_forum->getId()]);
360  $oldFrmData = $this->getOneTopic();
361 
362  $this->setMDB2WhereCondition('top_frm_fk = %s ', ['integer'], [$target_obj_id]);
363  $newFrmData = $this->getOneTopic();
364 
365  if (!$oldFrmData->getTopPk() || !$newFrmData->getTopPk()) {
366  return $errorMessages;
367  }
368 
369  $num_moved_posts = 0;
370  $num_moved_threads = 0;
371  $num_visits = 0;
372 
373  foreach ($thread_ids as $id) {
374  $objTmpThread = new ilForumTopic($id);
375 
376  try {
377  $numPosts = $objTmpThread->movePosts(
378  $src_forum->getId(),
379  $oldFrmData->getTopPk(),
380  $target_obj_id,
381  $newFrmData->getTopPk()
382  );
383 
384  if (($last_post_string = $objTmpThread->getLastPostString()) !== '') {
385  $last_post_string = explode('#', $last_post_string);
386  $last_post_string[0] = $newFrmData->getTopPk();
387  $last_post_string = implode('#', $last_post_string);
388  $objTmpThread->setLastPostString($last_post_string);
389  }
390 
391  $num_visits += $objTmpThread->getVisits();
392  $num_moved_posts += $numPosts;
393  ++$num_moved_threads;
394 
395  $objTmpThread->setForumId($newFrmData->getTopPk());
396  $objTmpThread->update();
397  } catch (ilFileUtilsException $exception) {
398  $errorMessages[] = sprintf($this->lng->txt('frm_move_invalid_file_type'), $objTmpThread->getSubject());
399  continue;
400  }
401  }
402 
403  if (0 === max($num_moved_threads, $num_moved_posts, $num_visits)) {
404  return $errorMessages;
405  }
406 
407  $this->db->setLimit(1, 0);
408  $res = $this->db->queryF(
409  'SELECT pos_thr_fk, pos_pk FROM frm_posts WHERE pos_top_fk = %s ORDER BY pos_date DESC',
410  ['integer'],
411  [$oldFrmData->getTopPk()]
412  );
413 
414  $last_post_src = '';
415  $row = $this->db->fetchObject($res);
416  if ($row !== null) {
417  $last_post_src = $oldFrmData->getTopPk() . '#' . $row->pos_thr_fk . '#' . $row->pos_pk;
418  }
419 
420  $this->db->manipulateF(
421  'UPDATE frm_data ' .
422  'SET top_num_posts = top_num_posts - %s, top_num_threads = top_num_threads - %s, visits = visits - %s, ' .
423  'top_last_post = %s WHERE top_pk = %s',
424  ['integer', 'integer', 'integer', 'text', 'integer'],
425  [
426  $num_moved_posts,
427  $num_moved_threads,
428  $num_visits,
429  $last_post_src,
430  $oldFrmData->getTopPk()
431  ]
432  );
433 
434  $this->db->setLimit(1, 0);
435  $res = $this->db->queryF(
436  'SELECT pos_thr_fk, pos_pk FROM frm_posts WHERE pos_top_fk = %s ORDER BY pos_date DESC',
437  ['integer'],
438  [$newFrmData->getTopPk()]
439  );
440 
441  $last_post_dest = '';
442  $row = $this->db->fetchObject($res);
443  if ($row !== null) {
444  $last_post_dest = $newFrmData->getTopPk() . '#' . $row->pos_thr_fk . '#' . $row->pos_pk;
445  }
446 
447  $this->db->manipulateF(
448  'UPDATE frm_data SET top_num_posts = top_num_posts + %s, top_num_threads = top_num_threads + %s, ' .
449  'visits = visits + %s, top_last_post = %s WHERE top_pk = %s',
450  ['integer', 'integer', 'integer', 'text', 'integer'],
451  [$num_moved_posts, $num_moved_threads, $num_visits, $last_post_dest, $newFrmData->getTopPk()]
452  );
453 
454  $this->event->raise(
455  'Modules/Forum',
456  'movedThreads',
457  [
458  'source_ref_id' => $src_forum->getId(),
459  'target_ref_id' => $src_forum->getId(),
460  'thread_ids' => $src_forum->getId(),
461  'source_frm_obj_id' => $src_forum->getId(),
462  'target_frm_obj_id' => $target_obj_id
463  ]
464  );
465 
466  return $errorMessages;
467  }
$res
Definition: ltiservices.php:69
setMDB2WhereCondition(string $query_string, array $data_type, array $data_value)
+ Here is the call graph for this function:

◆ postCensorship()

ilForum::postCensorship ( ilObjForum  $forum,
string  $message,
int  $pos_pk,
int  $cens = 0 
)

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

References $res, ilNewsItem\getFirstNewsIdForContext(), getForumRefId(), prepareText(), and ILIAS\Repository\user().

469  : void
470  {
471  $cens_date = date('Y-m-d H:i:s');
472 
473  $this->db->manipulateF(
474  'UPDATE frm_posts
475  SET pos_cens_com = %s,
476  pos_cens_date = %s,
477  pos_cens = %s,
478  update_user = %s
479  WHERE pos_pk = %s',
480  ['text', 'timestamp', 'integer', 'integer', 'integer'],
481  [$message,
482  $cens_date,
483  $cens,
484  $this->user->getId(),
485  $pos_pk
486  ]
487  );
488 
490  $this->id,
491  'frm',
492  $pos_pk,
493  'pos'
494  );
495  if ($news_id > 0) {
496  if ($cens > 0) {
497  $news_item = new ilNewsItem($news_id);
498  $news_item->setContent(nl2br($this->prepareText($message, 0)));
499  $news_item->setContentHtml(false);
500  if ($message !== strip_tags($message)) {
501  $news_item->setContentHtml(true);
502  }
503  } else {
504  $res = $this->db->queryF('SELECT pos_message FROM frm_posts WHERE pos_pk = %s', ['integer'], [$pos_pk]);
505  $rec = $this->db->fetchAssoc($res);
506 
507  $news_item = new ilNewsItem($news_id);
508  $news_item->setContent(nl2br($this->prepareText($rec['pos_message'], 0)));
509  $news_item->setContentHtml(false);
510  if ($rec['pos_message'] !== strip_tags($rec['pos_message'])) {
511  $news_item->setContentHtml(true);
512  }
513  }
514  $news_item->update();
515  }
516 
517  $this->event->raise(
518  'Modules/Forum',
519  'censoredPost',
520  [
521  'ref_id' => $this->getForumRefId(),
522  'post' => new ilForumPost($pos_pk),
523  'object' => $forum
524  ]
525  );
526  }
$res
Definition: ltiservices.php:69
prepareText(string $text, int $edit=0, string $quote_user='', string $type='')
A news item can be created by different sources.
static getFirstNewsIdForContext(int $a_context_obj_id, string $a_context_obj_type, int $a_context_sub_obj_id=0, string $a_context_sub_obj_type="")
Get first new id of news set related to a certain context.
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ prepareText()

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

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

References $i, $replQuote2, $txtQuote2, $type, ilMathJax\getInstance(), and ILIAS\Repository\lng().

Referenced by ilObjForumGUI\doHistoryCheck(), getOneThread(), and postCensorship().

1463  : string
1464  {
1465  if ($type === 'export') {
1466  $this->replQuote1 = "<blockquote class=\"quote\"><hr size=\"1\" color=\"#000000\">";
1467  $this->replQuote2 = "<hr size=\"1\" color=\"#000000\"/></blockquote>";
1468  }
1469 
1470  if ($edit === 1) {
1471  $lname = '';
1472  if ($quote_user !== '') {
1473  $lname = '="' . $quote_user . '"';
1474  }
1475 
1476  $text = "[quote$lname]" . $text . "[/quote]";
1477  } else {
1478  // check for quotation
1479  $startZ = substr_count($text, "[quote"); // also count [quote="..."]
1480  $endZ = substr_count($text, "[/quote]");
1481 
1482  if ($startZ > 0 || $endZ > 0) {
1483  // add missing opening and closing tags
1484  if ($startZ > $endZ) {
1485  $diff = $startZ - $endZ;
1486 
1487  for ($i = 0; $i < $diff; $i++) {
1488  if ($type === 'export') {
1489  $text .= $this->txtQuote2;
1490  } else {
1491  $text .= "[/quote]";
1492  }
1493  }
1494  } elseif ($startZ < $endZ) {
1495  $diff = $endZ - $startZ;
1496 
1497  for ($i = 0; $i < $diff; $i++) {
1498  if ($type === 'export') {
1499  $text = $this->txtQuote1 . $text;
1500  } else {
1501  $text = "[quote]" . $text;
1502  }
1503  }
1504  }
1505 
1506  if ($edit === 0) {
1507  $text = preg_replace(
1508  '@\[(quote\s*?=\s*?"([^"]*?)"\s*?)\]@i',
1509  $this->replQuote1 . '<div class="ilForumQuoteHead">' . $this->lng->txt('quote') . ' ($2)</div>',
1510  $text
1511  );
1512 
1513  $text = str_replace(
1514  ["[quote]", "[/quote]"],
1515  [
1516  $this->replQuote1 . '<div class="ilForumQuoteHead">' . $this->lng->txt('quote') . '</div>',
1518  ],
1519  $text
1520  );
1521  }
1522  }
1523  }
1524 
1525  if ($type !== 'export') {
1526  if ($edit === 0) {
1527  $text = ilMathJax::getInstance()->insertLatexImages($text, "<span class\=\"latex\">", "<\/span>");
1528  $text = ilMathJax::getInstance()->insertLatexImages($text, "\[tex\]", "\[\/tex\]");
1529  }
1530 
1531  // workaround for preventing template engine
1532  // from hiding text that is enclosed
1533  // in curly brackets (e.g. "{a}")
1534  $text = str_replace(["{", "}"], ["&#123;", "&#125;"], $text);
1535  }
1536 
1537  return $text;
1538  }
$type
string $txtQuote2
static getInstance()
Singleton: get instance for use in ILIAS requests with a config loaded from the settings.
string $replQuote2
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDbTable()

ilForum::setDbTable ( string  $dbTable)

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

References $dbTable.

88  : void
89  {
90  if ($dbTable === '') {
91  die($this->className . '::setDbTable(): No database table given.');
92  }
93 
94  $this->dbTable = $dbTable;
95  }
string $dbTable

◆ setForumId()

ilForum::setForumId ( int  $a_obj_id)

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

68  : void
69  {
70  $this->id = $a_obj_id;
71  }

◆ setForumRefId()

ilForum::setForumRefId ( int  $a_ref_id)

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

73  : void
74  {
75  $this->ref_id = $a_ref_id;
76  }

◆ setImportName()

ilForum::setImportName ( string  $a_import_name)

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

1560  : void
1561  {
1562  $this->import_name = $a_import_name;
1563  }

◆ setMDB2WhereCondition()

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

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

Referenced by moveThreads().

102  : bool
103  {
104  $this->mdb2Query = $query_string;
105  $this->mdb2DataValue = $data_value;
106  $this->mdb2DataType = $data_type;
107 
108  return true;
109  }
+ Here is the caller graph for this function:

◆ setPageHits()

ilForum::setPageHits ( int  $pageHits)

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

References $pageHits.

126  : bool
127  {
128  if ($pageHits < 1) {
129  $pageHits = 1;
130  }
131 
132  $this->pageHits = $pageHits;
133  return true;
134  }
int $pageHits

◆ updateVisits()

ilForum::updateVisits ( int  $ID)

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

References $query, ilSession\get(), getMDB2DataType(), getMDB2DataValue(), getMDB2Query(), and ilSession\set().

1442  : void
1443  {
1444  $checkTime = time() - (60 * 60);
1445  $session_key = 'frm_visit_' . $this->dbTable . '_' . $ID;
1446 
1447  if (ilSession::get($session_key) < $checkTime) {
1448  ilSession::set($session_key, time());
1449  $query = 'UPDATE ' . $this->dbTable . ' SET visits = visits + 1 WHERE ';
1450  $data_type = [];
1451  $data_value = [];
1452 
1453  if ($this->getMDB2Query() !== '' && $this->getMDB2DataType() !== [] && $this->getMDB2DataValue() !== []) {
1454  $query .= $this->getMDB2Query();
1455  $data_type += $this->getMDB2DataType();
1456  $data_value += $this->getMDB2DataValue();
1457 
1458  $this->db->manipulateF($query, $data_type, $data_value);
1459  }
1460  }
1461  }
static get(string $a_var)
$query
getMDB2DataValue()
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:

Field Documentation

◆ $className

string ilForum::$className = 'ilForum'
private

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

◆ $db

ilDBInterface ilForum::$db

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

◆ $dbTable

string ilForum::$dbTable
private

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

Referenced by getDbTable(), and setDbTable().

◆ $error

ilErrorHandling ilForum::$error

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

◆ $event

ilAppEventHandler ilForum::$event
private

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

◆ $id

int ilForum::$id
private

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

Referenced by getForumId().

◆ $import_name

string ilForum::$import_name = ''
private

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

Referenced by getImportName().

◆ $lng

ilLanguage ilForum::$lng

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

◆ $mdb2DataType

array ilForum::$mdb2DataType = []
private

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

◆ $mdb2DataValue

array ilForum::$mdb2DataValue = []
private

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

◆ $mdb2Query

string ilForum::$mdb2Query = ''
private

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

◆ $moderators_by_ref_id_map

array ilForum::$moderators_by_ref_id_map = []
staticprotected

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

◆ $pageHits

int ilForum::$pageHits = self::DEFAULT_PAGE_HITS
private

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

Referenced by getPageHits(), and setPageHits().

◆ $ref_id

int ilForum::$ref_id
private

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

Referenced by getForumRefId().

◆ $replQuote1

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

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

◆ $replQuote2

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

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

Referenced by prepareText().

◆ $settings

ilSetting ilForum::$settings

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

◆ $txtQuote1

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

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

◆ $txtQuote2

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

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

Referenced by prepareText().

◆ $user

ilObjUser ilForum::$user

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

◆ DEFAULT_PAGE_HITS

const ilForum::DEFAULT_PAGE_HITS = 30
private

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

◆ SORT_DATE

const ilForum::SORT_DATE = 2
private

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

◆ SORT_TITLE

const ilForum::SORT_TITLE = 1
private

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


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