コード例 #1
0
ファイル: area.php プロジェクト: ratbird/hope
 function add_action($category_id)
 {
     ForumPerm::check('add_area', $this->getId());
     $new_id = md5(uniqid(rand()));
     if (Request::isXhr()) {
         $name = studip_utf8decode(Request::get('name', _('Kein Titel')));
         $content = studip_utf8decode(Request::get('content'));
     } else {
         $name = Request::get('name', _('Kein Titel'));
         $content = Request::get('content');
     }
     ForumEntry::insert(array('topic_id' => $new_id, 'seminar_id' => $this->getId(), 'user_id' => $GLOBALS['user']->id, 'name' => $name, 'content' => $content, 'author' => get_fullname($GLOBALS['user']->id), 'author_host' => getenv('REMOTE_ADDR')), $this->getId());
     ForumCat::addArea($category_id, $new_id);
     if (Request::isXhr()) {
         $this->set_layout(null);
         $this->entry = array_pop(ForumEntry::parseEntries(array(ForumEntry::getEntry($new_id))));
         $this->visitdate = ForumVisit::getLastVisit($this->getId());
     } else {
         $this->redirect(PluginEngine::getLink('coreforum/index/index/'));
     }
 }
コード例 #2
0
ファイル: ForumEntry.php プロジェクト: ratbird/hope
 /**
  * get a list of postings of a special type
  *
  * @param string $type one of 'area', 'list', 'postings', 'latest', 'favorites', 'dump', 'flat'
  * @param string $parent_id the are to fetch from
  * @return array array('list' => ..., 'count' => ...);
  */
 static function getList($type, $parent_id)
 {
     $start = (ForumHelpers::getPage() - 1) * ForumEntry::POSTINGS_PER_PAGE;
     switch ($type) {
         case 'area':
             $list = ForumEntry::getEntries($parent_id, ForumEntry::WITHOUT_CHILDS, '', 'DESC', 0, 1000);
             $postings = $list['list'];
             $postings = ForumEntry::getLastPostings($postings);
             return array('list' => $postings, 'count' => $list['count']);
             break;
         case 'list':
             $constraint = ForumEntry::getConstraints($parent_id);
             // purpose of the following query is to retrieve the threads
             // for an area ordered by the mkdate of their latest posting
             $stmt = DBManager::get()->prepare("SELECT SQL_CALC_FOUND_ROWS\n                        fe.*, IF(ou.topic_id IS NOT NULL, 'fav', NULL) as fav\n                    FROM forum_entries AS fe\n                    LEFT JOIN forum_favorites as ou ON (ou.topic_id = fe.topic_id AND ou.user_id = :user_id)\n                    WHERE fe.seminar_id = :seminar_id AND fe.lft > :left\n                        AND fe.rgt < :right AND fe.depth = 2\n                    ORDER BY sticky DESC, latest_chdate DESC\n                    LIMIT {$start}, " . ForumEntry::POSTINGS_PER_PAGE);
             $stmt->bindParam(':seminar_id', $constraint['seminar_id']);
             $stmt->bindParam(':left', $constraint['lft'], PDO::PARAM_INT);
             $stmt->bindParam(':right', $constraint['rgt'], PDO::PARAM_INT);
             $stmt->bindParam(':user_id', $GLOBALS['user']->id);
             $stmt->execute();
             $postings = $stmt->fetchAll(PDO::FETCH_ASSOC);
             $count = DBManager::get()->query("SELECT FOUND_ROWS()")->fetchColumn();
             $postings = ForumEntry::parseEntries($postings);
             $postings = ForumEntry::getLastPostings($postings);
             return array('list' => $postings, 'count' => $count);
             break;
         case 'postings':
             return ForumEntry::getEntries($parent_id, ForumEntry::WITH_CHILDS, '', 'ASC', $start);
             break;
         case 'newest':
             $constraint = ForumEntry::getConstraints($parent_id);
             // get postings
             $stmt = DBManager::get()->prepare("SELECT forum_entries.*, IF(ou.topic_id IS NOT NULL, 'fav', NULL) as fav\n                    FROM forum_entries\n                    LEFT JOIN forum_favorites as ou ON (ou.topic_id = forum_entries.topic_id AND ou.user_id = :user_id)\n                    WHERE seminar_id = :seminar_id AND lft > :left\n                        AND rgt < :right AND (mkdate >= :mkdate OR chdate >= :mkdate)\n                    ORDER BY mkdate ASC\n                    LIMIT {$start}, " . ForumEntry::POSTINGS_PER_PAGE);
             $stmt->bindParam(':seminar_id', $constraint['seminar_id']);
             $stmt->bindParam(':left', $constraint['lft']);
             $stmt->bindParam(':right', $constraint['rgt']);
             $stmt->bindParam(':mkdate', ForumVisit::getLastVisit($constraint['seminar_id']));
             $stmt->bindParam(':user_id', $GLOBALS['user']->id);
             $stmt->execute();
             $postings = $stmt->fetchAll(PDO::FETCH_ASSOC);
             $postings = ForumEntry::parseEntries($postings);
             // var_dump($postings);
             // count found postings
             $stmt_count = DBManager::get()->prepare("SELECT COUNT(*)\n                    FROM forum_entries\n                    WHERE seminar_id = :seminar_id AND lft > :left\n                        AND rgt < :right AND mkdate >= :mkdate\n                    ORDER BY mkdate ASC");
             $stmt_count->bindParam(':seminar_id', $constraint['seminar_id']);
             $stmt_count->bindParam(':left', $constraint['lft']);
             $stmt_count->bindParam(':right', $constraint['rgt']);
             $stmt_count->bindParam(':mkdate', ForumVisit::getLastVisit($constraint['seminar_id']));
             $stmt_count->execute();
             // return results
             return array('list' => $postings, 'count' => $stmt_count->fetchColumn());
             break;
         case 'latest':
             return ForumEntry::getEntries($parent_id, ForumEntry::WITH_CHILDS, '', 'DESC', $start);
             break;
         case 'favorites':
             $add = "AND ou.topic_id IS NOT NULL";
             return ForumEntry::getEntries($parent_id, ForumEntry::WITH_CHILDS, $add, 'DESC', $start);
             break;
         case 'dump':
             return ForumEntry::getEntries($parent_id, ForumEntry::WITH_CHILDS, '', 'ASC', 0, false);
             break;
         case 'flat':
             $constraint = ForumEntry::getConstraints($parent_id);
             $stmt = DBManager::get()->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM forum_entries\n                    WHERE lft > ? AND rgt < ? AND seminar_id = ? AND depth = ?\n                    ORDER BY name ASC");
             $stmt->execute(array($constraint['lft'], $constraint['rgt'], $constraint['seminar_id'], $constraint['depth'] + 1));
             $count = DBManager::get()->query("SELECT FOUND_ROWS()")->fetchColumn();
             $posting_list = array();
             // speed up things a bit by leaving out the formatReady fields
             foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $data) {
                 $posting_list[$data['topic_id']] = array('author' => $data['author'], 'topic_id' => $data['topic_id'], 'name_raw' => $data['name'], 'content_raw' => ForumEntry::killEdit($data['content']), 'content_short' => $desc_short, 'chdate' => $data['chdate'], 'mkdate' => $data['mkdate'], 'user_id' => $data['user_id'], 'raw_title' => $data['name'], 'raw_description' => ForumEntry::killEdit($data['content']), 'fav' => $data['fav'] == 'fav', 'depth' => $data['depth'], 'seminar_id' => $data['seminar_id']);
             }
             return array('list' => $posting_list, 'count' => $count);
             break;
         case 'depth_to_large':
             $constraint = ForumEntry::getConstraints($parent_id);
             $stmt = DBManager::get()->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM forum_entries\n                    WHERE lft > ? AND rgt < ? AND seminar_id = ? AND depth > 3\n                    ORDER BY name ASC");
             $stmt->execute(array($constraint['lft'], $constraint['rgt'], $constraint['seminar_id']));
             $count = DBManager::get()->query("SELECT FOUND_ROWS()")->fetchColumn();
             return array('list' => $stmt->fetchAll(PDO::FETCH_ASSOC), 'count' => $count);
             break;
     }
 }
