ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilForumPost.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once './Modules/Forum/classes/class.ilForumTopic.php';
5
13{
14 private $id = 0;
15
16 private $forum_id = 0;
17
18 private $thread_id = 0;
19
20 private $display_user_id = 0;
21
22 private $user_alias = '';
23
24 private $subject = '';
25
26 private $message = '';
27
28 private $createdate = '0000-00-00 00:00:00';
29
30 private $changedate = '0000-00-00 00:00:00';
31
32 private $user_id_update = 0;
33
34 private $censored = 0;
35
36 private $censorship_comment = '';
37
38 private $censored_date = '0000-00-00 00:00:00';
39
40 private $notification = 0;
41
42 private $import_name = '';
43
44 private $status = 1;
45
46 private $tree_id = 0;
47
48 private $parent_id = 0;
49
50 private $lft = 0;
51
52 private $rgt = 0;
53
54 private $depth = 0;
55
56 private $fullname = '';
57
58 private $loginname = '';
59
63 private $objThread = null;
64
65 private $db = null;
66 private $lng = null;
67
72 private $is_moderator = false;
73
78 private $is_author_moderator = null;
79
80 private $post_read = false;
81
82 private $pos_author_id = 0;
83
84 private $post_activation_date = null;
85
92 public function __construct($a_id = 0, $a_is_moderator = false, $preventImplicitRead = false)
93 {
94 global $DIC;
95
96 $this->db = $DIC->database();
97 $this->lng = $DIC->language();
98 $this->id = $a_id;
99
100 if (!$preventImplicitRead) {
101 $this->read();
102 }
103 }
104
105 public function __destruct()
106 {
107 unset($this->db);
108 unset($this->objThread);
109 }
110
111 public function insert()
112 {
113 if ($this->forum_id && $this->thread_id) {
114 $this->id = $this->db->nextId('frm_posts');
115
116 $this->db->insert('frm_posts', array(
117 'pos_pk' => array('integer', $this->id),
118 'pos_top_fk' => array('integer', $this->forum_id),
119 'pos_thr_fk' => array('integer', $this->thread_id),
120 'pos_display_user_id' => array('integer', $this->display_user_id),
121 'pos_usr_alias' => array('text', $this->user_alias),
122 'pos_subject' => array('text', $this->subject),
123 'pos_message' => array('clob', $this->message),
124 'pos_date' => array('timestamp', $this->createdate),
125 'pos_update' => array('timestamp', $this->createdate),
126 'update_user' => array('integer', $this->user_id_update),
127 'pos_cens' => array('integer', $this->censored),
128 'notify' => array('integer', (int) $this->notification),
129 'import_name' => array('text', (string) $this->import_name),
130 'pos_status' => array('integer', (int) $this->status),
131 'pos_author_id' => array('integer', (int) $this->pos_author_id),
132 'is_author_moderator' => array('integer', $this->is_author_moderator),
133 'pos_activation_date' => array('timestamp', $this->createdate)
134 ));
135
136 return true;
137 }
138
139 return false;
140 }
141
142 public function update()
143 {
144 if ($this->id) {
145 $this->db->update(
146 'frm_posts',
147 array(
148 'pos_top_fk' => array('integer', $this->forum_id),
149 'pos_thr_fk' => array('integer', $this->thread_id),
150 'pos_subject' => array('text', $this->subject),
151 'pos_message' => array('clob', $this->message),
152 'pos_update' => array('timestamp', $this->changedate),
153 'update_user' => array('integer', $this->user_id_update),
154 'pos_cens' => array('integer', $this->censored),
155 'pos_cens_date' => array('timestamp', $this->censored_date),
156 'pos_cens_com' => array('text', $this->censorship_comment),
157 'notify' => array('integer', (int) $this->notification),
158 'pos_status' => array('integer', (int) $this->status)
159 ),
160 array(
161 'pos_pk' => array('integer', (int) $this->id)
162 )
163 );
164
165 if ($this->objThread->getFirstPostId() == $this->id) {
166 $this->objThread->setSubject($this->subject);
167 $this->objThread->update();
168 $this->objThread->reload();
169 }
170
171 return true;
172 }
173
174 return false;
175 }
176
177 private function read()
178 {
179 if ($this->id) {
180 $res = $this->db->queryF(
181 '
182 SELECT * FROM frm_posts
183 INNER JOIN frm_posts_tree ON pos_fk = pos_pk
184 WHERE pos_pk = %s',
185 array('integer'),
186 array($this->id)
187 );
188 $row = $this->db->fetchObject($res);
189
190 if (is_object($row)) {
191 $this->id = $row->pos_pk;
192 $this->forum_id = $row->pos_top_fk;
193 $this->thread_id = $row->pos_thr_fk;
194 $this->display_user_id = $row->pos_display_user_id;
195 $this->user_alias = $row->pos_usr_alias;
196 $this->subject = $row->pos_subject;
197 $this->message = $row->pos_message;
198 $this->createdate = $row->pos_date;
199 $this->changedate = $row->pos_update;
200 $this->user_id_update = $row->update_user;
201 $this->censored = $row->pos_cens;
202 $this->censored_date = $row->pos_cens_date;
203 $this->censorship_comment = $row->pos_cens_com;
204 $this->notification = $row->notify;
205 $this->import_name = $row->import_name;
206 $this->status = $row->pos_status;
207 $this->tree_id = $row->fpt_pk;
208 $this->parent_id = $row->parent_pos;
209 $this->lft = $row->lft;
210 $this->rgt = $row->rgt;
211 $this->depth = $row->depth;
212 $this->pos_author_id = $row->pos_author_id;
213 $this->is_author_moderator = $row->is_author_moderator;
214 $this->post_activation_date = $row->pos_activation_date;
215 $this->getUserData();
216
217 $this->objThread = new ilForumTopic($this->thread_id, $this->is_moderator);
218
219 return true;
220 }
221 $this->id = 0;
222 return false;
223 }
224
225 return false;
226 }
227
228 public function isAnyParentDeactivated()
229 {
230 if ($this->id) {
231 $res = $this->db->queryF(
232 '
233 SELECT * FROM frm_posts_tree
234 INNER JOIN frm_posts ON pos_pk = pos_fk
235 WHERE pos_status = %s
236 AND lft < %s AND rgt > %s
237 AND thr_fk = %s',
238 array('integer', 'integer', 'integer', 'integer'),
239 array('0', $this->lft, $this->rgt, $this->thread_id)
240 );
241
242 return $res->numRows();
243 }
244
245 return false;
246 }
247
248 protected function buildUserRelatedData($row)
249 {
250 if ($row['pos_display_user_id'] && $row['pos_pk']) {
251 require_once 'Services/User/classes/class.ilObjUser.php';
252 $tmp_user = new ilObjUser();
253 $tmp_user->setFirstname($row['firstname']);
254 $tmp_user->setLastname($row['lastname']);
255 $tmp_user->setUTitle($row['title']);
256 $tmp_user->setLogin($row['login']);
257
258 $this->fullname = $tmp_user->getFullname();
259 $this->loginname = $tmp_user->getLogin();
260
261 $this->fullname = $this->fullname ? $this->fullname : ($this->import_name ? $this->import_name : $this->lng->txt('unknown'));
262 }
263 }
264
265 private function getUserData()
266 {
267 if ($this->id && $this->display_user_id) {
268 require_once("Modules/Forum/classes/class.ilObjForumAccess.php");
269 if (($tmp_user = ilObjForumAccess::getCachedUserInstance($this->display_user_id))) {
270 $this->fullname = $tmp_user->getFullname();
271 $this->loginname = $tmp_user->getLogin();
272 unset($tmp_user);
273 }
274
275 $this->fullname = $this->fullname ? $this->fullname : ($this->import_name ? $this->import_name : $this->lng->txt('unknown'));
276
277 return true;
278 }
279
280 return false;
281 }
282
283 public function reload()
284 {
285 return $this->read();
286 }
287
288 public function setFullname($a_fullname)
289 {
290 $this->fullname = $a_fullname;
291 }
292 public function getFullname()
293 {
294 return $this->fullname;
295 }
296 public function setLoginName($a_loginname)
297 {
298 $this->loginname = $a_loginname;
299 }
300 public function getLoginName()
301 {
302 return $this->loginname;
303 }
304
305 public function activatePost()
306 {
307 if ($this->id) {
308 $now = date("Y-m-d H:i:s");
309 $this->db->update(
310 'frm_posts',
311 array('pos_status' => array('integer', 1),
312 'pos_activation_date' => array('timestamp', $now)),
313 array('pos_pk' => array('integer', $this->id))
314 );
315
316 $this->activateParentPosts();
317 $this->setPostActivationDate($now);
318 $this->setStatus(1);
319 return true;
320 }
321
322 return false;
323 }
324
326 {
327 if ($this->id) {
328 $query = "SELECT pos_pk FROM frm_posts_tree treea "
329 . "INNER JOIN frm_posts_tree treeb ON treeb.thr_fk = treea.thr_fk "
330 . "AND treeb.lft BETWEEN treea.lft AND treea.rgt "
331 . "INNER JOIN frm_posts ON pos_pk = treeb.pos_fk "
332 . "WHERE treea.pos_fk = %s";
333 $result = $this->db->queryF(
334 $query,
335 array('integer'),
336 array($this->id)
337 );
338
339 $now = date("Y-m-d H:i:s");
340 while ($row = $this->db->fetchAssoc($result)) {
341 $this->db->update(
342 'frm_posts',
343 array('pos_status' => array('integer', 1),
344 'pos_activation_date' => array('timestamp', $now)),
345 array('pos_pk' => array('integer', $row['pos_pk']))
346 );
347 }
348
349 $this->activateParentPosts();
350
351 return true;
352 }
353
354 return false;
355 }
356
357 public function activateParentPosts()
358 {
359 if ($this->id) {
360 $query = "SELECT pos_pk FROM frm_posts "
361 . "INNER JOIN frm_posts_tree ON pos_fk = pos_pk "
362 . "WHERE lft < %s AND rgt > %s AND thr_fk = %s";
363 $result = $this->db->queryF(
364 $query,
365 array('integer', 'integer', 'integer'),
366 array($this->lft, $this->rgt, $this->thread_id)
367 );
368
369 $now = date("Y-m-d H:i:s");
370 while ($row = $this->db->fetchAssoc($result)) {
371 $this->db->update(
372 'frm_posts',
373 array('pos_status' => array('integer', 1),
374 'pos_activation_date' => array('timestamp', $now)),
375 array('pos_pk' => array('integer', $row['pos_pk']))
376 );
377 }
378
379 return true;
380 }
381
382 return false;
383 }
384
385 public function isPostRead()
386 {
387 return $this->getIsRead();
388 }
389
390 public function isRead($a_user_id = 0)
391 {
392 if ($a_user_id && $this->id) {
393 $res = $this->db->queryF(
394 '
395 SELECT * FROM frm_user_read
396 WHERE usr_id = %s
397 AND post_id = %s',
398 array('integer', 'integer'),
399 array($a_user_id, $this->id)
400 );
401
402 return $res->numRows() ? true : false;
403 }
404
405 return false;
406 }
407
408 public function hasReplies()
409 {
410 if ($this->id && $this->rgt && $this->lft) {
411 $res = $this->db->queryF(
412 '
413 SELECT * FROM frm_posts_tree
414 WHERE lft > %s AND rgt < %s
415 AND thr_fk = %s',
416 array('integer', 'integer', 'integer'),
417 array($this->lft, $this->rgt, $this->thread_id)
418 );
419
420 return $res->numRows() ? true : false;
421 }
422
423 return false;
424 }
425
426 public function isOwner($a_user_id = 0)
427 {
428 if ($this->pos_author_id && $a_user_id) {
429 if ((int) $this->pos_author_id == (int) $a_user_id) {
430 return true;
431 }
432 return false;
433 }
434 return false;
435 }
436
437 public function setId($a_id)
438 {
439 $this->id = $a_id;
440 }
441 public function getId()
442 {
443 return $this->id;
444 }
445 public function setForumId($a_forum_id)
446 {
447 $this->forum_id = $a_forum_id;
448 }
449 public function getForumId()
450 {
451 return $this->forum_id;
452 }
453 public function setThreadId($a_thread_id)
454 {
455 $this->thread_id = $a_thread_id;
456 }
457 public function getThreadId()
458 {
459 return $this->thread_id;
460 }
461 public function setDisplayUserId($a_user_id)
462 {
463 $this->display_user_id = $a_user_id;
464 }
465 public function getDisplayUserId()
466 {
468 }
469 public function setUserAlias($a_user_alias)
470 {
471 $this->user_alias = $a_user_alias;
472 }
473 public function getUserAlias()
474 {
475 return $this->user_alias;
476 }
477 public function setSubject($a_subject)
478 {
479 $this->subject = $a_subject;
480 }
481 public function getSubject()
482 {
483 return $this->subject;
484 }
485 public function setMessage($a_message)
486 {
487 $this->message = $a_message;
488 }
489 public function getMessage()
490 {
491 return $this->message;
492 }
493 public function setCreateDate($a_createdate)
494 {
495 $this->createdate = $a_createdate;
496 }
497 public function getCreateDate()
498 {
499 return $this->createdate;
500 }
501 public function setChangeDate($a_changedate)
502 {
503 $this->changedate = $a_changedate;
504 }
505 public function getChangeDate()
506 {
507 return $this->changedate;
508 }
509 public function setUpdateUserId($a_user_id_update)
510 {
511 $this->user_id_update = $a_user_id_update;
512 }
513 public function getUpdateUserId()
514 {
516 }
517 public function setCensorship($a_censorship)
518 {
519 $this->censored = $a_censorship;
520 }
521 public function isCensored()
522 {
523 return $this->censored == 1 ? true : false;
524 }
525 public function setCensorshipComment($a_comment)
526 {
527 $this->censorship_comment = $a_comment;
528 }
529 public function getCensorshipComment()
530 {
532 }
533 public function setNotification($a_notification)
534 {
535 $this->notification = $a_notification;
536 }
537 public function isNotificationEnabled()
538 {
539 return $this->notification == 1 ? true : false;
540 }
541 public function setImportName($a_import_name)
542 {
543 $this->import_name = $a_import_name;
544 }
545 public function getImportName()
546 {
547 return $this->import_name;
548 }
549 public function setStatus($a_status)
550 {
551 $this->status = $a_status;
552 }
553 public function isActivated()
554 {
555 return $this->status == 1 ? true : false;
556 }
557 public function setTreeId($a_tree_id)
558 {
559 $this->tree_id = $a_tree_id;
560 }
561 public function getTreeId()
562 {
563 return $this->tree_id;
564 }
565 public function setParentId($a_parent_id)
566 {
567 $this->parent_id = $a_parent_id;
568 }
569
570 public function setIsRead($a_is_read)
571 {
572 $this->post_read = $a_is_read;
573 }
574
575 public function getIsRead()
576 {
577 return $this->post_read;
578 }
579
580 public function getParentId()
581 {
582 return $this->parent_id;
583 }
584 public function setLft($a_lft)
585 {
586 $this->lft = $a_lft;
587 }
588 public function getLft()
589 {
590 return $this->lft;
591 }
592 public function setRgt($a_rgt)
593 {
594 $this->rgt = $a_rgt;
595 }
596 public function getRgt()
597 {
598 return $this->rgt;
599 }
600 public function setDepth($a_depth)
601 {
602 $this->depth = $a_depth;
603 }
604 public function getDepth()
605 {
606 return $this->depth;
607 }
608 public function setThread(ilForumTopic $thread)
609 {
610 $this->objThread = $thread;
611 }
612 public function getThread()
613 {
614 return $this->objThread;
615 }
616
621 {
622 $this->pos_author_id = $pos_author_id;
623 }
624
628 public function getPosAuthorId()
629 {
631 }
635 public function getIsAuthorModerator()
636 {
638 }
639
644 {
645 $this->is_author_moderator = $is_author_moderator;
646 }
647
651 public function getCensoredDate()
652 {
654 }
655
659 public function getPostActivationDate()
660 {
662 }
663
668 {
669 $this->post_activation_date = $post_activation_date;
670 }
671
676 {
677 $this->censored_date = $censored_date;
678 }
679
683 public function assignData($row)
684 {
685 $this->setUserAlias($row['pos_usr_alias']);
686 $this->setSubject($row['pos_subject']);
687 $this->setCreateDate($row['pos_date']);
688 $this->setMessage($row['pos_message']);
689 $this->setForumId($row['pos_top_fk']);
690 $this->setThreadId($row['pos_thr_fk']);
691 $this->setChangeDate($row['pos_update']);
692 $this->setUpdateUserId($row['update_user']);
693 $this->setCensorship($row['pos_cens']);
694 $this->setCensoredDate($row['pos_cens_date']);
695 $this->setCensorshipComment($row['pos_cens_com']);
696 $this->setNotification($row['notify']);
697 $this->setImportName($row['import_name']);
698 $this->setStatus($row['pos_status']);
699 $this->setTreeId($row['fpt_pk']);
700 $this->setParentId($row['parent_pos']);
701 $this->setLft($row['lft']);
702 $this->setRgt($row['rgt']);
703 $this->setDepth($row['depth']);
704 $this->setIsRead($row['post_read']);
705 $this->setDisplayUserId($row['pos_display_user_id']);
706 $this->setPosAuthorId($row['pos_author_id']);
707 $this->setIsAuthorModerator($row['is_author_moderator']);
709 }
710
715 public static function mergePosts($source_thread_id, $target_thread_id)
716 {
717 global $DIC;
718 $ilDB = $DIC->database();
719
720 $ilDB->update(
721 'frm_posts',
722 array('pos_thr_fk' => array('integer', $target_thread_id)),
723 array('pos_thr_fk' => array('integer', $source_thread_id))
724 );
725 }
726}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$result
An exception for terminatinating execution or to throw for unit testing.
setNotification($a_notification)
setForumId($a_forum_id)
setTreeId($a_tree_id)
setThread(ilForumTopic $thread)
__construct($a_id=0, $a_is_moderator=false, $preventImplicitRead=false)
ilForumPost constructor.
setStatus($a_status)
setCreateDate($a_createdate)
isOwner($a_user_id=0)
setFullname($a_fullname)
setCensorshipComment($a_comment)
setIsRead($a_is_read)
setCensorship($a_censorship)
setDepth($a_depth)
setThreadId($a_thread_id)
setIsAuthorModerator($is_author_moderator)
setImportName($a_import_name)
setPosAuthorId($pos_author_id)
isRead($a_user_id=0)
setParentId($a_parent_id)
setUserAlias($a_user_alias)
setCensoredDate($censored_date)
setUpdateUserId($a_user_id_update)
setDisplayUserId($a_user_id)
setChangeDate($a_changedate)
setPostActivationDate($post_activation_date)
static mergePosts($source_thread_id, $target_thread_id)
setSubject($a_subject)
buildUserRelatedData($row)
setMessage($a_message)
setLoginName($a_loginname)
static getCachedUserInstance($usr_id)
notification()
Definition: notification.php:2
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB