Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/edit/outcome/edit_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 if (!defined('MOODLE_INTERNAL')) {
00019     die('Direct access to this script is forbidden.');    
00020 }
00021 
00022 require_once $CFG->libdir.'/formslib.php';
00023 
00024 class edit_outcome_form extends moodleform {
00025     public function definition() {
00026         global $CFG, $COURSE;
00027         $mform =& $this->_form;
00028 
00029         // visible elements
00030         $mform->addElement('header', 'general', get_string('outcomes', 'grades'));
00031 
00032         $mform->addElement('text', 'fullname', get_string('outcomefullname', 'grades'), 'size="40"');
00033         $mform->addRule('fullname', get_string('required'), 'required');
00034         $mform->setType('fullname', PARAM_TEXT);
00035 
00036         $mform->addElement('text', 'shortname', get_string('outcomeshortname', 'grades'), 'size="20"');
00037         $mform->addRule('shortname', get_string('required'), 'required');
00038         $mform->setType('shortname', PARAM_NOTAGS);
00039 
00040         $mform->addElement('advcheckbox', 'standard', get_string('outcomestandard', 'grades'));
00041         $mform->addHelpButton('standard', 'outcomestandard', 'grades');
00042 
00043         $options = array();
00044 
00045         $mform->addElement('selectwithlink', 'scaleid', get_string('scale'), $options, null,
00046             array('link' => $CFG->wwwroot.'/grade/edit/scale/edit.php?courseid='.$COURSE->id, 'label' => get_string('scalescustomcreate')));
00047         $mform->addHelpButton('scaleid', 'typescale', 'grades');
00048         $mform->addRule('scaleid', get_string('required'), 'required');
00049 
00050         $mform->addElement('editor', 'description_editor', get_string('description'), null, $this->_customdata['editoroptions']);
00051 
00052 
00053         // hidden params
00054         $mform->addElement('hidden', 'id', 0);
00055         $mform->setType('id', PARAM_INT);
00056 
00057         $mform->addElement('hidden', 'courseid', 0);
00058         $mform->setType('courseid', PARAM_INT);
00059 
00061         $gpr = $this->_customdata['gpr'];
00062         $gpr->add_mform_elements($mform);
00063 
00064 //-------------------------------------------------------------------------------
00065         // buttons
00066         $this->add_action_buttons();
00067     }
00068 
00069 
00071     function definition_after_data() {
00072         global $CFG;
00073 
00074         $mform =& $this->_form;
00075 
00076         // first load proper scales
00077         if ($courseid = $mform->getElementValue('courseid')) {
00078             $options = array();
00079             if ($scales = grade_scale::fetch_all_local($courseid)) {
00080                 $options[-1] = '--'.get_string('scalescustom');
00081                 foreach($scales as $scale) {
00082                     $options[$scale->id] = $scale->get_name();
00083                 }
00084             }
00085             if ($scales = grade_scale::fetch_all_global()) {
00086                 $options[-2] = '--'.get_string('scalesstandard');
00087                 foreach($scales as $scale) {
00088                     $options[$scale->id] = $scale->get_name();
00089                 }
00090             }
00091             $scale_el =& $mform->getElement('scaleid');
00092             $scale_el->load($options);
00093 
00094         } else {
00095             $options = array();
00096             if ($scales = grade_scale::fetch_all_global()) {
00097                 foreach($scales as $scale) {
00098                     $options[$scale->id] = $scale->get_name();
00099                 }
00100             }
00101             $scale_el =& $mform->getElement('scaleid');
00102             $scale_el->load($options);
00103         }
00104 
00105         if ($id = $mform->getElementValue('id')) {
00106             $outcome = grade_outcome::fetch(array('id'=>$id));
00107             $itemcount   = $outcome->get_item_uses_count();
00108             $coursecount = $outcome->get_course_uses_count();
00109 
00110             if ($itemcount) {
00111                 $mform->hardFreeze('scaleid');
00112             }
00113 
00114             if (empty($courseid)) {
00115                 $mform->hardFreeze('standard');
00116 
00117             } else if (empty($outcome->courseid) and !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
00118                 $mform->hardFreeze('standard');
00119 
00120             } else if ($coursecount and empty($outcome->courseid)) {
00121                 $mform->hardFreeze('standard');
00122             }
00123 
00124 
00125         } else {
00126             if (empty($courseid) or !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
00127                 $mform->hardFreeze('standard');
00128             }
00129         }
00130     }
00131 
00133     function validation($data, $files) {
00134         $errors = parent::validation($data, $files);
00135 
00136         if ($data['scaleid'] < 1) {
00137             $errors['scaleid'] = get_string('required');
00138         }
00139 
00140         if (!empty($data['standard']) and $scale = grade_scale::fetch(array('id'=>$data['scaleid']))) {
00141             if (!empty($scale->courseid)) {
00142                 //TODO: localize
00143                 $errors['scaleid'] = 'Can not use custom scale in global outcome!';
00144             }
00145         }
00146 
00147         return $errors;
00148     }
00149 
00150 
00151 }
00152 
00153 
 All Data Structures Namespaces Files Functions Variables Enumerations