1
<?php //$Id: edit_form.php,v 1.5.2.3 2008/10/22 09:09:32 nicolasconnault Exp $
3
///////////////////////////////////////////////////////////////////////////
5
// NOTICE OF COPYRIGHT //
7
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
8
// http://moodle.com //
10
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
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. //
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: //
22
// http://www.gnu.org/copyleft/gpl.html //
24
///////////////////////////////////////////////////////////////////////////
26
require_once $CFG->libdir.'/formslib.php';
28
class edit_outcome_form extends moodleform {
29
function definition() {
31
$mform =& $this->_form;
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'));
49
$mform->addElement('selectwithlink', 'scaleid', get_string('scale'), $options, null,
50
array('link' => $CFG->wwwroot.'/grade/edit/scale/edit.php?courseid='.$COURSE->id, 'label' => get_string('scalescustomcreate')));
51
$mform->setHelpButton('scaleid', array('scaleid', get_string('scale'), 'grade'));
52
$mform->addRule('scaleid', get_string('required'), 'required');
54
$mform->addElement('htmleditor', 'description', get_string('description'), array('cols'=>80, 'rows'=>20));
58
$mform->addElement('hidden', 'id', 0);
59
$mform->setType('id', PARAM_INT);
61
$mform->addElement('hidden', 'courseid', 0);
62
$mform->setType('courseid', PARAM_INT);
64
/// add return tracking info
65
$gpr = $this->_customdata['gpr'];
66
$gpr->add_mform_elements($mform);
68
//-------------------------------------------------------------------------------
70
$this->add_action_buttons();
74
/// tweak the form - depending on existing data
75
function definition_after_data() {
78
$mform =& $this->_form;
80
// first load proper scales
81
if ($courseid = $mform->getElementValue('courseid')) {
83
if ($scales = grade_scale::fetch_all_local($courseid)) {
84
$options[-1] = '--'.get_string('scalescustom');
85
foreach($scales as $scale) {
86
$options[$scale->id] = $scale->get_name();
89
if ($scales = grade_scale::fetch_all_global()) {
90
$options[-2] = '--'.get_string('scalesstandard');
91
foreach($scales as $scale) {
92
$options[$scale->id] = $scale->get_name();
95
$scale_el =& $mform->getElement('scaleid');
96
$scale_el->load($options);
100
if ($scales = grade_scale::fetch_all_global()) {
101
foreach($scales as $scale) {
102
$options[$scale->id] = $scale->get_name();
105
$scale_el =& $mform->getElement('scaleid');
106
$scale_el->load($options);
109
if ($id = $mform->getElementValue('id')) {
110
$outcome = grade_outcome::fetch(array('id'=>$id));
111
$itemcount = $outcome->get_item_uses_count();
112
$coursecount = $outcome->get_course_uses_count();
115
$mform->hardFreeze('scaleid');
118
if (empty($courseid)) {
119
$mform->hardFreeze('standard');
121
} else if (empty($outcome->courseid) and !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
122
$mform->hardFreeze('standard');
124
} else if ($coursecount and empty($outcome->courseid)) {
125
$mform->hardFreeze('standard');
130
if (empty($courseid) or !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
131
$mform->hardFreeze('standard');
136
/// perform extra validation before submission
137
function validation($data, $files) {
138
$errors = parent::validation($data, $files);
140
if ($data['scaleid'] < 1) {
141
$errors['scaleid'] = get_string('required');
144
if (!empty($data['standard']) and $scale = grade_scale::fetch(array('id'=>$data['scaleid']))) {
145
if (!empty($scale->courseid)) {
147
$errors['scaleid'] = 'Can not use custom scale in global outcome!';