"MDL-12304, fix double text"
[moodle-linuxchix.git] / grade / edit / outcome / edit_form.php
blobbd5ced992f3e32c4a8e8a84608c1bf03cd54c82c
1 <?php //$Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
9 // //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
11 // //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
16 // //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
21 // //
22 // http://www.gnu.org/copyleft/gpl.html //
23 // //
24 ///////////////////////////////////////////////////////////////////////////
26 require_once $CFG->libdir.'/formslib.php';
28 class edit_outcome_form extends moodleform {
29 function definition() {
30 global $CFG, $COURSE;
31 $mform =& $this->_form;
33 // visible elements
34 $mform->addElement('header', 'general', get_string('outcomes', 'grades'));
36 $mform->addElement('text', 'fullname', get_string('fullname'), 'size="40"');
37 $mform->addRule('fullname', get_string('required'), 'required');
38 $mform->setType('fullname', PARAM_TEXT);
40 $mform->addElement('text', 'shortname', get_string('shortname'), 'size="20"');
41 $mform->addRule('shortname', get_string('required'), 'required');
42 $mform->setType('shortname', PARAM_NOTAGS);
44 $mform->addElement('advcheckbox', 'standard', get_string('outcomestandard', 'grades'));
45 $mform->setHelpButton('standard', array('outcomestandard', get_string('outcomestandard'), 'grade'));
47 $options = array();
49 $mform->addElement('select', 'scaleid', get_string('scale'), $options);
50 $mform->setHelpButton('scaleid', array('scaleid', get_string('scale'), 'grade'));
51 $mform->addRule('scaleid', get_string('required'), 'required');
53 $mform->addElement('htmleditor', 'description', get_string('description'), array('cols'=>80, 'rows'=>20));
56 // hidden params
57 $mform->addElement('hidden', 'id', 0);
58 $mform->setType('id', PARAM_INT);
60 $mform->addElement('hidden', 'courseid', 0);
61 $mform->setType('courseid', PARAM_INT);
63 /// add return tracking info
64 $gpr = $this->_customdata['gpr'];
65 $gpr->add_mform_elements($mform);
67 //-------------------------------------------------------------------------------
68 // buttons
69 $this->add_action_buttons();
73 /// tweak the form - depending on existing data
74 function definition_after_data() {
75 global $CFG;
77 $mform =& $this->_form;
79 // first load proper scales
80 if ($courseid = $mform->getElementValue('courseid')) {
81 $options = array();
82 if ($scales = grade_scale::fetch_all_local($courseid)) {
83 $options[-1] = '--'.get_string('scalescustom');
84 foreach($scales as $scale) {
85 $options[$scale->id] = $scale->get_name();
88 if ($scales = grade_scale::fetch_all_global()) {
89 $options[-2] = '--'.get_string('scalesstandard');
90 foreach($scales as $scale) {
91 $options[$scale->id] = $scale->get_name();
94 $scale_el =& $mform->getElement('scaleid');
95 $scale_el->load($options);
97 } else {
98 $options = array();
99 if ($scales = grade_scale::fetch_all_global()) {
100 foreach($scales as $scale) {
101 $options[$scale->id] = $scale->get_name();
104 $scale_el =& $mform->getElement('scaleid');
105 $scale_el->load($options);
108 if ($id = $mform->getElementValue('id')) {
109 $outcome = grade_outcome::fetch(array('id'=>$id));
110 $itemcount = $outcome->get_item_uses_count();
111 $coursecount = $outcome->get_course_uses_count();
113 if ($itemcount) {
114 $mform->hardFreeze('scaleid');
117 if (empty($courseid)) {
118 $mform->hardFreeze('standard');
120 } else if (empty($outcome->courseid) and !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
121 $mform->hardFreeze('standard');
123 } else if ($coursecount and empty($outcome->courseid)) {
124 $mform->hardFreeze('standard');
128 } else {
129 if (empty($courseid) or !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
130 $mform->hardFreeze('standard');
135 /// perform extra validation before submission
136 function validation($data, $files) {
137 $errors = parent::validation($data, $files);
139 if ($data['scaleid'] < 1) {
140 $errors['scaleid'] = get_string('required');
143 if (!empty($data['standard']) and $scale = grade_scale::fetch(array('id'=>$data['scaleid']))) {
144 if (!empty($scale->courseid)) {
145 //TODO: localize
146 $errors['scaleid'] = 'Can not use custom scale in global outcome!';
150 return $errors;