Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.
   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   * A type of forum.
  19   *
  20   * @package    mod_forum
  21   * @copyright  2014 Andrew Robert Nicols <andrew@nicols.co.uk>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  require_once($CFG->dirroot.'/user/selector/lib.php');
  28  
  29  /**
  30   * User selector control for removing subscribed users
  31   * @package   mod_forum
  32   * @copyright 2009 Sam Hemelryk
  33   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class mod_forum_existing_subscriber_selector extends mod_forum_subscriber_selector_base {
  36  
  37      /**
  38       * Finds all subscribed users
  39       *
  40       * @param string $search
  41       * @return array
  42       */
  43      public function find_users($search) {
  44          global $DB;
  45          list($wherecondition, $params) = $this->search_sql($search, 'u');
  46          $params['forumid'] = $this->forumid;
  47  
  48          // only active enrolled or everybody on the frontpage
  49          list($esql, $eparams) = get_enrolled_sql($this->context, '', $this->currentgroup, true);
  50          $fields = $this->required_fields_sql('u');
  51          list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
  52          $params = array_merge($params, $eparams, $sortparams);
  53  
  54          $subscribers = $DB->get_records_sql("SELECT $fields
  55                                                 FROM {user} u
  56                                                 JOIN ($esql) je ON je.id = u.id
  57                                                 JOIN {forum_subscriptions} s ON s.userid = u.id
  58                                                WHERE $wherecondition AND s.forum = :forumid
  59                                             ORDER BY $sort", $params);
  60  
  61          $cm = get_coursemodule_from_instance('forum', $this->forumid);
  62          $modinfo = get_fast_modinfo($cm->course);
  63          $info = new \core_availability\info_module($modinfo->get_cm($cm->id));
  64          $subscribers = $info->filter_user_list($subscribers);
  65  
  66          return array(get_string("existingsubscribers", 'forum') => $subscribers);
  67      }
  68  
  69  }