ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups 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.parent_pos,
670  fp.pos_pk,
671  fp.pos_subject,
672  fp.pos_usr_alias,
673  fp.pos_date,
674  fp.pos_update,
675  fp.pos_status,
676  fp.pos_usr_id,
677  fp.pos_usr_alias,
678  fp.import_name,
679  fur.post_id,
680  (CASE
681  WHEN fur.post_id IS NULL '.
682  ($ilUser->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '').'
683  THEN 0
684  ELSE 1
685  END) post_read,
686  COUNT(fpt2.pos_fk) children
687 
688  FROM frm_posts_tree fpt
689 
690  INNER JOIN frm_posts fp
691  ON fp.pos_pk = fpt.pos_fk
692 
693  LEFT JOIN frm_posts_tree fpt2
694  ON fpt2.lft BETWEEN fpt.lft AND fpt.rgt
695  AND fpt.thr_fk = fpt2.thr_fk
696  AND fpt.pos_fk != fpt2.pos_fk ';
697 
698 
699  $query .= '
700  LEFT JOIN frm_user_read fur
701  ON fur.thread_id = fp.pos_thr_fk
702  AND fur.post_id = fp.pos_pk
703  AND fur.usr_id = '.$this->db->quote($ilUser->getId(), 'integer').'
704 
705  LEFT JOIN usr_data ud
706  ON ud.usr_id = fp.pos_usr_id
707 
708  WHERE fpt.thr_fk = '.$this->db->quote($this->id, 'integer');
709 
710  if( $data )
711  {
712  $query .= ' AND fpt.lft > '.$this->db->quote($data['lft'], 'integer').
713  ' AND fpt.lft < '.$this->db->quote($data['rgt'], 'integer').' ';
714  }
715 
716  if( !$this->is_moderator )
717  {
718  $query .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_usr_id = '.
719  $this->db->quote($ilUser->getId(), 'integer').') ';
720  }
721 
722  if( $expandedNodes )
723  {
724  $query .= ' AND '.$this->db->in('fpt.parent_pos', $expandedNodes, false, 'integer').' ';
725  }
726 
727 
728  $query .= ' GROUP BY fpt.depth,
729  fpt.parent_pos,
730  fp.pos_pk,
731  fp.pos_subject,
732  fp.pos_usr_alias,
733  fp.pos_date,
734  fp.pos_update,
735  fp.pos_status,
736  fp.pos_usr_id,
737  fp.pos_usr_alias,
738  fp.import_name,
739  fur.post_id
740  ORDER BY fpt.rgt DESC
741  ';
742 
743  $queryCounter = '
744  SELECT pos_fk
745  FROM frm_posts_tree fpt
746  INNER JOIN frm_posts fp
747  ON fp.pos_pk = fpt.pos_fk
748  WHERE fpt.thr_fk = '.$this->db->quote($this->id, 'integer');
749  if( !$this->is_moderator )
750  {
751  $queryCounter .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_usr_id = '.
752  $this->db->quote($ilUser->getId(), 'integer').') ';
753  }
754  $queryCounter .= ' ORDER BY fpt.rgt DESC';
755 
756  $resCounter = $this->db->query($queryCounter);
757  $counter = array();
758  $i = 0;
759  while( $row = $this->db->fetchAssoc($resCounter) )
760  {
761  $counter[$row['pos_fk']] = $i++;
762  }
763 
764  $res = $this->db->query($query);
765  $children = array();
766  $usr_ids = array();
767  while( $row = $this->db->fetchAssoc($res) )
768  {
769  if((int)$row['pos_usr_id'])
770  {
771  $usr_ids[] = (int)$row['pos_usr_id'];
772  }
773 
774  $row['counter'] = $counter[$row['pos_pk']];
775  $children[] = $row;
776  }
777 
778  require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
779  ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
780 
781  return $children;
782  }
783 
790  public function isNotificationEnabled($a_user_id)
791  {
792  if ($this->id && $a_user_id)
793  {
794  $result = $this->db->queryf('
795  SELECT COUNT(notification_id) cnt FROM frm_notification
796  WHERE user_id = %s AND thread_id = %s',
797  array('integer', 'integer'),
798  array($a_user_id, $this->id));
799 
800  while($record = $this->db->fetchAssoc($result))
801  {
802  return (bool)$record['cnt'];
803  }
804 
805  return false;
806  }
807 
808  return false;
809  }
810 
817  public function enableNotification($a_user_id)
818  {
819  if ($this->id && $a_user_id)
820  {
821  if (!$this->isNotificationEnabled($a_user_id))
822  {
823  $nextId = $this->db->nextId('frm_notification');
824  $statement = $this->db->manipulateF('
825  INSERT INTO frm_notification
826  ( notification_id,
827  user_id,
828  thread_id
829  )
830  VALUES(%s, %s, %s)',
831  array('integer', 'integer', 'integer'),
832  array($nextId, $a_user_id, $this->id));
833 
834  return true;
835  }
836  return false;
837  }
838 
839  return false;
840  }
841 
848  public function disableNotification($a_user_id)
849  {
850  if ($this->id && $a_user_id)
851  {
852  $statement = $this->db->manipulateF('
853  DELETE FROM frm_notification
854  WHERE user_id = %s
855  AND thread_id = %s',
856  array('integer', 'integer'),
857  array($a_user_id, $this->id));
858 
859  return false;
860  }
861 
862  return false;
863  }
864 
871  public function makeSticky()
872  {
873  if ($this->id && !$this->is_sticky)
874  {
875  $statement = $this->db->manipulateF('
876  UPDATE frm_threads
877  SET is_sticky = %s
878  WHERE thr_pk = %s',
879  array('integer', 'integer'),
880  array('1', $this->id));
881 
882  $this->is_sticky = 1;
883 
884  return true;
885  }
886 
887  return false;
888  }
889 
896  public function unmakeSticky()
897  {
898  if ($this->id && $this->is_sticky)
899  {
900  $statement = $this->db->manipulateF('
901  UPDATE frm_threads
902  SET is_sticky = %s
903  WHERE thr_pk = %s',
904  array('integer', 'integer'),
905  array('0', $this->id));
906 
907  $this->is_sticky = 0;
908 
909  return true;
910  }
911 
912  return false;
913  }
914 
921  public function close()
922  {
923  if ($this->id && !$this->is_closed)
924  {
925  $statement = $this->db->manipulateF('
926  UPDATE frm_threads
927  SET is_closed = %s
928  WHERE thr_pk = %s',
929  array('integer', 'integer'),
930  array('1', $this->id));
931 
932  $this->is_closed = 1;
933 
934  return true;
935  }
936 
937  return false;
938  }
939 
946  public function reopen()
947  {
948  if ($this->id && $this->is_closed)
949  {
950  $statement = $this->db->manipulateF('
951  UPDATE frm_threads
952  SET is_closed = %s
953  WHERE thr_pk = %s',
954  array('integer', 'integer'),
955  array('0', $this->id));
956 
957  $this->is_closed = 0;
958 
959  return true;
960  }
961 
962  return false;
963  }
964 
965  public function setId($a_id)
966  {
967  $this->id = $a_id;
968  }
969  public function getId()
970  {
971  return $this->id;
972  }
973  public function setForumId($a_forum_id)
974  {
975  $this->forum_id = $a_forum_id;
976  }
977  public function getForumId()
978  {
979  return $this->forum_id;
980  }
981  public function setUserId($a_user_id)
982  {
983  $this->user_id = $a_user_id;
984  }
985  public function getUserId()
986  {
987  return $this->user_id;
988  }
989  public function setUserAlias($a_user_alias)
990  {
991  $this->user_alias = $a_user_alias;
992  }
993  public function getUserAlias()
994  {
995  return $this->user_alias;
996  }
997  public function setSubject($a_subject)
998  {
999  $this->subject = $a_subject;
1000  }
1001  public function getSubject()
1002  {
1003  return $this->subject;
1004  }
1005  public function setCreateDate($a_createdate)
1006  {
1007  $this->createdate = $a_createdate;
1008  }
1009  public function getCreateDate()
1010  {
1011  return $this->createdate;
1012  }
1013  public function setChangeDate($a_changedate)
1014  {
1015  if($a_changedate == '0000-00-00 00:00:00')
1016  $this->changedate = NULL;
1017  else
1018  $this->changedate = $a_changedate;
1019  }
1020  public function getChangeDate()
1021  {
1022  return $this->changedate;
1023  }
1024  public function setImportName($a_import_name)
1025  {
1026  $this->import_name = $a_import_name;
1027  }
1028  public function getImportName()
1029  {
1030  return $this->import_name;
1031  }
1032  public function setLastPostString($a_last_post)
1033  {
1034  if($a_last_post == '') $a_last_post = NULL;
1035 
1036  $this->last_post_string = $a_last_post;
1037  }
1038  public function getLastPostString()
1039  {
1040  return $this->last_post_string;
1041  }
1042  public function setVisits($a_visits)
1043  {
1044  $this->visits = $a_visits;
1045  }
1046  public function getVisits()
1047  {
1048  return $this->visits;
1049  }
1050  public function setSticky($a_sticky)
1051  {
1052  $this->is_sticky = $a_sticky;
1053  }
1054  public function isSticky()
1055  {
1056  return $this->is_sticky == 1 ? true : false;
1057  }
1058  public function setClosed($a_closed)
1059  {
1060  $this->is_closed = $a_closed;
1061  }
1062  public function isClosed()
1063  {
1064  return $this->is_closed == 1 ? true : false;
1065  }
1066  function setOrderField($a_order_field)
1067  {
1068  $this->orderField = $a_order_field;
1069  }
1070  function getOrderField()
1071  {
1072  return $this->orderField;
1073  }
1074  function setModeratorRight($bool)
1075  {
1076  $this->is_moderator = $bool;
1077  }
1079  {
1080  return $this->is_moderator;
1081  }
1082  function getFrmObjId()
1083  {
1084  return $this->frm_obj_id;
1085  }
1086 
1095  public static function _lookupTitle($a_topic_id)
1096  {
1097  global $ilDB;
1098 
1099  $res = $ilDB->queryf('
1100  SELECT thr_subject
1101  FROM frm_threads
1102  WHERE thr_pk = %s',
1103  array('integer'), array($a_topic_id));
1104  $row = $ilDB->fetchObject($res);
1105 
1106  if(is_object($row))
1107  {
1108  return $row->thr_subject;
1109  }
1110 
1111  return '';
1112  }
1113 
1114  public function updateThreadTitle()
1115  {
1116  global $ilDB;
1117 
1118  $ilDB->update('frm_threads',
1119  array('thr_subject' => array('text',$this->getSubject())),
1120  array('thr_pk'=> array('integer', $this->getId()))
1121  );
1122  }
1123 
1128  public function setNumPosts($a_num_posts)
1129  {
1130  $this->num_posts = $a_num_posts;
1131  return $this;
1132  }
1133 
1137  public function getNumPosts()
1138  {
1139  return $this->num_posts;
1140  }
1141 
1146  public function setNumNewPosts($num_new_posts)
1147  {
1148  $this->num_new_posts = $num_new_posts;
1149  return $this;
1150  }
1151 
1155  public function getNumNewPosts()
1156  {
1157  return $this->num_new_posts;
1158  }
1159 
1164  public function setNumUnreadPosts($num_unread_posts)
1165  {
1166  $this->num_unread_posts = $num_unread_posts;
1167  return $this;
1168  }
1169 
1173  public function getNumUnreadPosts()
1174  {
1175  return $this->num_unread_posts;
1176  }
1177 
1182  public function setUserNotificationEnabled($user_notification_enabled)
1183  {
1184  $this->user_notification_enabled = $user_notification_enabled;
1185  return $this;
1186  }
1187 
1191  public function getUserNotificationEnabled()
1192  {
1193  return $this->user_notification_enabled;
1194  }
1195 
1196  public function setOrderDirection($direction)
1197  {
1198  if(!in_array(strtoupper($direction), self::$possibleOrderDirections))
1199  {
1200  $direction = current(self::$possibleOrderDirections);
1201  }
1202 
1203  $this->orderDirection = $direction;
1204  return $this;
1205  }
1206 
1207  public function getOrderDirection()
1208  {
1209  return $this->orderDirection;
1210  }
1211 
1212 }