1 |
efrain |
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 moodleform for editing grade letters
|
|
|
19 |
*
|
|
|
20 |
* @package core_grades
|
|
|
21 |
* @copyright 2007 Petr Skoda
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
if (!defined('MOODLE_INTERNAL')) {
|
|
|
26 |
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
require_once $CFG->libdir.'/formslib.php';
|
|
|
30 |
|
|
|
31 |
class edit_letter_form extends moodleform {
|
|
|
32 |
|
|
|
33 |
public function definition() {
|
|
|
34 |
$mform =& $this->_form;
|
|
|
35 |
|
|
|
36 |
[
|
|
|
37 |
'lettercount' => $lettercount,
|
|
|
38 |
'admin' => $admin,
|
|
|
39 |
] = $this->_customdata;
|
|
|
40 |
|
|
|
41 |
$mform->addElement('header', 'gradeletters', get_string('gradeletters', 'grades'));
|
|
|
42 |
|
|
|
43 |
// Only show "override site defaults" checkbox if editing the course grade letters
|
|
|
44 |
if (!$admin) {
|
|
|
45 |
$mform->addElement('checkbox', 'override', get_string('overridesitedefaultgradedisplaytype', 'grades'));
|
|
|
46 |
$mform->addHelpButton('override', 'overridesitedefaultgradedisplaytype', 'grades');
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
$gradeletter = get_string('gradeletter', 'grades');
|
|
|
50 |
$gradeboundary = get_string('gradeboundary', 'grades');
|
|
|
51 |
|
|
|
52 |
// The fields to create the grade letter/boundary.
|
|
|
53 |
$elements = [];
|
|
|
54 |
$elements[] = $mform->createElement('text', 'gradeletter', "{$gradeletter} {no}");
|
|
|
55 |
$elements[] = $mform->createElement('static', '', '', '≥');
|
|
|
56 |
$elements[] = $mform->createElement('float', 'gradeboundary', "{$gradeboundary} {no}");
|
|
|
57 |
$elements[] = $mform->createElement('static', '', '', '%');
|
|
|
58 |
|
|
|
59 |
// Element options/rules, fields should be disabled unless "Override" is checked for course grade letters.
|
|
|
60 |
$options = [];
|
|
|
61 |
$options['gradeletter']['type'] = PARAM_TEXT;
|
|
|
62 |
|
|
|
63 |
if (!$admin) {
|
|
|
64 |
$options['gradeletter']['disabledif'] = ['override', 'notchecked'];
|
|
|
65 |
$options['gradeboundary']['disabledif'] = ['override', 'notchecked'];
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
// Create our repeatable elements, each one a group comprised of the fields defined previously.
|
|
|
69 |
$this->repeat_elements([
|
|
|
70 |
$mform->createElement('group', 'gradeentry', "{$gradeletter} {no}", $elements, [' '], false)
|
|
|
71 |
], $lettercount, $options, 'gradeentrycount', 'gradeentryadd', 3);
|
|
|
72 |
|
|
|
73 |
// Add a help icon to first element group, if it exists.
|
|
|
74 |
if ($mform->elementExists('gradeentry[0]')) {
|
|
|
75 |
$mform->addHelpButton('gradeentry[0]', 'gradeletter', 'grades');
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
$mform->addElement('hidden', 'id');
|
|
|
79 |
$mform->setType('id', PARAM_INT);
|
|
|
80 |
|
|
|
81 |
$this->add_action_buttons();
|
|
|
82 |
}
|
|
|
83 |
}
|