ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilForum.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.ilForumProperties.php';
5 require_once './Modules/Forum/classes/class.ilObjForum.php';
6 require_once './Modules/Forum/classes/class.ilForumTopic.php';
7 require_once './Modules/Forum/classes/class.ilForumPost.php';
8 
18 class ilForum
19 {
20  const SORT_TITLE = 1;
21  const SORT_DATE = 2;
22 
28  public $ilias;
29  public $lng;
30 
37  private $dbTable;
38 
44  private $className="ilForum";
45 
52  private $orderField;
53 
54  private $mdb2Query;
55  private $mdb2DataValue;
56  private $mdb2DataType;
57 
58  private $txtQuote1 = "[quote]";
59  private $txtQuote2 = "[/quote]";
60  private $replQuote1 = '<blockquote class="ilForumQuote">';
61  private $replQuote2 = '</blockquote>';
62 
63  // max. datasets per page
64  private $pageHits = 30;
65 
66  // object id
67  private $id;
68 
73  public function __construct()
74  {
75  global $ilias,$lng;
76 
77  $this->ilias = $ilias;
78  $this->lng = $lng;
79  }
80 
81  public function setLanguage($lng)
82  {
83  $this->lng = $lng;
84  }
85 
96  public static function _getLanguageInstanceByUsrId($usr_id)
97  {
98  static $lngCache = array();
99 
100  $languageShorthandle = ilObjUser::_lookupLanguage($usr_id);
101 
102  // lookup in cache array
103  if(!isset($lngCache[$languageShorthandle]))
104  {
105  $lngCache[$languageShorthandle] = new ilLanguage($languageShorthandle);
106  $lngCache[$languageShorthandle]->loadLanguageModule('forum');
107  }
108 
109  return $lngCache[$languageShorthandle];
110  }
111 
117  public function setForumId($a_obj_id)
118  {
119 
120  if (!isset($a_obj_id))
121  {
122  $message = get_class($this)."::setForumId(): No obj_id given!";
123  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
124  }
125 
126  $this->id = $a_obj_id;
127  }
128 
134  public function setForumRefId($a_ref_id)
135  {
136  if (!isset($a_ref_id))
137  {
138  $message = get_class($this)."::setForumRefId(): No ref_id given!";
139  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
140  }
141 
142  $this->ref_id = $a_ref_id;
143  }
144 
150  public function getForumId()
151  {
152  return $this->id;
153  }
154 
160  public function getForumRefId()
161  {
162  return $this->ref_id;
163  }
164 
171  private function setOrderField($orderField)
172  {
173  if ($orderField == "")
174  {
175  die($this->className . "::setOrderField(): No orderField given.");
176  }
177  else
178  {
179  $this->orderField = $orderField;
180  }
181  }
182 
189  public function getOrderField()
190  {
191  return $this->orderField;
192  }
193 
200  public function setDbTable($dbTable)
201  {
202  if ($dbTable == "")
203  {
204  die($this->className . "::setDbTable(): No database table given.");
205  }
206  else
207  {
208  $this->dbTable = $dbTable;
209  }
210  }
211 
218  public function getDbTable()
219  {
220  return $this->dbTable;
221  }
222 
223 
233  public function setMDB2WhereCondition($query_string, $data_type, $data_value)
234  {
235  $this->mdb2Query = $query_string;
236  $this->mdb2DataValue = $data_value;
237  $this->mdb2DataType = $data_type;
238 
239  return true;
240  }
241 
242 
248  public function getMDB2Query()
249  {
250  if($this->mdb2Query != '')
251  {
252  return $this->mdb2Query;
253  }
254 
255  }
256 
262  public function getMDB2DataValue()
263  {
264  if($this->mdb2DataValue != '')
265  {
266  return $this->mdb2DataValue;
267  }
268  }
269 
275  public function getMDB2DataType()
276  {
277  if($this->mdb2DataType != '')
278  {
279  return $this->mdb2DataType;
280  }
281  }
282 
289  public function setPageHits($pageHits)
290  {
291  if ($pageHits < 1)
292  {
293  die($this->className . "::setPageHits(): No int pageHits given.");
294  }
295  else
296  {
297  $this->pageHits = $pageHits;
298  return true;
299  }
300  }
301 
308  public function getPageHits()
309  {
310  return $this->pageHits;
311  }
312 
313  // *******************************************************************************
314 
320  public function getOneTopic()
321  {
322  global $ilDB;
323 
324  $data_type = array();
325  $data_value = array();
326 
327  $query = 'SELECT * FROM frm_data WHERE ';
328 
329  if($this->getMDB2Query() != '' && $this->getMDB2DataType() != '' && $this->getMDB2DataValue() != '')
330  {
331  $query .= ''.$this->getMDB2Query().'';
332  $data_type = $data_type + $this->getMDB2DataType();
333  $data_value = $data_value + $this->getMDB2DataValue();
334 
335  $res = $ilDB->queryf($query, $data_type, $data_value);
336  $row = $ilDB->fetchAssoc($res);
337 
338  if(is_null($row)) return NULL;
339 
340  $row["top_name"] = trim($row["top_name"]);
341  $row["top_description"] = nl2br($row["top_description"]);
342 
343  return $row;
344 
345  }
346  else
347  {
348  $query .= '1 = 1';
349 
350  $res = $ilDB->query($query);
351  $row = $ilDB->fetchAssoc($res);
352 
353  if(!is_array($row) || !count($row)) return null;
354 
355  $row['top_name'] = trim($row['top_name']);
356  $row['top_description'] = nl2br($row['top_description']);
357 
358  return $row;
359  }
360  }
361 
367  public function getOneThread()
368  {
369  global $ilDB;
370 
371  $data_type = array();
372  $data_value = array();
373 
374  $query = 'SELECT * FROM frm_threads WHERE ';
375 
376  if($this->getMDB2Query() != '' && $this->getMDB2DataType() != '' && $this->getMDB2DataValue() != '')
377  {
378  $query .= $this->getMDB2Query();
379  $data_type = $data_type + $this->getMDB2DataType();
380  $data_value = $data_value + $this->getMDB2DataValue();
381 
382  $sql_res = $ilDB->queryf($query, $data_type, $data_value);
383  $result = $ilDB->fetchAssoc($sql_res);
384  $result["thr_subject"] = trim($result["thr_subject"]);
385  }
386 
387  return $result;
388  }
389 
396  public function getOnePost($post)
397  {
398  global $ilDB;
399 
400  $res = $ilDB->queryf('
401  SELECT frm_posts.*, usr_data.lastname FROM frm_posts, usr_data
402  WHERE pos_pk = %s
403  AND pos_usr_id = usr_id',
404  array('integer'), array($post));
405 
406  $row = $ilDB->fetchAssoc($res);
407 
408 
409  $row["pos_date"] = $this->convertDate($row["pos_date"]);
410  $row["pos_message"] = nl2br($row["pos_message"]);
411 
412  return $row;
413  }
414 
415  public function _lookupPostMessage($a_id)
416  {
417  global $ilDB;
418 
419  $res = $ilDB->queryf('
420  SELECT * FROM frm_posts WHERE pos_pk = %s',
421  array('integer'), array($a_id));
422 
423  while($row = $ilDB->fetchObject($res))
424  {
425  return $row->pos_message;
426  }
427  return '';
428  }
429 
444  public function generatePost($forum_id, $thread_id, $user, $message, $parent_pos, $notify, $subject = '', $alias = '', $date = '', $status = 1, $send_activation_mail = 0)
445  {
446  global $ilUser, $ilDB;
447 
448  $objNewPost = new ilForumPost();
449  $objNewPost->setForumId($forum_id);
450  $objNewPost->setThreadId($thread_id);
451  $objNewPost->setSubject($subject);
452  $objNewPost->setMessage($message);
453  $objNewPost->setUserId($user);
454  $objNewPost->setUserAlias($alias);
455  if ($date == "")
456  {
457  $objNewPost->setCreateDate(date("Y-m-d H:i:s"));
458  }
459  else
460  {
461  if (strpos($date, "-") > 0) // in mysql format
462  {
463  $objNewPost->setCreateDate($date);
464  }
465  else // a timestamp
466  {
467  $objNewPost->setCreateDate(date("Y-m-d H:i:s", $date));
468  }
469  }
470 
471  $objNewPost->setImportName($this->getImportName());
472  $objNewPost->setNotification($notify);
473  $objNewPost->setStatus($status);
474  $objNewPost->insert();
475 
476  // entry in tree-table
477  if ($parent_pos == 0)
478  {
479  $this->addPostTree($objNewPost->getThreadId(), $objNewPost->getId(), $objNewPost->getCreateDate());
480  }
481  else
482  {
483  $this->insertPostNode($objNewPost->getId(), $parent_pos, $objNewPost->getThreadId(), $objNewPost->getCreateDate());
484  }
485 //echo "<br>->".$objNewPost->getId()."-".$parent_pos."-".$objNewPost->getThreadId()."-".
486 // $objNewPost->getCreateDate()."-".$forum_id."-".$message."-".$user."-";
487  // string last post
488  $lastPost = $objNewPost->getForumId()."#".$objNewPost->getThreadId()."#".$objNewPost->getId();
489 
490  // update thread
491  $result = $ilDB->manipulateF('
492  UPDATE frm_threads
493  SET thr_num_posts = thr_num_posts + 1,
494  thr_last_post = %s
495  WHERE thr_pk = %s',
496  array('text', 'integer'),
497  array($lastPost, $objNewPost->getThreadId()));
498 
499  // update forum
500  $result = $ilDB->manipulateF('
501  UPDATE frm_data
502  SET top_num_posts = top_num_posts + 1,
503  top_last_post = %s
504  WHERE top_pk = %s',
505  array('text', 'integer'),
506  array($lastPost, $objNewPost->getForumId()));
507 
508  // MARK READ
509  $forum_obj = ilObjectFactory::getInstanceByRefId($this->getForumRefId());
510  $forum_obj->markPostRead($objNewPost->getUserId(), $objNewPost->getThreadId(), $objNewPost->getId());
511 
512  $pos_data = $objNewPost->getDataAsArray();
513  $pos_data["ref_id"] = $this->getForumRefId();
514 
515  // Send notification to moderators if they have to enable a post
516 
517  if (!$status && $send_activation_mail)
518  {
519  $pos_data["top_name"] = $forum_obj->getTitle();
520  $this->sendPostActivationNotification($pos_data);
521  }
522 
523  // Add Notification to news
524  if ($status)
525  {
526  require_once 'Services/RTE/classes/class.ilRTE.php';
527  include_once("./Services/News/classes/class.ilNewsItem.php");
528  $news_item = new ilNewsItem();
529  $news_item->setContext($forum_obj->getId(), 'frm', $objNewPost->getId(), 'pos');
530  $news_item->setPriority(NEWS_NOTICE);
531  $news_item->setTitle($objNewPost->getSubject());
532  $news_item->setContent(ilRTE::_replaceMediaObjectImageSrc($this->prepareText($objNewPost->getMessage(), 0), 1));
533  $news_item->setUserId($user);
534  $news_item->setVisibility(NEWS_USERS);
535  $news_item->create();
536  }
537 
538  return $objNewPost->getId();
539  }
540 
554  public function generateThread($forum_id, $user, $subject, $message, $notify, $notify_posts, $alias = '', $date = '')
555  {
556  global $ilDB;
557 
558  $objNewThread = new ilForumTopic();
559  $objNewThread->setForumId($forum_id);
560  $objNewThread->setUserId($user);
561  $objNewThread->setSubject($subject);
562  if ($date == "")
563  {
564  $objNewThread->setCreateDate(date("Y-m-d H:i:s"));
565  }
566  else
567  {
568  if (strpos($date, "-") > 0) // in mysql format
569  {
570  $objNewThread->setCreateDate($date);
571  }
572  else // a timestamp
573  {
574  $objNewThread->setCreateDate(date("Y-m-d H:i:s", $date));
575  }
576  }
577  $objNewThread->setImportName($this->getImportName());
578  $objNewThread->setUserAlias($alias);
579  $objNewThread->insert();
580 
581  if ($notify_posts == 1)
582  {
583  $objNewThread->enableNotification($user);
584  }
585 
586  // update forum
587  $statement = $ilDB->manipulateF('
588  UPDATE frm_data
589  SET top_num_threads = top_num_threads + 1
590  WHERE top_pk = %s',
591  array('integer'), array($forum_id));
592 
593  return $this->generatePost($forum_id, $objNewThread->getId(), $user, $message, 0, $notify, $subject, $alias, $objNewThread->getCreateDate());
594  }
595 
604  public function moveThreads($thread_ids = array(), $src_ref_id = 0, $dest_top_frm_fk = 0)
605  {
606  global $ilDB;
607 
608  $src_top_frm_fk = ilObject::_lookupObjectId($src_ref_id);
609 
610  if (is_numeric($src_top_frm_fk) && $src_top_frm_fk > 0 && is_numeric($dest_top_frm_fk) && $dest_top_frm_fk > 0)
611  {
612 
613  $this->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($src_top_frm_fk));
614 
615  $oldFrmData = $this->getOneTopic();
616 
617  $this->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($dest_top_frm_fk));
618 
619  $newFrmData = $this->getOneTopic();
620 
621  if ($oldFrmData['top_pk'] && $newFrmData['top_pk'])
622  {
623  $moved_posts = 0;
624  $moved_threads = 0;
625  $visits = 0;
626  foreach ($thread_ids as $id)
627  {
628  $objTmpThread = new ilForumTopic($id);
629 
630  $numPosts = $objTmpThread->movePosts($src_top_frm_fk, $oldFrmData['top_pk'], $dest_top_frm_fk, $newFrmData['top_pk']);
631  if (($last_post_string = $objTmpThread->getLastPostString()) != '')
632  {
633  $last_post_string = explode('#', $last_post_string);
634  $last_post_string[0] = $newFrmData['top_pk'];
635  $last_post_string = implode('#', $last_post_string);
636  $objTmpThread->setLastPostString($last_post_string);
637  }
638 
639  $visits += $objTmpThread->getVisits();
640 
641  $moved_posts += $numPosts;
642  ++$moved_threads;
643 
644  $objTmpThread->setForumId($newFrmData['top_pk']);
645  $objTmpThread->update();
646 
647  unset($objTmpThread);
648  }
649 
650  // update frm_data source forum
651  $ilDB->setLimit(1);
652  $res = $ilDB->queryf('
653  SELECT pos_thr_fk, pos_pk
654  FROM frm_posts
655  WHERE pos_top_fk = %s
656  ORDER BY pos_date DESC',
657  array('integer'), array($oldFrmData['top_pk']));
658 
659  $row = $ilDB->fetchObject($res);
660  $last_post_src = $oldFrmData['top_pk'] . '#' . $row->pos_thr_fk . '#' . $row->pos_pk;
661 
662  $statement = $ilDB->manipulateF('
663  UPDATE frm_data
664  SET top_num_posts = top_num_posts - %s,
665  top_num_threads = top_num_threads - %s,
666  visits = visits - %s,
667  top_last_post = %s
668  WHERE top_pk = %s',
669  array('integer', 'integer', 'integer', 'text', 'integer'),
670  array( $moved_posts,
671  $moved_threads,
672  $visits,
673  $last_post_src,
674  $oldFrmData['top_pk']));
675 
676  // update frm_data destination forum
677 
678  $ilDB->setLimit(1);
679  $res = $ilDB->queryf('
680  SELECT pos_thr_fk, pos_pk
681  FROM frm_posts
682  WHERE pos_top_fk = %s
683  ORDER BY pos_date DESC',
684  array('integer'), array($newFrmData['top_kp']));
685 
686  $row = $ilDB->fetchObject($res);
687  $last_post_dest = $newFrmData['top_pk'] . '#' . $row->pos_thr_fk . '#' . $row->pos_pk;
688 
689  $statement = $ilDB->manipulateF('
690  UPDATE frm_data
691  SET top_num_posts = top_num_posts + %s,
692  top_num_threads = top_num_threads + %s,
693  visits = visits + %s,
694  top_last_post = %s
695  WHERE top_pk = %s',
696  array('integer', 'integer', 'integer', 'text', 'integer'),
697  array($moved_posts, $moved_threads, $visits, $last_post_dest, $newFrmData['top_pk']));
698 
699  /*
700  // update news items
701  include_once("./Services/News/classes/class.ilNewsItem.php");
702  $objNewsItem = new ilNewsItem();
703  $news_items = $objNewsItem->getNewsForRefId($src_ref_id);
704  foreach ($news_items as $news_item)
705  {
706  $tmpObjNewsItem = new ilNewsItem($news_item['id']);
707  if ($tmpObjNewsItem->getContextObjId() == $src_top_frm_fk)
708  {
709  $tmpObjNewsItem->setContextObjId($dest_top_frm_fk);
710  $tmpObjNewsItem->update();
711  }
712  unset($tmpObjNewsItem);
713  }
714  */
715  }
716  }
717 }
718 
719 
727  public function postCensorship($message, $pos_pk, $cens = 0)
728  {
729  global $ilDB;
730 
731  $statement = $ilDB->manipulateF('
732  UPDATE frm_posts
733  SET pos_cens_com = %s,
734  pos_update = %s,
735  pos_cens = %s,
736  update_user = %s
737  WHERE pos_pk = %s',
738  array('text', 'timestamp', 'integer', 'integer', 'integer'),
739  array($message, date("Y-m-d H:i:s"), $cens, $_SESSION['AccountId'], $pos_pk));
740 
741  // Change news item accordingly
742  include_once("./Services/News/classes/class.ilNewsItem.php");
743  $news_id = ilNewsItem::getFirstNewsIdForContext($this->id,
744  "frm", $pos_pk, "pos");
745  if ($news_id > 0)
746  {
747  if ($cens > 0) // censor
748  {
749  $news_item = new ilNewsItem($news_id);
750  //$news_item->setTitle($subject);
751  $news_item->setContent(nl2br($this->prepareText($message, 0)));
752  $news_item->update();
753  }
754  else // revoke censorship
755  {
756  // get original message
757  $res = $ilDB->queryf('
758  SELECT * FROM frm_posts
759  WHERE pos_pk = %s',
760  array('integer'), array($pos_pk));
761 
762  $rec = $ilDB->fetchAssoc($res);
763 
764  $news_item = new ilNewsItem($news_id);
765  //$news_item->setTitle($subject);
766  $news_item->setContent(nl2br($this->prepareText($rec["pos_message"], 0)));
767  $news_item->update();
768  }
769  }
770 
771  return true;
772  }
773 
780  public function deletePost($post)
781  {
782  global $ilDB;
783 
784  include_once "./Modules/Forum/classes/class.ilObjForum.php";
785 
786  // delete tree and get id's of all posts to delete
787  $p_node = $this->getPostNode($post);
788  $del_id = $this->deletePostTree($p_node);
789 
790 
791  // Delete User read entries
792  foreach($del_id as $post_id)
793  {
794  ilObjForum::_deleteReadEntries($post_id);
795  }
796 
797  // DELETE ATTACHMENTS ASSIGNED TO POST
798  $this->__deletePostFiles($del_id);
799 
800  $dead_pos = count($del_id);
801  $dead_thr = 0;
802 
803  // if deletePost is thread opener ...
804  if ($p_node["parent"] == 0)
805  {
806  // delete thread access data
807  include_once './Modules/Forum/classes/class.ilObjForum.php';
808 
809  ilObjForum::_deleteAccessEntries($p_node['tree']);
810 
811  // delete thread
812  $dead_thr = $p_node["tree"];
813 
814  $statement = $ilDB->manipulateF('
815  DELETE FROM frm_threads
816  WHERE thr_pk = %s',
817  array('integer'), array($p_node['tree']));
818 
819  // update num_threads
820  $statement = $ilDB->manipulateF('
821  UPDATE frm_data
822  SET top_num_threads = top_num_threads - 1
823  WHERE top_frm_fk = %s',
824  array('integer'), array($this->id));
825 
826  // delete all related news
827  $posset = $ilDB->queryf('
828  SELECT * FROM frm_posts
829  WHERE pos_thr_fk = %s',
830  array('integer'), array($p_node['tree']));
831 
832  while ($posrec = $ilDB->fetchAssoc($posset))
833  {
834  include_once("./Services/News/classes/class.ilNewsItem.php");
835  $news_id = ilNewsItem::getFirstNewsIdForContext($this->id,
836  "frm", $posrec["pos_pk"], "pos");
837  if ($news_id > 0)
838  {
839  $news_item = new ilNewsItem($news_id);
840  $news_item->delete();
841  }
842 
843  try
844  {
845  include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
846  $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', $posrec['pos_pk']);
847  foreach($mobs as $mob)
848  {
849  if(ilObjMediaObject::_exists($mob))
850  {
851  ilObjMediaObject::_removeUsage($mob, 'frm:html', $posrec['pos_pk']);
852  $mob_obj = new ilObjMediaObject($mob);
853  $mob_obj->delete();
854  }
855  }
856  }
857  catch(Exception $e)
858  {
859  }
860  }
861 
862 
863  // delete all posts of this thread
864  $statement = $ilDB->manipulateF('
865  DELETE FROM frm_posts
866  WHERE pos_thr_fk = %s',
867  array('integer'), array($p_node['tree']));
868 
869  }
870  else
871  {
872 
873  // delete this post and its sub-posts
874  for ($i = 0; $i < $dead_pos; $i++)
875  {
876  $statement = $ilDB->manipulateF('
877  DELETE FROM frm_posts
878  WHERE pos_pk = %s',
879  array('integer'), array($del_id[$i]));
880 
881  // delete related news item
882  include_once("./Services/News/classes/class.ilNewsItem.php");
883  $news_id = ilNewsItem::getFirstNewsIdForContext($this->id,
884  "frm", $del_id[$i], "pos");
885  if ($news_id > 0)
886  {
887  $news_item = new ilNewsItem($news_id);
888  $news_item->delete();
889  }
890 
891  try
892  {
893  include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
894  $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', $del_id[$i]);
895  foreach($mobs as $mob)
896  {
897  if(ilObjMediaObject::_exists($mob))
898  {
899  ilObjMediaObject::_removeUsage($mob, 'frm:html', $del_id[$i]);
900  $mob_obj = new ilObjMediaObject($mob);
901  $mob_obj->delete();
902  }
903  }
904  }
905  catch(Exception $e)
906  {
907  }
908  }
909 
910  // update num_posts in frm_threads
911  $statement = $ilDB->manipulateF('
912  UPDATE frm_threads
913  SET thr_num_posts = thr_num_posts - %s
914  WHERE thr_pk = %s',
915  array('integer', 'integer'),
916  array($dead_pos, $p_node['tree']));
917 
918 
919  // get latest post of thread and update last_post
920  $res1 = $ilDB->queryf('
921  SELECT * FROM frm_posts
922  WHERE pos_thr_fk = %s
923  ORDER BY pos_date DESC',
924  array('integer'), array($p_node['tree']));
925 
926  if ($res1->numRows() == 0)
927  {
928  $lastPost_thr = "";
929  }
930  else
931  {
932  $z = 0;
933 
934  while ($selData = $ilDB->fetchAssoc($res1))
935  {
936  if ($z > 0)
937  {
938  break;
939  }
940 
941  $lastPost_thr = $selData["pos_top_fk"]."#".$selData["pos_thr_fk"]."#".$selData["pos_pk"];
942  $z ++;
943  }
944  }
945 
946  $statement = $ilDB->manipulateF('
947  UPDATE frm_threads
948  SET thr_last_post = %s
949  WHERE thr_pk = %s',
950  array('text', 'integer'), array($lastPost_thr, $p_node['tree']));
951  }
952 
953  // update num_posts in frm_data
954  $statement = $ilDB->manipulateF('
955  UPDATE frm_data
956  SET top_num_posts = top_num_posts - %s
957  WHERE top_frm_fk = %s',
958  array('integer', 'integer'), array($dead_pos, $this->id));
959 
960 
961  // get latest post of forum and update last_post
962  $res2 = $ilDB->queryf('
963  SELECT * FROM frm_posts, frm_data
964  WHERE pos_top_fk = top_pk
965  AND top_frm_fk = %s
966  ORDER BY pos_date DESC',
967  array('integer'), array($this->id));
968 
969  if ($res2->numRows() == 0)
970  {
971  $lastPost_top = "";
972  }
973  else
974  {
975  $z = 0;
976 
977  while ($selData = $ilDB->fetchAssoc($res2))
978  {
979  if ($z > 0)
980  {
981  break;
982  }
983 
984  $lastPost_top = $selData["pos_top_fk"]."#".$selData["pos_thr_fk"]."#".$selData["pos_pk"];
985  $z ++;
986  }
987  }
988 
989  $statement = $ilDB->manipulateF('
990  UPDATE frm_data
991  SET top_last_post = %s
992  WHERE top_frm_fk = %s',
993  array('text', 'integer'), array($lastPost_top, $this->id));
994 
995  return $dead_thr;
996  }
997 
1005  public function getAllThreads($a_topic_id, $is_moderator = false, $limit = 0, $offset = 0)
1006  {
1007  global $ilDB, $ilUser;
1008 
1009  // Count all threads for the passed forum
1010  $query = 'SELECT COUNT(thr_pk) cnt
1011  FROM frm_threads
1012  WHERE thr_top_fk = %s';
1013  $res = $ilDB->queryF($query, array('integer'), array($a_topic_id));
1014  $data = $ilDB->fetchAssoc($res);
1015  $cnt = (int) $data['cnt'];
1016 
1017  $threads = array();
1018 
1019  $data = array();
1020  $data_types = array();
1021 
1022  $active_query = '';
1023  $active_inner_query = '';
1024  if(!$is_moderator)
1025  {
1026  $active_query = ' AND (pos_status = %s OR pos_usr_id = %s) ';
1027  $active_inner_query = ' AND (ipos.pos_status = %s OR ipos.pos_usr_id = %s) ';
1028  }
1029 
1030  if(!$ilUser->isAnonymous())
1031  {
1032  $query = "SELECT
1033  (CASE WHEN COUNT(DISTINCT(notification_id)) > 0 THEN 1 ELSE 0 END) usr_notification_is_enabled,
1034  MAX(pos_date) post_date,
1035  COUNT(DISTINCT(pos_pk)) num_posts,
1036 
1037  COUNT(DISTINCT(pos_pk)) - COUNT(DISTINCT(postread.post_id)) num_unread_posts,
1038 
1039  (
1040  SELECT COUNT(DISTINCT(ipos.pos_pk))
1041  FROM frm_posts ipos
1042  LEFT JOIN frm_user_read iread ON iread.post_id = ipos.pos_pk AND iread.usr_id = %s
1043  LEFT JOIN frm_thread_access iacc ON (iacc.thread_id = ipos.pos_thr_fk AND iacc.usr_id = %s)
1044  WHERE ipos.pos_thr_fk = thr_pk
1045 
1046  AND (
1047  (ipos.pos_date > iacc.access_old_ts OR ipos.pos_update > iacc.access_old_ts)
1048  OR
1049  (iacc.access_old IS NULL AND (ipos.pos_date > ".$ilDB->quote(date('Y-m-d H:i:s', NEW_DEADLINE), 'timestamp')." OR ipos.pos_update > ".$ilDB->quote(date('Y-m-d H:i:s', NEW_DEADLINE), 'timestamp')."))
1050  )
1051 
1052  AND ipos.pos_usr_id != %s
1053  AND iread.usr_id IS NULL $active_inner_query
1054  ) num_new_posts,
1055 
1056  thr_pk, thr_top_fk, thr_subject, thr_usr_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed
1057 
1058  FROM frm_threads
1059 
1060  LEFT JOIN frm_notification
1061  ON frm_notification.thread_id = thr_pk
1062  AND frm_notification.user_id = %s
1063 
1064  LEFT JOIN frm_posts
1065  ON pos_thr_fk = thr_pk $active_query
1066 
1067  LEFT JOIN frm_user_read postread
1068  ON postread.post_id = pos_pk
1069  AND postread.usr_id = %s
1070 
1071  WHERE thr_top_fk = %s
1072  GROUP BY thr_pk, thr_top_fk, thr_subject, thr_usr_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed
1073  ORDER BY is_sticky DESC, post_date DESC, thr_date DESC";
1074 
1075  $data_types[] = 'integer';
1076  $data_types[] = 'integer';
1077  $data_types[] = 'integer';
1078  if(!$is_moderator)
1079  {
1080  array_push($data_types, 'integer', 'integer');
1081  }
1082  $data_types[] = 'integer';
1083  if(!$is_moderator)
1084  {
1085  array_push($data_types, 'integer', 'integer');
1086  }
1087  $data_types[] = 'integer';
1088  $data_types[] = 'integer';
1089 
1090  $data[] = $ilUser->getId();
1091  $data[] = $ilUser->getId();
1092  $data[] = $ilUser->getId();
1093  if(!$is_moderator)
1094  {
1095  array_push($data, '1', $ilUser->getId());
1096  }
1097  $data[] = $ilUser->getId();
1098  if(!$is_moderator)
1099  {
1100  array_push($data, '1', $ilUser->getId());
1101  }
1102  $data[] = $ilUser->getId();
1103  $data[] = $a_topic_id;
1104  }
1105  else
1106  {
1107  $query = "SELECT
1108  0 usr_notification_is_enabled,
1109  MAX(pos_date) post_date,
1110  COUNT(DISTINCT(pos_pk)) num_posts,
1111  COUNT(DISTINCT(pos_pk)) num_unread_posts,
1112  COUNT(DISTINCT(pos_pk)) num_new_posts,
1113  thr_pk, thr_top_fk, thr_subject, thr_usr_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed
1114  FROM frm_threads
1115 
1116  LEFT JOIN frm_posts
1117  ON pos_thr_fk = thr_pk $active_query";
1118 
1119 
1120  $query .= " WHERE thr_top_fk = %s
1121  GROUP BY thr_pk, thr_top_fk, thr_subject, thr_usr_id, thr_usr_alias, thr_num_posts, thr_last_post, thr_date, thr_update, visits, frm_threads.import_name, is_sticky, is_closed
1122  ORDER BY is_sticky DESC, thr_date DESC";
1123 
1124  if(!$is_moderator)
1125  {
1126  array_push($data_types, 'integer', 'integer');
1127  }
1128  $data_types[] = 'integer';
1129 
1130  if(!$is_moderator)
1131  {
1132  array_push($data, '1', $ilUser->getId());
1133  }
1134  $data[] = $a_topic_id;
1135  }
1136 
1137  if($limit || $offset)
1138  {
1139  $ilDB->setLimit($limit, $offset);
1140  }
1141  $res = $ilDB->queryF($query, $data_types, $data);
1142  while($row = $ilDB->fetchAssoc($res))
1143  {
1144  $thread = new ilForumTopic($row['thr_pk'], $is_moderator, true);
1145  $thread->assignData($row);
1146  $threads[] = $thread;
1147  }
1148 
1149  return array(
1150  'items' => $threads,
1151  'cnt' => $cnt
1152  );
1153  }
1154 
1155  public function getUserStatistic($is_moderator = false)
1156  {
1157  global $ilDB, $ilUser;
1158 
1159  $statistic = array();
1160 
1161  $data_types = array();
1162  $data = array();
1163 
1164  $query = "SELECT COUNT(f.pos_usr_id) ranking, u.login, p.value, u.lastname, u.firstname
1165  FROM frm_posts f
1166  INNER JOIN frm_posts_tree t
1167  ON f.pos_pk = t.pos_fk
1168  INNER JOIN frm_threads th
1169  ON t.thr_fk = th.thr_pk
1170  INNER JOIN usr_data u
1171  ON u.usr_id = f.pos_usr_id
1172  INNER JOIN frm_data d
1173  ON d.top_pk = f.pos_top_fk
1174  LEFT JOIN usr_pref p
1175  ON p.usr_id = u.usr_id AND p.keyword = %s
1176  WHERE 1 = 1";
1177 
1178  array_push($data_types, 'text');
1179  array_push($data, 'public_profile');
1180 
1181  if (!$is_moderator)
1182  {
1183  $query .= ' AND (pos_status = %s
1184  OR (pos_status = %s
1185  AND pos_usr_id = %s ))';
1186 
1187  array_push($data_types,'integer', 'integer', 'integer');
1188  array_push($data, '1', '0', $ilUser->getId());
1189  }
1190 
1191  $query .= ' AND d.top_frm_fk = %s
1192  GROUP BY pos_usr_id, u.login, p.value,u.lastname, u.firstname';
1193 
1194  array_push($data_types,'integer');
1195  array_push($data, $this->getForumId());
1196 
1197  $res = $ilDB->queryf($query, $data_types, $data);
1198 
1199  $counter = 0;
1200  while ($row = $ilDB->fetchAssoc($res))
1201  {
1202  $statistic[$counter][] = $row['ranking'];
1203  $statistic[$counter][] = $row['login'];
1204 
1205  $lastname = '';
1206  $firstname = '';
1207 
1208  if(!$ilUser->getId() == ANONYMOUS_USER_ID && in_array($row['value'], array('y', 'g')) ||
1209  $ilUser->getId() == ANONYMOUS_USER_ID && 'g' == $row['value'])
1210  {
1211  $lastname = $row['lastname'];
1212  $firstname = $row['firstname'];
1213  }
1214 
1215  $statistic[$counter][] = $lastname;
1216  $statistic[$counter][] = $firstname;
1217  ++$counter;
1218  }
1219 
1220  return is_array($statistic) ? $statistic : array();
1221  }
1222 
1223 
1231  public function getFirstPostByThread($a_thread_id)
1232  {
1233  global $ilDB;
1234 
1235  $res = $ilDB->queryf('
1236  SELECT * FROM frm_posts_tree
1237  WHERE thr_fk = %s
1238  AND parent_pos = %s',
1239  array('integer', 'integer'), array($a_thread_id, '0'));
1240 
1241  $row = $ilDB->fetchObject($res);
1242 
1243  return $row->pos_fk ? $row->pos_fk : 0;
1244  }
1245 
1252  public function getModerators()
1253  {
1254  global $rbacreview;
1255 
1256  return $this->_getModerators($this->getForumRefId());
1257  }
1258 
1266  function _getModerators($a_ref_id)
1267  {
1268  global $rbacreview;
1269 
1270  $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
1271  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1272 
1273  foreach ($role_arr as $role_id)
1274  {
1275  //$roleObj = $this->ilias->obj_factory->getInstanceByObjId($role_id);
1276  $title = ilObject::_lookupTitle($role_id);
1277  if ($title == "il_frm_moderator_".$a_ref_id)
1278  {
1279  #return $rbacreview->assignedUsers($roleObj->getId());
1280  return $title = $rbacreview->assignedUsers($role_id);
1281  }
1282  }
1283 
1284  return array();
1285  }
1286 
1295  public static function _isModerator($a_ref_id, $a_usr_id)
1296  {
1297  return in_array($a_usr_id, ilForum::_getModerators($a_ref_id));
1298  }
1299 
1307  public function countUserArticles($a_user_id)
1308  {
1309  global $ilDB;
1310 
1311  $res = $ilDB->queryf('
1312  SELECT * FROM frm_data
1313  INNER JOIN frm_posts ON pos_top_fk = top_pk
1314  WHERE top_frm_fk = %s
1315  AND pos_usr_id = %s',
1316  array('integer', 'integer'),
1317  array($this->getForumId(), $a_user_id));
1318 
1319  return $res->numRows();
1320  }
1321 
1322  public function countActiveUserArticles($a_user_id)
1323  {
1324  global $ilDB, $ilUser;
1325 
1326  $res = $ilDB->queryf('
1327  SELECT * FROM frm_data
1328  INNER JOIN frm_posts ON pos_top_fk = top_pk
1329  WHERE top_frm_fk = %s
1330  AND (pos_status = %s
1331  OR (pos_status = %s
1332  AND pos_usr_id = %s
1333  )
1334  )
1335  AND pos_usr_id = %s',
1336  array('integer', 'integer', 'integer', 'integer', 'integer'),
1337  array($this->getForumId(),'1', '0', $ilUser->getId(), $a_user_id));
1338 
1339  return $res->numRows();
1340  }
1341 
1348  public function convertDate($date)
1349  {
1351  }
1352 
1360  public function addPostTree($a_tree_id, $a_node_id = -1, $a_date = '')
1361  {
1362  global $ilDB;
1363 
1364  $a_date = $a_date ? $a_date : date("Y-m-d H:i:s");
1365 
1366  if ($a_node_id <= 0)
1367  {
1368  $a_node_id = $a_tree_id;
1369  }
1370 
1371  $nextId = $ilDB->nextId('frm_posts_tree');
1372 
1373  $statement = $ilDB->manipulateF('
1374  INSERT INTO frm_posts_tree
1375  ( fpt_pk,
1376  thr_fk,
1377  pos_fk,
1378  parent_pos,
1379  lft,
1380  rgt,
1381  depth,
1382  fpt_date
1383  )
1384  VALUES(%s, %s, %s, %s, %s, %s, %s, %s )',
1385  array('integer','integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'timestamp'),
1386  array($nextId, $a_tree_id, $a_node_id, '0', '1', '2', '1', $a_date));
1387 
1388  return true;
1389  }
1390 
1398  public function insertPostNode($a_node_id, $a_parent_id, $tree_id, $a_date = '')
1399  {
1400  global $ilDB;
1401 
1402  $a_date = $a_date ? $a_date : date("Y-m-d H:i:s");
1403 
1404  // get left value
1405  $sql_res = $ilDB->queryf('
1406  SELECT * FROM frm_posts_tree
1407  WHERE pos_fk = %s
1408  AND thr_fk = %s',
1409  array('integer', 'integer'),
1410  array($a_parent_id, $tree_id));
1411 
1412  $res = $ilDB->fetchObject($sql_res);
1413 
1414  $left = $res->lft;
1415 
1416  $lft = $left + 1;
1417  $rgt = $left + 2;
1418 
1419  // spread tree
1420  $statement = $ilDB->manipulateF('
1421  UPDATE frm_posts_tree
1422  SET lft = CASE
1423  WHEN lft > %s
1424  THEN lft + 2
1425  ELSE lft
1426  END,
1427  rgt = CASE
1428  WHEN rgt > %s
1429  THEN rgt + 2
1430  ELSE rgt
1431  END
1432  WHERE thr_fk = %s',
1433  array('integer', 'integer', 'integer'),
1434  array($left, $left, $tree_id));
1435 
1436  $depth = $this->getPostDepth($a_parent_id, $tree_id) + 1;
1437 
1438  // insert node
1439  $nextId = $ilDB->nextId('frm_posts_tree');
1440  $statement = $ilDB->manipulateF('
1441  INSERT INTO frm_posts_tree
1442  ( fpt_pk,
1443  thr_fk,
1444  pos_fk,
1445  parent_pos,
1446  lft,
1447  rgt,
1448  depth,
1449  fpt_date
1450  )
1451  VALUES(%s,%s,%s, %s, %s, %s,%s, %s)',
1452  array('integer','integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'timestamp'),
1453  array( $nextId,
1454  $tree_id,
1455  $a_node_id,
1456  $a_parent_id,
1457  $lft,
1458  $rgt,
1459  $depth,
1460  $a_date)
1461  );
1462 
1463  }
1464 
1472  public function getPostDepth($a_node_id, $tree_id)
1473  {
1474  global $ilDB;
1475 
1476  if ($tree_id)
1477  {
1478  $sql_res = $ilDB->queryf('
1479  SELECT depth FROM frm_posts_tree
1480  WHERE pos_fk = %s
1481  AND thr_fk = %s',
1482  array('integer', 'integer'),
1483  array($a_node_id, $tree_id));
1484 
1485  $res = $ilDB->fetchObject($sql_res);
1486 
1487  return $res->depth;
1488  }
1489  else
1490  {
1491  return 0;
1492  }
1493  }
1494 
1501  public function getFirstPostNode($tree_id)
1502  {
1503  global $ilDB;
1504 
1505  $res = $ilDB->queryf('
1506  SELECT * FROM frm_posts, frm_posts_tree
1507  WHERE pos_pk = pos_fk
1508  AND parent_pos = %s
1509  AND thr_fk = %s',
1510  array('integer', 'integer'),
1511  array('0', $tree_id));
1512 
1513  $row = $ilDB->fetchObject($res);
1514 
1515  return $this->fetchPostNodeData($row);
1516  }
1517 
1524  public function getPostNode($post_id)
1525  {
1526  global $ilDB;
1527 
1528  $res = $ilDB->queryf('
1529  SELECT * FROM frm_posts, frm_posts_tree
1530  WHERE pos_pk = pos_fk
1531  AND pos_pk = %s',
1532  array('integer'),
1533  array($post_id));
1534 
1535  $row = $ilDB->fetchObject($res);
1536 
1537  return $this->fetchPostNodeData($row);
1538  }
1539 
1546  public function fetchPostNodeData($a_row)
1547  {
1548  global $lng;
1549 
1550  require_once('./Services/User/classes/class.ilObjUser.php');
1551 
1552  if (ilObject::_exists($a_row->pos_usr_id))
1553  {
1554  $tmp_user = new ilObjUser($a_row->pos_usr_id);
1555  $fullname = $tmp_user->getFullname();
1556  $loginname = $tmp_user->getLogin();
1557  }
1558 
1559  $fullname = $fullname ? $fullname : ($a_row->import_name ? $a_row->import_name : $lng->txt("unknown"));
1560 
1561  $data = array(
1562  "pos_pk" => $a_row->pos_pk,
1563  "child" => $a_row->pos_pk,
1564  "author" => $a_row->pos_usr_id,
1565  "alias" => $a_row->pos_usr_alias,
1566  "title" => $fullname,
1567  "loginname" => $loginname,
1568  "type" => "post",
1569  "message" => $a_row->pos_message,
1570  "subject" => $a_row->pos_subject,
1571  "pos_cens_com" => $a_row->pos_cens_com,
1572  "pos_cens" => $a_row->pos_cens,
1573  // "date" => $a_row->date,
1574  "date" => $a_row->fpt_date,
1575  "create_date" => $a_row->pos_date,
1576  "update" => $a_row->pos_update,
1577  "update_user" => $a_row->update_user,
1578  "tree" => $a_row->thr_fk,
1579  "parent" => $a_row->parent_pos,
1580  "lft" => $a_row->lft,
1581  "rgt" => $a_row->rgt,
1582  "depth" => $a_row->depth,
1583  "id" => $a_row->fpt_pk,
1584  "notify" => $a_row->notify,
1585  "import_name" => $a_row->import_name,
1586  "pos_status" => $a_row->pos_status
1587  );
1588 
1589  // why this line? data should be stored without slashes in db
1590  //$data["message"] = stripslashes($data["message"]);
1591 
1592  return $data ? $data : array();
1593  }
1594 
1601  public function deletePostTree($a_node)
1602  {
1603  global $ilDB;
1604 
1605  // GET LEFT AND RIGHT VALUES
1606  $res = $ilDB->queryf('
1607  SELECT * FROM frm_posts_tree
1608  WHERE thr_fk = %s
1609  AND pos_fk = %s
1610  AND parent_pos = %s',
1611  array('integer', 'integer', 'integer'),
1612  array($a_node['tree'], $a_node['pos_pk'], $a_node['parent']));
1613 
1614  while($row = $ilDB->fetchObject($res))
1615  {
1616  $a_node["lft"] = $row->lft;
1617  $a_node["rgt"] = $row->rgt;
1618  }
1619 
1620  $diff = $a_node["rgt"] - $a_node["lft"] + 1;
1621 
1622  // get data of posts
1623  $result = $ilDB->queryf('
1624  SELECT * FROM frm_posts_tree
1625  WHERE lft BETWEEN %s AND %s
1626  AND thr_fk = %s',
1627  array('integer', 'integer', 'integer'),
1628  array($a_node['lft'], $a_node['rgt'], $a_node['tree']));
1629 
1630  $del_id = array();
1631 
1632  while ($treeData = $ilDB->fetchAssoc($result))
1633  {
1634  $del_id[] = $treeData["pos_fk"];
1635  }
1636 
1637  // delete subtree
1638  $statement = $ilDB->manipulateF('
1639  DELETE FROM frm_posts_tree
1640  WHERE lft BETWEEN %s AND %s
1641  AND thr_fk = %s',
1642  array('integer', 'integer', 'integer'),
1643  array($a_node['lft'], $a_node['rgt'], $a_node['tree']));
1644 
1645 
1646  // close gaps
1647  $statement = $ilDB->manipulateF('
1648  UPDATE frm_posts_tree
1649  SET lft = CASE
1650  WHEN lft > %s
1651  THEN lft - %s
1652  ELSE lft
1653  END,
1654  rgt = CASE
1655  WHEN rgt > %s
1656  THEN rgt - %s
1657  ELSE rgt
1658  END
1659  WHERE thr_fk = %s',
1660  array('integer', 'integer', 'integer', 'integer', 'integer'),
1661  array($a_node['lft'], $diff, $a_node['lft'], $diff, $a_node['tree']));
1662 
1663  return $del_id;
1664 
1665  }
1666 
1672  public function updateVisits($ID)
1673  {
1674 
1675  global $ilDB;
1676 
1677  $checkTime = time() - (60*60);
1678 
1679  if ($_SESSION["frm_visit_".$this->dbTable."_".$ID] < $checkTime)
1680  {
1681 
1682  $_SESSION["frm_visit_".$this->dbTable."_".$ID] = time();
1683  $query = 'UPDATE '.$this->dbTable.' SET visits = visits + 1 WHERE ';
1684 
1685  $data_type = array();
1686  $data_value = array();
1687 
1688  if($this->getMDB2Query() != '' && $this->getMDB2DataType() != '' && $this->getMDB2DataValue() != '')
1689  {
1690  $query .= $this->getMDB2Query();
1691  $data_type = $data_type + $this->getMDB2DataType();
1692  $data_value = $data_value + $this->getMDB2DataValue();
1693 
1694  $res = $ilDB->queryf($query, $data_type, $data_value);
1695  }
1696  }
1697  }
1698 
1706  public function prepareText($text, $edit=0, $quote_user = '', $type = '')
1707  {
1708  global $lng;
1709 
1710  if($type == 'export')
1711  {
1712  $this->replQuote1 = "<blockquote class=\"quote\"><hr size=\"1\" color=\"#000000\">";
1713  $this->replQuote2 = "<hr size=\"1\" color=\"#000000\"/></blockquote>";
1714  }
1715 
1716  if($edit == 1)
1717  {
1718  // add login name of quoted users
1719  $lname = ($quote_user != "")
1720  ? '="'.$quote_user.'"'
1721  : "";
1722 
1723  $text = "[quote$lname]".$text."[/quote]";
1724  }
1725  else
1726  {
1727  // check for quotation
1728  $startZ = substr_count ($text, "[quote"); // also count [quote="..."]
1729  $endZ = substr_count ($text, "[/quote]");
1730 
1731  if ($startZ > 0 || $endZ > 0)
1732  {
1733  // add missing opening and closing tags
1734  if ($startZ > $endZ)
1735  {
1736  $diff = $startZ - $endZ;
1737 
1738  for ($i = 0; $i < $diff; $i++)
1739  {
1740  if ($type == 'export') $text .= $this->txtQuote2;
1741  else $text .= "[/quote]";
1742  }
1743  }
1744  elseif ($startZ < $endZ)
1745  {
1746  $diff = $endZ - $startZ;
1747 
1748  for ($i = 0; $i < $diff; $i++)
1749  {
1750  if ($type == 'export') $text = $this->txtQuote1.$text;
1751  else $text = "[quote]".$text;
1752  }
1753  }
1754 
1755  if($edit == 0)
1756  {
1757  $ws= "[ \t\r\f\v\n]*";
1758 
1759  $text = eregi_replace("\[(quote$ws=$ws\"([^\"]*)\"$ws)\]",
1760  $this->replQuote1.'<div class="ilForumQuoteHead">'.$lng->txt("quote")." (\\2)".'</div>', $text);
1761 
1762  $text = str_replace("[quote]",
1763  $this->replQuote1.'<div class="ilForumQuoteHead">'.$lng->txt("quote").'</div>', $text);
1764 
1765  $text = str_replace("[/quote]", $this->replQuote2, $text);
1766  }
1767  }
1768  }
1769 
1770  if($type != 'export')
1771  {
1772  if($edit == 0)
1773  {
1774  $text = ilUtil::insertLatexImages($text, "<span class\=\"latex\">", "<\/span>");
1775  $text = ilUtil::insertLatexImages($text, "\[tex\]", "\[\/tex\]");
1776  }
1777 
1778  // workaround for preventing template engine
1779  // from hiding text that is enclosed
1780  // in curly brackets (e.g. "{a}")
1781  $text = str_replace("{", "&#123;", $text);
1782  $text = str_replace("}", "&#125;", $text);
1783  }
1784 
1785  return $text;
1786  }
1787 
1788 
1795  public function getModeratorFromPost($pos_pk)
1796  {
1797  global $ilDB;
1798 
1799  $res = $ilDB->queryf('
1800  SELECT frm_data.* FROM frm_data, frm_posts
1801  WHERE pos_pk = %s
1802  AND pos_top_fk = top_pk',
1803  array('integer'), array($pos_pk));
1804 
1805  $row = $ilDB->fetchAssoc($res);
1806 
1807  return $row;
1808 
1809  }
1810 
1811  function __deletePostFiles($a_ids)
1812  {
1813  if(!is_array($a_ids))
1814  {
1815  return false;
1816  }
1817  include_once "./Modules/Forum/classes/class.ilFileDataForum.php";
1818 
1819  $tmp_file_obj =& new ilFileDataForum($this->getForumId());
1820  foreach($a_ids as $pos_id)
1821  {
1822  $tmp_file_obj->setPosId($pos_id);
1823  $files = $tmp_file_obj->getFilesOfPost();
1824  foreach($files as $file)
1825  {
1826  $tmp_file_obj->unlinkFile($file["name"]);
1827  }
1828  }
1829  unset($tmp_file_obj);
1830  return true;
1831  }
1832 
1833 
1834  function __sendMessage($a_parent_pos, $post_data = array())
1835  {
1836  global $ilUser, $ilDB;
1837 
1838  $parent_data = $this->getOnePost($a_parent_pos);
1839 
1840  // only if the current user is not the owner of the parent post and the parent's notification flag is set...
1841  if($parent_data["notify"] && $parent_data["pos_usr_id"] != $ilUser->getId())
1842  {
1843  // SEND MESSAGE
1844  include_once "Services/Mail/classes/class.ilMail.php";
1845  include_once './Services/User/classes/class.ilObjUser.php';
1846 
1847  $tmp_user =& new ilObjUser($parent_data["pos_usr_id"]);
1848 
1849  // NONSENSE
1850  $this->setMDB2WhereCondition('thr_pk = %s ', array('integer'), array($parent_data["pos_thr_fk"]));
1851 
1852  $thread_data = $this->getOneThread();
1853 
1854  $tmp_mail_obj = new ilMail(ANONYMOUS_USER_ID);
1855  $message = $tmp_mail_obj->sendMail($tmp_user->getLogin(),"","",
1856  $this->formatNotificationSubject($post_data),
1857  $this->__formatMessage($thread_data, $post_data, $tmp_user),
1858  array(),array("system"));
1859 
1860  unset($tmp_user);
1861  unset($tmp_mail_obj);
1862  }
1863  }
1864 
1873  private function __formatMessage($thread_data, $post_data = array(), $user_obj)
1874  {
1875  include_once "./Services/Object/classes/class.ilObjectFactory.php";
1876  $user_lang = self::_getLanguageInstanceByUsrId($user_obj->getId());
1877 
1878  $frm_obj =& ilObjectFactory::getInstanceByRefId($this->getForumRefId());
1879  $title = $frm_obj->getTitle();
1880  unset($frm_obj);
1881 
1882  $message = '';
1883  $message .= ilMail::getSalutation($user_obj->getId(), $user_lang);
1884 
1885  $message .= "\n\n";
1886  $message .= $this->lng->txt("forum_post_replied");
1887  $message .= $this->lng->txt("forum").": ".$title." -> ".$thread_data["thr_subject"]."\n\n";
1888 
1889  $message .= "\n------------------------------------------------------------\n";
1890  $message .= $post_data["pos_message"];
1891  $message .= "\n------------------------------------------------------------\n";
1892  $message .= sprintf($this->lng->txt("forums_notification_show_post"), "http://".$_SERVER["HTTP_HOST"].dirname($_SERVER["PHP_SELF"])."/goto.php?target=frm_".$post_data["ref_id"]."_".$post_data["pos_thr_fk"].'&client_id='.CLIENT_ID)."\n\n";
1893 
1894  $message .= ilMail::_getInstallationSignature();
1895  return $message;
1896  }
1897 
1898  function getImportName()
1899  {
1900  return $this->import_name;
1901  }
1902  function setImportName($a_import_name)
1903  {
1904  $this->import_name = $a_import_name;
1905  }
1906 
1913  function enableForumNotification($user_id)
1914  {
1915  global $ilDB;
1916 
1917  if (!$this->isForumNotificationEnabled($user_id))
1918  {
1919  /* Remove all notifications of threads that belong to the forum */
1920 
1921  $res = $ilDB->queryf('
1922  SELECT frm_notification.thread_id FROM frm_data, frm_notification, frm_threads
1923  WHERE frm_notification.user_id = %s
1924  AND frm_notification.thread_id = frm_threads.thr_pk
1925  AND frm_threads.thr_top_fk = frm_data.top_pk
1926  AND frm_data.top_frm_fk = %s
1927  GROUP BY frm_notification.thread_id',
1928  array('integer', 'integer'),
1929  array($user_id, $this->id));
1930 
1931  if (is_object($res) && $res->numRows() > 0)
1932  {
1933  $thread_data = array();
1934  $thread_data_types = array();
1935 
1936  $query = ' DELETE FROM frm_notification
1937  WHERE user_id = %s
1938  AND thread_id IN (';
1939 
1940  array_push($thread_data, $user_id);
1941  array_push($thread_data_types, 'integer');
1942 
1943  $counter = 1;
1944 
1945  while($row = $ilDB->fetchAssoc($res))
1946  {
1947  if($counter < $res->numRows())
1948  {
1949  $query .= '%s, ';
1950  array_push($thread_data, $row['thread_id']);
1951  array_push($thread_data_types, 'integer');
1952  }
1953 
1954  if($counter == $res->numRows())
1955  {
1956  $query .= '%s)';
1957  array_push($thread_data, $row['thread_id']);
1958  array_push($thread_data_types, 'integer');
1959 
1960  }
1961  $counter++;
1962  }
1963 
1964  $statement = $ilDB->manipulateF($query, $thread_data_types, $thread_data);
1965  }
1966 
1967  /* Insert forum notification */
1968 
1969  $nextId = $ilDB->nextId('frm_notification');
1970 
1971  $statement = $ilDB->manipulateF('
1972  INSERT INTO frm_notification
1973  ( notification_id,
1974  user_id,
1975  frm_id
1976  )
1977  VALUES(%s, %s, %s)',
1978  array('integer','integer', 'integer'),
1979  array($nextId, $user_id, $this->id));
1980 
1981  }
1982 
1983  return true;
1984  }
1985 
1992  function disableForumNotification($user_id)
1993  {
1994  global $ilDB;
1995 
1996  $statement = $ilDB->manipulateF('
1997  DELETE FROM frm_notification
1998  WHERE user_id = %s
1999  AND frm_id = %s',
2000  array('integer', 'integer'),
2001  array($user_id, $this->id));
2002 
2003  return true;
2004  }
2005 
2012  function isForumNotificationEnabled($user_id)
2013  {
2014  global $ilDB;
2015 
2016  $result = $ilDB->queryf('SELECT COUNT(*) cnt FROM frm_notification WHERE user_id = %s AND frm_id = %s',
2017  array('integer', 'integer'), array($user_id, $this->id));
2018 
2019  while($record = $ilDB->fetchAssoc($result))
2020  {
2021  return (bool)$record['cnt'];
2022  }
2023 
2024  return false;
2025  }
2026 
2034  function enableThreadNotification($user_id, $thread_id)
2035  {
2036  global $ilDB;
2037 
2038  if (!$this->isThreadNotificationEnabled($user_id, $thread_id))
2039  {
2040  $nextId = $ilDB->nextId('frm_notification');
2041  $statement = $ilDB->manipulateF('
2042  INSERT INTO frm_notification
2043  ( notification_id,
2044  user_id,
2045  thread_id
2046  )
2047  VALUES (%s, %s, %s)',
2048  array('integer', 'integer', 'integer'), array($nextId, $user_id, $thread_id));
2049 
2050  }
2051 
2052  return true;
2053  }
2054 
2062  function isThreadNotificationEnabled($user_id, $thread_id)
2063  {
2064  global $ilDB;
2065 
2066  $result = $ilDB->queryf('
2067  SELECT COUNT(*) cnt FROM frm_notification
2068  WHERE user_id = %s
2069  AND thread_id = %s',
2070  array('integer', 'integer'),
2071  array($user_id, $thread_id));
2072 
2073 
2074  while($record = $ilDB->fetchAssoc($result))
2075  {
2076  return (bool)$record['cnt'];
2077  }
2078 
2079  return false;
2080  }
2081 
2082  function sendThreadNotifications($post_data)
2083  {
2084  global $ilDB, $ilAccess, $lng;
2085 
2086  include_once "Services/Mail/classes/class.ilMail.php";
2087  include_once './Services/User/classes/class.ilObjUser.php';
2088 
2089  // GET THREAD DATA
2090  $result = $ilDB->queryf('
2091  SELECT thr_subject FROM frm_threads
2092  WHERE thr_pk = %s',
2093  array('integer'), array($post_data['pos_thr_fk']));
2094 
2095  while($record = $ilDB->fetchAssoc($result))
2096  {
2097  $post_data['thr_subject'] = $record['thr_subject'];
2098  break;
2099  }
2100 
2101  // determine obj_id of the forum
2102  $obj_id = self::_lookupObjIdForForumId($post_data['pos_top_fk']);
2103 
2104  // GET AUTHOR OF NEW POST
2105  if($post_data['pos_usr_id'])
2106  {
2107  $post_data['pos_usr_name'] = ilObjUser::_lookupLogin($post_data['pos_usr_id']);
2108  }
2109  else if(strlen($post_data['pos_usr_alias']))
2110  {
2111  $post_data['pos_usr_name'] = $post_data['pos_usr_alias'].' ('.$lng->txt('frm_pseudonym').')';
2112  }
2113 
2114  if($post_data['pos_usr_name'] == '')
2115  {
2116  $post_data['pos_usr_name'] = $this->lng->txt('forums_anonymous');
2117  }
2118 
2119  // GET USERS WHO WANT TO BE INFORMED ABOUT NEW POSTS
2120  $res = $ilDB->queryf('
2121  SELECT user_id FROM frm_notification
2122  WHERE thread_id = %s
2123  AND user_id <> %s',
2124  array('integer', 'integer'),
2125  array($post_data['pos_thr_fk'], $_SESSION['AccountId']));
2126 
2127  // get all references of obj_id
2128  $frm_references = ilObject::_getAllReferences($obj_id);
2129 
2130  // save language of the current user
2131  global $lng;
2132  $userLanguage = $lng;
2133 
2134  // get attachments data
2135  $fileDataForum = new ilFileDataForum($obj_id, $post_data['pos_pk']);
2136  $filesOfPost = $fileDataForum->getFilesOfPost();
2137 
2138  $attachments = array();
2139  foreach($filesOfPost as $attachment)
2140  {
2141  $attachments[] = $attachment['name'];
2142  }
2143 
2144  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
2145  while($row = $ilDB->fetchAssoc($res))
2146  {
2147  // do rbac check before sending notification
2148  $send_mail = false;
2149  foreach((array)$frm_references as $ref_id)
2150  {
2151  if($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id))
2152  {
2153  $send_mail = true;
2154  break;
2155  }
2156  }
2157 
2158  if($send_mail)
2159  {
2160  $this->setLanguage(self::_getLanguageInstanceByUsrId($row['user_id']));
2161  $mail_obj->sendMail(
2162  ilObjUser::_lookupLogin($row["user_id"]), "", "",
2163  $this->formatNotificationSubject($post_data),
2164  $this->formatNotification($post_data, 0, $attachments, $row['user_id']),
2165  array(), array("system")
2166  );
2167  }
2168  }
2169 
2170  // reset language
2171  $this->setLanguage($userLanguage);
2172  }
2173 
2174  function sendForumNotifications($post_data)
2175  {
2176  global $ilDB, $ilAccess, $lng, $ilUser;
2177 
2178  include_once "Services/Mail/classes/class.ilMail.php";
2179  include_once './Services/User/classes/class.ilObjUser.php';
2180 
2181  // GET THREAD DATA
2182  $result = $ilDB->queryf('
2183  SELECT thr_subject FROM frm_threads
2184  WHERE thr_pk = %s',
2185  array('integer'),
2186  array($post_data['pos_thr_fk']));
2187 
2188  while($record = $ilDB->fetchAssoc($result))
2189  {
2190  $post_data['thr_subject'] = $record['thr_subject'];
2191  break;
2192  }
2193 
2194  // determine obj_id of the forum
2195  $obj_id = self::_lookupObjIdForForumId($post_data['pos_top_fk']);
2196 
2197  // GET AUTHOR OF NEW POST
2198  if($post_data['pos_usr_id'])
2199  {
2200  $post_data['pos_usr_name'] = ilObjUser::_lookupLogin($post_data['pos_usr_id']);
2201  }
2202  else if(strlen($post_data['pos_usr_alias']))
2203  {
2204  $post_data['pos_usr_name'] = $post_data['pos_usr_alias'].' ('.$lng->txt('frm_pseudonym').')';
2205  }
2206 
2207  if($post_data['pos_usr_name'] == '')
2208  {
2209  $post_data['pos_usr_name'] = $this->lng->txt('forums_anonymous');
2210  }
2211 
2212  // GET USERS WHO WANT TO BE INFORMED ABOUT NEW POSTS
2213  $res = $ilDB->queryf('
2214  SELECT frm_notification.user_id FROM frm_notification, frm_data
2215  WHERE frm_data.top_pk = %s
2216  AND frm_notification.frm_id = frm_data.top_frm_fk
2217  AND frm_notification.user_id <> %s
2218  GROUP BY frm_notification.user_id',
2219  array('integer', 'integer'),
2220  array($post_data['pos_top_fk'], $ilUser->getId()));
2221 
2222  // get all references of obj_id
2223  $frm_references = ilObject::_getAllReferences($obj_id);
2224 
2225  // save language of the current user
2226  global $lng;
2227  $userLanguage = $lng;
2228 
2229  // get attachments data
2230  $fileDataForum = new ilFileDataForum($obj_id, $post_data['pos_pk']);
2231  $filesOfPost = $fileDataForum->getFilesOfPost();
2232  $attachments = array();
2233  foreach($filesOfPost as $attachment)
2234  {
2235  $attachments[] = $attachment['name'];
2236  }
2237 
2238  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
2239  while($row = $ilDB->fetchAssoc($res))
2240  {
2241  // do rbac check before sending notification
2242  $send_mail = false;
2243  foreach((array)$frm_references as $ref_id)
2244  {
2245  if($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id))
2246  {
2247  $send_mail = true;
2248  break;
2249  }
2250  }
2251 
2252  if($send_mail)
2253  {
2254  $this->setLanguage(self::_getLanguageInstanceByUsrId($row['user_id']));
2255  $mail_obj->sendMail(
2256  ilObjUser::_lookupLogin($row["user_id"]), "", "",
2257  $this->formatNotificationSubject($post_data),
2258  $this->formatNotification($post_data, 0, $attachments, $row['user_id']),
2259  array(), array("system")
2260  );
2261  }
2262  }
2263 
2264  // reset language
2265  $this->setLanguage($userLanguage);
2266  }
2267 
2273  private function formatPostActivationNotification($post_data, $user_id)
2274  {
2275  $user_lang = self::_getLanguageInstanceByUsrId($user_id);
2276 
2277  $message = "";
2278  $message .= ilMail::getSalutation($user_id, $user_lang);
2279  $message .= "\n\n";
2280  $message .= $this->lng->txt('forums_post_activation_mail')."\n\n";
2281 
2282  $message .= $this->lng->txt("forum").": ".$post_data["top_name"]."\n\n";
2283  $message .= $this->lng->txt("thread").": ".$post_data["thr_subject"]."\n\n";
2284  $message .= $this->lng->txt("new_post").":\n------------------------------------------------------------\n";
2285  $message .= $this->lng->txt("author").": ".$post_data["pos_usr_name"]."\n";
2286  $message .= $this->lng->txt("date").": ".$post_data["pos_date"]."\n";
2287  $message .= $this->lng->txt("subject").": ".$post_data["pos_subject"]."\n\n";
2288  if ($post_data["pos_cens"] == 1)
2289  {
2290  $message .= $post_data["pos_cens_com"]."\n";
2291  }
2292  else
2293  {
2294  $pos_message = $post_data['pos_message'];
2295  if(strip_tags($pos_message) != $pos_message)
2296  {
2297  $pos_message = preg_replace("/\n/i", "", $pos_message);
2298  $pos_message = preg_replace("/<br(\s*)(\/?)>/i", "\n", $pos_message);
2299  $pos_message = preg_replace("/<p([^>]*)>/i", "\n\n", $pos_message);
2300  $pos_message = preg_replace("/<\/p([^>]*)>/i", '', $pos_message);
2301  }
2302  $message .= strip_tags($pos_message)."\n";
2303  }
2304  $message .= "------------------------------------------------------------\n";
2305 
2306  $message .= sprintf($this->lng->txt('forums_notification_show_post'), ILIAS_HTTP_PATH."/goto.php?target=frm_".$post_data["ref_id"]."_".$post_data["pos_thr_fk"]."_".$post_data["pos_pk"].'&client_id='.CLIENT_ID)."\n\n";
2307  $message .= sprintf($this->lng->txt('forums_notification_intro'),
2308  $this->ilias->ini->readVariable('client', 'name'),
2309  ILIAS_HTTP_PATH.'/?client_id='.CLIENT_ID)."\n\n";
2310 
2311  return $message;
2312  }
2313 
2314  function sendPostActivationNotification($post_data)
2315  {
2316  global $ilDB, $ilUser, $lng;
2317 
2318  if (is_array($moderators = $this->getModerators()))
2319  {
2320  // GET THREAD DATA
2321  $result = $ilDB->queryf('
2322  SELECT thr_subject FROM frm_threads
2323  WHERE thr_pk = %s',
2324  array('integer'),
2325  array($post_data['pos_thr_fk']));
2326 
2327  while($record = $ilDB->fetchAssoc($result))
2328  {
2329  $post_data['thr_subject'] = $record['thr_subject'];
2330  break;
2331  }
2332 
2333  // GET AUTHOR OF NEW POST
2334  if($post_data['pos_usr_id'])
2335  {
2336  $post_data['pos_usr_name'] = ilObjUser::_lookupLogin($post_data['pos_usr_id']);
2337  }
2338  else if(strlen($post_data['pos_usr_alias']))
2339  {
2340  $post_data['pos_usr_name'] = $post_data['pos_usr_alias'].' ('.$lng->txt('frm_pseudonym').')';
2341  }
2342 
2343  if($post_data['pos_usr_name'] == '')
2344  {
2345  $post_data['pos_usr_name'] = $this->lng->txt('forums_anonymous');
2346  }
2347 
2348  // save language of the current user
2349  global $lng;
2350  $userLanguage = $lng;
2351 
2352  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
2353  foreach($moderators as $moderator)
2354  {
2355  // set forum language instance for earch user
2356  $this->setLanguage(self::_getLanguageInstanceByUsrId($moderator));
2357  $subject = $this->formatNotificationSubject($post_data);
2358  $message = $this->formatPostActivationNotification($post_data, $moderator);
2359  $mail_obj->sendMail(
2360  ilObjUser::_lookupLogin($moderator), '', '',
2361  $subject,
2362  $message,
2363  array(), array("system")
2364  );
2365  }
2366 
2367  // reset language
2368  $this->setLanguage($userLanguage);
2369  }
2370  }
2371 
2376  public function formatNotificationSubject($post_data)
2377  {
2378  return $this->lng->txt("forums_notification_subject").' '.$post_data['top_name'];
2379  }
2380 
2388  public function formatNotification($post_data, $cron = 0, $attachments = array(), $user_id)
2389  {
2390  global $ilIliasIniFile;
2391 
2392  $user_lang = self::_getLanguageInstanceByUsrId($user_id);
2393 
2394  $message = "";
2395 
2396  $message .= ilMail::getSalutation($user_id, $user_lang);
2397  $message .= "\n\n";
2398  $message .= $this->lng->txt("forums_notification_subject")." ".$post_data['top_name']."\n\n";
2399 
2400  $message .= $this->lng->txt("forum").": ".$post_data["top_name"]."\n\n";
2401  $message .= $this->lng->txt("thread").": ".$post_data["thr_subject"]."\n\n";
2402  $message .= $this->lng->txt("new_post").":\n------------------------------------------------------------\n";
2403  $message .= $this->lng->txt("author").": ".$post_data["pos_usr_name"]."\n";
2404  $message .= $this->lng->txt("date").": ".$post_data["pos_date"]."\n";
2405  $message .= $this->lng->txt("subject").": ".$post_data["pos_subject"]."\n\n";
2406 
2407  if ($post_data["pos_cens"] == 1)
2408  {
2409  $message .= $post_data["pos_cens_com"]."\n";
2410  }
2411  else
2412  {
2413  $pos_message = $post_data['pos_message'];
2414  if(strip_tags($pos_message) != $pos_message)
2415  {
2416  $pos_message = preg_replace("/\n/i", "", $pos_message);
2417  $pos_message = preg_replace("/<br(\s*)(\/?)>/i", "\n", $pos_message);
2418  $pos_message = preg_replace("/<p([^>]*)>/i", "\n\n", $pos_message);
2419  $pos_message = preg_replace("/<\/p([^>]*)>/i", '', $pos_message);
2420  }
2421  $message .= strip_tags($pos_message)."\n";
2422  }
2423  $message .= "------------------------------------------------------------\n";
2424 
2425  if(count($attachments) > 0)
2426  {
2427  foreach($attachments as $attachment)
2428  {
2429  $message .= $this->lng->txt('attachment').": ".$attachment."\n";
2430  }
2431  $message .= "\n------------------------------------------------------------\n";
2432  }
2433 
2434  if ($cron == 1)
2435  {
2436  $message .= sprintf($this->lng->txt("forums_notification_show_post"), $ilIliasIniFile->readVariable("server","http_path")."/goto.php?target=frm_".$post_data["ref_id"]."_".$post_data["pos_thr_fk"]."_".$post_data["pos_pk"].'&client_id='.CLIENT_ID)."\n\n";
2437  }
2438  else
2439  {
2440  $message .= sprintf($this->lng->txt("forums_notification_show_post"), ILIAS_HTTP_PATH."/goto.php?target=frm_".$post_data["ref_id"]."_".$post_data["pos_thr_fk"]."_".$post_data["pos_pk"].'&client_id='.CLIENT_ID)."\n\n";
2441  }
2442 
2443  if ($cron == 1)
2444  {
2445  $message .= sprintf($this->lng->txt("forums_notification_intro"),
2446  $this->ilias->ini->readVariable("client","name"),
2447  $ilIliasIniFile->readVariable("server","http_path").'/?client_id='.CLIENT_ID)."\n\n";
2448  }
2449  else
2450  {
2451  $message .= sprintf($this->lng->txt("forums_notification_intro"),
2452  $this->ilias->ini->readVariable("client","name"),
2453  ILIAS_HTTP_PATH.'/?client_id='.CLIENT_ID)."\n\n";
2454  }
2455 
2456  return $message;
2457  }
2458 
2468  public static function _getThreads($a_obj_id,$a_sort_mode = self::SORT_DATE)
2469  {
2470  global $ilDB;
2471 
2472  switch($a_sort_mode)
2473  {
2474  case self::SORT_DATE:
2475  $sort = 'thr_date';
2476  break;
2477 
2478  case self::SORT_TITLE:
2479  default:
2480  $sort = 'thr_subject';
2481  break;
2482  }
2483 
2484  $res = $ilDB->queryf('
2485  SELECT * FROM frm_threads
2486  JOIN frm_data ON top_pk = thr_top_fk
2487  WHERE top_frm_fk = %s
2488  ORDER BY %s',
2489  array('integer', 'text'), array($a_obj_id, $sort));
2490 
2491  while($row = $ilDB->fetchObject($res))
2492  {
2493  $threads[$row->thr_pk] = $row->thr_subject;
2494  }
2495  return $threads ? $threads : array();
2496  }
2497 
2498  function _lookupObjIdForForumId($a_for_id)
2499  {
2500  global $ilDB;
2501 
2502  $res = $ilDB->queryf('
2503  SELECT top_frm_fk FROM frm_data
2504  WHERE top_pk = %s',
2505  array('integer'), array($a_for_id));
2506 
2507  if ($fdata = $ilDB->fetchAssoc($res))
2508  {
2509  return $fdata["top_frm_fk"];
2510  }
2511  return false;
2512  }
2513 
2514 } // END class.Forum