コード例 #3
0
ファイル: index.php プロジェクト: ratbird/hope
 /**
  * show search results
  * 
  * @param int $page show entries on submitted page
  */
 function search_action($page = null)
 {
     ForumPerm::check('search', $this->getId());
     $nav = Navigation::getItem('course/forum2');
     $nav->setImage(Icon::create('forum', 'info'));
     Navigation::activateItem('course/forum2/index');
     // set page to which we shall jump
     if ($page) {
         ForumHelpers::setPage($page);
     }
     $this->section = 'search';
     $this->topic_id = $this->getId();
     $this->show_full_path = true;
     // parse filter-options
     foreach (array('search_title', 'search_content', 'search_author') as $option) {
         $this->options[$option] = Request::option($option);
     }
     $this->searchfor = Request::get('searchfor');
     if (strlen($this->searchfor) < 3) {
         $this->flash['messages'] = array('error' => _('Ihr Suchbegriff muss mindestens 3 Zeichen lang sein und darf nur Buchstaben und Zahlen enthalten!'));
     } else {
         // get search-results
         $list = ForumEntry::getSearchResults($this->getId(), $this->searchfor, $this->options);
         $this->postings = $list['list'];
         $this->number_of_entries = $list['count'];
         $this->highlight = $list['highlight'];
         if (empty($this->postings)) {
             $this->flash['messages'] = array('info' => _('Es wurden keine Beiträge gefunden, die zu Ihren Suchkriterien passen!'));
         }
     }
     // set default layout
     $layout = $GLOBALS['template_factory']->open('layouts/base');
     $this->set_layout($layout);
     // exploit the visitdate for this view
     $this->visitdate = ForumVisit::getLastVisit($this->getId());
     $this->render_action('index');
 }