source: moodle/trunk/fuentes/availability/condition/grade/classes/frontend.php @ 1331

Last change on this file since 1331 was 1331, checked in by jrpelegrina, 3 years ago

Updated to moodle 3.0.3

File size: 2.4 KB
Line 
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
25namespace availability_grade;
26
27defined('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 */
36class 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
46        // Get grades as basic associative array.
47        $gradeoptions = array();
48        $items = \grade_item::fetch_all(array('courseid' => $course->id));
49        // For some reason the fetch_all things return null if none.
50        $items = $items ? $items : array();
51        foreach ($items as $id => $item) {
52            // Do not include grades for current item.
53            if ($cm && $cm->instance == $item->iteminstance
54                    && $cm->modname == $item->itemmodule
55                    && $item->itemtype == 'mod') {
56                continue;
57            }
58            $gradeoptions[$id] = $item->get_name(true);
59        }
60        \core_collator::asort($gradeoptions);
61
62        // Change to JS array format and return.
63        $jsarray = array();
64        foreach ($gradeoptions as $id => $name) {
65            $jsarray[] = (object)array('id' => $id, 'name' => $name);
66        }
67        return array($jsarray);
68    }
69}
Note: See TracBrowser for help on using the repository browser.