Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/edit/tree/outcomeitem_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_outcomeitem_form extends moodleform {
00025     function definition() {
00026         global $COURSE, $CFG;
00027 
00028         $mform =& $this->_form;
00029 
00031         $mform->addElement('header', 'general', get_string('gradeoutcomeitem', 'grades'));
00032 
00033         $mform->addElement('text', 'itemname', get_string('itemname', 'grades'));
00034         $mform->addRule('itemname', get_string('required'), 'required', null, 'client');
00035 
00036         $mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades'));
00037         $mform->addHelpButton('iteminfo', 'iteminfo', 'grades');
00038 
00039         $mform->addElement('text', 'idnumber', get_string('idnumbermod'));
00040         $mform->addHelpButton('idnumber', 'idnumbermod');
00041 
00042         // allow setting of outcomes on module items too
00043         $options = array();
00044         if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
00045             foreach ($outcomes as $outcome) {
00046                 $options[$outcome->id] = $outcome->get_name();
00047             }
00048         }
00049         $mform->addElement('selectwithlink', 'outcomeid', get_string('outcome', 'grades'), $options, null,
00050             array('link' => $CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$COURSE->id, 'label' => get_string('outcomeassigntocourse', 'grades')));
00051         $mform->addHelpButton('outcomeid', 'outcome', 'grades');
00052         $mform->addRule('outcomeid', get_string('required'), 'required');
00053 
00054         $options = array(0=>get_string('none'));
00055         if ($coursemods = get_course_mods($COURSE->id)) {
00056             foreach ($coursemods as $coursemod) {
00057                 if ($mod = get_coursemodule_from_id($coursemod->modname, $coursemod->id)) {
00058                     $options[$coursemod->id] = format_string($mod->name);
00059                 }
00060             }
00061         }
00062         $mform->addElement('select', 'cmid', get_string('linkedactivity', 'grades'), $options);
00063         $mform->addHelpButton('cmid', 'linkedactivity', 'grades');
00064         $mform->setDefault('cmid', 0);
00065 
00068         $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
00069         $mform->addHelpButton('hidden', 'hidden', 'grades');
00070         $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true));
00071         $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked');
00072 
00073         //locking
00074         $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));
00075         $mform->addHelpButton('locked', 'locked', 'grades');
00076         $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional'=>true));
00077 
00079         $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));
00080 
00081         $options = array();
00082         $default = '';
00083         $coefstring = '';
00084         $categories = grade_category::fetch_all(array('courseid'=>$COURSE->id));
00085         foreach ($categories as $cat) {
00086             $cat->apply_forced_settings();
00087             $options[$cat->id] = $cat->get_name();
00088             if ($cat->is_course_category()) {
00089                 $default = $cat->id;
00090             }
00091             if ($cat->is_aggregationcoef_used()) {
00092                 if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
00093                     $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefweight') ? 'aggregationcoefweight' : 'aggregationcoef';
00094 
00095                 } else if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
00096                     $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextrasum') ? 'aggregationcoefextrasum' : 'aggregationcoef';
00097 
00098                 } else if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
00099                     $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextraweight') ? 'aggregationcoefextraweight' : 'aggregationcoef';
00100 
00101                 } else if ($cat->aggregation == GRADE_AGGREGATE_SUM) {
00102                     $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextrasum') ? 'aggregationcoefextrasum' : 'aggregationcoef';
00103 
00104                 } else {
00105                     $coefstring = 'aggregationcoef';
00106                 }
00107             } else {
00108                 $mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $cat->id);
00109             }
00110         }
00111 
00112         if (count($categories) > 1) {
00113             $mform->addElement('select', 'parentcategory', get_string('gradecategory', 'grades'), $options);
00114             $mform->disabledIf('parentcategory', 'cmid', 'noteq', 0);
00115         }
00116 
00117         if ($coefstring !== '') {
00118             if ($coefstring == 'aggregationcoefextrasum') {
00119                 // advcheckbox is not compatible with disabledIf!
00120                 $mform->addElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades'));
00121             } else {
00122                 $mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
00123             }
00124             $mform->addHelpButton('aggregationcoef', $coefstring, 'grades');
00125         }
00126 
00128         $mform->addElement('hidden', 'id', 0);
00129         $mform->setType('id', PARAM_INT);
00130 
00131         $mform->addElement('hidden', 'courseid', $COURSE->id);
00132         $mform->setType('courseid', PARAM_INT);
00133 
00135         $gpr = $this->_customdata['gpr'];
00136         $gpr->add_mform_elements($mform);
00137 
00139         if (isset($CFG->grade_item_advanced)) {
00140             $advanced = explode(',', $CFG->grade_item_advanced);
00141             foreach ($advanced as $el) {
00142                 if ($mform->elementExists($el)) {
00143                     $mform->setAdvanced($el);
00144                 }
00145             }
00146         }
00147 //-------------------------------------------------------------------------------
00148         // buttons
00149         $this->add_action_buttons();
00150     }
00151 
00152 
00154     function definition_after_data() {
00155         global $CFG, $COURSE;
00156 
00157         $mform =& $this->_form;
00158 
00159         if ($id = $mform->getElementValue('id')) {
00160             $grade_item = grade_item::fetch(array('id'=>$id));
00161 
00162             //remove the aggregation coef element if not needed
00163             if ($grade_item->is_course_item()) {
00164                 if ($mform->elementExists('parentcategory')) {
00165                     $mform->removeElement('parentcategory');
00166                 }
00167                 if ($mform->elementExists('aggregationcoef')) {
00168                     $mform->removeElement('aggregationcoef');
00169                 }
00170 
00171             } else {
00172                 // if we wanted to change parent of existing item - we would have to verify there are no circular references in parents!!!
00173                 if ($mform->elementExists('parentcategory')) {
00174                     $mform->hardFreeze('parentcategory');
00175                 }
00176 
00177                 if ($grade_item->is_category_item()) {
00178                     $category = $grade_item->get_item_category();
00179                     $parent_category = $category->get_parent_category();
00180                 } else {
00181                     $parent_category = $grade_item->get_parent_category();
00182                 }
00183 
00184                 $parent_category->apply_forced_settings();
00185 
00186                 if (!$parent_category->is_aggregationcoef_used() or $parent_category->aggregation == GRADE_AGGREGATE_SUM) {
00187                     if ($mform->elementExists('aggregationcoef')) {
00188                         $mform->removeElement('aggregationcoef');
00189                     }
00190                 } else {
00191                     //fix label if needed
00192                     $agg_el =& $mform->getElement('aggregationcoef');
00193                     $aggcoef = '';
00194                     if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
00195                         $aggcoef = 'aggregationcoefweight';
00196 
00197                     } else if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
00198                         $aggcoef = 'aggregationcoefextrasum';
00199 
00200                     } else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
00201                         $aggcoef = 'aggregationcoefextraweight';
00202 
00203                     } else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
00204                         $aggcoef = 'aggregationcoefextrasum';
00205                     }
00206 
00207                     if ($aggcoef !== '') {
00208                         $agg_el->setLabel(get_string($aggcoef, 'grades'));
00209                         $mform->addHelpButton('aggregationcoef', $aggcoef, 'grades');
00210                     }
00211                 }
00212             }
00213 
00214         }
00215 
00216         // no parent header for course category
00217         if (!$mform->elementExists('aggregationcoef') and !$mform->elementExists('parentcategory')) {
00218             $mform->removeElement('headerparent');
00219         }
00220     }
00221 
00222 
00224     function validation($data, $files) {
00225         global $COURSE;
00226 
00227         $errors = parent::validation($data, $files);
00228 
00229         if (array_key_exists('idnumber', $data)) {
00230             if ($data['id']) {
00231                 $grade_item = new grade_item(array('id'=>$data['id'], 'courseid'=>$data['courseid']));
00232             } else {
00233                 $grade_item = null;
00234             }
00235             if (!grade_verify_idnumber($data['idnumber'], $COURSE->id, $grade_item, null)) {
00236                 $errors['idnumber'] = get_string('idnumbertaken');
00237             }
00238         }
00239 
00240         return $errors;
00241     }
00242 
00243 }
00244 
 All Data Structures Namespaces Files Functions Variables Enumerations