Ejemplo n.º 1
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;
     }
 }
Ejemplo n.º 2
0
 /**
  * move the submitted topics[] to the passed destination
  * 
  * @param string $destination id of seminar to move topics to
  */
 function move_action($destination)
 {
     // check if destination is a category_id. if yes, use seminar_id instead
     if (ForumCat::get($destination)) {
         $category_id = $destination;
         $destination = $this->getId();
     }
     ForumPerm::check('admin', $this->getId(), $destination);
     foreach (Request::getArray('topics') as $topic_id) {
         // make sure every passed topic_id is checked against the current seminar
         ForumPerm::check('admin', $this->getId(), $topic_id);
         // if the source is an area and the target a category, just move this area to the category
         $entry = ForumEntry::getEntry($topic_id);
         if ($entry['depth'] == 1 && $category_id) {
             ForumCat::removeArea($topic_id);
             ForumCat::addArea($category_id, $topic_id);
         } else {
             // first step: move the whole topic with all childs
             ForumEntry::move($topic_id, $destination);
             // if the current topic id is an area, remove it from any categories
             ForumCat::removeArea($topic_id);
             // second step: move all to deep childs a level up (depth > 3)
             $data = ForumEntry::getList('depth_to_large', $topic_id);
             foreach ($data['list'] as $entry) {
                 $path = ForumEntry::getPathToPosting($entry['topic_id']);
                 array_shift($path);
                 // Category
                 array_shift($path);
                 // Area
                 $thread = array_shift($path);
                 // Thread
                 ForumEntry::move($entry['topic_id'], $thread['id']);
             }
             // add entry to passed category when moving to the top
             if ($category_id) {
                 ForumCat::addArea($category_id, $topic_id);
             }
         }
     }
     $this->render_nothing();
 }