Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   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   * User searching requests.
  19   *
  20   * @package    gradereport_history
  21   * @copyright  2013 NetSpot Pty Ltd (https://www.netspot.com.au)
  22   * @author     Adam Olley <adam.olley@netspot.com.au>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  define('AJAX_SCRIPT', true);
  27  
  28  require_once(__DIR__ . '/../../../config.php');
  29  
  30  $id = required_param('id', PARAM_INT); // Course id.
  31  $search = optional_param('search', '', PARAM_RAW);
  32  $page = optional_param('page', 0, PARAM_INT);
  33  
  34  $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
  35  $context = context_course::instance($course->id, MUST_EXIST);
  36  
  37  if ($course->id == SITEID) {
  38      throw new moodle_exception('invalidcourse');
  39  }
  40  
  41  require_sesskey();
  42  require_login($course);
  43  require_capability('gradereport/history:view', $context);
  44  require_capability('moodle/grade:viewall', $context);
  45  
  46  $outcome = new stdClass();
  47  $outcome->success = true;
  48  $outcome->error = '';
  49  
  50  $users = \gradereport_history\helper::get_users($context, $search, $page, 25);
  51  $outcome->response = array('users' => array());
  52  $outcome->response['totalusers'] = \gradereport_history\helper::get_users_count($context, $search);;
  53  
  54  // TODO Does not support custom user profile fields (MDL-70456).
  55  $extrafields = \core_user\fields::get_identity_fields($context, false);
  56  $useroptions = array('link' => false, 'visibletoscreenreaders' => false);
  57  
  58  // Format the user record.
  59  foreach ($users as $user) {
  60      $newuser = new stdClass();
  61      $newuser->userid = $user->id;
  62      $newuser->picture = $OUTPUT->user_picture($user, $useroptions);
  63      $newuser->fullname = fullname($user);
  64      $fieldvalues = array();
  65      foreach ($extrafields as $field) {
  66          $fieldvalues[] = s($user->{$field});
  67      }
  68      $newuser->extrafields = implode(', ', $fieldvalues);
  69      $outcome->response['users'][] = $newuser;
  70  }
  71  
  72  $outcome->success = true;
  73  echo $OUTPUT->header();
  74  echo json_encode($outcome);
  75  echo $OUTPUT->footer();