MDL-29794 Initial support for re-using a shared grading form
[moodle.git] / grade / edit / letter / edit_form.php
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
18 if (!defined('MOODLE_INTERNAL')) {
19     die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
20 }
22 require_once $CFG->libdir.'/formslib.php';
24 class edit_letter_form extends moodleform {
26     public function definition() {
27         $mform =& $this->_form;
28         $num   = $this->_customdata['num'];
29         $admin = $this->_customdata['admin'];
31         $mform->addElement('header', 'gradeletters', get_string('gradeletters', 'grades'));
33         // Only show "override site defaults" checkbox if editing the course grade letters
34         if (!$admin) {
35             $mform->addElement('checkbox', 'override', get_string('overridesitedefaultgradedisplaytype', 'grades'));
36             $mform->addHelpButton('override', 'overridesitedefaultgradedisplaytype', 'grades');
37         }
39         $gradeletter       = get_string('gradeletter', 'grades');
40         $gradeboundary     = get_string('gradeboundary', 'grades');
42         $percentages = array(-1 => get_string('unused', 'grades'));
43         for ($i=100; $i > -1; $i--) {
44             $percentages[$i] = "$i %";
45         }
47         for($i=1; $i<$num+1; $i++) {
48             $gradelettername = 'gradeletter'.$i;
49             $gradeboundaryname = 'gradeboundary'.$i;
51             $mform->addElement('text', $gradelettername, $gradeletter." $i");
52             if ($i == 1) {
53                 $mform->addHelpButton($gradelettername, 'gradeletter', 'grades');
54             }
55             $mform->setType($gradelettername, PARAM_TEXT);
57             if (!$admin) {
58                 $mform->disabledIf($gradelettername, 'override', 'notchecked');
59                 $mform->disabledIf($gradelettername, $gradeboundaryname, 'eq', -1);
60             }
62             $mform->addElement('select', $gradeboundaryname, $gradeboundary." $i", $percentages);
63             if ($i == 1) {
64                 $mform->addHelpButton($gradeboundaryname, 'gradeboundary', 'grades');
65             }
66             $mform->setDefault($gradeboundaryname, -1);
67             $mform->setType($gradeboundaryname, PARAM_INT);
69             if (!$admin) {
70                 $mform->disabledIf($gradeboundaryname, 'override', 'notchecked');
71             }
72         }
74         // hidden params
75         $mform->addElement('hidden', 'id');
76         $mform->setType('id', PARAM_INT);
78 //-------------------------------------------------------------------------------
79         // buttons
80         $this->add_action_buttons(!$admin);
81     }
83 }