[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/forum/ -> view.php (source)

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * @package   mod_forum
  20   * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
  21   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24      require_once('../../config.php');
  25      require_once ('lib.php');
  26      require_once($CFG->libdir.'/completionlib.php');
  27  
  28      $id          = optional_param('id', 0, PARAM_INT);       // Course Module ID
  29      $f           = optional_param('f', 0, PARAM_INT);        // Forum ID
  30      $mode        = optional_param('mode', 0, PARAM_INT);     // Display mode (for single forum)
  31      $showall     = optional_param('showall', '', PARAM_INT); // show all discussions on one page
  32      $changegroup = optional_param('group', -1, PARAM_INT);   // choose the current group
  33      $page        = optional_param('page', 0, PARAM_INT);     // which page to show
  34      $search      = optional_param('search', '', PARAM_CLEAN);// search string
  35  
  36      $params = array();
  37      if ($id) {
  38          $params['id'] = $id;
  39      } else {
  40          $params['f'] = $f;
  41      }
  42      if ($page) {
  43          $params['page'] = $page;
  44      }
  45      if ($search) {
  46          $params['search'] = $search;
  47      }
  48      $PAGE->set_url('/mod/forum/view.php', $params);
  49  
  50      if ($id) {
  51          if (! $cm = get_coursemodule_from_id('forum', $id)) {
  52              print_error('invalidcoursemodule');
  53          }
  54          if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
  55              print_error('coursemisconf');
  56          }
  57          if (! $forum = $DB->get_record("forum", array("id" => $cm->instance))) {
  58              print_error('invalidforumid', 'forum');
  59          }
  60          if ($forum->type == 'single') {
  61              $PAGE->set_pagetype('mod-forum-discuss');
  62          }
  63          // move require_course_login here to use forced language for course
  64          // fix for MDL-6926
  65          require_course_login($course, true, $cm);
  66          $strforums = get_string("modulenameplural", "forum");
  67          $strforum = get_string("modulename", "forum");
  68      } else if ($f) {
  69  
  70          if (! $forum = $DB->get_record("forum", array("id" => $f))) {
  71              print_error('invalidforumid', 'forum');
  72          }
  73          if (! $course = $DB->get_record("course", array("id" => $forum->course))) {
  74              print_error('coursemisconf');
  75          }
  76  
  77          if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
  78              print_error('missingparameter');
  79          }
  80          // move require_course_login here to use forced language for course
  81          // fix for MDL-6926
  82          require_course_login($course, true, $cm);
  83          $strforums = get_string("modulenameplural", "forum");
  84          $strforum = get_string("modulename", "forum");
  85      } else {
  86          print_error('missingparameter');
  87      }
  88  
  89      if (!$PAGE->button) {
  90          $PAGE->set_button(forum_search_form($course, $search));
  91      }
  92  
  93      $context = context_module::instance($cm->id);
  94      $PAGE->set_context($context);
  95  
  96      if (!empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds) && $forum->rsstype && $forum->rssarticles) {
  97          require_once("$CFG->libdir/rsslib.php");
  98  
  99          $rsstitle = format_string($course->shortname, true, array('context' => context_course::instance($course->id))) . ': ' . format_string($forum->name);
 100          rss_add_http_header($context, 'mod_forum', $forum, $rsstitle);
 101      }
 102  
 103  /// Print header.
 104  
 105      $PAGE->set_title($forum->name);
 106      $PAGE->add_body_class('forumtype-'.$forum->type);
 107      $PAGE->set_heading($course->fullname);
 108  
 109  /// Some capability checks.
 110      if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
 111          notice(get_string("activityiscurrentlyhidden"));
 112      }
 113  
 114      if (!has_capability('mod/forum:viewdiscussion', $context)) {
 115          notice(get_string('noviewdiscussionspermission', 'forum'));
 116      }
 117  
 118      // Mark viewed and trigger the course_module_viewed event.
 119      forum_view($forum, $course, $cm, $context);
 120  
 121      echo $OUTPUT->header();
 122  
 123      echo $OUTPUT->heading(format_string($forum->name), 2);
 124      if (!empty($forum->intro) && $forum->type != 'single' && $forum->type != 'teacher') {
 125          echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro');
 126      }
 127  
 128  /// find out current groups mode
 129      groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/forum/view.php?id=' . $cm->id);
 130  
 131      $SESSION->fromdiscussion = qualified_me();   // Return here if we post or set subscription etc
 132  
 133  
 134  /// Print settings and things across the top
 135  
 136      // If it's a simple single discussion forum, we need to print the display
 137      // mode control.
 138      if ($forum->type == 'single') {
 139          $discussion = NULL;
 140          $discussions = $DB->get_records('forum_discussions', array('forum'=>$forum->id), 'timemodified ASC');
 141          if (!empty($discussions)) {
 142              $discussion = array_pop($discussions);
 143          }
 144          if ($discussion) {
 145              if ($mode) {
 146                  set_user_preference("forum_displaymode", $mode);
 147              }
 148              $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
 149              forum_print_mode_form($forum->id, $displaymode, $forum->type);
 150          }
 151      }
 152  
 153      if (!empty($forum->blockafter) && !empty($forum->blockperiod)) {
 154          $a = new stdClass();
 155          $a->blockafter = $forum->blockafter;
 156          $a->blockperiod = get_string('secondstotime'.$forum->blockperiod);
 157          echo $OUTPUT->notification(get_string('thisforumisthrottled', 'forum', $a));
 158      }
 159  
 160      if ($forum->type == 'qanda' && !has_capability('moodle/course:manageactivities', $context)) {
 161          echo $OUTPUT->notification(get_string('qandanotify','forum'));
 162      }
 163  
 164      switch ($forum->type) {
 165          case 'single':
 166              if (!empty($discussions) && count($discussions) > 1) {
 167                  echo $OUTPUT->notification(get_string('warnformorepost', 'forum'));
 168              }
 169              if (! $post = forum_get_post_full($discussion->firstpost)) {
 170                  print_error('cannotfindfirstpost', 'forum');
 171              }
 172              if ($mode) {
 173                  set_user_preference("forum_displaymode", $mode);
 174              }
 175  
 176              $canreply    = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $context);
 177              $canrate     = has_capability('mod/forum:rate', $context);
 178              $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
 179  
 180              echo '&nbsp;'; // this should fix the floating in FF
 181              forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate);
 182              break;
 183  
 184          case 'eachuser':
 185              echo '<p class="mdl-align">';
 186              if (forum_user_can_post_discussion($forum, null, -1, $cm)) {
 187                  print_string("allowsdiscussions", "forum");
 188              } else {
 189                  echo '&nbsp;';
 190              }
 191              echo '</p>';
 192              if (!empty($showall)) {
 193                  forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm);
 194              } else {
 195                  forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm);
 196              }
 197              break;
 198  
 199          case 'teacher':
 200              if (!empty($showall)) {
 201                  forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm);
 202              } else {
 203                  forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm);
 204              }
 205              break;
 206  
 207          case 'blog':
 208              echo '<br />';
 209              if (!empty($showall)) {
 210                  forum_print_latest_discussions($course, $forum, 0, 'plain', 'd.pinned DESC, p.created DESC', -1, -1, -1, 0, $cm);
 211              } else {
 212                  forum_print_latest_discussions($course, $forum, -1, 'plain', 'd.pinned DESC, p.created DESC', -1, -1, $page,
 213                      $CFG->forum_manydiscussions, $cm);
 214              }
 215              break;
 216  
 217          default:
 218              echo '<br />';
 219              if (!empty($showall)) {
 220                  forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm);
 221              } else {
 222                  forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm);
 223              }
 224  
 225  
 226              break;
 227      }
 228  
 229      // Add the subscription toggle JS.
 230      $PAGE->requires->yui_module('moodle-mod_forum-subscriptiontoggle', 'Y.M.mod_forum.subscriptiontoggle.init');
 231  
 232      echo $OUTPUT->footer($course);


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1