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