ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
All Data Structures Namespaces Files Functions Variables Typedefs Modules Pages
class.ilForumTopic.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once './Modules/Forum/classes/class.ilForumPost.php';
5 
13 {
14  private $id = 0;
15 
16  private $forum_id = 0;
17 
18  private $frm_obj_id = 0;
19 
20  private $display_user_id = 0;
21 
22  private $user_alias = '';
23 
24  private $subject = '';
25 
26  private $createdate = null;
27 
28  private $changedate = null;
29 
30  private $num_posts = 0;
31 
32  private $last_post_string = '';
33 
34  private $visits = 0;
35 
36  private $import_name = '';
37 
38  private $is_sticky = 0;
39 
40  private $is_closed = 0;
41 
42  private $orderField = '';
43 
44  private $last_post = null;
45 
46  private $db = null;
47 
48  private $is_moderator = false;
49 
50  private $thr_author_id = 0;
51 
55  private $average_rating = 0;
56 
57  private $orderDirection = 'DESC';
58 
59  protected static $possibleOrderDirections = array('ASC', 'DESC');
60 
73  public function __construct($a_id = 0, $a_is_moderator = false, $preventImplicitRead = false)
74  {
75  global $DIC;
76 
77  $this->is_moderator = $a_is_moderator;
78  $this->db = $DIC->database();
79  $this->user = $DIC->user();
80  $this->id = $a_id;
81 
82  if (!$preventImplicitRead) {
83  $this->read();
84  }
85  }
86 
90  public function assignData($data)
91  {
92  $this->setId((int) $data['thr_pk']);
93  $this->setForumId((int) $data['thr_top_fk']);
94  $this->setSubject($data['thr_subject']);
95  $this->setDisplayUserId((int) $data['thr_display_user_id']);
96  $this->setUserAlias($data['thr_usr_alias']);
97  $this->setLastPostString($data['last_post_string']);
98  $this->setCreateDate($data['thr_date']);
99  $this->setChangeDate($data['thr_update']);
100  $this->setVisits((int) $data['visits']);
101  $this->setImportName($data['import_name']);
102  $this->setSticky((int) $data['is_sticky']);
103  $this->setClosed((int) $data['is_closed']);
104  $this->setAverageRating($data['avg_rating']);
105  $this->setThrAuthorId($data['thr_author_id']);
106 
107  // Aggregated values
108  $this->setNumPosts((int) $data['num_posts']);
109  $this->setNumUnreadPosts((int) $data['num_unread_posts']);
110  $this->setNumNewPosts((int) $data['num_new_posts']);
111  $this->setUserNotificationEnabled((bool) $data['usr_notification_is_enabled']);
112  }
113 
120  public function insert()
121  {
122  if ($this->forum_id) {
123  $nextId = $this->db->nextId('frm_threads');
124 
125  $this->db->insert(
126  'frm_threads',
127  array(
128  'thr_pk' => array('integer', $nextId),
129  'thr_top_fk' => array('integer', $this->forum_id),
130  'thr_subject' => array('text', $this->subject),
131  'thr_display_user_id' => array('integer', $this->display_user_id),
132  'thr_usr_alias' => array('text', $this->user_alias),
133  'thr_num_posts' => array('integer', $this->num_posts),
134  'thr_last_post' => array('text', $this->last_post_string),
135  'thr_date' => array('timestamp', $this->createdate),
136  'thr_update' => array('timestamp', null),
137  'import_name' => array('text', $this->import_name),
138  'is_sticky' => array('integer', $this->is_sticky),
139  'is_closed' => array('integer', $this->is_closed),
140  'avg_rating' => array('float', $this->average_rating),
141  'thr_author_id' => array('integer', $this->thr_author_id)
142  )
143  );
144 
145  $this->id = $nextId;
146 
147  return true;
148  }
149 
150  return false;
151  }
152 
159  public function update()
160  {
161  if ($this->id) {
162  $this->db->manipulateF(
163  '
164  UPDATE frm_threads
165  SET thr_top_fk = %s,
166  thr_subject = %s,
167  thr_update = %s,
168  thr_num_posts = %s,
169  thr_last_post = %s,
170  avg_rating = %s
171  WHERE thr_pk = %s',
172  array('integer', 'text','timestamp', 'integer', 'text', 'float', 'integer'),
173  array( $this->forum_id,
174  $this->subject,
175  /* $this->changedate, */
176  date('Y-m-d H:i:s'),
177  $this->num_posts,
178  $this->last_post_string,
179  $this->average_rating,
180  $this->id
181  )
182  );
183 
184  return true;
185  }
186 
187  return false;
188  }
189 
197  private function read()
198  {
199  if ($this->id) {
200  $res = $this->db->queryf(
201  '
202  SELECT frm_threads.*, top_frm_fk frm_obj_id
203  FROM frm_threads
204  INNER JOIN frm_data ON top_pk = thr_top_fk
205  WHERE thr_pk = %s',
206  array('integer'),
207  array($this->id)
208  );
209 
211 
212  if (is_object($row)) {
213  $this->thr_pk = $row->pos_pk; // thr_pk = pos_pk ??!??!
214  $this->forum_id = $row->thr_top_fk;
215  $this->display_user_id = $row->thr_display_user_id;
216  $this->user_alias = $row->thr_usr_alias;
217  $this->subject = html_entity_decode($row->thr_subject);
218  $this->createdate = $row->thr_date;
219  $this->changedate = $row->thr_update;
220  $this->import_name = $row->import_name;
221  $this->num_posts = $row->thr_num_posts;
222  $this->last_post_string = $row->thr_last_post;
223  $this->visits = $row->visits;
224  $this->is_sticky = $row->is_sticky;
225  $this->is_closed = $row->is_closed;
226  $this->frm_obj_id = $row->frm_obj_id;
227  $this->average_rating = $row->avg_rating;
228  $this->thr_author_id = $row->thr_author_id;
229 
230  return true;
231  }
232  $this->id = 0;
233  return false;
234  }
235 
236  return false;
237  }
238 
245  public function reload()
246  {
247  return $this->read();
248  }
249 
256  public function getFirstPostId()
257  {
258  $res = $this->db->queryf(
259  '
260  SELECT * FROM frm_posts_tree
261  WHERE thr_fk = %s
262  AND parent_pos = %s',
263  array('integer', 'integer'),
264  array($this->id, '1')
265  );
266 
268 
269  return $row->pos_fk ? $row->pos_fk : 0;
270  }
271 
277  public function updateVisits()
278  {
279  $checkTime = time() - (60 * 60);
280 
281  if ($_SESSION['frm_visit_frm_threads_' . $this->id] < $checkTime) {
282  $_SESSION['frm_visit_frm_threads_' . $this->id] = time();
283 
284  $this->db->manipulateF(
285  '
286  UPDATE frm_threads
287  SET visits = visits + 1
288  WHERE thr_pk = %s',
289  array('integer'),
290  array($this->id)
291  );
292  }
293 
294  return true;
295  }
296 
304  public function countPosts()
305  {
306  $res = $this->db->queryf(
307  '
308  SELECT COUNT(*) cnt
309  FROM frm_posts
310  WHERE pos_thr_fk = %s',
311  array('integer'),
312  array($this->id)
313  );
314 
315  $rec = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
316 
317  return $rec['cnt'];
318  }
319 
327  public function countActivePosts()
328  {
329  $res = $this->db->queryf(
330  '
331  SELECT COUNT(*) cnt
332  FROM frm_posts
333  WHERE (pos_status = %s
334  OR (pos_status = %s AND pos_display_user_id = %s))
335  AND pos_thr_fk = %s',
336  array('integer', 'integer', 'integer', 'integer'),
337  array('1', '0', $this->user->getId(), $this->id)
338  );
339 
340  $rec = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
341 
342  return $rec['cnt'];
343  }
344 
351  public function getFirstPostNode()
352  {
353  $res = $this->db->queryf(
354  '
355  SELECT pos_pk
356  FROM frm_posts
357  INNER JOIN frm_posts_tree ON pos_fk = pos_pk
358  WHERE parent_pos = %s
359  AND thr_fk = %s',
360  array('integer', 'integer'),
361  array('0', $this->id)
362  );
363 
365 
366  return new ilForumPost($row->pos_pk);
367  }
368 
375  public function getLastPost()
376  {
377  if ($this->id) {
378  $this->db->setLimit(1);
379  $res = $this->db->queryf(
380  '
381  SELECT pos_pk
382  FROM frm_posts
383  WHERE pos_thr_fk = %s
384  ORDER BY pos_date DESC',
385  array('integer'),
386  array($this->id)
387  );
388 
390 
391  return new ilForumPost($row->pos_pk);
392  }
393 
394  return false;
395  }
396 
403  public function getLastActivePost()
404  {
405  if ($this->id) {
406  $this->db->setLimit(1);
407  $res = $this->db->queryf(
408  '
409  SELECT pos_pk
410  FROM frm_posts
411  WHERE pos_thr_fk = %s
412  AND (pos_status = %s OR
413  (pos_status = %s AND pos_display_user_id = %s))
414  ORDER BY pos_date DESC',
415  array('integer', 'integer', 'integer', 'integer'),
416  array($this->id, '1', '0', $this->user->getId())
417  );
418 
420 
421  return new ilForumPost($row->pos_pk);
422  }
423 
424  return false;
425  }
426 
427  public function getAllPosts()
428  {
429  $posts = array();
430 
431  if ($this->id) {
432  $res = $this->db->queryf(
433  '
434  SELECT pos_pk
435  FROM frm_posts
436  WHERE pos_thr_fk = %s',
437  array('integer'),
438  array($this->id)
439  );
440 
441  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
442  $posts[$row->pos_pk] = $row;
443  }
444  }
445 
446  return is_array($posts) ? $posts : array();
447  }
448 
457  public function getPostTree(ilForumPost $a_post_node)
458  {
459  $posts = array();
460 
461  $data = array();
462  $data_types = array();
463 
464  $query = '
465  SELECT is_author_moderator, pos_author_id, pos_pk, fpt_date, rgt, pos_top_fk, pos_thr_fk,
466  pos_display_user_id, pos_usr_alias, pos_subject,
467  pos_status, pos_message, pos_date, pos_update,
468  update_user, pos_cens, pos_cens_com, notify,
469  import_name, fpt_pk, parent_pos, lft, depth,
470  (CASE
471  WHEN fur.post_id IS NULL ' .
472  ($this->user->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '') . '
473  THEN 0
474  ELSE 1
475  END) post_read,
476  firstname, lastname, title, login
477 
478  FROM frm_posts_tree
479 
480  INNER JOIN frm_posts
481  ON pos_fk = pos_pk
482 
483  LEFT JOIN usr_data
484  ON pos_display_user_id = usr_id
485 
486  LEFT JOIN frm_user_read fur
487  ON fur.thread_id = pos_thr_fk
488  AND fur.post_id = pos_pk
489  AND fur.usr_id = %s
490 
491  WHERE lft BETWEEN %s AND %s
492  AND thr_fk = %s';
493 
494  array_push($data_types, 'integer', 'integer', 'integer', 'integer');
495  array_push($data, $this->user->getId(), $a_post_node->getLft(), $a_post_node->getRgt(), $a_post_node->getThreadId());
496 
497  if ($this->orderField != "") {
498  $query .= " ORDER BY " . $this->orderField . " " . $this->getOrderDirection();
499  }
500 
501  $res = $this->db->queryf($query, $data_types, $data);
502 
503  $usr_ids = array();
504 
505  $deactivated = array();
506  while ($row = $this->db->fetchAssoc($res)) {
507  $tmp_object = new ilForumPost($row['pos_pk'], false, true);
508  $tmp_object->assignData($row);
509 
510  if (!$this->is_moderator) {
511  if (!$tmp_object->isActivated() && $tmp_object->getDisplayUserId() != $this->user->getId()) {
512  $deactivated[] = $tmp_object;
513  unset($tmp_object);
514  continue;
515  }
516 
517  foreach ($deactivated as $deactivated_node) {
518  if ($deactivated_node->getLft() < $tmp_object->getLft() && $deactivated_node->getRgt() > $tmp_object->getLft()) {
519  $deactivated[] = $tmp_object;
520  unset($tmp_object);
521  continue 2;
522  }
523  }
524  }
525 
526  if ((int) $row['pos_display_user_id']) {
527  $usr_ids[] = (int) $row['pos_display_user_id'];
528  }
529  if ((int) $row['update_user']) {
530  $usr_ids[] = (int) $row['update_user'];
531  }
532 
533  $posts[] = $tmp_object;
534 
535  unset($tmp_object);
536  }
537 
538  require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
540 
541  return $posts;
542  }
543 
554  public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
555  {
556  if ($this->id) {
557  $nodes = $this->getAllPosts();
558  if (is_array($nodes)) {
559  $postsMoved = array();
560  // Move attachments
561  try {
562  foreach ($nodes as $node) {
563  $file_obj = new ilFileDataForum((int) $old_obj_id, (int) $node->pos_pk);
564  $moved = $file_obj->moveFilesOfPost((int) $new_obj_id);
565 
566  if (true === $moved) {
567  $postsMoved[] = array(
568  'from' => $old_obj_id,
569  'to' => $new_obj_id,
570  'position_id' => (int) $node->pos_pk
571  );
572  }
573 
574  unset($file_obj);
575  }
576  } catch (\ilFileUtilsException $exception) {
577  foreach ($postsMoved as $postedInformation) {
578  $file_obj = new ilFileDataForum($postedInformation['to'], $postedInformation['position_id']);
579  $file_obj->moveFilesOfPost($postedInformation['from']);
580  }
581 
582  throw $exception;
583  }
584  }
585 
586  $current_id = $this->id;
587 
588  $ilAtomQuery = $this->db->buildAtomQuery();
589  $ilAtomQuery->addTableLock('frm_user_read');
590  $ilAtomQuery->addTableLock('frm_thread_access');
591 
592  $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) use ($new_obj_id, $current_id) {
593  $ilDB->manipulateF(
594  '
595  DELETE FROM frm_user_read
596  WHERE obj_id = %s AND thread_id =%s',
597  array('integer', 'integer'),
598  array($new_obj_id, $current_id)
599  );
600 
601  $ilDB->manipulateF(
602  '
603  UPDATE frm_user_read
604  SET obj_id = %s
605  WHERE thread_id = %s',
606  array('integer', 'integer'),
607  array($new_obj_id, $current_id)
608  );
609 
610  $ilDB->manipulateF(
611  '
612  DELETE FROM frm_thread_access
613  WHERE obj_id = %s AND thread_id =%s',
614  array('integer', 'integer'),
615  array($new_obj_id, $current_id)
616  );
617 
618  $ilDB->manipulateF(
619  '
620  UPDATE frm_thread_access
621  SET obj_id = %s
622  WHERE thread_id =%s',
623  array('integer', 'integer'),
624  array($new_obj_id, $current_id)
625  );
626  });
627 
628  $ilAtomQuery->run();
629 
630  $this->db->manipulateF(
631  '
632  UPDATE frm_posts
633  SET pos_top_fk = %s
634  WHERE pos_thr_fk = %s',
635  array('integer', 'integer'),
636  array($new_pk, $this->id)
637  );
638 
639  // update all related news
640  $posts = $this->db->queryf(
641  '
642  SELECT * FROM frm_posts WHERE pos_thr_fk = %s',
643  array('integer'),
644  array($this->id)
645  );
646 
647  $old_obj_id = ilForum::_lookupObjIdForForumId($old_pk);
648 
649  $new_obj_id = ilForum::_lookupObjIdForForumId($new_pk);
650 
651  while ($post = $posts->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
652  include_once("./Services/News/classes/class.ilNewsItem.php");
654  $old_obj_id,
655  "frm",
656  $post["pos_pk"],
657  "pos"
658  );
659  $news_item = new ilNewsItem($news_id);
660  $news_item->setContextObjId($new_obj_id);
661  $news_item->update();
662  //echo "<br>-".$post["pos_pk"]."-".$old_obj_id."-".$new_obj_id."-";
663  }
664 
665  return count($nodes);
666  }
667 
668  return 0;
669  }
670 
671  public function getNestedSetPostChildren($pos_id = null, $levels = null)
672  {
673  $data = null;
674  $objProperties = ilForumProperties::getInstance($this->getFrmObjId());
675  $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
676 
677  if ($pos_id !== null) {
678  $res = $this->db->queryF(
679  "
680  SELECT lft, rgt, depth
681  FROM frm_posts_tree
682  WHERE pos_fk = %s
683  AND thr_fk = %s",
684  array('integer', 'integer'),
685  array($pos_id, $this->id)
686  );
687 
688  $data = $this->db->fetchAssoc($res);
689  }
690 
691  $query = '
692  SELECT fpt.depth,
693  fpt.rgt,
694  fpt.parent_pos,
695  fp.pos_pk,
696  fp.pos_subject,
697  fp.pos_usr_alias,
698  fp.pos_date,
699  fp.pos_update,
700  fp.pos_status,
701  fp.pos_display_user_id,
702  fp.pos_usr_alias,
703  fp.import_name,
704  fp.pos_author_id,
705  fp.is_author_moderator,
706  fur.post_id,
707  (CASE
708  WHEN fur.post_id IS NULL ' .
709  ($this->user->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '') . '
710  THEN 0
711  ELSE 1
712  END) post_read,
713  COUNT(fpt2.pos_fk) children
714 
715  FROM frm_posts_tree fpt
716 
717  INNER JOIN frm_posts fp
718  ON fp.pos_pk = fpt.pos_fk
719 
720  LEFT JOIN frm_posts_tree fpt2
721  ON fpt2.lft BETWEEN fpt.lft AND fpt.rgt
722  AND fpt.thr_fk = fpt2.thr_fk
723  AND fpt.pos_fk != fpt2.pos_fk ';
724 
725 
726  $query .= '
727  LEFT JOIN frm_user_read fur
728  ON fur.thread_id = fp.pos_thr_fk
729  AND fur.post_id = fp.pos_pk
730  AND fur.usr_id = ' . $this->db->quote($this->user->getId(), 'integer') . '
731 
732  LEFT JOIN usr_data ud
733  ON ud.usr_id = fp.pos_display_user_id
734 
735  WHERE fpt.thr_fk = ' . $this->db->quote($this->id, 'integer');
736 
737  if ($data) {
738  $query .= ' AND fpt.lft > ' . $this->db->quote($data['lft'], 'integer') .
739  ' AND fpt.lft < ' . $this->db->quote($data['rgt'], 'integer') . ' ';
740  }
741  if ($is_post_activation_enabled && !$this->is_moderator) {
742  $query .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($this->user->getId(), 'integer') . ') ';
743  }
744 
745  if ($data && is_numeric($levels)) {
746  $query .= ' AND fpt.depth <= ' . $this->db->quote($data['depth'] + $levels, 'integer') . ' ';
747  }
748 
749  $query .= ' GROUP BY fpt.depth,
750  fpt.rgt,
751  fpt.parent_pos,
752  fp.pos_pk,
753  fp.pos_subject,
754  fp.pos_usr_alias,
755  fp.pos_date,
756  fp.pos_update,
757  fp.pos_status,
758  fp.pos_display_user_id,
759  fp.pos_usr_alias,
760  fp.import_name,
761  fp.pos_author_id,
762  fp.is_author_moderator,
763  fur.post_id
764  ORDER BY fpt.rgt DESC
765  ';
766 
767  $queryCounter = '
768  SELECT pos_fk
769  FROM frm_posts_tree fpt
770  INNER JOIN frm_posts fp
771  ON fp.pos_pk = fpt.pos_fk
772  WHERE fpt.thr_fk = ' . $this->db->quote($this->id, 'integer');
773 
774  if ($is_post_activation_enabled && !$this->is_moderator) {
775  $queryCounter .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($this->user->getId(), 'integer') . ') ';
776  }
777  $queryCounter .= ' ORDER BY fpt.rgt DESC';
778 
779  $resCounter = $this->db->query($queryCounter);
780  $counter = array();
781  $i = 0;
782  while ($row = $this->db->fetchAssoc($resCounter)) {
783  $counter[$row['pos_fk']] = $i++;
784  }
785 
786  $res = $this->db->query($query);
787  $children = array();
788  $usr_ids = array();
789  while ($row = $this->db->fetchAssoc($res)) {
790  if ((int) $row['pos_display_user_id']) {
791  $usr_ids[] = (int) $row['pos_display_user_id'];
792  }
793 
794  $row['counter'] = $counter[$row['pos_pk']];
795  $children[] = $row;
796  }
797 
798  require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
800 
801  return $children;
802  }
803 
810  public function isNotificationEnabled($a_user_id)
811  {
812  if ($this->id && $a_user_id) {
813  $result = $this->db->queryf(
814  '
815  SELECT COUNT(notification_id) cnt FROM frm_notification
816  WHERE user_id = %s AND thread_id = %s',
817  array('integer', 'integer'),
818  array($a_user_id, $this->id)
819  );
820 
821  while ($record = $this->db->fetchAssoc($result)) {
822  return (bool) $record['cnt'];
823  }
824 
825  return false;
826  }
827 
828  return false;
829  }
830 
837  public function enableNotification($a_user_id)
838  {
839  if ($this->id && $a_user_id) {
840  if (!$this->isNotificationEnabled($a_user_id)) {
841  $nextId = $this->db->nextId('frm_notification');
842  $this->db->manipulateF(
843  '
844  INSERT INTO frm_notification
845  ( notification_id,
846  user_id,
847  thread_id
848  )
849  VALUES(%s, %s, %s)',
850  array('integer', 'integer', 'integer'),
851  array($nextId, $a_user_id, $this->id)
852  );
853 
854  return true;
855  }
856  return false;
857  }
858 
859  return false;
860  }
861 
868  public function disableNotification($a_user_id)
869  {
870  if ($this->id && $a_user_id) {
871  $this->db->manipulateF(
872  '
873  DELETE FROM frm_notification
874  WHERE user_id = %s
875  AND thread_id = %s',
876  array('integer', 'integer'),
877  array($a_user_id, $this->id)
878  );
879 
880  return false;
881  }
882 
883  return false;
884  }
885 
892  public function makeSticky()
893  {
894  if ($this->id && !$this->is_sticky) {
895  $this->db->manipulateF(
896  '
897  UPDATE frm_threads
898  SET is_sticky = %s
899  WHERE thr_pk = %s',
900  array('integer', 'integer'),
901  array('1', $this->id)
902  );
903 
904  $this->is_sticky = 1;
905 
906  return true;
907  }
908 
909  return false;
910  }
911 
918  public function unmakeSticky()
919  {
920  if ($this->id && $this->is_sticky) {
921  $this->db->manipulateF(
922  '
923  UPDATE frm_threads
924  SET is_sticky = %s
925  WHERE thr_pk = %s',
926  array('integer', 'integer'),
927  array('0', $this->id)
928  );
929 
930  $this->is_sticky = 0;
931 
932  return true;
933  }
934 
935  return false;
936  }
937 
944  public function close()
945  {
946  if ($this->id && !$this->is_closed) {
947  $this->db->manipulateF(
948  '
949  UPDATE frm_threads
950  SET is_closed = %s
951  WHERE thr_pk = %s',
952  array('integer', 'integer'),
953  array('1', $this->id)
954  );
955 
956  $this->is_closed = 1;
957 
958  return true;
959  }
960 
961  return false;
962  }
963 
970  public function reopen()
971  {
972  if ($this->id && $this->is_closed) {
973  $this->db->manipulateF(
974  '
975  UPDATE frm_threads
976  SET is_closed = %s
977  WHERE thr_pk = %s',
978  array('integer', 'integer'),
979  array('0', $this->id)
980  );
981 
982  $this->is_closed = 0;
983 
984  return true;
985  }
986 
987  return false;
988  }
989 
993  public function getAverageRating()
994  {
995  return $this->average_rating;
996  }
997 
1002  {
1003  $this->average_rating = $average_rating;
1004  }
1005 
1006  public function setId($a_id)
1007  {
1008  $this->id = $a_id;
1009  }
1010  public function getId()
1011  {
1012  return $this->id;
1013  }
1014  public function setForumId($a_forum_id)
1015  {
1016  $this->forum_id = $a_forum_id;
1017  }
1018  public function getForumId()
1019  {
1020  return $this->forum_id;
1021  }
1022  public function setDisplayUserId($a_user_id)
1023  {
1024  $this->display_user_id = $a_user_id;
1025  }
1026  public function getDisplayUserId()
1027  {
1028  return $this->display_user_id;
1029  }
1030  public function setUserAlias($a_user_alias)
1031  {
1032  $this->user_alias = $a_user_alias;
1033  }
1034  public function getUserAlias()
1035  {
1036  return $this->user_alias;
1037  }
1038  public function setSubject($a_subject)
1039  {
1040  $this->subject = $a_subject;
1041  }
1042  public function getSubject()
1043  {
1044  return $this->subject;
1045  }
1046  public function setCreateDate($a_createdate)
1047  {
1048  $this->createdate = $a_createdate;
1049  }
1050  public function getCreateDate()
1051  {
1052  return $this->createdate;
1053  }
1054  public function setChangeDate($a_changedate)
1055  {
1056  if ($a_changedate == '0000-00-00 00:00:00') {
1057  $this->changedate = null;
1058  } else {
1059  $this->changedate = $a_changedate;
1060  }
1061  }
1062  public function getChangeDate()
1063  {
1064  return $this->changedate;
1065  }
1066  public function setImportName($a_import_name)
1067  {
1068  $this->import_name = $a_import_name;
1069  }
1070  public function getImportName()
1071  {
1072  return $this->import_name;
1073  }
1074  public function setLastPostString($a_last_post)
1075  {
1076  if ($a_last_post == '') {
1077  $a_last_post = null;
1078  }
1079 
1080  $this->last_post_string = $a_last_post;
1081  }
1082  public function getLastPostString()
1083  {
1084  return $this->last_post_string;
1085  }
1086  public function setVisits($a_visits)
1087  {
1088  $this->visits = $a_visits;
1089  }
1090  public function getVisits()
1091  {
1092  return $this->visits;
1093  }
1094  public function setSticky($a_sticky)
1095  {
1096  $this->is_sticky = $a_sticky;
1097  }
1098  public function isSticky()
1099  {
1100  return $this->is_sticky == 1 ? true : false;
1101  }
1102  public function setClosed($a_closed)
1103  {
1104  $this->is_closed = $a_closed;
1105  }
1106  public function isClosed()
1107  {
1108  return $this->is_closed == 1 ? true : false;
1109  }
1110  public function setOrderField($a_order_field)
1111  {
1112  $this->orderField = $a_order_field;
1113  }
1114  public function getOrderField()
1115  {
1116  return $this->orderField;
1117  }
1118  public function setModeratorRight($bool)
1119  {
1120  $this->is_moderator = $bool;
1121  }
1122  public function getModeratorRight()
1123  {
1124  return $this->is_moderator;
1125  }
1126  public function getFrmObjId()
1127  {
1128  return $this->frm_obj_id;
1129  }
1130 
1135  {
1136  $this->thr_author_id = $thr_author_id;
1137  }
1138 
1142  public function getThrAuthorId()
1143  {
1144  return $this->thr_author_id;
1145  }
1146 
1155  public static function _lookupTitle($a_topic_id)
1156  {
1157  global $DIC;
1158  $ilDB = $DIC->database();
1159 
1160  $res = $ilDB->queryf(
1161  '
1162  SELECT thr_subject
1163  FROM frm_threads
1164  WHERE thr_pk = %s',
1165  array('integer'),
1166  array($a_topic_id)
1167  );
1168  $row = $ilDB->fetchObject($res);
1169 
1170  if (is_object($row)) {
1171  return $row->thr_subject;
1172  }
1173 
1174  return '';
1175  }
1176 
1177  public function updateThreadTitle()
1178  {
1179  $this->db->update(
1180  'frm_threads',
1181  array('thr_subject' => array('text',$this->getSubject())),
1182  array('thr_pk'=> array('integer', $this->getId()))
1183  );
1184  }
1185 
1190  public function setNumPosts($a_num_posts)
1191  {
1192  $this->num_posts = $a_num_posts;
1193  return $this;
1194  }
1195 
1199  public function getNumPosts()
1200  {
1201  return $this->num_posts;
1202  }
1203 
1208  public function setNumNewPosts($num_new_posts)
1209  {
1210  $this->num_new_posts = $num_new_posts;
1211  return $this;
1212  }
1213 
1217  public function getNumNewPosts()
1218  {
1219  return $this->num_new_posts;
1220  }
1221 
1226  public function setNumUnreadPosts($num_unread_posts)
1227  {
1228  $this->num_unread_posts = $num_unread_posts;
1229  return $this;
1230  }
1231 
1235  public function getNumUnreadPosts()
1236  {
1237  return $this->num_unread_posts;
1238  }
1239 
1244  public function setUserNotificationEnabled($user_notification_enabled)
1245  {
1246  $this->user_notification_enabled = $user_notification_enabled;
1247  return $this;
1248  }
1249 
1253  public function getUserNotificationEnabled()
1254  {
1255  return $this->user_notification_enabled;
1256  }
1257 
1258  public function setOrderDirection($direction)
1259  {
1260  if (!in_array(strtoupper($direction), self::$possibleOrderDirections)) {
1261  $direction = current(self::$possibleOrderDirections);
1262  }
1263 
1264  $this->orderDirection = $direction;
1265  return $this;
1266  }
1267 
1268  public function getOrderDirection()
1269  {
1270  return $this->orderDirection;
1271  }
1272 
1274  {
1275  return $this->last_post;
1276  }
1277 
1279  {
1280  $this->last_post = $post;
1281  }
1282 
1283  public static function lookupForumIdByTopicId($a_topic_id)
1284  {
1285  global $DIC;
1286  $ilDB = $DIC->database();
1287 
1288  $res = $ilDB->queryF(
1289  'SELECT thr_top_fk FROM frm_threads WHERE thr_pk = %s',
1290  array('integer'),
1291  array($a_topic_id)
1292  );
1293 
1294  $row = $ilDB->fetchAssoc($res);
1295 
1296  return $row['thr_top_fk'];
1297  }
1298 
1299  public function getSorting()
1300  {
1301  return $this->thread_sorting;
1302  }
1303  public function updateMergedThread()
1304  {
1305  $this->db->update(
1306  'frm_threads',
1307  array(
1308  'thr_num_posts' => array('integer', $this->getNumPosts()),
1309  'visits' => array('integer', $this->getVisits()),
1310  'thr_last_post' => array('text', $this->getLastPostString()),
1311  'thr_subject' => array('text', $this->getSubject())
1312  ),
1313  array('thr_pk' => array('integer', $this->getId()))
1314  );
1315  }
1316 
1317  public static function deleteByThreadId($thr_id)
1318  {
1319  global $DIC;
1320  $DIC->database()->manipulateF(
1321  'DELETE FROM frm_threads WHERE thr_pk = %s',
1322  array('integer'),
1323  array($thr_id)
1324  );
1325  }
1326 
1327 
1332  public static function _lookupDate($thread_id)
1333  {
1334  global $DIC;
1335  $ilDB = $DIC->database();
1336 
1337  $res = $ilDB->queryF(
1338  'SELECT thr_date FROM frm_threads WHERE thr_pk = %s',
1339  array('integer'),
1340  array((int) $thread_id)
1341  );
1342 
1343  $row = $ilDB->fetchAssoc($res);
1344 
1345  return $row['thr_date'] ? $row['thr_date'] : '0000-00-00 00:00:00';
1346  }
1347 }
insert()
Inserts the object data into database.
static _lookupDate($thread_id)
updateVisits()
Updates the visit counter of the current topic.
setSubject($a_subject)
static _lookupObjIdForForumId($a_for_id)
unmakeSticky()
Sets the current topic non-sticky.
isNotificationEnabled($a_user_id)
Check whether a user&#39;s notification about new posts in a thread is enabled (result > 0) or not (resul...
setOrderDirection($direction)
setUserNotificationEnabled($user_notification_enabled)
setForumId($a_forum_id)
setOrderField($a_order_field)
$_SESSION["AccountId"]
$result
getFirstPostId()
Fetches the primary key of the first post node of the current topic from database and returns it...
__construct($a_id=0, $a_is_moderator=false, $preventImplicitRead=false)
Constructor.
setAverageRating($average_rating)
global $DIC
Definition: saml.php:7
getLastActivePost()
Fetches and returns an object of the last active post in the current topic.
movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
Moves all posts within the current thread to a new forum.
setNumNewPosts($num_new_posts)
static $possibleOrderDirections
update()
Updates an existing topic.
user()
Definition: user.php:4
setNumUnreadPosts($num_unread_posts)
setCreateDate($a_createdate)
$counter
Interface ilDBInterface.
getNestedSetPostChildren($pos_id=null, $levels=null)
setThrAuthorId($thr_author_id)
static getInstance($a_obj_id=0)
makeSticky()
Sets the current topic sticky.
close()
Closes the current topic.
foreach($_POST as $key=> $value) $res
countActivePosts()
Fetches and returns the number of active posts for the given user id.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$post
Definition: post.php:34
setDisplayUserId($a_user_id)
$query
setLastPostString($a_last_post)
Create styles array
The data for the language used.
setChangeDate($a_changedate)
getLastPost()
Fetches and returns an object of the last post in the current topic.
getFirstPostNode()
Fetches and returns an object of the first post in the current topic.
static getFirstNewsIdForContext( $a_context_obj_id, $a_context_obj_type, $a_context_sub_obj_id="", $a_context_sub_obj_type="")
Get first new id of news set related to a certain context.
setUserAlias($a_user_alias)
setNumPosts($a_num_posts)
static deleteByThreadId($thr_id)
disableNotification($a_user_id)
Disable a user&#39;s notification about new posts in a thread.
setLastPostForThreadOverview(ilForumPost $post)
This class handles all operations on files for the forum object.
global $ilDB
$i
Definition: disco.tpl.php:19
reopen()
Reopens the current topic.
getPostTree(ilForumPost $a_post_node)
Fetches and returns an array of posts from the post tree, starting with the node object passed by the...
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
countPosts()
Fetches and returns the number of posts for the given user id.
static _lookupTitle($a_topic_id)
Looks up the title/subject of a topic/thread.
read()
Reads the data of the current object id from database and loads it into the object.
reload()
Calls the private method read() to load the topic data from database into the object.
enableNotification($a_user_id)
Enable a user&#39;s notification about new posts in a thread.
manipulateF($query, $types, $values)
setImportName($a_import_name)
static lookupForumIdByTopicId($a_topic_id)
Class to report exception.