[ Index ] |
PHP Cross Reference of moodle-2.8 |
[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 * Edit and review page for grade categories and items 19 * 20 * @package core_grades 21 * @copyright 2008 Nicolas Connault 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require_once '../../../config.php'; 26 require_once $CFG->dirroot.'/grade/lib.php'; 27 require_once $CFG->dirroot.'/grade/report/lib.php'; // for preferences 28 require_once $CFG->dirroot.'/grade/edit/tree/lib.php'; 29 30 $courseid = required_param('id', PARAM_INT); 31 $action = optional_param('action', 0, PARAM_ALPHA); 32 $eid = optional_param('eid', 0, PARAM_ALPHANUM); 33 $category = optional_param('category', null, PARAM_INT); 34 $aggregationtype = optional_param('aggregationtype', null, PARAM_INT); 35 36 $url = new moodle_url('/grade/edit/tree/index.php', array('id' => $courseid)); 37 $PAGE->set_url($url); 38 $PAGE->set_pagelayout('admin'); 39 40 /// Make sure they can even access this course 41 if (!$course = $DB->get_record('course', array('id' => $courseid))) { 42 print_error('nocourseid'); 43 } 44 45 require_login($course); 46 $context = context_course::instance($course->id); 47 require_capability('moodle/grade:manage', $context); 48 49 // todo $PAGE->requires->js_module() should be used here instead 50 $PAGE->requires->js('/grade/edit/tree/functions.js'); 51 52 /// return tracking object 53 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'tree', 'courseid'=>$courseid)); 54 $returnurl = $gpr->get_return_url(null); 55 56 // Change category aggregation if requested 57 if (!is_null($category) && !is_null($aggregationtype) && confirm_sesskey()) { 58 if (!$grade_category = grade_category::fetch(array('id'=>$category, 'courseid'=>$courseid))) { 59 print_error('invalidcategoryid'); 60 } 61 62 $data = new stdClass(); 63 $data->aggregation = $aggregationtype; 64 grade_category::set_properties($grade_category, $data); 65 $grade_category->update(); 66 67 grade_regrade_final_grades($courseid); 68 } 69 70 //first make sure we have proper final grades - we need it for locking changes 71 $normalisationmessage = null; 72 73 $originalweights = grade_helper::fetch_all_natural_weights_for_course($courseid); 74 75 grade_regrade_final_grades($courseid); 76 77 $alteredweights = grade_helper::fetch_all_natural_weights_for_course($courseid); 78 79 if (array_diff($originalweights, $alteredweights)) { 80 $normalisationmessage = get_string('weightsadjusted', 'grades'); 81 } 82 83 // get the grading tree object 84 // note: total must be first for moving to work correctly, if you want it last moving code must be rewritten! 85 $gtree = new grade_tree($courseid, false, false); 86 87 if (empty($eid)) { 88 $element = null; 89 $object = null; 90 91 } else { 92 if (!$element = $gtree->locate_element($eid)) { 93 print_error('invalidelementid', '', $returnurl); 94 } 95 $object = $element['object']; 96 } 97 98 $switch = grade_get_setting($course->id, 'aggregationposition', $CFG->grade_aggregationposition); 99 100 $strgrades = get_string('grades'); 101 $strgraderreport = get_string('graderreport', 'grades'); 102 103 $moving = false; 104 $movingeid = false; 105 106 if ($action == 'moveselect') { 107 if ($eid and confirm_sesskey()) { 108 $movingeid = $eid; 109 $moving=true; 110 } 111 } 112 113 $grade_edit_tree = new grade_edit_tree($gtree, $movingeid, $gpr); 114 115 switch ($action) { 116 case 'delete': 117 if ($eid && confirm_sesskey()) { 118 if (!$grade_edit_tree->element_deletable($element)) { 119 // no deleting of external activities - they would be recreated anyway! 120 // exception is activity without grading or misconfigured activities 121 break; 122 } 123 $confirm = optional_param('confirm', 0, PARAM_BOOL); 124 125 if ($confirm) { 126 $object->delete('grade/report/grader/category'); 127 redirect($returnurl); 128 129 } else { 130 $PAGE->set_title($strgrades . ': ' . $strgraderreport); 131 $PAGE->set_heading($course->fullname); 132 echo $OUTPUT->header(); 133 $strdeletecheckfull = get_string('deletecheck', '', $object->get_name()); 134 $optionsyes = array('eid'=>$eid, 'confirm'=>1, 'sesskey'=>sesskey(), 'id'=>$course->id, 'action'=>'delete'); 135 $optionsno = array('id'=>$course->id); 136 $formcontinue = new single_button(new moodle_url('index.php', $optionsyes), get_string('yes')); 137 $formcancel = new single_button(new moodle_url('index.php', $optionsno), get_string('no'), 'get'); 138 echo $OUTPUT->confirm($strdeletecheckfull, $formcontinue, $formcancel); 139 echo $OUTPUT->footer(); 140 die; 141 } 142 } 143 break; 144 145 case 'autosort': 146 //TODO: implement autosorting based on order of mods on course page, categories first, manual items last 147 break; 148 149 case 'move': 150 if ($eid and confirm_sesskey()) { 151 $moveafter = required_param('moveafter', PARAM_ALPHANUM); 152 $first = optional_param('first', false, PARAM_BOOL); // If First is set to 1, it means the target is the first child of the category $moveafter 153 154 if(!$after_el = $gtree->locate_element($moveafter)) { 155 print_error('invalidelementid', '', $returnurl); 156 } 157 158 $after = $after_el['object']; 159 $sortorder = $after->get_sortorder(); 160 161 if (!$first) { 162 $parent = $after->get_parent_category(); 163 $object->set_parent($parent->id); 164 } else { 165 $object->set_parent($after->id); 166 } 167 168 $object->move_after_sortorder($sortorder); 169 170 redirect($returnurl); 171 } 172 break; 173 174 default: 175 break; 176 } 177 178 //if we go straight to the db to update an element we need to recreate the tree as 179 // $grade_edit_tree has already been constructed. 180 //Ideally we could do the updates through $grade_edit_tree to avoid recreating it 181 $recreatetree = false; 182 183 if ($data = data_submitted() and confirm_sesskey()) { 184 // Perform bulk actions first 185 if (!empty($data->bulkmove)) { 186 $elements = array(); 187 188 foreach ($data as $key => $value) { 189 if (preg_match('/select_(ig[0-9]*)/', $key, $matches)) { 190 $elements[] = $matches[1]; 191 } 192 } 193 194 $grade_edit_tree->move_elements($elements, $returnurl); 195 } 196 197 // Update weights (extra credits) on categories and items. 198 foreach ($data as $key => $value) { 199 if (preg_match('/^weight_([0-9]+)$/', $key, $matches)) { 200 $aid = $matches[1]; 201 202 $value = unformat_float($value); 203 $value = clean_param($value, PARAM_FLOAT); 204 205 $grade_item = grade_item::fetch(array('id' => $aid, 'courseid' => $courseid)); 206 207 // Convert weight to aggregation coef2. 208 $aggcoef = $grade_item->get_coefstring(); 209 if ($aggcoef == 'aggregationcoefextraweightsum') { 210 // The field 'weight' should only be sent when the checkbox 'weighoverride' is checked, 211 // so there is not need to set weightoverride here, it is done below. 212 $value = $value / 100.0; 213 $grade_item->aggregationcoef2 = $value; 214 } else if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoefextraweight') { 215 $grade_item->aggregationcoef = $value; 216 } 217 218 $grade_item->update(); 219 220 $recreatetree = true; 221 222 // Grade item checkbox inputs. 223 } elseif (preg_match('/^(weightoverride)_([0-9]+)$/', $key, $matches)) { 224 $param = $matches[1]; 225 $aid = $matches[2]; 226 $value = clean_param($value, PARAM_BOOL); 227 228 $grade_item = grade_item::fetch(array('id' => $aid, 'courseid' => $courseid)); 229 $grade_item->$param = $value; 230 231 $grade_item->update(); 232 233 $recreatetree = true; 234 } 235 } 236 237 $originalweights = grade_helper::fetch_all_natural_weights_for_course($courseid); 238 239 grade_regrade_final_grades($courseid); 240 241 $alteredweights = grade_helper::fetch_all_natural_weights_for_course($courseid); 242 if (array_diff($originalweights, $alteredweights)) { 243 $normalisationmessage = get_string('weightsadjusted', 'grades'); 244 } 245 } 246 247 print_grade_page_head($courseid, 'settings', 'setup', get_string('categoriesanditems', 'grades')); 248 249 // Print Table of categories and items 250 echo $OUTPUT->box_start('gradetreebox generalbox'); 251 252 echo '<form id="gradetreeform" method="post" action="'.$returnurl.'">'; 253 echo '<div>'; 254 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; 255 256 //did we update something in the db and thus invalidate $grade_edit_tree? 257 if ($recreatetree) { 258 $grade_edit_tree = new grade_edit_tree($gtree, $movingeid, $gpr); 259 } 260 // Check to see if we have a normalisation message to send. 261 if (!empty($normalisationmessage)) { 262 echo $OUTPUT->notification($normalisationmessage, 'notifymessage'); 263 } 264 265 echo html_writer::table($grade_edit_tree->table); 266 267 echo '<div id="gradetreesubmit">'; 268 if (!$moving) { 269 echo '<input class="advanced" type="submit" value="'.get_string('savechanges').'" />'; 270 } 271 272 // We don't print a bulk move menu if there are no other categories than course category 273 if (!$moving && count($grade_edit_tree->categories) > 1) { 274 echo '<br /><br />'; 275 echo '<input type="hidden" name="bulkmove" value="0" id="bulkmoveinput" />'; 276 $attributes = array('id'=>'menumoveafter', 'class' => 'ignoredirty'); 277 echo html_writer::label(get_string('moveselectedto', 'grades'), 'menumoveafter'); 278 echo html_writer::select($grade_edit_tree->categories, 'moveafter', '', array(''=>'choosedots'), $attributes); 279 $OUTPUT->add_action_handler(new component_action('change', 'submit_bulk_move'), 'menumoveafter'); 280 echo '<div id="noscriptgradetreeform" class="hiddenifjs"> 281 <input type="submit" value="'.get_string('go').'" /> 282 </div>'; 283 } 284 285 echo '</div>'; 286 287 echo '</div></form>'; 288 289 echo $OUTPUT->box_end(); 290 291 // Print action buttons 292 echo $OUTPUT->container_start('buttons mdl-align'); 293 294 if ($moving) { 295 echo $OUTPUT->single_button(new moodle_url('index.php', array('id'=>$course->id)), get_string('cancel'), 'get'); 296 } else { 297 echo $OUTPUT->single_button(new moodle_url('category.php', array('courseid'=>$course->id)), get_string('addcategory', 'grades'), 'get'); 298 echo $OUTPUT->single_button(new moodle_url('item.php', array('courseid'=>$course->id)), get_string('additem', 'grades'), 'get'); 299 300 if (!empty($CFG->enableoutcomes)) { 301 echo $OUTPUT->single_button(new moodle_url('outcomeitem.php', array('courseid'=>$course->id)), get_string('addoutcomeitem', 'grades'), 'get'); 302 } 303 304 //echo $OUTPUT->(new moodle_url('index.php', array('id'=>$course->id, 'action'=>'autosort')), get_string('autosort', 'grades'), 'get'); 305 } 306 307 echo $OUTPUT->container_end(); 308 309 $PAGE->requires->yui_module('moodle-core-formchangechecker', 310 'M.core_formchangechecker.init', 311 array(array( 312 'formid' => 'gradetreeform' 313 )) 314 ); 315 $PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle'); 316 317 echo $OUTPUT->footer(); 318 die; 319 320
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |