ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables 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 $user_id = 0;
21 
22  private $user_alias = '';
23 
24  private $subject = '';
25 
26  private $createdate = '0000-00-00 00:00:00';
27 
28  private $changedate = '0000-00-00 00:00:00';
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 $posts = array();
45 
46  private $db = null;
47 
48  private $is_moderator = false;
49 
50  protected $orderDirection = 'DESC';
51 
52  protected static $possibleOrderDirections = array('ASC', 'DESC');
53 
66  public function __construct($a_id = 0, $a_is_moderator = false, $preventImplicitRead = false)
67  {
68  global $ilDB;
69 
70  $this->is_moderator = $a_is_moderator;
71  $this->db = $ilDB;
72  $this->id = $a_id;
73 
74  if(!$preventImplicitRead)
75  {
76  $this->read();
77  }
78  }
79 
83  public function assignData($data)
84  {
85  $this->setId((int) $data['thr_pk']);
86  $this->setForumId((int) $data['thr_top_fk']);
87  $this->setSubject($data['thr_subject']);
88  $this->setUserId((int) $data['thr_usr_id']);
89  $this->setUserAlias($data['thr_usr_alias']);
90  $this->setLastPostString($data['last_post_string']);
91  $this->setCreateDate($data['thr_date']);
92  $this->setChangeDate($data['thr_update']);
93  $this->setVisits((int) $data['visits']);
94  $this->setImportName($data['import_name']);
95  $this->setSticky((int) $data['is_sticky']);
96  $this->setClosed((int) $data['is_closed']);
97 
98  // Aggregated values
99  $this->setNumPosts((int) $data['num_posts']);
100  $this->setNumUnreadPosts((int) $data['num_unread_posts']);
101  $this->setNumNewPosts((int) $data['num_new_posts']);
102  $this->setUserNotificationEnabled((bool) $data['usr_notification_is_enabled']);
103  }
104 
111  public function insert()
112  {
113  if ($this->forum_id)
114  {
115  $nextId = $this->db->nextId('frm_threads');
116  $statement = $this->db->manipulateF('
117  INSERT INTO frm_threads
118  ( thr_pk,
119  thr_top_fk,
120  thr_subject,
121  thr_usr_id,
122  thr_usr_alias,
123  thr_num_posts,
124  thr_last_post,
125  thr_date,
126  thr_update,
127  import_name,
128  is_sticky,
129  is_closed
130  )
131  VALUES(%s,%s,%s,%s,%s,%s,%s,%s, %s, %s,%s,%s)',
132 
133  array( 'integer',
134  'integer',
135  'text',
136  'integer',
137  'text',
138  'integer',
139  'text',
140  'timestamp',
141  'timestamp',
142  'text',
143  'integer',
144  'integer'),
145  array( $nextId,
146  $this->forum_id,
147  $this->subject,
148  $this->user_id,
149  $this->user_alias,
150  $this->num_posts,
151  $this->last_post_string,
152  $this->createdate,
153  NULL,
154  $this->import_name,
155  $this->is_sticky,
156  $this->is_closed
157  ));
158  $this->id = $nextId;
159 
160  return true;
161  }
162 
163  return false;
164  }
165 
172  public function update()
173  {
174  if ($this->id)
175  {
176  $statement = $this->db->manipulateF('
177  UPDATE frm_threads
178  SET thr_top_fk = %s,
179  thr_subject = %s,
180  thr_update = %s,
181  thr_num_posts = %s,
182  thr_last_post = %s
183  WHERE thr_pk = %s',
184  array('integer', 'text','timestamp', 'integer', 'text', 'integer'),
185  array( $this->forum_id,
186  $this->subject,
187  /* $this->changedate, */
188  date('Y-m-d H:i:s'),
189  $this->num_posts,
190  $this->last_post_string,
191  $this->id
192  ));
193 
194  return true;
195  }
196 
197  return false;
198  }
199 
207  private function read()
208  {
209 
210  if ($this->id)
211  {
212  $res = $this->db->queryf('
213  SELECT frm_threads.*, top_frm_fk frm_obj_id
214  FROM frm_threads
215  INNER JOIN frm_data ON top_pk = thr_top_fk
216  WHERE thr_pk = %s',
217  array('integer'), array($this->id));
218 
219  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
220 
221  if (is_object($row))
222  {
223 
224  $this->thr_pk = $row->pos_pk; // thr_pk = pos_pk ??!??!
225  $this->forum_id = $row->thr_top_fk;
226  $this->user_id = $row->thr_usr_id;
227  $this->user_alias = $row->thr_usr_alias;
228  $this->subject = html_entity_decode($row->thr_subject);
229  $this->createdate = $row->thr_date;
230  $this->changedate = $row->thr_update;
231  $this->import_name = $row->import_name;
232  $this->num_posts = $row->thr_num_posts;
233  $this->last_post_string = $row->thr_last_post;
234  $this->visits = $row->visits;
235  $this->is_sticky = $row->is_sticky;
236  $this->is_closed = $row->is_closed;
237  $this->frm_obj_id = $row->frm_obj_id;
238 
239  return true;
240  }
241  $this->id = 0;
242  return false;
243  }
244 
245  return false;
246  }
247 
254  public function reload()
255  {
256  return $this->read();
257  }
258 
265  public function getFirstPostId()
266  {
267  $res = $this->db->queryf('
268  SELECT * FROM frm_posts_tree
269  WHERE thr_fk = %s
270  AND parent_pos = %s',
271  array('integer', 'integer'), array($this->id, '1'));
272 
273  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
274 
275  return $row->pos_fk ? $row->pos_fk : 0;
276  }
277 
283  public function updateVisits()
284  {
285  $checkTime = time() - (60 * 60);
286 
287  if ($_SESSION['frm_visit_frm_threads_'.$this->id] < $checkTime)
288  {
289  $_SESSION['frm_visit_frm_threads_'.$this->id] = time();
290 
291  $statement = $this->db->manipulateF('
292  UPDATE frm_threads
293  SET visits = visits + 1
294  WHERE thr_pk = %s',
295  array('integer'), array($this->id));
296  }
297 
298  return true;
299  }
300 
308  public function countPosts()
309  {
310  $res = $this->db->queryf('
311  SELECT COUNT(*) cnt
312  FROM frm_posts
313  WHERE pos_thr_fk = %s',
314  array('integer'), array($this->id));
315 
316  $rec = $res->fetchRow(DB_FETCHMODE_ASSOC);
317 
318  return $rec['cnt'];
319  }
320 
328  public function countActivePosts()
329  {
330  global $ilUser;
331 
332  $res = $this->db->queryf('
333  SELECT COUNT(*) cnt
334  FROM frm_posts
335  WHERE (pos_status = %s
336  OR (pos_status = %s AND pos_usr_id = %s))
337  AND pos_thr_fk = %s',
338  array('integer', 'integer', 'integer', 'integer'), array('1', '0', $ilUser->getId(), $this->id));
339 
340  $rec = $res->fetchRow(DB_FETCHMODE_ASSOC);
341 
342  return $rec['cnt'];
343  }
344 
351  public function getFirstPostNode()
352  {
353  $res = $this->db->queryf('
354  SELECT pos_pk
355  FROM frm_posts
356  INNER JOIN frm_posts_tree ON pos_fk = pos_pk
357  WHERE parent_pos = %s
358  AND thr_fk = %s',
359  array('integer', 'integer'),
360  array('0', $this->id));
361 
362  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
363 
364  return new ilForumPost($row->pos_pk);
365  }
366 
373  public function getLastPost()
374  {
375  if ($this->id)
376  {
377  $this->db->setLimit(1);
378  $res = $this->db->queryf('
379  SELECT pos_pk
380  FROM frm_posts
381  WHERE pos_thr_fk = %s
382  ORDER BY pos_date DESC',
383  array('integer'), array($this->id));
384 
385  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
386 
387  return new ilForumPost($row->pos_pk);
388  }
389 
390  return false;
391  }
392 
399  public function getLastActivePost()
400  {
401  global $ilUser;
402 
403  if ($this->id)
404  {
405  $this->db->setLimit(1);
406  $res = $this->db->queryf('
407  SELECT pos_pk
408  FROM frm_posts
409  WHERE pos_thr_fk = %s
410  AND (pos_status = %s OR
411  (pos_status = %s AND pos_usr_id = %s))
412  ORDER BY pos_date DESC',
413  array('integer', 'integer', 'integer', 'integer'),
414  array($this->id, '1', '0', $ilUser->getId()));
415 
416  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
417 
418  return new ilForumPost($row->pos_pk);
419  }
420 
421  return false;
422  }
423 
424  public function getAllPosts()
425  {
426  $posts = array();
427 
428  if($this->id)
429  {
430  $res = $this->db->queryf('
431  SELECT pos_pk
432  FROM frm_posts
433  WHERE pos_thr_fk = %s',
434  array('integer'),
435  array($this->id));
436 
437  while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
438  {
439  $posts[$row->pos_pk] = $row;
440  }
441  }
442 
443  return is_array($posts) ? $posts : array();
444  }
445 
454  public function getPostTree(ilForumPost $a_post_node)
455  {
456  global $ilUser;
457 
458  $posts = array();
459 
460  $data = array();
461  $data_types = array();
462 
463  $query = '
464  SELECT pos_pk, fpt_date, rgt, pos_top_fk, pos_thr_fk,
465  pos_usr_id, pos_usr_alias, pos_subject,
466  pos_status, pos_message, pos_date, pos_update,
467  update_user, pos_cens, pos_cens_com, notify,
468  import_name, fpt_pk, parent_pos, lft, depth,
469  (CASE
470  WHEN fur.post_id IS NULL '.
471  ($ilUser->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '').'
472  THEN 0
473  ELSE 1
474  END) post_read,
475  firstname, lastname, title, login
476 
477  FROM frm_posts_tree
478 
479  INNER JOIN frm_posts
480  ON pos_fk = pos_pk
481 
482  LEFT JOIN usr_data
483  ON pos_usr_id = usr_id
484 
485  LEFT JOIN frm_user_read fur
486  ON fur.thread_id = pos_thr_fk
487  AND fur.post_id = pos_pk
488  AND fur.usr_id = %s
489 
490  WHERE lft BETWEEN %s AND %s
491  AND thr_fk = %s';
492 
493  array_push($data_types, 'integer', 'integer', 'integer', 'integer');
494  array_push($data, $ilUser->getId(), $a_post_node->getLft(), $a_post_node->getRgt(), $a_post_node->getThreadId());
495 
496  if($this->orderField != "")
497  {
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  {
508  $tmp_object = new ilForumPost($row['pos_pk'], false, true);
509  $tmp_object->assignData($row);
510 
511  if (!$this->is_moderator)
512  {
513  if (!$tmp_object->isActivated() && $tmp_object->getUserId() != $ilUser->getId())
514  {
515  $deactivated[] = $tmp_object;
516  unset($tmp_object);
517  continue;
518  }
519 
520  foreach ($deactivated as $deactivated_node)
521  {
522  if ($deactivated_node->getLft() < $tmp_object->getLft() && $deactivated_node->getRgt() > $tmp_object->getLft())
523  {
524  $deactivated[] = $tmp_object;
525  unset($tmp_object);
526  continue 2;
527  }
528  }
529  }
530 
531  if((int)$row['pos_usr_id'])
532  {
533  $usr_ids[] = (int)$row['pos_usr_id'];
534  }
535  if((int)$row['update_user'])
536  {
537  $usr_ids[] = (int)$row['update_user'];
538  }
539 
540  $posts[] = $tmp_object;
541 
542  unset($tmp_object);
543  }
544 
545  require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
546  ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
547 
548  return $posts;
549  }
550 
561  public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
562  {
563  global $ilDB;
564 
565  if ($this->id)
566  {
567  $nodes = $this->getAllPosts();
568  if(is_array($nodes))
569  {
570  // Move attachments
571  foreach($nodes as $node)
572  {
573  $file_obj = new ilFileDataForum((int)$old_obj_id, (int)$node->pos_pk);
574  $file_obj->moveFilesOfPost((int)$new_obj_id);
575  unset($file_obj);
576  }
577  }
578 
579  $this->db->lockTables(
580  array(
581  0 => array('name' => 'frm_user_read', 'type' => ilDB::LOCK_WRITE),
582  1 => array('name' => 'frm_thread_access', 'type' => ilDB::LOCK_WRITE)
583  )
584  );
585 
586  $this->db->manipulateF('
587  DELETE FROM frm_user_read
588  WHERE obj_id = %s AND thread_id =%s',
589  array('integer', 'integer'),
590  array($new_obj_id, $this->id));
591 
592  $this->db->manipulateF('
593  UPDATE frm_user_read
594  SET obj_id = %s
595  WHERE thread_id = %s',
596  array('integer', 'integer'),
597  array($new_obj_id, $this->id));
598 
599  $this->db->manipulateF('
600  DELETE FROM frm_thread_access
601  WHERE obj_id = %s AND thread_id =%s',
602  array('integer', 'integer'),
603  array($new_obj_id, $this->id));
604 
605  $this->db->manipulateF('
606  UPDATE frm_thread_access
607  SET obj_id = %s
608  WHERE thread_id =%s',
609  array('integer', 'integer'),
610  array($new_obj_id, $this->id));
611 
612  $this->db->unlockTables();
613 
614  $this->db->manipulateF('
615  UPDATE frm_posts
616  SET pos_top_fk = %s
617  WHERE pos_thr_fk = %s',
618  array('integer', 'integer'),
619  array($new_pk, $this->id));
620 
621  // update all related news
622  $posts = $ilDB->queryf('
623  SELECT * FROM frm_posts WHERE pos_thr_fk = %s',
624  array('integer'), array($this->id));
625 
626  $old_obj_id = ilForum::_lookupObjIdForForumId($old_pk);
627 
628  $new_obj_id = ilForum::_lookupObjIdForForumId($new_pk);
629 
630  while($post = $posts->fetchRow(DB_FETCHMODE_ASSOC))
631  {
632  include_once("./Services/News/classes/class.ilNewsItem.php");
633  $news_id = ilNewsItem::getFirstNewsIdForContext($old_obj_id,
634  "frm", $post["pos_pk"], "pos");
635  $news_item = new ilNewsItem($news_id);
636  $news_item->setContextObjId($new_obj_id);
637  $news_item->update();
638  //echo "<br>-".$post["pos_pk"]."-".$old_obj_id."-".$new_obj_id."-";
639  }
640 
641  return count($nodes);
642  }
643 
644  return 0;
645  }
646 
647  public function getNestedSetPostChildren($pos_id = null, $expandedNodes = array())
648  {
649  global $ilUser;
650 
651  $data = null;
652 
653  if( $pos_id !== null )
654  {
655  $res = $this->db->queryF("
656  SELECT lft, rgt
657  FROM frm_posts_tree
658  WHERE pos_fk = %s
659  AND thr_fk = %s",
660  array('integer', 'integer'),
661  array($pos_id, $this->id)
662  );
663 
664  $data = $this->db->fetchAssoc($res);
665  }
666 
667  $query = '
668  SELECT fpt.depth,
669  fpt.rgt,
670  fpt.parent_pos,
671  fp.pos_pk,
672  fp.pos_subject,
673  fp.pos_usr_alias,
674  fp.pos_date,
675  fp.pos_update,
676  fp.pos_status,
677  fp.pos_usr_id,
678  fp.pos_usr_alias,
679  fp.import_name,
680  fur.post_id,
681  (CASE
682  WHEN fur.post_id IS NULL '.
683  ($ilUser->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '').'
684  THEN 0
685  ELSE 1
686  END) post_read,
687  COUNT(fpt2.pos_fk) children
688 
689  FROM frm_posts_tree fpt
690 
691  INNER JOIN frm_posts fp
692  ON fp.pos_pk = fpt.pos_fk
693 
694  LEFT JOIN frm_posts_tree fpt2
695  ON fpt2.lft BETWEEN fpt.lft AND fpt.rgt
696  AND fpt.thr_fk = fpt2.thr_fk
697  AND fpt.pos_fk != fpt2.pos_fk ';
698 
699 
700  $query .= '
701  LEFT JOIN frm_user_read fur
702  ON fur.thread_id = fp.pos_thr_fk
703  AND fur.post_id = fp.pos_pk
704  AND fur.usr_id = '.$this->db->quote($ilUser->getId(), 'integer').'
705 
706  LEFT JOIN usr_data ud
707  ON ud.usr_id = fp.pos_usr_id
708 
709  WHERE fpt.thr_fk = '.$this->db->quote($this->id, 'integer');
710 
711  if( $data )
712  {
713  $query .= ' AND fpt.lft > '.$this->db->quote($data['lft'], 'integer').
714  ' AND fpt.lft < '.$this->db->quote($data['rgt'], 'integer').' ';
715  }
716 
717  if( !$this->is_moderator )
718  {
719  $query .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_usr_id = '.
720  $this->db->quote($ilUser->getId(), 'integer').') ';
721  }
722 
723  if( $expandedNodes )
724  {
725  $query .= ' AND '.$this->db->in('fpt.parent_pos', $expandedNodes, false, 'integer').' ';
726  }
727 
728 
729  $query .= ' GROUP BY fpt.depth,
730  fpt.parent_pos,
731  fp.pos_pk,
732  fp.pos_subject,
733  fp.pos_usr_alias,
734  fp.pos_date,
735  fp.pos_update,
736  fp.pos_status,
737  fp.pos_usr_id,
738  fp.pos_usr_alias,
739  fp.import_name,
740  fur.post_id,
741  fpt.rgt
742  ORDER BY fpt.rgt DESC
743  ';
744 
745  $queryCounter = '
746  SELECT pos_fk
747  FROM frm_posts_tree fpt
748  INNER JOIN frm_posts fp
749  ON fp.pos_pk = fpt.pos_fk
750  WHERE fpt.thr_fk = '.$this->db->quote($this->id, 'integer');
751  if( !$this->is_moderator )
752  {
753  $queryCounter .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_usr_id = '.
754  $this->db->quote($ilUser->getId(), 'integer').') ';
755  }
756  $queryCounter .= ' ORDER BY fpt.rgt DESC';
757 
758  $resCounter = $this->db->query($queryCounter);
759  $counter = array();
760  $i = 0;
761  while( $row = $this->db->fetchAssoc($resCounter) )
762  {
763  $counter[$row['pos_fk']] = $i++;
764  }
765 
766  $res = $this->db->query($query);
767  $children = array();
768  $usr_ids = array();
769  while( $row = $this->db->fetchAssoc($res) )
770  {
771  if((int)$row['pos_usr_id'])
772  {
773  $usr_ids[] = (int)$row['pos_usr_id'];
774  }
775 
776  $row['counter'] = $counter[$row['pos_pk']];
777  $children[] = $row;
778  }
779 
780  require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
781  ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
782 
783  return $children;
784  }
785 
792  public function isNotificationEnabled($a_user_id)
793  {
794  if ($this->id && $a_user_id)
795  {
796  $result = $this->db->queryf('
797  SELECT COUNT(notification_id) cnt FROM frm_notification
798  WHERE user_id = %s AND thread_id = %s',
799  array('integer', 'integer'),
800  array($a_user_id, $this->id));
801 
802  while($record = $this->db->fetchAssoc($result))
803  {
804  return (bool)$record['cnt'];
805  }
806 
807  return false;
808  }
809 
810  return false;
811  }
812 
819  public function enableNotification($a_user_id)
820  {
821  if ($this->id && $a_user_id)
822  {
823  if (!$this->isNotificationEnabled($a_user_id))
824  {
825  $nextId = $this->db->nextId('frm_notification');
826  $statement = $this->db->manipulateF('
827  INSERT INTO frm_notification
828  ( notification_id,
829  user_id,
830  thread_id
831  )
832  VALUES(%s, %s, %s)',
833  array('integer', 'integer', 'integer'),
834  array($nextId, $a_user_id, $this->id));
835 
836  return true;
837  }
838  return false;
839  }
840 
841  return false;
842  }
843 
850  public function disableNotification($a_user_id)
851  {
852  if ($this->id && $a_user_id)
853  {
854  $statement = $this->db->manipulateF('
855  DELETE FROM frm_notification
856  WHERE user_id = %s
857  AND thread_id = %s',
858  array('integer', 'integer'),
859  array($a_user_id, $this->id));
860 
861  return false;
862  }
863 
864  return false;
865  }
866 
873  public function makeSticky()
874  {
875  if ($this->id && !$this->is_sticky)
876  {
877  $statement = $this->db->manipulateF('
878  UPDATE frm_threads
879  SET is_sticky = %s
880  WHERE thr_pk = %s',
881  array('integer', 'integer'),
882  array('1', $this->id));
883 
884  $this->is_sticky = 1;
885 
886  return true;
887  }
888 
889  return false;
890  }
891 
898  public function unmakeSticky()
899  {
900  if ($this->id && $this->is_sticky)
901  {
902  $statement = $this->db->manipulateF('
903  UPDATE frm_threads
904  SET is_sticky = %s
905  WHERE thr_pk = %s',
906  array('integer', 'integer'),
907  array('0', $this->id));
908 
909  $this->is_sticky = 0;
910 
911  return true;
912  }
913 
914  return false;
915  }
916 
923  public function close()
924  {
925  if ($this->id && !$this->is_closed)
926  {
927  $statement = $this->db->manipulateF('
928  UPDATE frm_threads
929  SET is_closed = %s
930  WHERE thr_pk = %s',
931  array('integer', 'integer'),
932  array('1', $this->id));
933 
934  $this->is_closed = 1;
935 
936  return true;
937  }
938 
939  return false;
940  }
941 
948  public function reopen()
949  {
950  if ($this->id && $this->is_closed)
951  {
952  $statement = $this->db->manipulateF('
953  UPDATE frm_threads
954  SET is_closed = %s
955  WHERE thr_pk = %s',
956  array('integer', 'integer'),
957  array('0', $this->id));
958 
959  $this->is_closed = 0;
960 
961  return true;
962  }
963 
964  return false;
965  }
966 
967  public function setId($a_id)
968  {
969  $this->id = $a_id;
970  }
971  public function getId()
972  {
973  return $this->id;
974  }
975  public function setForumId($a_forum_id)
976  {
977  $this->forum_id = $a_forum_id;
978  }
979  public function getForumId()
980  {
981  return $this->forum_id;
982  }
983  public function setUserId($a_user_id)
984  {
985  $this->user_id = $a_user_id;
986  }
987  public function getUserId()
988  {
989  return $this->user_id;
990  }
991  public function setUserAlias($a_user_alias)
992  {
993  $this->user_alias = $a_user_alias;
994  }
995  public function getUserAlias()
996  {
997  return $this->user_alias;
998  }
999  public function setSubject($a_subject)
1000  {
1001  $this->subject = $a_subject;
1002  }
1003  public function getSubject()
1004  {
1005  return $this->subject;
1006  }
1007  public function setCreateDate($a_createdate)
1008  {
1009  $this->createdate = $a_createdate;
1010  }
1011  public function getCreateDate()
1012  {
1013  return $this->createdate;
1014  }
1015  public function setChangeDate($a_changedate)
1016  {
1017  if($a_changedate == '0000-00-00 00:00:00')
1018  $this->changedate = NULL;
1019  else
1020  $this->changedate = $a_changedate;
1021  }
1022  public function getChangeDate()
1023  {
1024  return $this->changedate;
1025  }
1026  public function setImportName($a_import_name)
1027  {
1028  $this->import_name = $a_import_name;
1029  }
1030  public function getImportName()
1031  {
1032  return $this->import_name;
1033  }
1034  public function setLastPostString($a_last_post)
1035  {
1036  if($a_last_post == '') $a_last_post = NULL;
1037 
1038  $this->last_post_string = $a_last_post;
1039  }
1040  public function getLastPostString()
1041  {
1042  return $this->last_post_string;
1043  }
1044  public function setVisits($a_visits)
1045  {
1046  $this->visits = $a_visits;
1047  }
1048  public function getVisits()
1049  {
1050  return $this->visits;
1051  }
1052  public function setSticky($a_sticky)
1053  {
1054  $this->is_sticky = $a_sticky;
1055  }
1056  public function isSticky()
1057  {
1058  return $this->is_sticky == 1 ? true : false;
1059  }
1060  public function setClosed($a_closed)
1061  {
1062  $this->is_closed = $a_closed;
1063  }
1064  public function isClosed()
1065  {
1066  return $this->is_closed == 1 ? true : false;
1067  }
1068  function setOrderField($a_order_field)
1069  {
1070  $this->orderField = $a_order_field;
1071  }
1072  function getOrderField()
1073  {
1074  return $this->orderField;
1075  }
1076  function setModeratorRight($bool)
1077  {
1078  $this->is_moderator = $bool;
1079  }
1081  {
1082  return $this->is_moderator;
1083  }
1084  function getFrmObjId()
1085  {
1086  return $this->frm_obj_id;
1087  }
1088 
1097  public static function _lookupTitle($a_topic_id)
1098  {
1099  global $ilDB;
1100 
1101  $res = $ilDB->queryf('
1102  SELECT thr_subject
1103  FROM frm_threads
1104  WHERE thr_pk = %s',
1105  array('integer'), array($a_topic_id));
1106  $row = $ilDB->fetchObject($res);
1107 
1108  if(is_object($row))
1109  {
1110  return $row->thr_subject;
1111  }
1112 
1113  return '';
1114  }
1115 
1116  public function updateThreadTitle()
1117  {
1118  global $ilDB;
1119 
1120  $ilDB->update('frm_threads',
1121  array('thr_subject' => array('text',$this->getSubject())),
1122  array('thr_pk'=> array('integer', $this->getId()))
1123  );
1124  }
1125 
1130  public function setNumPosts($a_num_posts)
1131  {
1132  $this->num_posts = $a_num_posts;
1133  return $this;
1134  }
1135 
1139  public function getNumPosts()
1140  {
1141  return $this->num_posts;
1142  }
1143 
1148  public function setNumNewPosts($num_new_posts)
1149  {
1150  $this->num_new_posts = $num_new_posts;
1151  return $this;
1152  }
1153 
1157  public function getNumNewPosts()
1158  {
1159  return $this->num_new_posts;
1160  }
1161 
1166  public function setNumUnreadPosts($num_unread_posts)
1167  {
1168  $this->num_unread_posts = $num_unread_posts;
1169  return $this;
1170  }
1171 
1175  public function getNumUnreadPosts()
1176  {
1177  return $this->num_unread_posts;
1178  }
1179 
1184  public function setUserNotificationEnabled($user_notification_enabled)
1185  {
1186  $this->user_notification_enabled = $user_notification_enabled;
1187  return $this;
1188  }
1189 
1193  public function getUserNotificationEnabled()
1194  {
1195  return $this->user_notification_enabled;
1196  }
1197 
1198  public function setOrderDirection($direction)
1199  {
1200  if(!in_array(strtoupper($direction), self::$possibleOrderDirections))
1201  {
1202  $direction = current(self::$possibleOrderDirections);
1203  }
1204 
1205  $this->orderDirection = $direction;
1206  return $this;
1207  }
1208 
1209  public function getOrderDirection()
1210  {
1211  return $this->orderDirection;
1212  }
1213 
1214  public static function lookupForumIdByTopicId($a_topic_id)
1215  {
1216  global $ilDB;
1217 
1218  $res = $ilDB->queryF('SELECT thr_top_fk FROM frm_threads WHERE thr_pk = %s',
1219  array('integer'), array($a_topic_id));
1220 
1221  $row = $ilDB->fetchAssoc($res);
1222 
1223  return $row['thr_top_fk'];
1224  }
1225 
1226  public function getSorting()
1227  {
1228  return $this->thread_sorting;
1229  }
1230  public function updateMergedThread()
1231  {
1232  global $ilDB;
1233 
1234  $ilDB->update('frm_threads',
1235  array(
1236  'thr_num_posts' => array('integer', $this->getNumPosts()),
1237  'visits' => array('integer', $this->getVisits()),
1238  'thr_last_post' => array('text', $this->getLastPostString()),
1239  'thr_subject' => array('text', $this->getSubject())
1240  ),
1241  array('thr_pk' => array('integer', $this->getId())));
1242  }
1243 
1244  public static function deleteByThreadId($thr_id)
1245  {
1246  global $ilDB;
1247 
1248  $ilDB->manipulateF('DELETE FROM frm_threads WHERE thr_pk = %s',
1249  array('integer'), array($thr_id));
1250  }
1251 
1252 
1257  public static function _lookupDate($thread_id)
1258  {
1259  global $ilDB;
1260 
1261  $res = $ilDB->queryF('SELECT thr_date FROM frm_threads WHERE thr_pk = %s',
1262  array('integer'), array((int)$thread_id));
1263 
1264  $row = $ilDB->fetchAssoc($res);
1265 
1266  return $row['thr_date'] ? $row['thr_date'] : '0000-00-00 00:00:00';
1267 
1268  }
1269 }
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
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)
$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.
setUserId($a_user_id)
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.
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.
getNestedSetPostChildren($pos_id=null, $expandedNodes=array())
setNumNewPosts($num_new_posts)
static $possibleOrderDirections
update()
Updates an existing topic.
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
setNumUnreadPosts($num_unread_posts)
setCreateDate($a_createdate)
fetchAssoc($a_set)
Fetch row as associative array from result set.
makeSticky()
Sets the current topic sticky.
close()
Closes the current topic.
countActivePosts()
Fetches and returns the number of active posts for the given user id.
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
const LOCK_WRITE
Definition: class.ilDB.php:30
setLastPostString($a_last_post)
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.
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
setUserAlias($a_user_alias)
global $ilUser
Definition: imgupload.php:15
setNumPosts($a_num_posts)
static deleteByThreadId($thr_id)
disableNotification($a_user_id)
Disable a user&#39;s notification about new posts in a thread.
This class handles all operations on files for the forum object.
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...
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.
setImportName($a_import_name)
static lookupForumIdByTopicId($a_topic_id)