1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * This file defines an mform to edit rubric grading strategy forms. 20 * 21 * @package workshopform_rubric 22 * @copyright 2009 David Mudrak <david.mudrak@gmail.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 require_once (__DIR__ . '/../edit_form.php'); // parent class definition 29 30 /** 31 * Class for editing rubric grading strategy forms. 32 * 33 * @uses moodleform 34 */ 35 class workshop_edit_rubric_strategy_form extends workshop_edit_strategy_form { 36 37 const MINLEVELS = 4; 38 const ADDLEVELS = 2; 39 40 /** 41 * Define the elements to be displayed at the form 42 * 43 * Called by the parent::definition() 44 * 45 * @return void 46 */ 47 protected function definition_inner(&$mform) { 48 49 $norepeats = $this->_customdata['norepeats']; // number of dimensions to display 50 $descriptionopts = $this->_customdata['descriptionopts']; // wysiwyg fields options 51 $current = $this->_customdata['current']; // current data to be set 52 53 $mform->addElement('hidden', 'norepeats', $norepeats); 54 $mform->setType('norepeats', PARAM_INT); 55 // value not to be overridden by submitted value 56 $mform->setConstants(array('norepeats' => $norepeats)); 57 58 $levelgrades = array(); 59 for ($i = 100; $i >= 0; $i--) { 60 $levelgrades[$i] = $i; 61 } 62 63 for ($i = 0; $i < $norepeats; $i++) { 64 $mform->addElement('header', 'dimension'.$i, get_string('dimensionnumber', 'workshopform_rubric', $i+1)); 65 $mform->addElement('hidden', 'dimensionid__idx_'.$i); 66 $mform->setType('dimensionid__idx_'.$i, PARAM_INT); 67 $mform->addElement('editor', 'description__idx_'.$i.'_editor', 68 get_string('dimensiondescription', 'workshopform_rubric'), '', $descriptionopts); 69 if (isset($current->{'numoflevels__idx_' . $i})) { 70 $numoflevels = max($current->{'numoflevels__idx_' . $i} + self::ADDLEVELS, self::MINLEVELS); 71 } else { 72 $numoflevels = self::MINLEVELS; 73 } 74 $prevlevel = -1; 75 for ($j = 0; $j < $numoflevels; $j++) { 76 $mform->addElement('hidden', 'levelid__idx_' . $i . '__idy_' . $j); 77 $mform->setType('levelid__idx_' . $i . '__idy_' . $j, PARAM_INT); 78 $levelgrp = array(); 79 $levelgrp[] = $mform->createElement('select', 'grade__idx_'.$i.'__idy_'.$j,'', $levelgrades); 80 $levelgrp[] = $mform->createElement('textarea', 'definition__idx_'.$i.'__idy_'.$j, '', array('cols' => 60, 'rows' => 3)); 81 $mform->addGroup($levelgrp, 'level__idx_'.$i.'__idy_'.$j, get_string('levelgroup', 'workshopform_rubric'), array(' '), false); 82 $mform->setDefault('grade__idx_'.$i.'__idy_'.$j, $prevlevel + 1); 83 if (isset($current->{'grade__idx_'.$i.'__idy_'.$j})) { 84 $prevlevel = $current->{'grade__idx_'.$i.'__idy_'.$j}; 85 } else { 86 $prevlevel++; 87 } 88 } 89 } 90 91 $mform->registerNoSubmitButton('adddims'); 92 $mform->addElement('submit', 'adddims', get_string('addmoredimensions', 'workshopform_rubric', 93 workshop_rubric_strategy::ADDDIMS)); 94 $mform->closeHeaderBefore('adddims'); 95 96 $mform->addElement('header', 'configheader', get_string('configuration', 'workshopform_rubric')); 97 $layoutgrp = array(); 98 $layoutgrp[] = $mform->createElement('radio', 'config_layout', '', 99 get_string('layoutlist', 'workshopform_rubric'), 'list'); 100 $layoutgrp[] = $mform->createElement('radio', 'config_layout', '', 101 get_string('layoutgrid', 'workshopform_rubric'), 'grid'); 102 $mform->addGroup($layoutgrp, 'layoutgrp', get_string('layout', 'workshopform_rubric'), array('<br />'), false); 103 $mform->setDefault('config_layout', 'list'); 104 $this->set_data($current); 105 } 106 107 /** 108 * Provide validation rules for the rubric editor form. 109 * 110 * @param array $data 111 * @param array $files 112 * @return array 113 */ 114 protected function validation_inner($data, $files) { 115 116 $errors = array(); 117 118 // Iterate over all submitted dimensions (criteria). 119 for ($i = 0; isset($data['dimensionid__idx_'.$i]); $i++) { 120 121 $dimgrades = array(); 122 123 if (0 == strlen(trim($data['description__idx_'.$i.'_editor']['text']))) { 124 // The description text is empty and this criterion will be deleted. 125 continue; 126 } 127 128 // Make sure the levels grades are unique within the criterion. 129 $atleastonelevel = false; 130 for ($j = 0; isset($data['levelid__idx_'.$i.'__idy_'.$j]); $j++) { 131 if (0 == strlen(trim($data['definition__idx_'.$i.'__idy_'.$j]))) { 132 // The level definition is empty and will not be saved. 133 continue; 134 } 135 $atleastonelevel = true; 136 137 $levelgrade = $data['grade__idx_'.$i.'__idy_'.$j]; 138 139 if (isset($dimgrades[$levelgrade])) { 140 // This grade has already been set for another level. 141 $k = $dimgrades[$levelgrade]; 142 $errors['level__idx_'.$i.'__idy_'.$j] = $errors['level__idx_'.$i.'__idy_'.$k] = get_string('mustbeunique', 143 'workshopform_rubric'); 144 } else { 145 $dimgrades[$levelgrade] = $j; 146 } 147 } 148 if (!$atleastonelevel) { 149 $errors['level__idx_'.$i.'__idy_0'] = get_string('mustdefinelevel', 'workshopform_rubric'); 150 } 151 } 152 153 return $errors; 154 } 155 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body