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.
   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   * Front-end class.
  19   *
  20   * @package availability_grade
  21   * @copyright 2014 The Open University
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace availability_grade;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Front-end class.
  31   *
  32   * @package availability_grade
  33   * @copyright 2014 The Open University
  34   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class frontend extends \core_availability\frontend {
  37      protected function get_javascript_strings() {
  38          return array('option_min', 'option_max', 'label_min', 'label_max');
  39      }
  40  
  41      protected function get_javascript_init_params($course, \cm_info $cm = null,
  42              \section_info $section = null) {
  43          global $DB, $CFG;
  44          require_once($CFG->libdir . '/gradelib.php');
  45          require_once($CFG->dirroot . '/course/lib.php');
  46  
  47          // Get grades as basic associative array.
  48          $gradeoptions = array();
  49          $items = \grade_item::fetch_all(array('courseid' => $course->id));
  50          // For some reason the fetch_all things return null if none.
  51          $items = $items ? $items : array();
  52          foreach ($items as $id => $item) {
  53              // Don't include the grade item if it's linked with a module that is being deleted.
  54              if (course_module_instance_pending_deletion($item->courseid, $item->itemmodule, $item->iteminstance)) {
  55                  continue;
  56              }
  57              // Do not include grades for current item.
  58              if ($cm && $cm->instance == $item->iteminstance
  59                      && $cm->modname == $item->itemmodule
  60                      && $item->itemtype == 'mod') {
  61                  continue;
  62              }
  63              $gradeoptions[$id] = $item->get_name(true);
  64          }
  65          \core_collator::asort($gradeoptions);
  66  
  67          // Change to JS array format and return.
  68          $jsarray = array();
  69          foreach ($gradeoptions as $id => $name) {
  70              $jsarray[] = (object)array('id' => $id, 'name' => $name);
  71          }
  72          return array($jsarray);
  73      }
  74  }