MDL-29794 Initial support for re-using a shared grading form
[moodle.git] / grade / edit / letter / edit_form.php
CommitLineData
e060e33d 1<?php
284abb09 2
e060e33d 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/>.
8ad36f4c 17
bfebaf64
MD
18if (!defined('MOODLE_INTERNAL')) {
19 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
20}
21
284abb09 22require_once $CFG->libdir.'/formslib.php';
23
24class edit_letter_form extends moodleform {
25
d24832f9 26 public function definition() {
284abb09 27 $mform =& $this->_form;
28 $num = $this->_customdata['num'];
29 $admin = $this->_customdata['admin'];
30
31 $mform->addElement('header', 'gradeletters', get_string('gradeletters', 'grades'));
d24832f9 32
395a53ae 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'));
8b61b671 36 $mform->addHelpButton('override', 'overridesitedefaultgradedisplaytype', 'grades');
395a53ae 37 }
284abb09 38
284abb09 39 $gradeletter = get_string('gradeletter', 'grades');
40 $gradeboundary = get_string('gradeboundary', 'grades');
41
42 $percentages = array(-1 => get_string('unused', 'grades'));
43 for ($i=100; $i > -1; $i--) {
44 $percentages[$i] = "$i %";
45 }
46
47 for($i=1; $i<$num+1; $i++) {
48 $gradelettername = 'gradeletter'.$i;
49 $gradeboundaryname = 'gradeboundary'.$i;
50
51 $mform->addElement('text', $gradelettername, $gradeletter." $i");
395a53ae 52 if ($i == 1) {
05a5434a 53 $mform->addHelpButton($gradelettername, 'gradeletter', 'grades');
395a53ae 54 }
284abb09 55 $mform->setType($gradelettername, PARAM_TEXT);
d24832f9 56
395a53ae 57 if (!$admin) {
58 $mform->disabledIf($gradelettername, 'override', 'notchecked');
59 $mform->disabledIf($gradelettername, $gradeboundaryname, 'eq', -1);
60 }
284abb09 61
62 $mform->addElement('select', $gradeboundaryname, $gradeboundary." $i", $percentages);
395a53ae 63 if ($i == 1) {
4d73fde1 64 $mform->addHelpButton($gradeboundaryname, 'gradeboundary', 'grades');
395a53ae 65 }
284abb09 66 $mform->setDefault($gradeboundaryname, -1);
67 $mform->setType($gradeboundaryname, PARAM_INT);
d24832f9 68
395a53ae 69 if (!$admin) {
70 $mform->disabledIf($gradeboundaryname, 'override', 'notchecked');
71 }
284abb09 72 }
73
74 // hidden params
75 $mform->addElement('hidden', 'id');
76 $mform->setType('id', PARAM_INT);
77
78//-------------------------------------------------------------------------------
79 // buttons
80 $this->add_action_buttons(!$admin);
81 }
82
83}
84
6c3ef410 85