function save_order_action() { ForumPerm::check('sort_area', $this->getId()); foreach (Request::getArray('areas') as $category_id => $areas) { $pos = 0; foreach ($areas as $area_id) { ForumPerm::checkCategoryId($this->getId(), $category_id); ForumPerm::check('sort_area', $this->getId(), $area_id); ForumCat::addArea($category_id, $area_id); ForumCat::setAreaPosition($area_id, $pos); $pos++; } } $this->render_nothing(); }
/** * Add a new forum entry to an existing one * * @post /forum_category/:category_id/areas */ public function appendForumEntry($category_id) { $category = $this->findCategory($category_id); $cid = $category['course_id']; if (!\ForumPerm::has('add_area', $cid)) { $this->error(401); } if (!isset($this->data['subject']) || !strlen($subject = trim($this->data['subject']))) { $this->error(400, 'Subject required.'); } if (!isset($this->data['content'])) { $this->error(400, 'Content required.'); } $content = trim($this->data['content']); $anonymous = isset($this->data['anonymous']) ? intval($this->data['anonymous']) : 0; $entry_id = $this->createEntry($cid, $cid, $subject, $content, $anonymous); \ForumCat::addArea($category_id, $entry_id); $this->redirect('forum_entry/' . $entry_id, 201, "ok"); }
/** * 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(); }