2009-07-07 02:26:36 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-10 06:34:20 +00:00
|
|
|
|
2009-08-27 09:39:50 +00:00
|
|
|
/**
|
|
|
|
* Listing page for grade outcomes.
|
|
|
|
*
|
2012-01-06 11:52:46 +07:00
|
|
|
* @package core_grades
|
2009-08-27 09:39:50 +00:00
|
|
|
* @copyright 2008 Nicolas Connault
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2016-02-26 17:47:58 +11:00
|
|
|
require_once(__DIR__.'/../../../config.php');
|
2009-08-27 09:39:50 +00:00
|
|
|
require_once($CFG->dirroot.'/grade/lib.php');
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
2007-07-30 22:56:45 +00:00
|
|
|
|
|
|
|
$courseid = optional_param('id', 0, PARAM_INT);
|
|
|
|
$action = optional_param('action', '', PARAM_ALPHA);
|
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->set_url('/grade/edit/outcome/index.php', array('id' => $courseid));
|
2010-07-21 06:51:12 +00:00
|
|
|
$PAGE->set_pagelayout('admin');
|
2009-08-27 09:39:50 +00:00
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
/// Make sure they can even access this course
|
|
|
|
if ($courseid) {
|
2013-08-21 13:42:30 +08:00
|
|
|
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
|
2007-07-30 22:56:45 +00:00
|
|
|
require_login($course);
|
2012-07-24 14:04:40 +08:00
|
|
|
$context = context_course::instance($course->id);
|
2008-02-05 08:42:34 +00:00
|
|
|
require_capability('moodle/grade:manageoutcomes', $context);
|
2007-07-30 22:56:45 +00:00
|
|
|
|
2007-08-01 04:34:08 +00:00
|
|
|
if (empty($CFG->enableoutcomes)) {
|
|
|
|
redirect('../../index.php?id='.$courseid);
|
|
|
|
}
|
2010-07-21 06:51:12 +00:00
|
|
|
// This page doesn't exist on the navigation so map it to another
|
|
|
|
navigation_node::override_active_url(new moodle_url('/grade/edit/outcome/course.php', array('id'=>$courseid)));
|
2007-07-30 22:56:45 +00:00
|
|
|
} else {
|
2009-04-03 08:14:01 +00:00
|
|
|
if (empty($CFG->enableoutcomes)) {
|
|
|
|
redirect('../../../');
|
|
|
|
}
|
2007-07-30 22:56:45 +00:00
|
|
|
require_once $CFG->libdir.'/adminlib.php';
|
|
|
|
admin_externalpage_setup('outcomes');
|
|
|
|
}
|
|
|
|
|
|
|
|
/// return tracking object
|
|
|
|
$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'outcome', 'courseid'=>$courseid));
|
|
|
|
|
MDL-13481 Strings fullname and shortname are now deprecated
This is a final cleanup commit of fullname and shortname issue. All
places where these strings were detected yet have been replaced with
proper fullnamecourse or fullnameuser or some other context specific
string.
AMOS BEGIN
CPY [fullname,core],[outcomefullname,core_grades]
CPY [shortname,core],[outcomeshortname,core_grades]
CPY [name,core],[rolefullname,core_role]
CPY [shortname,core],[roleshortname,core_role]
AMOS END
2011-02-22 10:12:10 +01:00
|
|
|
$strshortname = get_string('outcomeshortname', 'grades');
|
|
|
|
$strfullname = get_string('outcomefullname', 'grades');
|
2007-07-30 22:56:45 +00:00
|
|
|
$strscale = get_string('scale');
|
|
|
|
$strstandardoutcome = get_string('outcomesstandard', 'grades');
|
|
|
|
$strcustomoutcomes = get_string('outcomescustom', 'grades');
|
2008-02-26 07:30:34 +00:00
|
|
|
$strcreatenewoutcome = get_string('outcomecreate', 'grades');
|
2007-07-31 12:03:45 +00:00
|
|
|
$stritems = get_string('items', 'grades');
|
|
|
|
$strcourses = get_string('courses');
|
2007-07-30 22:56:45 +00:00
|
|
|
$stredit = get_string('edit');
|
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
case 'delete':
|
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$outcomeid = required_param('outcomeid', PARAM_INT);
|
|
|
|
if (!$outcome = grade_outcome::fetch(array('id'=>$outcomeid))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($outcome->courseid)) {
|
2012-07-24 14:04:40 +08:00
|
|
|
require_capability('moodle/grade:manage', context_system::instance());
|
2007-07-30 22:56:45 +00:00
|
|
|
} else if ($outcome->courseid != $courseid) {
|
2008-05-14 07:01:32 +00:00
|
|
|
print_error('invalidcourseid');
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$outcome->can_delete()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-12 21:14:44 +00:00
|
|
|
$deleteconfirmed = optional_param('deleteconfirmed', 0, PARAM_BOOL);
|
|
|
|
|
|
|
|
if(!$deleteconfirmed){
|
2009-09-07 06:04:46 +00:00
|
|
|
$PAGE->set_title(get_string('outcomedelete', 'grades'));
|
|
|
|
echo $OUTPUT->header();
|
2009-08-20 08:40:49 +00:00
|
|
|
$confirmurl = new moodle_url('index.php', array(
|
|
|
|
'id' => $courseid, 'outcomeid' => $outcome->id,
|
|
|
|
'action'=> 'delete',
|
|
|
|
'sesskey' => sesskey(),
|
|
|
|
'deleteconfirmed'=> 1));
|
|
|
|
|
|
|
|
echo $OUTPUT->confirm(get_string('outcomeconfirmdelete', 'grades', $outcome->fullname), $confirmurl, "index.php?id={$courseid}");
|
2009-08-06 14:21:57 +00:00
|
|
|
echo $OUTPUT->footer();
|
2008-02-12 21:14:44 +00:00
|
|
|
die;
|
|
|
|
}else{
|
|
|
|
$outcome->delete();
|
|
|
|
}
|
2007-07-30 22:56:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-07-24 14:04:40 +08:00
|
|
|
$systemcontext = context_system::instance();
|
2007-07-31 09:15:39 +00:00
|
|
|
$caneditsystemscales = has_capability('moodle/course:managescales', $systemcontext);
|
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
if ($courseid) {
|
|
|
|
|
2007-07-31 09:15:39 +00:00
|
|
|
$caneditcoursescales = has_capability('moodle/course:managescales', $context);
|
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
} else {
|
2010-03-31 08:05:53 +00:00
|
|
|
echo $OUTPUT->header();
|
2007-07-31 09:15:39 +00:00
|
|
|
$caneditcoursescales = $caneditsystemscales;
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
|
|
|
|
2007-07-31 09:15:39 +00:00
|
|
|
|
2008-02-12 08:01:00 +00:00
|
|
|
$outcomes_tables = array();
|
2009-02-09 10:49:41 +00:00
|
|
|
$heading = get_string('outcomes', 'grades');
|
2008-02-11 02:22:48 +00:00
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) {
|
2009-08-06 08:16:46 +00:00
|
|
|
$return = $OUTPUT->heading($strcustomoutcomes, 3, 'main');
|
2007-07-30 22:56:45 +00:00
|
|
|
$data = array();
|
|
|
|
foreach($outcomes as $outcome) {
|
|
|
|
$line = array();
|
|
|
|
$line[] = $outcome->get_name();
|
|
|
|
$line[] = $outcome->get_shortname();
|
|
|
|
|
|
|
|
$scale = $outcome->load_scale();
|
2007-07-31 09:15:39 +00:00
|
|
|
if (empty($scale->id)) { // hopefully never happens
|
|
|
|
$line[] = $scale->get_name();
|
2012-10-26 10:43:39 +08:00
|
|
|
debugging("Found a scale with no ID ({$scale->get_name()}) while outputting course outcomes", DEBUG_DEVELOPER);
|
2007-07-31 09:15:39 +00:00
|
|
|
} else {
|
|
|
|
if (empty($scale->courseid)) {
|
|
|
|
$caneditthisscale = $caneditsystemscales;
|
|
|
|
} else if ($scale->courseid == $courseid) {
|
|
|
|
$caneditthisscale = $caneditcoursescales;
|
|
|
|
} else {
|
2012-07-24 14:04:40 +08:00
|
|
|
$context = context_course::instance($scale->courseid);
|
2007-07-31 09:15:39 +00:00
|
|
|
$caneditthisscale = has_capability('moodle/course:managescales', $context);
|
|
|
|
}
|
|
|
|
if ($caneditthisscale) {
|
2009-08-27 09:39:50 +00:00
|
|
|
$line[] = grade_print_scale_link($courseid, $scale, $gpr);
|
2007-07-31 09:15:39 +00:00
|
|
|
} else {
|
|
|
|
$line[] = $scale->get_name();
|
|
|
|
}
|
|
|
|
}
|
2007-07-30 22:56:45 +00:00
|
|
|
|
2007-07-31 12:03:45 +00:00
|
|
|
$line[] = $outcome->get_item_uses_count();
|
2007-07-30 22:56:45 +00:00
|
|
|
|
2009-08-27 09:39:50 +00:00
|
|
|
$buttons = grade_button('edit', $courseid, $outcome);
|
|
|
|
|
2007-07-31 12:03:45 +00:00
|
|
|
if ($outcome->can_delete()) {
|
2009-08-27 09:39:50 +00:00
|
|
|
$buttons .= grade_button('delete', $courseid, $outcome);
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
|
|
|
$line[] = $buttons;
|
2008-06-02 16:06:33 +00:00
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
$data[] = $line;
|
|
|
|
}
|
2009-08-20 08:40:49 +00:00
|
|
|
$table = new html_table();
|
2008-02-26 07:30:34 +00:00
|
|
|
$table->head = array($strfullname, $strshortname, $strscale, $stritems, $stredit);
|
|
|
|
$table->size = array('30%', '20%', '20%', '20%', '10%' );
|
|
|
|
$table->align = array('left', 'left', 'left', 'center', 'center');
|
2007-07-30 22:56:45 +00:00
|
|
|
$table->width = '90%';
|
|
|
|
$table->data = $data;
|
2010-03-20 22:15:54 +00:00
|
|
|
$return .= html_writer::table($table);
|
2008-02-12 08:01:00 +00:00
|
|
|
$outcomes_tables[] = $return;
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-05 08:42:34 +00:00
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
if ($outcomes = grade_outcome::fetch_all_global()) {
|
2009-08-06 08:16:46 +00:00
|
|
|
$return = $OUTPUT->heading($strstandardoutcome, 3, 'main');
|
2007-07-30 22:56:45 +00:00
|
|
|
$data = array();
|
|
|
|
foreach($outcomes as $outcome) {
|
|
|
|
$line = array();
|
|
|
|
$line[] = $outcome->get_name();
|
|
|
|
$line[] = $outcome->get_shortname();
|
|
|
|
|
|
|
|
$scale = $outcome->load_scale();
|
2007-07-31 09:15:39 +00:00
|
|
|
if (empty($scale->id)) { // hopefully never happens
|
|
|
|
$line[] = $scale->get_name();
|
2012-10-26 10:43:39 +08:00
|
|
|
debugging("Found a scale with no ID ({$scale->get_name()}) while outputting global outcomes", DEBUG_DEVELOPER);
|
2007-07-31 09:15:39 +00:00
|
|
|
} else {
|
|
|
|
if (empty($scale->courseid)) {
|
|
|
|
$caneditthisscale = $caneditsystemscales;
|
|
|
|
} else if ($scale->courseid == $courseid) {
|
|
|
|
$caneditthisscale = $caneditcoursescales;
|
|
|
|
} else {
|
2012-07-24 14:04:40 +08:00
|
|
|
$context = context_course::instance($scale->courseid);
|
2007-07-31 09:15:39 +00:00
|
|
|
$caneditthisscale = has_capability('moodle/course:managescales', $context);
|
|
|
|
}
|
|
|
|
if ($caneditthisscale) {
|
2009-08-27 09:39:50 +00:00
|
|
|
$line[] = grade_print_scale_link($courseid, $scale, $gpr);
|
2007-07-31 09:15:39 +00:00
|
|
|
} else {
|
|
|
|
$line[] = $scale->get_name();
|
|
|
|
}
|
|
|
|
}
|
2007-07-30 22:56:45 +00:00
|
|
|
|
2007-07-31 12:03:45 +00:00
|
|
|
$line[] = $outcome->get_course_uses_count();
|
|
|
|
$line[] = $outcome->get_item_uses_count();
|
2007-07-30 22:56:45 +00:00
|
|
|
|
|
|
|
$buttons = "";
|
2012-07-24 14:04:40 +08:00
|
|
|
if (has_capability('moodle/grade:manage', context_system::instance())) {
|
2009-08-27 09:39:50 +00:00
|
|
|
$buttons .= grade_button('edit', $courseid, $outcome);
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
2012-07-24 14:04:40 +08:00
|
|
|
if (has_capability('moodle/grade:manage', context_system::instance()) and $outcome->can_delete()) {
|
2009-08-27 09:39:50 +00:00
|
|
|
$buttons .= grade_button('delete', $courseid, $outcome);
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
|
|
|
$line[] = $buttons;
|
2008-02-05 08:42:34 +00:00
|
|
|
|
2007-07-30 22:56:45 +00:00
|
|
|
$data[] = $line;
|
|
|
|
}
|
2009-08-20 08:40:49 +00:00
|
|
|
$table = new html_table();
|
2008-02-26 07:30:34 +00:00
|
|
|
$table->head = array($strfullname, $strshortname, $strscale, $strcourses, $stritems, $stredit);
|
|
|
|
$table->size = array('30%', '20%', '20%', '10%', '10%', '10%');
|
|
|
|
$table->align = array('left', 'left', 'left', 'center', 'center', 'center');
|
2007-07-30 22:56:45 +00:00
|
|
|
$table->width = '90%';
|
|
|
|
$table->data = $data;
|
2010-03-20 22:15:54 +00:00
|
|
|
$return .= html_writer::table($table);
|
2008-02-12 08:01:00 +00:00
|
|
|
$outcomes_tables[] = $return;
|
2007-07-30 22:56:45 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 10:49:41 +00:00
|
|
|
if ($courseid) {
|
|
|
|
/// Print header
|
|
|
|
print_grade_page_head($courseid, 'outcome', 'edit', $heading);
|
|
|
|
}
|
|
|
|
|
2008-02-26 07:30:34 +00:00
|
|
|
foreach($outcomes_tables as $table) {
|
2009-08-27 09:39:50 +00:00
|
|
|
echo $table;
|
2008-02-12 08:01:00 +00:00
|
|
|
}
|
2007-07-30 22:56:45 +00:00
|
|
|
|
2009-08-20 08:40:49 +00:00
|
|
|
echo $OUTPUT->container_start('buttons');
|
2010-01-03 15:46:14 +00:00
|
|
|
echo $OUTPUT->single_button(new moodle_url('edit.php', array('courseid'=>$courseid)), $strcreatenewoutcome);
|
2008-02-26 07:30:34 +00:00
|
|
|
if ( !empty($outcomes_tables) ) {
|
2010-01-03 15:46:14 +00:00
|
|
|
echo $OUTPUT->single_button(new moodle_url('export.php', array('id'=>$courseid, 'sesskey'=>sesskey())), get_string('exportalloutcomes', 'grades'));
|
2008-02-26 07:30:34 +00:00
|
|
|
}
|
2009-08-20 08:40:49 +00:00
|
|
|
echo $OUTPUT->container_end();
|
2007-07-30 22:56:45 +00:00
|
|
|
|
2009-08-06 14:21:57 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-08-27 09:39:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Local shortcut function for creating a link to a scale.
|
|
|
|
* @param int $courseid The Course ID
|
|
|
|
* @param grade_scale $scale The Scale to link to
|
|
|
|
* @param grade_plugin_return $gpr An object used to identify the page we just came from
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
function grade_print_scale_link($courseid, $scale, $gpr) {
|
|
|
|
global $CFG, $OUTPUT;
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/grade/edit/scale/edit.php', array('courseid' => $courseid, 'id' => $scale->id));
|
2009-08-27 09:39:50 +00:00
|
|
|
$url = $gpr->add_url_params($url);
|
2010-02-11 16:27:53 +00:00
|
|
|
return html_writer::link($url, $scale->get_name());
|
2009-08-27 09:39:50 +00:00
|
|
|
}
|