[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * A moodleform to edit the grade options for an individual grade category 19 * 20 * @package core_grades 21 * @copyright 2007 Petr Skoda 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 if (!defined('MOODLE_INTERNAL')) { 26 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page 27 } 28 29 require_once $CFG->libdir.'/formslib.php'; 30 31 class edit_category_form extends moodleform { 32 private $aggregation_options = array(); 33 34 function definition() { 35 global $CFG, $COURSE, $DB, $OUTPUT; 36 $mform =& $this->_form; 37 38 $category = $this->_customdata['current']; 39 40 $this->aggregation_options = grade_helper::get_aggregation_strings(); 41 42 // visible elements 43 $mform->addElement('header', 'headercategory', get_string('gradecategory', 'grades')); 44 $mform->addElement('text', 'fullname', get_string('categoryname', 'grades')); 45 $mform->setType('fullname', PARAM_TEXT); 46 $mform->addRule('fullname', null, 'required', null, 'client'); 47 48 $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_options); 49 $mform->addHelpButton('aggregation', 'aggregation', 'grades'); 50 51 if ((int)$CFG->grade_aggregation_flag & 2) { 52 $mform->setAdvanced('aggregation'); 53 } 54 55 $mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades')); 56 $mform->addHelpButton('aggregateonlygraded', 'aggregateonlygraded', 'grades'); 57 58 if ((int)$CFG->grade_aggregateonlygraded_flag & 2) { 59 $mform->setAdvanced('aggregateonlygraded'); 60 } 61 62 if (empty($CFG->enableoutcomes)) { 63 $mform->addElement('hidden', 'aggregateoutcomes'); 64 $mform->setType('aggregateoutcomes', PARAM_INT); 65 } else { 66 $mform->addElement('checkbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades')); 67 $mform->addHelpButton('aggregateoutcomes', 'aggregateoutcomes', 'grades'); 68 if ((int)$CFG->grade_aggregateoutcomes_flag & 2) { 69 $mform->setAdvanced('aggregateoutcomes'); 70 } 71 } 72 73 $mform->addElement('text', 'keephigh', get_string('keephigh', 'grades'), 'size="3"'); 74 $mform->setType('keephigh', PARAM_INT); 75 $mform->addHelpButton('keephigh', 'keephigh', 'grades'); 76 if ((int)$CFG->grade_keephigh_flag & 2) { 77 $mform->setAdvanced('keephigh'); 78 } 79 80 $mform->addElement('text', 'droplow', get_string('droplow', 'grades'), 'size="3"'); 81 $mform->setType('droplow', PARAM_INT); 82 $mform->addHelpButton('droplow', 'droplow', 'grades'); 83 $mform->disabledIf('droplow', 'keephigh', 'noteq', 0); 84 if ((int)$CFG->grade_droplow_flag & 2) { 85 $mform->setAdvanced('droplow'); 86 } 87 88 $mform->disabledIf('keephigh', 'droplow', 'noteq', 0); 89 $mform->disabledIf('droplow', 'keephigh', 'noteq', 0); 90 91 // Grade item settings 92 // Displayed as Category total to avoid confusion between grade items requiring marking and category totals 93 $mform->addElement('header', 'general', get_string('categorytotal', 'grades')); 94 95 $mform->addElement('text', 'grade_item_itemname', get_string('categorytotalname', 'grades')); 96 $mform->setType('grade_item_itemname', PARAM_TEXT); 97 $mform->setAdvanced('grade_item_itemname'); 98 99 $mform->addElement('text', 'grade_item_iteminfo', get_string('iteminfo', 'grades')); 100 $mform->addHelpButton('grade_item_iteminfo', 'iteminfo', 'grades'); 101 $mform->setType('grade_item_iteminfo', PARAM_TEXT); 102 103 $mform->addElement('text', 'grade_item_idnumber', get_string('idnumbermod')); 104 $mform->addHelpButton('grade_item_idnumber', 'idnumbermod'); 105 $mform->setType('grade_item_idnumber', PARAM_RAW); 106 107 if (!empty($category->id)) { 108 $gradecategory = grade_category::fetch(array('id' => $category->id)); 109 $gradeitem = $gradecategory->load_grade_item(); 110 111 // If grades exist set a message so the user knows why they can not alter the grade type or scale. 112 // We could never change the grade type for external items, so only need to show this for manual grade items. 113 if ($gradeitem->has_overridden_grades()) { 114 // Set a message so the user knows why the can not alter the grade type or scale. 115 if ($gradeitem->gradetype == GRADE_TYPE_SCALE) { 116 $gradesexistmsg = get_string('modgradecategorycantchangegradetyporscalemsg', 'grades'); 117 } else { 118 $gradesexistmsg = get_string('modgradecategorycantchangegradetypemsg', 'grades'); 119 } 120 $notification = new \core\output\notification($gradesexistmsg, \core\output\notification::NOTIFY_INFO); 121 $notification->set_show_closebutton(false); 122 $mform->addElement('static', 'gradesexistmsg', '', $OUTPUT->render($notification)); 123 } 124 } 125 126 $options = array(GRADE_TYPE_NONE=>get_string('typenone', 'grades'), 127 GRADE_TYPE_VALUE=>get_string('typevalue', 'grades'), 128 GRADE_TYPE_SCALE=>get_string('typescale', 'grades'), 129 GRADE_TYPE_TEXT=>get_string('typetext', 'grades')); 130 131 $mform->addElement('select', 'grade_item_gradetype', get_string('gradetype', 'grades'), $options); 132 $mform->addHelpButton('grade_item_gradetype', 'gradetype', 'grades'); 133 $mform->setDefault('grade_item_gradetype', GRADE_TYPE_VALUE); 134 $mform->disabledIf('grade_item_gradetype', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); 135 136 //$mform->addElement('text', 'calculation', get_string('calculation', 'grades')); 137 //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_TEXT); 138 //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE); 139 140 $options = array(0=>get_string('usenoscale', 'grades')); 141 if ($scales = grade_scale::fetch_all_local($COURSE->id)) { 142 foreach ($scales as $scale) { 143 $options[$scale->id] = $scale->get_name(); 144 } 145 } 146 if ($scales = grade_scale::fetch_all_global()) { 147 foreach ($scales as $scale) { 148 $options[$scale->id] = $scale->get_name(); 149 } 150 } 151 // ugly BC hack - it was possible to use custom scale from other courses :-( 152 if (!empty($category->grade_item_scaleid) and !isset($options[$category->grade_item_scaleid])) { 153 if ($scale = grade_scale::fetch(array('id'=>$category->grade_item_scaleid))) { 154 $options[$scale->id] = $scale->get_name().' '.get_string('incorrectcustomscale', 'grades'); 155 } 156 } 157 $mform->addElement('select', 'grade_item_scaleid', get_string('scale'), $options); 158 $mform->addHelpButton('grade_item_scaleid', 'typescale', 'grades'); 159 $mform->disabledIf('grade_item_scaleid', 'grade_item_gradetype', 'noteq', GRADE_TYPE_SCALE); 160 $mform->disabledIf('grade_item_scaleid', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); 161 162 $choices = array(); 163 $choices[''] = get_string('choose'); 164 $choices['no'] = get_string('no'); 165 $choices['yes'] = get_string('yes'); 166 $mform->addElement('select', 'grade_item_rescalegrades', get_string('modgradecategoryrescalegrades', 'grades'), $choices); 167 $mform->addHelpButton('grade_item_rescalegrades', 'modgradecategoryrescalegrades', 'grades'); 168 $mform->disabledIf('grade_item_rescalegrades', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE); 169 170 $mform->addElement('text', 'grade_item_grademax', get_string('grademax', 'grades')); 171 $mform->setType('grade_item_grademax', PARAM_RAW); 172 $mform->addHelpButton('grade_item_grademax', 'grademax', 'grades'); 173 $mform->disabledIf('grade_item_grademax', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE); 174 $mform->disabledIf('grade_item_grademax', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); 175 176 if ((bool) get_config('moodle', 'grade_report_showmin')) { 177 $mform->addElement('text', 'grade_item_grademin', get_string('grademin', 'grades')); 178 $mform->setType('grade_item_grademin', PARAM_RAW); 179 $mform->addHelpButton('grade_item_grademin', 'grademin', 'grades'); 180 $mform->disabledIf('grade_item_grademin', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE); 181 $mform->disabledIf('grade_item_grademin', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); 182 } 183 184 $mform->addElement('text', 'grade_item_gradepass', get_string('gradepass', 'grades')); 185 $mform->setType('grade_item_gradepass', PARAM_RAW); 186 $mform->addHelpButton('grade_item_gradepass', 'gradepass', 'grades'); 187 $mform->disabledIf('grade_item_gradepass', 'grade_item_gradetype', 'eq', GRADE_TYPE_NONE); 188 $mform->disabledIf('grade_item_gradepass', 'grade_item_gradetype', 'eq', GRADE_TYPE_TEXT); 189 190 /// grade display prefs 191 $default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype); 192 $options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'), 193 GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), 194 GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), 195 GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'), 196 GRADE_DISPLAY_TYPE_REAL_PERCENTAGE => get_string('realpercentage', 'grades'), 197 GRADE_DISPLAY_TYPE_REAL_LETTER => get_string('realletter', 'grades'), 198 GRADE_DISPLAY_TYPE_LETTER_REAL => get_string('letterreal', 'grades'), 199 GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE => get_string('letterpercentage', 'grades'), 200 GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER => get_string('percentageletter', 'grades'), 201 GRADE_DISPLAY_TYPE_PERCENTAGE_REAL => get_string('percentagereal', 'grades') 202 ); 203 204 asort($options); 205 206 foreach ($options as $key=>$option) { 207 if ($key == $default_gradedisplaytype) { 208 $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option); 209 break; 210 } 211 } 212 $mform->addElement('select', 'grade_item_display', get_string('gradedisplaytype', 'grades'), $options); 213 $mform->addHelpButton('grade_item_display', 'gradedisplaytype', 'grades'); 214 215 $default_gradedecimals = grade_get_setting($COURSE->id, 'decimalpoints', $CFG->grade_decimalpoints); 216 $options = array(-1=>get_string('defaultprev', 'grades', $default_gradedecimals), 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5); 217 $mform->addElement('select', 'grade_item_decimals', get_string('decimalpoints', 'grades'), $options); 218 $mform->addHelpButton('grade_item_decimals', 'decimalpoints', 'grades'); 219 $mform->setDefault('grade_item_decimals', -1); 220 $mform->disabledIf('grade_item_decimals', 'grade_item_display', 'eq', GRADE_DISPLAY_TYPE_LETTER); 221 222 if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) { 223 $mform->disabledIf('grade_item_decimals', 'grade_item_display', "eq", GRADE_DISPLAY_TYPE_DEFAULT); 224 } 225 226 /// hiding 227 // advcheckbox is not compatible with disabledIf! 228 $mform->addElement('checkbox', 'grade_item_hidden', get_string('hidden', 'grades')); 229 $mform->addHelpButton('grade_item_hidden', 'hidden', 'grades'); 230 $mform->addElement('date_time_selector', 'grade_item_hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true)); 231 $mform->disabledIf('grade_item_hidden', 'grade_item_hiddenuntil[off]', 'notchecked'); 232 233 /// locking 234 $mform->addElement('checkbox', 'grade_item_locked', get_string('locked', 'grades')); 235 $mform->addHelpButton('grade_item_locked', 'locked', 'grades'); 236 237 $mform->addElement('date_time_selector', 'grade_item_locktime', get_string('locktime', 'grades'), array('optional'=>true)); 238 $mform->disabledIf('grade_item_locktime', 'grade_item_gradetype', 'eq', GRADE_TYPE_NONE); 239 240 /// parent category related settings 241 $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades')); 242 243 $mform->addElement('advcheckbox', 'grade_item_weightoverride', get_string('adjustedweight', 'grades')); 244 $mform->addHelpButton('grade_item_weightoverride', 'weightoverride', 'grades'); 245 246 $mform->addElement('text', 'grade_item_aggregationcoef2', get_string('weight', 'grades')); 247 $mform->addHelpButton('grade_item_aggregationcoef2', 'weight', 'grades'); 248 $mform->setType('grade_item_aggregationcoef2', PARAM_RAW); 249 $mform->disabledIf('grade_item_aggregationcoef2', 'grade_item_weightoverride'); 250 251 $options = array(); 252 $default = -1; 253 $categories = grade_category::fetch_all(array('courseid'=>$COURSE->id)); 254 255 foreach ($categories as $cat) { 256 $cat->apply_forced_settings(); 257 $options[$cat->id] = $cat->get_name(); 258 if ($cat->is_course_category()) { 259 $default = $cat->id; 260 } 261 } 262 263 if (count($categories) > 1) { 264 $mform->addElement('select', 'parentcategory', get_string('parentcategory', 'grades'), $options); 265 $mform->setDefault('parentcategory', $default); 266 $mform->addElement('static', 'currentparentaggregation', get_string('currentparentaggregation', 'grades')); 267 } 268 269 // hidden params 270 $mform->addElement('hidden', 'id', 0); 271 $mform->setType('id', PARAM_INT); 272 273 $mform->addElement('hidden', 'courseid', 0); 274 $mform->setType('courseid', PARAM_INT); 275 276 /// add return tracking info 277 $gpr = $this->_customdata['gpr']; 278 $gpr->add_mform_elements($mform); 279 280 /// mark advanced according to site settings 281 if (isset($CFG->grade_item_advanced)) { 282 $advanced = explode(',', $CFG->grade_item_advanced); 283 foreach ($advanced as $el) { 284 $el = 'grade_item_'.$el; 285 if ($mform->elementExists($el)) { 286 $mform->setAdvanced($el); 287 } 288 } 289 } 290 291 //------------------------------------------------------------------------------- 292 // buttons 293 $this->add_action_buttons(); 294 //------------------------------------------------------------------------------- 295 $this->set_data($category); 296 } 297 298 299 /// tweak the form - depending on existing data 300 function definition_after_data() { 301 global $CFG, $COURSE; 302 303 $mform =& $this->_form; 304 305 $somecat = new grade_category(); 306 307 foreach ($somecat->forceable as $property) { 308 if ((int)$CFG->{"grade_{$property}_flag"} & 1) { 309 if ($mform->elementExists($property)) { 310 if (empty($CFG->grade_hideforcedsettings)) { 311 $mform->hardFreeze($property); 312 } else { 313 if ($mform->elementExists($property)) { 314 $mform->removeElement($property); 315 } 316 } 317 } 318 } 319 } 320 321 if ($CFG->grade_droplow > 0) { 322 if ($mform->elementExists('keephigh')) { 323 $mform->removeElement('keephigh'); 324 } 325 } else if ($CFG->grade_keephigh > 0) { 326 if ($mform->elementExists('droplow')) { 327 $mform->removeElement('droplow'); 328 } 329 } 330 331 if ($id = $mform->getElementValue('id')) { 332 $grade_category = grade_category::fetch(array('id'=>$id)); 333 $grade_item = $grade_category->load_grade_item(); 334 335 // remove agg coef if not used 336 if ($grade_category->is_course_category()) { 337 if ($mform->elementExists('parentcategory')) { 338 $mform->removeElement('parentcategory'); 339 } 340 if ($mform->elementExists('currentparentaggregation')) { 341 $mform->removeElement('currentparentaggregation'); 342 } 343 344 } else { 345 // if we wanted to change parent of existing category - we would have to verify there are no circular references in parents!!! 346 if ($mform->elementExists('parentcategory')) { 347 $mform->hardFreeze('parentcategory'); 348 } 349 $parent_cat = $grade_category->get_parent_category(); 350 $mform->setDefault('currentparentaggregation', $this->aggregation_options[$parent_cat->aggregation]); 351 352 } 353 354 // Prevent the user from using drop lowest/keep highest when the aggregation method cannot handle it. 355 if (!$grade_category->can_apply_limit_rules()) { 356 if ($mform->elementExists('keephigh')) { 357 $mform->setConstant('keephigh', 0); 358 $mform->hardFreeze('keephigh'); 359 } 360 if ($mform->elementExists('droplow')) { 361 $mform->setConstant('droplow', 0); 362 $mform->hardFreeze('droplow'); 363 } 364 } 365 366 if ($grade_item->is_calculated()) { 367 // following elements are ignored when calculation formula used 368 if ($mform->elementExists('aggregation')) { 369 $mform->removeElement('aggregation'); 370 } 371 if ($mform->elementExists('keephigh')) { 372 $mform->removeElement('keephigh'); 373 } 374 if ($mform->elementExists('droplow')) { 375 $mform->removeElement('droplow'); 376 } 377 if ($mform->elementExists('aggregateonlygraded')) { 378 $mform->removeElement('aggregateonlygraded'); 379 } 380 if ($mform->elementExists('aggregateoutcomes')) { 381 $mform->removeElement('aggregateoutcomes'); 382 } 383 } 384 385 // If it is a course category, remove the "required" rule from the "fullname" element 386 if ($grade_category->is_course_category()) { 387 unset($mform->_rules['fullname']); 388 $key = array_search('fullname', $mform->_required); 389 unset($mform->_required[$key]); 390 } 391 392 // If it is a course category and its fullname is ?, show an empty field 393 if ($grade_category->is_course_category() && $mform->getElementValue('fullname') == '?') { 394 $mform->setDefault('fullname', ''); 395 } 396 // remove unwanted aggregation options 397 if ($mform->elementExists('aggregation')) { 398 $allaggoptions = array_keys($this->aggregation_options); 399 $agg_el =& $mform->getElement('aggregation'); 400 $visible = explode(',', $CFG->grade_aggregations_visible); 401 if (!is_null($grade_category->aggregation)) { 402 // current type is always visible 403 $visible[] = $grade_category->aggregation; 404 } 405 foreach ($allaggoptions as $type) { 406 if (!in_array($type, $visible)) { 407 $agg_el->removeOption($type); 408 } 409 } 410 } 411 412 } else { 413 // adding new category 414 if ($mform->elementExists('currentparentaggregation')) { 415 $mform->removeElement('currentparentaggregation'); 416 } 417 // remove unwanted aggregation options 418 if ($mform->elementExists('aggregation')) { 419 $allaggoptions = array_keys($this->aggregation_options); 420 $agg_el =& $mform->getElement('aggregation'); 421 $visible = explode(',', $CFG->grade_aggregations_visible); 422 foreach ($allaggoptions as $type) { 423 if (!in_array($type, $visible)) { 424 $agg_el->removeOption($type); 425 } 426 } 427 } 428 429 $mform->removeElement('grade_item_rescalegrades'); 430 } 431 432 433 // no parent header for course category 434 if (!$mform->elementExists('parentcategory')) { 435 $mform->removeElement('headerparent'); 436 } 437 438 /// GRADE ITEM 439 if ($id = $mform->getElementValue('id')) { 440 $grade_category = grade_category::fetch(array('id'=>$id)); 441 $grade_item = $grade_category->load_grade_item(); 442 443 $mform->setDefault('grade_item_hidden', (int) $grade_item->hidden); 444 445 if ($grade_item->is_outcome_item()) { 446 // we have to prevent incompatible modifications of outcomes if outcomes disabled 447 $mform->removeElement('grade_item_grademax'); 448 if ($mform->elementExists('grade_item_grademin')) { 449 $mform->removeElement('grade_item_grademin'); 450 } 451 $mform->removeElement('grade_item_gradetype'); 452 $mform->removeElement('grade_item_display'); 453 $mform->removeElement('grade_item_decimals'); 454 $mform->hardFreeze('grade_item_scaleid'); 455 // Only show the option to rescale grades on a category if its corresponding grade_item has overridden grade_grades. 456 } else if ($grade_item->has_overridden_grades()) { 457 // Can't change the grade type or the scale if there are grades. 458 $mform->hardFreeze('grade_item_gradetype, grade_item_scaleid'); 459 460 // If we are using scles then remove the unnecessary rescale and grade fields. 461 if ($grade_item->gradetype == GRADE_TYPE_SCALE) { 462 $mform->removeElement('grade_item_rescalegrades'); 463 $mform->removeElement('grade_item_grademax'); 464 if ($mform->elementExists('grade_item_grademin')) { 465 $mform->removeElement('grade_item_grademin'); 466 } 467 } else { // Not using scale, so remove it. 468 $mform->removeElement('grade_item_scaleid'); 469 $mform->disabledIf('grade_item_grademax', 'grade_item_rescalegrades', 'eq', ''); 470 $mform->disabledIf('grade_item_grademin', 'grade_item_rescalegrades', 'eq', ''); 471 } 472 } else { // Remove the rescale element if there are no grades. 473 $mform->removeElement('grade_item_rescalegrades'); 474 } 475 476 //remove the aggregation coef element if not needed 477 if ($grade_item->is_course_item()) { 478 if ($mform->elementExists('grade_item_aggregationcoef')) { 479 $mform->removeElement('grade_item_aggregationcoef'); 480 } 481 482 if ($mform->elementExists('grade_item_weightoverride')) { 483 $mform->removeElement('grade_item_weightoverride'); 484 } 485 if ($mform->elementExists('grade_item_aggregationcoef2')) { 486 $mform->removeElement('grade_item_aggregationcoef2'); 487 } 488 } else { 489 if ($grade_item->is_category_item()) { 490 $category = $grade_item->get_item_category(); 491 $parent_category = $category->get_parent_category(); 492 } else { 493 $parent_category = $grade_item->get_parent_category(); 494 } 495 496 $parent_category->apply_forced_settings(); 497 498 if (!$parent_category->is_aggregationcoef_used()) { 499 if ($mform->elementExists('grade_item_aggregationcoef')) { 500 $mform->removeElement('grade_item_aggregationcoef'); 501 } 502 } else { 503 504 $coefstring = $grade_item->get_coefstring(); 505 506 if ($coefstring == 'aggregationcoefextrasum' || $coefstring == 'aggregationcoefextraweightsum') { 507 // advcheckbox is not compatible with disabledIf! 508 $coefstring = 'aggregationcoefextrasum'; 509 $element =& $mform->createElement('checkbox', 'grade_item_aggregationcoef', get_string($coefstring, 'grades')); 510 } else { 511 $element =& $mform->createElement('text', 'grade_item_aggregationcoef', get_string($coefstring, 'grades')); 512 } 513 $mform->insertElementBefore($element, 'parentcategory'); 514 $mform->addHelpButton('grade_item_aggregationcoef', $coefstring, 'grades'); 515 } 516 517 // Remove fields used by natural weighting if the parent category is not using natural weighting. 518 // Or if the item is a scale and scales are not used in aggregation. 519 if ($parent_category->aggregation != GRADE_AGGREGATE_SUM 520 || (empty($CFG->grade_includescalesinaggregation) && $grade_item->gradetype == GRADE_TYPE_SCALE)) { 521 if ($mform->elementExists('grade_item_weightoverride')) { 522 $mform->removeElement('grade_item_weightoverride'); 523 } 524 if ($mform->elementExists('grade_item_aggregationcoef2')) { 525 $mform->removeElement('grade_item_aggregationcoef2'); 526 } 527 } 528 } 529 } 530 } 531 532 /// perform extra validation before submission 533 function validation($data, $files) { 534 global $COURSE; 535 $gradeitem = false; 536 if ($data['id']) { 537 $gradecategory = grade_category::fetch(array('id' => $data['id'])); 538 $gradeitem = $gradecategory->load_grade_item(); 539 } 540 541 $errors = parent::validation($data, $files); 542 543 if (array_key_exists('grade_item_gradetype', $data) and $data['grade_item_gradetype'] == GRADE_TYPE_SCALE) { 544 if (empty($data['grade_item_scaleid'])) { 545 $errors['grade_item_scaleid'] = get_string('missingscale', 'grades'); 546 } 547 } 548 if (array_key_exists('grade_item_grademin', $data) and array_key_exists('grade_item_grademax', $data)) { 549 if (($data['grade_item_grademax'] != 0 OR $data['grade_item_grademin'] != 0) AND 550 ($data['grade_item_grademax'] == $data['grade_item_grademin'] OR 551 $data['grade_item_grademax'] < $data['grade_item_grademin'])) { 552 $errors['grade_item_grademin'] = get_string('incorrectminmax', 'grades'); 553 $errors['grade_item_grademax'] = get_string('incorrectminmax', 'grades'); 554 } 555 } 556 557 if ($data['id'] && $gradeitem->has_overridden_grades()) { 558 if ($gradeitem->gradetype == GRADE_TYPE_VALUE) { 559 if (grade_floats_different($data['grade_item_grademin'], $gradeitem->grademin) || 560 grade_floats_different($data['grade_item_grademax'], $gradeitem->grademax)) { 561 if (empty($data['grade_item_rescalegrades'])) { 562 $errors['grade_item_rescalegrades'] = get_string('mustchooserescaleyesorno', 'grades'); 563 } 564 } 565 } 566 } 567 return $errors; 568 } 569 } 570 571
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |