Пример #1
0
 /**
  * Create/Update the linked posting for the passed issue_id
  * 
  * @param string $seminar_id
  * @param string $issue_id    issue id to link to
  * @param string $title       (new) title of the posting
  * @param string $content     (new) content of the posting
  */
 static function setThreadForIssue($seminar_id, $issue_id, $title, $content)
 {
     if ($topic_id = self::getThreadIdForIssue($issue_id)) {
         // update
         ForumEntry::update($topic_id, $title ?: _('Ohne Titel'), $content);
     } else {
         // create
         // make sure the forum is set up properly
         ForumEntry::checkRootEntry($seminar_id);
         $topic_id = md5(uniqid(rand()));
         ForumEntry::insert(array('topic_id' => $topic_id, 'seminar_id' => $seminar_id, 'user_id' => $GLOBALS['user']->id, 'name' => $title ?: _('Ohne Titel'), 'content' => $content, 'author' => get_fullname($GLOBALS['user']->id), 'author_host' => getenv('REMOTE_ADDR')), $seminar_id);
         $stmt = DBManager::get()->prepare("INSERT INTO forum_entries_issues\n                (issue_id, topic_id) VALUES (?, ?)");
         $stmt->execute(array($issue_id, $topic_id));
     }
 }
Пример #2
0
 /**
  * the main action for the forum. May be called with a topic_id to be displayed
  * and optionally the page to display
  * 
  * @param type $topic_id the topic to display, defaults to the main
  *                       view of the current seminar
  * @param type $page the page to be displayed (for thread-view)
  */
 function index_action($topic_id = null, $page = null)
 {
     $nav = Navigation::getItem('course/forum2');
     $nav->setImage(Icon::create('forum', 'info'));
     Navigation::activateItem('course/forum2/index');
     // check, if the root entry is present
     ForumEntry::checkRootEntry($this->getId());
     /* * * * * * * * * * * * * * * * * * *
      * V A R I A B L E N   F U E L L E N *
      * * * * * * * * * * * * * * * * * * */
     $this->section = 'index';
     $this->topic_id = $topic_id ? $topic_id : $this->getId();
     $this->constraint = ForumEntry::getConstraints($this->topic_id);
     // check if there has been submitted an invalid id and use seminar_id in case
     if (!$this->constraint) {
         $this->topic_id = $this->getId();
         $this->constraint = ForumEntry::getConstraints($this->topic_id);
     }
     $this->highlight_topic = Request::option('highlight_topic', null);
     // set page to which we shall jump
     if ($page) {
         ForumHelpers::setPage($page);
     }
     // we do not crawl deeper than level 2, we show a page chooser instead
     if ($this->constraint['depth'] > 2) {
         ForumHelpers::setPage(ForumEntry::getPostingPage($this->topic_id, $this->constraint));
         $path = ForumEntry::getPathToPosting($this->topic_id);
         array_shift($path);
         array_shift($path);
         $path_element = array_shift($path);
         $this->child_topic = $this->topic_id;
         $this->topic_id = $path_element['id'];
         $this->constraint = ForumEntry::getConstraints($this->topic_id);
     }
     // check if the topic_id matches the currently selected seminar
     ForumPerm::checkTopicId($this->getId(), $this->topic_id);
     /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
      * B E R E I C H E / T H R E A D S / P O S T I N G S   L A D E N *
      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
     // load list of areas for use in thread-movement
     if (ForumPerm::has('move_thread', $this->getId())) {
         $this->areas = ForumEntry::getList('flat', $this->getId());
     }
     if ($this->constraint['depth'] > 1) {
         // POSTINGS
         $list = ForumEntry::getList('postings', $this->topic_id);
         if (!empty($list['list'])) {
             $this->postings = $list['list'];
             $this->number_of_entries = $list['count'];
         }
     } else {
         if ($this->constraint['depth'] == 0) {
             // BEREICHE
             $list = ForumEntry::getList('area', $this->topic_id);
         } else {
             $list = ForumEntry::getList('list', $this->topic_id);
         }
         if ($this->constraint['depth'] == 0) {
             // BEREICHE
             $new_list = array();
             // iterate over all categories and add the belonging areas to them
             foreach ($categories = ForumCat::getListWithAreas($this->getId(), false) as $category) {
                 if ($category['topic_id']) {
                     $new_list[$category['category_id']][$category['topic_id']] = $list['list'][$category['topic_id']];
                     unset($list['list'][$category['topic_id']]);
                 } else {
                     if (ForumPerm::has('add_area', $this->seminar_id)) {
                         $new_list[$category['category_id']] = array();
                     }
                 }
                 $this->categories[$category['category_id']] = $category['entry_name'];
             }
             if (!empty($list['list'])) {
                 // append the remaining entries to the standard category
                 $new_list[$this->getId()] = array_merge((array) $new_list[$this->getId()], $list['list']);
             }
             // check, if there are any orphaned entries
             foreach ($new_list as $key1 => $list_item) {
                 foreach ($list_item as $key2 => $contents) {
                     if (empty($contents)) {
                         // remove the orphaned entry from the list and from the database
                         unset($new_list[$key1][$key2]);
                         ForumCat::removeArea($key2);
                     }
                 }
             }
             $this->list = $new_list;
         } else {
             if ($this->constraint['depth'] == 1) {
                 // THREADS
                 if (!empty($list['list'])) {
                     $this->list = array($list['list']);
                 }
             }
         }
         $this->number_of_entries = $list['count'];
     }
     // set the visit-date and get the stored last_visitdate
     $this->visitdate = ForumVisit::getLastVisit($this->getId());
     $this->seminar_id = $this->getId();
     // highlight text if passed some words to highlight
     if (Request::getArray('highlight')) {
         $this->highlight = Request::optionArray('highlight');
     }
     if (($this->edit_posting = Request::get('edit_posting', null)) && !ForumPerm::hasEditPerms($this->edit_posting)) {
         $this->edit_posting = null;
     }
 }