Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 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   * 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  $extrafields = get_extra_user_fields($context);
  55  $useroptions = array('link' => false, 'visibletoscreenreaders' => false);
  56  
  57  // Format the user record.
  58  foreach ($users as $user) {
  59      $newuser = new stdClass();
  60      $newuser->userid = $user->id;
  61      $newuser->picture = $OUTPUT->user_picture($user, $useroptions);
  62      $newuser->fullname = fullname($user);
  63      $fieldvalues = array();
  64      foreach ($extrafields as $field) {
  65          $fieldvalues[] = s($user->{$field});
  66      }
  67      $newuser->extrafields = implode(', ', $fieldvalues);
  68      $outcome->response['users'][] = $newuser;
  69  }
  70  
  71  $outcome->success = true;
  72  
  73  echo $OUTPUT->header();
  74  echo json_encode($outcome);
  75  echo $OUTPUT->footer();