Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402]
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 * Listing page for grade outcomes. 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(__DIR__.'/../../../config.php'); 26 require_once($CFG->dirroot.'/grade/lib.php'); 27 require_once($CFG->libdir.'/gradelib.php'); 28 29 $courseid = optional_param('id', 0, PARAM_INT); 30 $action = optional_param('action', '', PARAM_ALPHA); 31 32 $url = new moodle_url('/grade/edit/outcome/index.php', ['id' => $courseid]); 33 $PAGE->set_url($url); 34 $PAGE->set_pagelayout('admin'); 35 36 /// Make sure they can even access this course 37 if ($courseid) { 38 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); 39 require_login($course); 40 $context = context_course::instance($course->id); 41 require_capability('moodle/grade:manageoutcomes', $context); 42 43 if (empty($CFG->enableoutcomes)) { 44 redirect('../../index.php?id='.$courseid); 45 } 46 // This page doesn't exist on the navigation so map it to another 47 navigation_node::override_active_url(new moodle_url('/grade/edit/outcome/course.php', array('id'=>$courseid))); 48 $PAGE->navbar->add(get_string('manageoutcomes', 'grades'), $url); 49 } else { 50 if (empty($CFG->enableoutcomes)) { 51 redirect('../../../'); 52 } 53 require_once $CFG->libdir.'/adminlib.php'; 54 admin_externalpage_setup('outcomes'); 55 $context = context_system::instance(); 56 $PAGE->set_primary_active_tab('siteadminnode'); 57 } 58 59 /// return tracking object 60 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'outcome', 'courseid'=>$courseid)); 61 62 $strshortname = get_string('outcomeshortname', 'grades'); 63 $strfullname = get_string('outcomefullname', 'grades'); 64 $strscale = get_string('scale'); 65 $strstandardoutcome = get_string('outcomesstandard', 'grades'); 66 $strcustomoutcomes = get_string('outcomescustom', 'grades'); 67 $strcreatenewoutcome = get_string('outcomecreate', 'grades'); 68 $stritems = get_string('items', 'grades'); 69 $strcourses = get_string('courses'); 70 $stredit = get_string('edit'); 71 72 switch ($action) { 73 case 'delete': 74 if (!confirm_sesskey()) { 75 break; 76 } 77 $outcomeid = required_param('outcomeid', PARAM_INT); 78 if (!$outcome = grade_outcome::fetch(array('id'=>$outcomeid))) { 79 break; 80 } 81 82 if (empty($outcome->courseid)) { 83 require_capability('moodle/grade:manage', context_system::instance()); 84 } else if ($outcome->courseid != $courseid) { 85 throw new \moodle_exception('invalidcourseid'); 86 } 87 88 if (!$outcome->can_delete()) { 89 break; 90 } 91 92 $deleteconfirmed = optional_param('deleteconfirmed', 0, PARAM_BOOL); 93 94 if(!$deleteconfirmed){ 95 $PAGE->set_title(get_string('outcomedelete', 'grades')); 96 $PAGE->navbar->add(get_string('outcomedelete', 'grades')); 97 echo $OUTPUT->header(); 98 $confirmurl = new moodle_url('index.php', array( 99 'id' => $courseid, 'outcomeid' => $outcome->id, 100 'action'=> 'delete', 101 'sesskey' => sesskey(), 102 'deleteconfirmed'=> 1)); 103 104 echo $OUTPUT->confirm(get_string('outcomeconfirmdelete', 'grades', $outcome->fullname), $confirmurl, "index.php?id={$courseid}"); 105 echo $OUTPUT->footer(); 106 die; 107 }else{ 108 $outcome->delete(); 109 } 110 break; 111 } 112 113 $systemcontext = context_system::instance(); 114 $caneditsystemscales = has_capability('moodle/course:managescales', $systemcontext); 115 116 if ($courseid) { 117 118 $caneditcoursescales = has_capability('moodle/course:managescales', $context); 119 120 } else { 121 $caneditcoursescales = $caneditsystemscales; 122 } 123 124 125 $outcomes_tables = array(); 126 $heading = get_string('outcomes', 'grades'); 127 128 if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) { 129 $return = $OUTPUT->heading($strcustomoutcomes, 3, 'main mt-3'); 130 $data = array(); 131 foreach($outcomes as $outcome) { 132 $line = array(); 133 $line[] = $outcome->get_name(); 134 $line[] = $outcome->get_shortname(); 135 136 $scale = $outcome->load_scale(); 137 if (empty($scale->id)) { // hopefully never happens 138 $line[] = $scale->get_name(); 139 debugging("Found a scale with no ID ({$scale->get_name()}) while outputting course outcomes", DEBUG_DEVELOPER); 140 } else { 141 if (empty($scale->courseid)) { 142 $caneditthisscale = $caneditsystemscales; 143 } else if ($scale->courseid == $courseid) { 144 $caneditthisscale = $caneditcoursescales; 145 } else { 146 $context = context_course::instance($scale->courseid); 147 $caneditthisscale = has_capability('moodle/course:managescales', $context); 148 } 149 if ($caneditthisscale) { 150 $line[] = grade_print_scale_link($courseid, $scale, $gpr); 151 } else { 152 $line[] = $scale->get_name(); 153 } 154 } 155 156 $line[] = $outcome->get_item_uses_count(); 157 158 $buttons = grade_button('edit', $courseid, $outcome); 159 160 if ($outcome->can_delete()) { 161 $buttons .= grade_button('delete', $courseid, $outcome); 162 } 163 $line[] = $buttons; 164 165 $data[] = $line; 166 } 167 $table = new html_table(); 168 $table->head = array($strfullname, $strshortname, $strscale, $stritems, $stredit); 169 $table->size = array('30%', '20%', '20%', '20%', '10%' ); 170 $table->align = array('left', 'left', 'left', 'center', 'center'); 171 $table->width = '90%'; 172 $table->data = $data; 173 $return .= html_writer::table($table); 174 $outcomes_tables[] = $return; 175 } 176 177 178 if ($outcomes = grade_outcome::fetch_all_global()) { 179 $return = $OUTPUT->heading($strstandardoutcome, 3, 'main mt-3'); 180 $data = array(); 181 foreach($outcomes as $outcome) { 182 $line = array(); 183 $line[] = $outcome->get_name(); 184 $line[] = $outcome->get_shortname(); 185 186 $scale = $outcome->load_scale(); 187 if (empty($scale->id)) { // hopefully never happens 188 $line[] = $scale->get_name(); 189 debugging("Found a scale with no ID ({$scale->get_name()}) while outputting global outcomes", DEBUG_DEVELOPER); 190 } else { 191 if (empty($scale->courseid)) { 192 $caneditthisscale = $caneditsystemscales; 193 } else if ($scale->courseid == $courseid) { 194 $caneditthisscale = $caneditcoursescales; 195 } else { 196 $context = context_course::instance($scale->courseid); 197 $caneditthisscale = has_capability('moodle/course:managescales', $context); 198 } 199 if ($caneditthisscale) { 200 $line[] = grade_print_scale_link($courseid, $scale, $gpr); 201 } else { 202 $line[] = $scale->get_name(); 203 } 204 } 205 206 $line[] = $outcome->get_course_uses_count(); 207 $line[] = $outcome->get_item_uses_count(); 208 209 $buttons = ""; 210 if (has_capability('moodle/grade:manage', context_system::instance())) { 211 $buttons .= grade_button('edit', $courseid, $outcome); 212 } 213 if (has_capability('moodle/grade:manage', context_system::instance()) and $outcome->can_delete()) { 214 $buttons .= grade_button('delete', $courseid, $outcome); 215 } 216 $line[] = $buttons; 217 218 $data[] = $line; 219 } 220 $table = new html_table(); 221 $table->head = array($strfullname, $strshortname, $strscale, $strcourses, $stritems, $stredit); 222 $table->size = array('30%', '20%', '20%', '10%', '10%', '10%'); 223 $table->align = array('left', 'left', 'left', 'center', 'center', 'center'); 224 $table->width = '90%'; 225 $table->data = $data; 226 $return .= html_writer::table($table); 227 $outcomes_tables[] = $return; 228 } 229 230 $actionbar = new \core_grades\output\manage_outcomes_action_bar($context, !empty($outcomes_tables)); 231 print_grade_page_head($courseid ?: SITEID, 'outcome', 'edit', $heading, false, false, 232 true, null, null, null, $actionbar); 233 234 // If there are existing outcomes, output the outcome tables. 235 if (!empty($outcomes_tables)) { 236 foreach ($outcomes_tables as $table) { 237 echo $table; 238 } 239 } else { 240 echo $OUTPUT->notification(get_string('noexistingoutcomes', 'grades'), 'info', false); 241 } 242 243 echo $OUTPUT->footer(); 244 245 /** 246 * Local shortcut function for creating a link to a scale. 247 * @param int $courseid The Course ID 248 * @param grade_scale $scale The Scale to link to 249 * @param grade_plugin_return $gpr An object used to identify the page we just came from 250 * @return string html 251 */ 252 function grade_print_scale_link($courseid, $scale, $gpr) { 253 global $CFG, $OUTPUT; 254 $url = new moodle_url('/grade/edit/scale/edit.php', array('courseid' => $courseid, 'id' => $scale->id)); 255 $url = $gpr->add_url_params($url); 256 return html_writer::link($url, $scale->get_name()); 257 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body