Exemplo n.º 1
0
 /**
  * Common code for all actions: set default layout and page title.
  *
  * @param type $action
  * @param type $args
  */
 function before_filter(&$action, &$args)
 {
     $this->validate_args($args, array('option', 'option'));
     parent::before_filter($action, $args);
     // set correct encoding if this is an ajax-call
     if (Request::isAjax()) {
         header('Content-Type: text/html; charset=Windows-1252');
     }
     $this->flash = Trails_Flash::instance();
     // set default layout
     $layout = $GLOBALS['template_factory']->open('layouts/base');
     $this->set_layout($layout);
     // Set help keyword for Stud.IP's user-documentation and page title
     PageLayout::setHelpKeyword('Basis.Forum');
     PageLayout::setTitle($_SESSION['SessSemName']['header_line'] . ' - ' . _('Forum'));
     $this->AVAILABLE_DESIGNS = array('web20', 'studip');
     if ($GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP'] && $GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP'] != '/') {
         $this->picturepath = $GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP'] . '/' . $this->dispatcher->trails_root . '/img';
     } else {
         $this->picturepath = '/' . $this->dispatcher->trails_root . '/img';
     }
     // we want to display the dates in german
     setlocale(LC_TIME, 'de_DE@euro', 'de_DE', 'de', 'ge');
     // the default for displaying timestamps
     $this->time_format_string = "%a %d. %B %Y, %H:%M";
     $this->time_format_string_short = "%d.%m.%Y, %H:%M";
     $this->template_factory = new Flexi_TemplateFactory(dirname(__FILE__) . '/../templates');
     //$this->check_token();
     ForumVisit::setVisit($this->getId());
     if (Request::int('page')) {
         ForumHelpers::setPage(Request::int('page'));
     }
     $this->seminar_id = $this->getId();
 }
Exemplo n.º 2
0
 /**
  * Get all entries for the passed parent_id.
  * Returns an array of the following structure:
  * Array (
  *     'list'  => Array (
  *         'author'          =>
  *         'topic_id'        =>
  *         'name'            => formatReady()
  *         'name_raw'        =>
  *         'content'         => formatReady()
  *         'content_raw'     =>
  *         'content_short'   =>
  *         'chdate'          =>
  *         'mkdate'          =>
  *         'user_id'        =>
  *         'raw_title'       =>
  *         'raw_description' =>
  *         'fav'             =>
  *         'depth'           =>
  *         'sticky'          =>
  *         'closed'          =>
  *         'seminar_id'      =>
  *     )
  *     'count' =>
  * )
  *
  * @param type $parent_id    id of parent-element to get entries for.
  * @param type $with_childs  if true, the whole subtree is fetched
  * @param type $add          for additional constraints in the WHERE-part of the query
  * @param type $sort_order   can be ASC or DESC
  * @param type $start        can be used for pagination, is used for the LIMIT-part of the query
  * @param type $limit        number of entries to fetch, defaults to ForumEntry::POSTINGS_PER_PAGE
  *
  * @return array
  *
  * @throws Exception  if the retrieval failed, an Exception is thrown
  */
 static function getEntries($parent_id, $with_childs = false, $add = '', $sort_order = 'DESC', $start = 0, $limit = ForumEntry::POSTINGS_PER_PAGE)
 {
     $constraint = ForumEntry::getConstraints($parent_id);
     $seminar_id = $constraint['seminar_id'];
     $depth = $constraint['depth'] + 1;
     // count the entries and set correct page if necessary
     if ($with_childs) {
         $count_stmt = DBManager::get()->prepare("SELECT COUNT(*) FROM forum_entries\n                LEFT JOIN forum_favorites as ou ON (ou.topic_id = forum_entries.topic_id AND ou.user_id = ?)\n                WHERE (forum_entries.seminar_id = ?\n                    AND forum_entries.seminar_id != forum_entries.topic_id\n                    AND lft > ? AND rgt < ?) " . ($depth > 2 ? " OR forum_entries.topic_id = " . DBManager::get()->quote($parent_id) : '') . $add . " ORDER BY forum_entries.mkdate {$sort_order}");
         $count_stmt->execute(array($GLOBALS['user']->id, $seminar_id, $constraint['lft'], $constraint['rgt']));
         $count = $count_stmt->fetchColumn();
     } else {
         $count_stmt = DBManager::get()->prepare("SELECT COUNT(*) FROM forum_entries\n                LEFT JOIN forum_favorites as ou ON (ou.topic_id = forum_entries.topic_id AND ou.user_id = ?)\n                WHERE ((depth = ? AND forum_entries.seminar_id = ?\n                    AND forum_entries.seminar_id != forum_entries.topic_id\n                    AND lft > ? AND rgt < ?) " . ($depth > 2 ? " OR forum_entries.topic_id = " . DBManager::get()->quote($parent_id) : '') . ') ' . $add . " ORDER BY forum_entries.mkdate {$sort_order}");
         $count_stmt->execute(array($GLOBALS['user']->id, $depth, $seminar_id, $constraint['lft'], $constraint['rgt']));
         $count = $count_stmt->fetchColumn();
     }
     // use the last page if the requested page does not exist
     if ($start > $count) {
         $page = ceil($count / ForumEntry::POSTINGS_PER_PAGE);
         ForumHelpers::setPage($page);
         $start = max(1, $page - 1) * ForumEntry::POSTINGS_PER_PAGE;
     }
     if ($with_childs) {
         $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 = ?)\n                WHERE (forum_entries.seminar_id = ?\n                    AND forum_entries.seminar_id != forum_entries.topic_id\n                    AND lft > ? AND rgt < ?) " . ($depth > 2 ? " OR forum_entries.topic_id = " . DBManager::get()->quote($parent_id) : '') . $add . " ORDER BY forum_entries.mkdate {$sort_order}" . ($limit ? " LIMIT {$start}, {$limit}" : ''));
         $stmt->execute(array($GLOBALS['user']->id, $seminar_id, $constraint['lft'], $constraint['rgt']));
     } else {
         $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 = ?)\n                WHERE ((depth = ? AND forum_entries.seminar_id = ?\n                    AND lft > ? AND rgt < ?) " . ($depth > 2 ? " OR forum_entries.topic_id = " . DBManager::get()->quote($parent_id) : '') . ') ' . $add . " ORDER BY forum_entries.mkdate {$sort_order}" . ($limit ? " LIMIT {$start}, {$limit}" : ''));
         $stmt->execute(array($GLOBALS['user']->id, $depth, $seminar_id, $constraint['lft'], $constraint['rgt']));
     }
     if (!$stmt) {
         throw new Exception("Error while retrieving postings in " . __FILE__ . " on line " . __LINE__);
     }
     return array('list' => ForumEntry::parseEntries($stmt->fetchAll(PDO::FETCH_ASSOC)), 'count' => $count);
 }
Exemplo n.º 3
0
 /**
  * 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');
 }