19 declare(strict_types=1);
56 public function __construct(
int $a_id = 0,
bool $a_is_moderator =
false,
bool $preventImplicitRead =
false)
60 $this->db = $DIC->database();
63 if (!$preventImplicitRead) {
70 if ($this->forum_id && $this->thread_id) {
71 $this->
id = $this->db->nextId(
'frm_posts');
73 $this->db->insert(
'frm_posts', [
74 'pos_pk' => [
'integer', $this->
id],
75 'pos_top_fk' => [
'integer', $this->forum_id],
76 'pos_thr_fk' => [
'integer', $this->thread_id],
77 'pos_display_user_id' => [
'integer', $this->display_user_id],
78 'pos_usr_alias' => [
'text', $this->user_alias],
79 'pos_subject' => [
'text', $this->subject],
80 'pos_message' => [
'clob', $this->message],
81 'pos_date' => [
'timestamp', $this->createdate],
82 'pos_update' => [
'timestamp', $this->createdate],
83 'update_user' => [
'integer', $this->user_id_update],
84 'pos_cens' => [
'integer', (
int) $this->censored],
86 'import_name' => [
'text', $this->import_name],
87 'pos_status' => [
'integer', (
int) $this->status],
88 'pos_author_id' => [
'integer', $this->pos_author_id],
89 'is_author_moderator' => [
'integer', $this->is_author_moderator],
90 'pos_activation_date' => [
'timestamp', $this->createdate]
101 'pos_top_fk' => [
'integer', $this->forum_id],
102 'pos_thr_fk' => [
'integer', $this->thread_id],
103 'pos_subject' => [
'text', $this->subject],
104 'pos_message' => [
'clob', $this->message],
105 'pos_update' => [
'timestamp', $this->changedate],
106 'update_user' => [
'integer', $this->user_id_update],
107 'pos_cens' => [
'integer', (
int) $this->censored],
108 'pos_cens_date' => [
'timestamp', $this->censored_date],
109 'pos_cens_com' => [
'text', $this->censorship_comment],
111 'pos_status' => [
'integer', (
int) $this->status]
114 'pos_pk' => [
'integer', $this->
id]
118 if ($this->objThread->getFirstVisiblePostId() ===
$this->id) {
119 $this->objThread->setSubject($this->subject);
120 $this->objThread->update();
121 $this->objThread->reload();
133 $res = $this->db->queryF(
135 SELECT * FROM frm_posts 136 INNER JOIN frm_posts_tree ON pos_fk = pos_pk 141 $row = $this->db->fetchObject(
$res);
143 if (is_object($row)) {
144 $this->
id = (
int) $row->pos_pk;
145 $this->forum_id = (
int) $row->pos_top_fk;
146 $this->thread_id = (
int) $row->pos_thr_fk;
147 $this->display_user_id = (
int) $row->pos_display_user_id;
148 $this->user_alias = $row->pos_usr_alias;
149 $this->subject = (string) $row->pos_subject;
150 $this->message = (
string) $row->pos_message;
151 $this->createdate = $row->pos_date;
152 $this->changedate = $row->pos_update;
153 $this->user_id_update = (
int) $row->update_user;
154 $this->censored = (
bool) $row->pos_cens;
155 $this->censored_date = $row->pos_cens_date;
156 $this->censorship_comment = $row->pos_cens_com;
158 $this->import_name = $row->import_name;
159 $this->status = (
bool) $row->pos_status;
160 $this->tree_id = (
int) $row->fpt_pk;
161 $this->parent_id = (
int) $row->parent_pos;
162 $this->lft = (
int) $row->lft;
163 $this->rgt = (
int) $row->rgt;
164 $this->depth = (
int) $row->depth;
165 $this->pos_author_id = (
int) $row->pos_author_id;
166 $this->is_author_moderator = (bool) $row->is_author_moderator;
167 $this->post_activation_date = $row->pos_activation_date;
169 $this->objThread =
new ilForumTopic($this->thread_id, $this->is_moderator);
177 $res = $this->db->queryF(
179 SELECT * FROM frm_posts_tree 180 INNER JOIN frm_posts ON pos_pk = pos_fk 181 WHERE pos_status = %s 182 AND lft < %s AND rgt > %s 184 [
'integer',
'integer',
'integer',
'integer'],
185 [0, $this->lft, $this->rgt, $this->thread_id]
188 return $res->numRows() > 0;
202 $now = date(
'Y-m-d H:i:s');
206 'pos_status' => [
'integer', 1],
207 'pos_activation_date' => [
'timestamp', $now]
209 [
'pos_pk' => [
'integer', $this->
id]]
221 $query =
"SELECT pos_pk FROM frm_posts_tree treea " 222 .
"INNER JOIN frm_posts_tree treeb ON treeb.thr_fk = treea.thr_fk " 223 .
"AND treeb.lft BETWEEN treea.lft AND treea.rgt " 224 .
"INNER JOIN frm_posts ON pos_pk = treeb.pos_fk " 225 .
"WHERE treea.pos_fk = %s";
226 $result = $this->db->queryF(
232 $now = date(
'Y-m-d H:i:s');
233 while ($row = $this->db->fetchAssoc($result)) {
237 'pos_status' => [
'integer', 1],
238 'pos_activation_date' => [
'timestamp', $now]
240 [
'pos_pk' => [
'integer', $row[
'pos_pk']]]
255 $query =
"SELECT pos_pk FROM frm_posts " 256 .
"INNER JOIN frm_posts_tree ON pos_fk = pos_pk " 257 .
"WHERE lft < %s AND rgt > %s AND thr_fk = %s";
258 $result = $this->db->queryF(
260 [
'integer',
'integer',
'integer'],
261 [$this->lft, $this->rgt, $this->thread_id]
264 $now = date(
'Y-m-d H:i:s');
265 while ($row = $this->db->fetchAssoc($result)) {
269 'pos_status' => [
'integer', 1],
270 'pos_activation_date' => [
'timestamp', $now]
272 [
'pos_pk' => [
'integer', $row[
'pos_pk']]]
287 public function isRead(
int $a_user_id = 0): bool
289 if ($a_user_id && $this->
id) {
290 $res = $this->db->queryF(
291 'SELECT * FROM frm_user_read WHERE usr_id = %s AND post_id = %s',
292 [
'integer',
'integer'],
293 [$a_user_id, $this->
id]
296 return $res->numRows() > 0;
304 if ($this->
id && $this->rgt && $this->lft) {
305 $res = $this->db->queryF(
306 'SELECT * FROM frm_posts_tree WHERE lft > %s AND rgt < %s AND thr_fk = %s',
307 [
'integer',
'integer',
'integer'],
308 [$this->lft, $this->rgt, $this->thread_id]
311 return $res->numRows() > 0;
317 public function isOwner(
int $a_user_id = 0): bool
319 if ($this->pos_author_id && $a_user_id) {
320 return $this->pos_author_id === $a_user_id;
326 public function setId(
int $a_id): void
338 $this->forum_id = $a_forum_id;
348 $this->thread_id = $a_thread_id;
358 $this->display_user_id = $a_user_id;
368 $this->user_alias = $a_user_alias;
378 $this->subject = $a_subject;
388 $this->message = $a_message;
398 $this->createdate = $a_createdate;
408 $this->changedate = $a_changedate;
418 $this->user_id_update = $a_user_id_update;
428 $this->censored = $a_censorship;
438 $this->censorship_comment = $a_comment;
458 $this->import_name = $a_import_name;
468 $this->status = $a_status;
478 $this->tree_id = $a_tree_id;
488 $this->parent_id = $a_parent_id;
493 $this->post_read = $a_is_read;
528 $this->depth = $a_depth;
538 $this->objThread = $thread;
589 $this->
setSubject((
string) $row[
'pos_subject']);
591 $this->
setMessage((
string) $row[
'pos_message']);
601 $this->
setStatus((
bool) $row[
'pos_status']);
604 $this->
setLft((
int) $row[
'lft']);
605 $this->
setRgt((
int) $row[
'rgt']);
606 $this->
setDepth((
int) $row[
'depth']);
607 $this->
setIsRead(isset($row[
'post_read']) && (
int) $row[
'post_read']);
618 public static function mergePosts(
int $sourceThreadId,
int $targetThreadId, array $excludedPostIds = []): void
621 $ilDB = $DIC->database();
623 $conditions = [
'pos_thr_fk = ' .
$ilDB->quote($sourceThreadId,
'integer')];
624 if ($excludedPostIds !== []) {
625 $conditions[] =
$ilDB->in(
'pos_pk', $excludedPostIds,
true,
'integer');
629 'UPDATE frm_posts SET pos_thr_fk = %s WHERE ' . implode(
' AND ', $conditions),
639 $res = $DIC->database()->queryF(
640 'SELECT notify FROM frm_posts WHERE pos_pk = %s',
645 $row = $DIC->database()->fetchAssoc(
$res);
646 return (
bool) $row[
'notify'];
652 $ilDB = $DIC->database();
655 'SELECT pos_message FROM frm_posts WHERE pos_pk = %s',
661 return $row->pos_message ?:
'';
string $censorship_comment
setTreeId(int $a_tree_id)
setIsAuthorModerator(?bool $is_author_moderator)
__construct(int $a_id=0, bool $a_is_moderator=false, bool $preventImplicitRead=false)
setThread(ilForumTopic $thread)
setCensoredDate(?string $censored_date)
setMessage(string $a_message)
activatePostAndChildPosts()
bool $is_author_moderator
setImportName(?string $a_import_name)
static mergePosts(int $sourceThreadId, int $targetThreadId, array $excludedPostIds=[])
static lookupNotificationStatusByPostId(int $post_id)
setCensorshipComment(?string $a_comment)
isOwner(int $a_user_id=0)
static lookupPostMessage(int $post_id)
setIsRead(bool $a_is_read)
setStatus(bool $a_status)
setForumId(int $a_forum_id)
setPosAuthorId(int $pos_author_id)
setParentId(int $a_parent_id)
setCensorship(bool $a_censorship)
setChangeDate(?string $a_changedate)
setDisplayUserId(int $a_user_id)
setSubject(string $a_subject)
setNotification(bool $a_notification)
setUpdateUserId(int $a_user_id_update)
setPostActivationDate(?string $post_activation_date)
setUserAlias(?string $a_user_alias)
string $post_activation_date
setThreadId(int $a_thread_id)
setCreateDate(?string $a_createdate)