Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * @package   mod_forum
  19   * @copyright 2014 Andrew Robert Nicols <andrew@nicols.co.uk>
  20   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21   */
  22  
  23  defined('MOODLE_INTERNAL') || die();
  24  
  25  // Deprecated a very long time ago.
  26  
  27  /**
  28   * @deprecated since Moodle 1.1 - please do not use this function any more.
  29   */
  30  function forum_count_unrated_posts() {
  31      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
  32  }
  33  
  34  
  35  // Since Moodle 1.5.
  36  
  37  /**
  38   * @deprecated since Moodle 1.5 - please do not use this function any more.
  39   */
  40  function forum_tp_count_discussion_read_records() {
  41      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
  42  }
  43  
  44  /**
  45   * @deprecated since Moodle 1.5 - please do not use this function any more.
  46   */
  47  function forum_get_user_discussions() {
  48      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
  49  }
  50  
  51  
  52  // Since Moodle 1.6.
  53  
  54  /**
  55   * @deprecated since Moodle 1.6 - please do not use this function any more.
  56   */
  57  function forum_tp_count_forum_posts() {
  58      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
  59  }
  60  
  61  /**
  62   * @deprecated since Moodle 1.6 - please do not use this function any more.
  63   */
  64  function forum_tp_count_forum_read_records() {
  65      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
  66  }
  67  
  68  
  69  // Since Moodle 1.7.
  70  
  71  /**
  72   * @deprecated since Moodle 1.7 - please do not use this function any more.
  73   */
  74  function forum_get_open_modes() {
  75      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
  76  }
  77  
  78  
  79  // Since Moodle 1.9.
  80  
  81  /**
  82   * @deprecated since Moodle 1.9 MDL-13303 - please do not use this function any more.
  83   */
  84  function forum_get_child_posts() {
  85      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
  86  }
  87  
  88  /**
  89   * @deprecated since Moodle 1.9 MDL-13303 - please do not use this function any more.
  90   */
  91  function forum_get_discussion_posts() {
  92      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
  93  }
  94  
  95  
  96  // Since Moodle 2.0.
  97  
  98  /**
  99   * @deprecated since Moodle 2.0 MDL-21657 - please do not use this function any more.
 100   */
 101  function forum_get_ratings() {
 102      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
 103  }
 104  
 105  /**
 106   * @deprecated since Moodle 2.0 MDL-14632 - please do not use this function any more.
 107   */
 108  function forum_get_tracking_link() {
 109      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
 110  }
 111  
 112  /**
 113   * @deprecated since Moodle 2.0 MDL-14113 - please do not use this function any more.
 114   */
 115  function forum_tp_count_discussion_unread_posts() {
 116      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
 117  }
 118  
 119  /**
 120   * @deprecated since Moodle 2.0 MDL-23479 - please do not use this function any more.
 121   */
 122  function forum_convert_to_roles() {
 123      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
 124  }
 125  
 126  /**
 127   * @deprecated since Moodle 2.0 MDL-14113 - please do not use this function any more.
 128   */
 129  function forum_tp_get_read_records() {
 130      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
 131  }
 132  
 133  /**
 134   * @deprecated since Moodle 2.0 MDL-14113 - please do not use this function any more.
 135   */
 136  function forum_tp_get_discussion_read_records() {
 137      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
 138  }
 139  
 140  // Deprecated in 2.3.
 141  
 142  /**
 143   * @deprecated since Moodle 2.3 MDL-33166 - please do not use this function any more.
 144   */
 145  function forum_user_enrolled() {
 146      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
 147  }
 148  
 149  
 150  // Deprecated in 2.4.
 151  
 152  /**
 153   * @deprecated since Moodle 2.4 use forum_user_can_see_post() instead
 154   */
 155  function forum_user_can_view_post() {
 156      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
 157  }
 158  
 159  
 160  // Deprecated in 2.6.
 161  
 162  /**
 163   * FORUM_TRACKING_ON - deprecated alias for FORUM_TRACKING_FORCED.
 164   * @deprecated since 2.6
 165   */
 166  define('FORUM_TRACKING_ON', 2);
 167  
 168  /**
 169   * @deprecated since Moodle 2.6
 170   * @see shorten_text()
 171   */
 172  function forum_shorten_post($message) {
 173      throw new coding_exception(__FUNCTION__ . '() can not be used any more. '
 174          . 'Please use shorten_text($message, $CFG->forum_shortpost) instead.');
 175  }
 176  
 177  // Deprecated in 2.8.
 178  
 179  /**
 180   * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::is_subscribed() instead
 181   */
 182  function forum_is_subscribed() {
 183      throw new coding_exception(__FUNCTION__ . '() can not be used any more.');
 184  }
 185  
 186  /**
 187   * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::subscribe_user() instead
 188   */
 189  function forum_subscribe() {
 190      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
 191          . \mod_forum\subscriptions::class . '::subscribe_user() instead');
 192  }
 193  
 194  /**
 195   * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::unsubscribe_user() instead
 196   */
 197  function forum_unsubscribe() {
 198      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
 199          . \mod_forum\subscriptions::class . '::unsubscribe_user() instead');
 200  }
 201  
 202  /**
 203   * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::fetch_subscribed_users() instead
 204    */
 205  function forum_subscribed_users() {
 206      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
 207          . \mod_forum\subscriptions::class . '::fetch_subscribed_users() instead');
 208  }
 209  
 210  /**
 211   * Determine whether the forum is force subscribed.
 212   *
 213   * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::is_forcesubscribed() instead
 214   */
 215  function forum_is_forcesubscribed($forum) {
 216      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
 217          . \mod_forum\subscriptions::class . '::is_forcesubscribed() instead');
 218  }
 219  
 220  /**
 221   * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::set_subscription_mode() instead
 222   */
 223  function forum_forcesubscribe($forumid, $value = 1) {
 224      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
 225          . \mod_forum\subscriptions::class . '::set_subscription_mode() instead');
 226  }
 227  
 228  /**
 229   * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::get_subscription_mode() instead
 230   */
 231  function forum_get_forcesubscribed($forum) {
 232      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
 233          . \mod_forum\subscriptions::class . '::set_subscription_mode() instead');
 234  }
 235  
 236  /**
 237   * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::is_subscribed in combination wtih
 238   * \mod_forum\subscriptions::fill_subscription_cache_for_course instead.
 239   */
 240  function forum_get_subscribed_forums() {
 241      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
 242          . \mod_forum\subscriptions::class . '::is_subscribed(), and '
 243          . \mod_forum\subscriptions::class . '::fill_subscription_cache_for_course() instead');
 244  }
 245  
 246  /**
 247   * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::get_unsubscribable_forums() instead
 248   */
 249  function forum_get_optional_subscribed_forums() {
 250      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
 251          . \mod_forum\subscriptions::class . '::get_unsubscribable_forums() instead');
 252  }
 253  
 254  /**
 255   * @deprecated since Moodle 2.8 use \mod_forum\subscriptions::get_potential_subscribers() instead
 256   */
 257  function forum_get_potential_subscribers() {
 258      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
 259          . \mod_forum\subscriptions::class . '::get_potential_subscribers() instead');
 260  }
 261  
 262  /**
 263   * @deprecated since Moodle 3.0 use \mod_forum\output\forum_post_email instead
 264   */
 265  function forum_make_mail_text() {
 266      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
 267          . '\mod_forum\output\forum_post_email');
 268  }
 269  
 270  /**
 271   * @deprecated since Moodle 3.0 use \mod_forum\output\forum_post_email instead
 272   */
 273  function forum_make_mail_html() {
 274      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
 275          . '\mod_forum\output\forum_post_email');
 276  }
 277  
 278  /**
 279   * @deprecated since Moodle 3.0 use \mod_forum\output\forum_post_email instead
 280   */
 281  function forum_make_mail_post() {
 282      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use '
 283          . '\mod_forum\output\forum_post_email');
 284  }
 285  
 286  /**
 287   * @deprecated since Moodle 3.7
 288   */
 289  function forum_cron_minimise_user_record() {
 290      throw new coding_exception(__FUNCTION__ . '() can not be used any more. It has not been replaced.');
 291  }
 292  
 293  /**
 294   * @deprecated since Moodle 3.7
 295   */
 296  function forum_cron() {
 297      throw new coding_exception(__FUNCTION__ . '() can not be used any more. Please use the forum tasks');
 298  }
 299  
 300  /**
 301   * @deprecated since Moodle 3.7
 302   */
 303  function forum_print_discussion() {
 304      throw new coding_exception(__FUNCTION__ . '() can not be used any more. ' .
 305          'please use \mod_forum\local\renderers\discussion instead');
 306  }
 307  
 308  
 309  /**
 310   * @deprecated since Moodle 3.7
 311   */
 312  function forum_post_nesting_cache() {
 313      throw new coding_exception(__FUNCTION__ . '() can not be used any more. ' .
 314          'please use \mod_forum\local\renderers\posts instead');
 315  }
 316  
 317  /**
 318   * @deprecated since Moodle 3.7
 319   */
 320  function forum_should_start_post_nesting() {
 321      throw new coding_exception(__FUNCTION__ . '() can not be used any more. ' .
 322          'please use \mod_forum\local\renderers\posts instead');
 323  }
 324  
 325  /**
 326   * @deprecated since Moodle 3.7
 327   */
 328  function forum_should_end_post_nesting() {
 329      throw new coding_exception(__FUNCTION__ . '() can not be used any more. ' .
 330          'please use \mod_forum\local\renderers\posts instead');
 331  }
 332  
 333  /**
 334   * @deprecated since Moodle 3.7
 335   */
 336  function forum_print_post_start() {
 337      throw new coding_exception(__FUNCTION__ . '() can not be used any more. ' .
 338          'please use \mod_forum\local\renderers\posts instead');
 339  }
 340  
 341  /**
 342   * @deprecated since Moodle 3.7
 343   */
 344  function forum_print_post_end() {
 345      throw new coding_exception(__FUNCTION__ . '() can not be used any more. ' .
 346          'please use \mod_forum\local\renderers\posts instead');
 347  }
 348  
 349  /**
 350   * @deprecated since Moodle 3.7
 351   */
 352  function forum_print_post() {
 353      throw new coding_exception(__FUNCTION__ . '() can not be used any more. ' .
 354          'please use \mod_forum\local\renderers\posts instead');
 355  }
 356  
 357  /**
 358   * @deprecated since Moodle 3.7
 359   */
 360  function forum_print_posts_flat() {
 361      throw new coding_exception(__FUNCTION__ . '() can not be used any more. ' .
 362          'please use \mod_forum\local\renderers\posts instead');
 363  }
 364  
 365  /**
 366   * @deprecated since Moodle 3.7
 367   */
 368  function forum_print_posts_threaded() {
 369      throw new coding_exception(__FUNCTION__ . '() can not be used any more. ' .
 370          'please use \mod_forum\local\renderers\posts instead');
 371  }
 372  
 373  /**
 374   * @deprecated since Moodle 3.7
 375   */
 376  function forum_print_posts_nested() {
 377      throw new coding_exception(__FUNCTION__ . '() can not be used any more. ' .
 378          'please use \mod_forum\local\renderers\posts instead');
 379  }
 380  
 381  /**
 382   * @deprecated since Moodle 3.7
 383   */
 384  function forum_print_latest_discussions() {
 385      throw new coding_exception(__FUNCTION__ . '() can not be used any more. ');
 386  }
 387  
 388  /**
 389   * @deprecated since Moodle 3.7
 390   */
 391  function forum_count_replies() {
 392      throw new coding_exception(__FUNCTION__ . ' has been removed. Please use get_reply_count_for_post_id_in_discussion_id in
 393      the post vault.');
 394  }
 395  
 396  /**
 397   * @deprecated since Moodle 3.8
 398   */
 399  function forum_scale_used() {
 400      throw new coding_exception('forum_scale_used() can not be used anymore. Plugins can implement ' .
 401          '<modname>_scale_used_anywhere, all implementations of <modname>_scale_used are now ignored');
 402  }
 403  
 404  /**
 405   * @deprecated since Moodle 3.8
 406   */
 407  function forum_get_user_grades() {
 408      throw new \coding_exception('forum_get_user_grades() is deprecated and no longer used. '  .
 409          'Please use rating_manager::get_user_grades() instead.');
 410  }
 411  
 412  /**
 413   * Obtains the automatic completion state for this forum based on any conditions
 414   * in forum settings.
 415   *
 416   * @deprecated since Moodle 3.11
 417   * @todo MDL-71196 Final deprecation in Moodle 4.3
 418   * @see \mod_forum\completion\custom_completion
 419   * @global object
 420   * @global object
 421   * @param object $course Course
 422   * @param object $cm Course-module
 423   * @param int $userid User ID
 424   * @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
 425   * @return bool True if completed, false if not. (If no conditions, then return
 426   *   value depends on comparison type)
 427   */
 428  function forum_get_completion_state($course, $cm, $userid, $type) {
 429      global $DB;
 430  
 431      // No need to call debugging here. Deprecation debugging notice already being called in \completion_info::internal_get_state().
 432  
 433      // Get forum details.
 434      if (!($forum = $DB->get_record('forum', array('id' => $cm->instance)))) {
 435          throw new Exception("Can't find forum {$cm->instance}");
 436      }
 437  
 438      $result = $type; // Default return value.
 439  
 440      $postcountparams = array('userid' => $userid, 'forumid' => $forum->id);
 441      $postcountsql = "
 442  SELECT
 443      COUNT(1)
 444  FROM
 445      {forum_posts} fp
 446      INNER JOIN {forum_discussions} fd ON fp.discussion=fd.id
 447  WHERE
 448      fp.userid=:userid AND fd.forum=:forumid";
 449  
 450      if ($forum->completiondiscussions) {
 451          $value = $forum->completiondiscussions <=
 452              $DB->count_records('forum_discussions', array('forum' => $forum->id, 'userid' => $userid));
 453          if ($type == COMPLETION_AND) {
 454              $result = $result && $value;
 455          } else {
 456              $result = $result || $value;
 457          }
 458      }
 459      if ($forum->completionreplies) {
 460          $value = $forum->completionreplies <=
 461              $DB->get_field_sql($postcountsql . ' AND fp.parent<>0', $postcountparams);
 462          if ($type == COMPLETION_AND) {
 463              $result = $result && $value;
 464          } else {
 465              $result = $result || $value;
 466          }
 467      }
 468      if ($forum->completionposts) {
 469          $value = $forum->completionposts <= $DB->get_field_sql($postcountsql, $postcountparams);
 470          if ($type == COMPLETION_AND) {
 471              $result = $result && $value;
 472          } else {
 473              $result = $result || $value;
 474          }
 475      }
 476  
 477      return $result;
 478  }
 479  
 480  /**
 481   * Prints the editing button on subscribers page
 482   *
 483   * @deprecated since Moodle 4.0
 484   * @todo MDL-73956 Final deprecation in Moodle 4.4
 485   * @global object
 486   * @global object
 487   * @param int $courseid
 488   * @param int $forumid
 489   * @return string
 490   */
 491  function forum_update_subscriptions_button($courseid, $forumid): string {
 492      global $CFG, $USER;
 493  
 494      debugging('The method forum_update_subscriptions_button() has been deprecated as it is no longer used.' .
 495              'The \'Manage subscribers\' button has been replaced with tertiary navigation.', DEBUG_DEVELOPER);
 496  
 497      if (!empty($USER->subscriptionsediting)) {
 498          $string = get_string('managesubscriptionsoff', 'forum');
 499          $edit = "off";
 500      } else {
 501          $string = get_string('managesubscriptionson', 'forum');
 502          $edit = "on";
 503      }
 504  
 505      $subscribers = html_writer::start_tag('form', array('action' => $CFG->wwwroot . '/mod/forum/subscribers.php',
 506          'method' => 'get', 'class' => 'form-inline'));
 507      $subscribers .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => $string,
 508          'class' => 'btn btn-secondary'));
 509      $subscribers .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $forumid));
 510      $subscribers .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'edit', 'value' => $edit));
 511      $subscribers .= html_writer::end_tag('form');
 512  
 513      return $subscribers;
 514  }