Merge branch 'wip-MDL-34463-master' of git://github.com/abgreeve/moodle

This commit is contained in:
Dan Poltawski 2012-07-24 16:16:45 +08:00
commit 4ea5885e87
61 changed files with 95 additions and 100 deletions

View File

@ -34,7 +34,7 @@ $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
/// Make sure they can even access this course /// Make sure they can even access this course
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/course:update', $context); require_capability('moodle/course:update', $context);
/// return tracking object /// return tracking object

View File

@ -40,7 +40,7 @@ if ($id !== 0) {
$PAGE->set_url($url); $PAGE->set_url($url);
$PAGE->set_pagelayout('admin'); $PAGE->set_pagelayout('admin');
$systemcontext = get_context_instance(CONTEXT_SYSTEM); $systemcontext = context_system::instance();
$heading = null; $heading = null;
// a bit complex access control :-O // a bit complex access control :-O
@ -57,7 +57,7 @@ if ($id) {
print_error('invalidcourseid'); print_error('invalidcourseid');
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/grade:manage', $context); require_capability('moodle/grade:manage', $context);
$courseid = $course->id; $courseid = $course->id;
} else { } else {
@ -77,7 +77,7 @@ if ($id) {
/// adding new outcome from course /// adding new outcome from course
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/grade:manage', $context); require_capability('moodle/grade:manage', $context);
navigation_node::override_active_url(new moodle_url('/grade/edit/outcome/course.php', array('id'=>$courseid))); navigation_node::override_active_url(new moodle_url('/grade/edit/outcome/course.php', array('id'=>$courseid)));

View File

@ -121,7 +121,7 @@ class edit_outcome_form extends moodleform {
if (empty($courseid)) { if (empty($courseid)) {
$mform->hardFreeze('standard'); $mform->hardFreeze('standard');
} else if (empty($outcome->courseid) and !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) { } else if (empty($outcome->courseid) and !has_capability('moodle/grade:manage', context_system::instance())) {
$mform->hardFreeze('standard'); $mform->hardFreeze('standard');
} else if ($coursecount and empty($outcome->courseid)) { } else if ($coursecount and empty($outcome->courseid)) {
@ -130,7 +130,7 @@ class edit_outcome_form extends moodleform {
} else { } else {
if (empty($courseid) or !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) { if (empty($courseid) or !has_capability('moodle/grade:manage', context_system::instance())) {
$mform->hardFreeze('standard'); $mform->hardFreeze('standard');
} }
} }

View File

@ -35,7 +35,7 @@ if ($courseid) {
print_error('nocourseid'); print_error('nocourseid');
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/grade:manage', $context); require_capability('moodle/grade:manage', $context);
if (empty($CFG->enableoutcomes)) { if (empty($CFG->enableoutcomes)) {
@ -49,10 +49,6 @@ if ($courseid) {
require_sesskey(); require_sesskey();
// $outcome = grade_outcome::fetch(array('id'=>$outcomeid));
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
header("Content-Type: text/csv; charset=utf-8"); header("Content-Type: text/csv; charset=utf-8");
// TODO: make the filename more useful, include a date, a specific name, something... // TODO: make the filename more useful, include a date, a specific name, something...
header('Content-Disposition: attachment; filename=outcomes.csv'); header('Content-Disposition: attachment; filename=outcomes.csv');

View File

@ -40,7 +40,7 @@ if ($courseid) {
print_error('nocourseid'); print_error('nocourseid');
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
if (empty($CFG->enableoutcomes)) { if (empty($CFG->enableoutcomes)) {
redirect('../../index.php?id='.$courseid); redirect('../../index.php?id='.$courseid);
@ -49,7 +49,7 @@ if ($courseid) {
} else { } else {
require_once $CFG->libdir.'/adminlib.php'; require_once $CFG->libdir.'/adminlib.php';
admin_externalpage_setup('outcomes'); admin_externalpage_setup('outcomes');
$context = get_context_instance(CONTEXT_SYSTEM); $context = context_system::instance();
} }
require_capability('moodle/grade:manageoutcomes', $context); require_capability('moodle/grade:manageoutcomes', $context);
@ -79,7 +79,7 @@ if (!$upload_form->save_file('userfile', $imported_file, true)) {
if (isset($courseid) && ($scope == 'custom')) { if (isset($courseid) && ($scope == 'custom')) {
// custom scale // custom scale
$local_scope = true; $local_scope = true;
} elseif (($scope == 'global') && has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) { } elseif (($scope == 'global') && has_capability('moodle/grade:manage', context_system::instance())) {
// global scale // global scale
$local_scope = false; $local_scope = false;
} else { } else {

View File

@ -41,7 +41,7 @@ class import_outcomes_form extends moodleform {
$mform->setType('id', PARAM_INT); $mform->setType('id', PARAM_INT);
$scope = array(); $scope = array();
if (($PAGE->course->id > 1) && has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) { if (($PAGE->course->id > 1) && has_capability('moodle/grade:manage', context_system::instance())) {
$mform->addElement('radio', 'scope', get_string('importcustom', 'grades'), null, 'custom'); $mform->addElement('radio', 'scope', get_string('importcustom', 'grades'), null, 'custom');
$mform->addElement('radio', 'scope', get_string('importstandard', 'grades'), null, 'global'); $mform->addElement('radio', 'scope', get_string('importstandard', 'grades'), null, 'global');
$mform->setDefault('scope', 'custom'); $mform->setDefault('scope', 'custom');

View File

@ -36,7 +36,7 @@ $PAGE->set_pagelayout('admin');
if ($courseid) { if ($courseid) {
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/grade:manageoutcomes', $context); require_capability('moodle/grade:manageoutcomes', $context);
if (empty($CFG->enableoutcomes)) { if (empty($CFG->enableoutcomes)) {
@ -76,7 +76,7 @@ switch ($action) {
} }
if (empty($outcome->courseid)) { if (empty($outcome->courseid)) {
require_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM)); require_capability('moodle/grade:manage', context_system::instance());
} else if ($outcome->courseid != $courseid) { } else if ($outcome->courseid != $courseid) {
print_error('invalidcourseid'); print_error('invalidcourseid');
} }
@ -105,7 +105,7 @@ switch ($action) {
break; break;
} }
$systemcontext = get_context_instance(CONTEXT_SYSTEM); $systemcontext = context_system::instance();
$caneditsystemscales = has_capability('moodle/course:managescales', $systemcontext); $caneditsystemscales = has_capability('moodle/course:managescales', $systemcontext);
if ($courseid) { if ($courseid) {
@ -138,7 +138,7 @@ if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) {
} else if ($scale->courseid == $courseid) { } else if ($scale->courseid == $courseid) {
$caneditthisscale = $caneditcoursescales; $caneditthisscale = $caneditcoursescales;
} else { } else {
$context = get_context_instance(CONTEXT_COURSE, $scale->courseid); $context = context_course::instance($scale->courseid);
$caneditthisscale = has_capability('moodle/course:managescales', $context); $caneditthisscale = has_capability('moodle/course:managescales', $context);
} }
if ($caneditthisscale) { if ($caneditthisscale) {
@ -187,7 +187,7 @@ if ($outcomes = grade_outcome::fetch_all_global()) {
} else if ($scale->courseid == $courseid) { } else if ($scale->courseid == $courseid) {
$caneditthisscale = $caneditcoursescales; $caneditthisscale = $caneditcoursescales;
} else { } else {
$context = get_context_instance(CONTEXT_COURSE, $scale->courseid); $context = context_course::instance($scale->courseid);
$caneditthisscale = has_capability('moodle/course:managescales', $context); $caneditthisscale = has_capability('moodle/course:managescales', $context);
} }
if ($caneditthisscale) { if ($caneditthisscale) {
@ -201,10 +201,10 @@ if ($outcomes = grade_outcome::fetch_all_global()) {
$line[] = $outcome->get_item_uses_count(); $line[] = $outcome->get_item_uses_count();
$buttons = ""; $buttons = "";
if (has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) { if (has_capability('moodle/grade:manage', context_system::instance())) {
$buttons .= grade_button('edit', $courseid, $outcome); $buttons .= grade_button('edit', $courseid, $outcome);
} }
if (has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM)) and $outcome->can_delete()) { if (has_capability('moodle/grade:manage', context_system::instance()) and $outcome->can_delete()) {
$buttons .= grade_button('delete', $courseid, $outcome); $buttons .= grade_button('delete', $courseid, $outcome);
} }
$line[] = $buttons; $line[] = $buttons;

View File

@ -24,7 +24,7 @@
$row = $tabs = array(); $row = $tabs = array();
$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid); $context = context_course::instance($courseid);
$row[] = new tabobject('courseoutcomes', $row[] = new tabobject('courseoutcomes',
$CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$courseid, $CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$courseid,

View File

@ -33,7 +33,7 @@ $id = optional_param('id', 0, PARAM_INT);
$PAGE->set_url('/grade/edit/scale/edit.php', array('id' => $id, 'courseid' => $courseid)); $PAGE->set_url('/grade/edit/scale/edit.php', array('id' => $id, 'courseid' => $courseid));
$PAGE->set_pagelayout('admin'); $PAGE->set_pagelayout('admin');
$systemcontext = get_context_instance(CONTEXT_SYSTEM); $systemcontext = context_system::instance();
$heading = ''; $heading = '';
// a bit complex access control :-O // a bit complex access control :-O
@ -50,7 +50,7 @@ if ($id) {
print_error('invalidcourseid'); print_error('invalidcourseid');
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/course:managescales', $context); require_capability('moodle/course:managescales', $context);
$courseid = $course->id; $courseid = $course->id;
} else { } else {
@ -75,7 +75,7 @@ if ($id) {
$scale_rec->standard = 0; $scale_rec->standard = 0;
$scale_rec->courseid = $courseid; $scale_rec->courseid = $courseid;
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/course:managescales', $context); require_capability('moodle/course:managescales', $context);
} else { } else {

View File

@ -88,7 +88,7 @@ class edit_scale_form extends moodleform {
if (empty($courseid)) { if (empty($courseid)) {
$mform->hardFreeze('standard'); $mform->hardFreeze('standard');
} else if (!has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) { } else if (!has_capability('moodle/course:managescales', context_system::instance())) {
//if they dont have managescales at system level the shouldnt be allowed to make scales standard (or not standard) //if they dont have managescales at system level the shouldnt be allowed to make scales standard (or not standard)
$mform->hardFreeze('standard'); $mform->hardFreeze('standard');
@ -102,7 +102,7 @@ class edit_scale_form extends moodleform {
} else { } else {
$mform->removeElement('used'); $mform->removeElement('used');
if (empty($courseid) or !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) { if (empty($courseid) or !has_capability('moodle/course:managescales', context_system::instance())) {
$mform->hardFreeze('standard'); $mform->hardFreeze('standard');
} }
} }

View File

@ -37,7 +37,7 @@ if ($courseid) {
print_error('nocourseid'); print_error('nocourseid');
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/course:managescales', $context); require_capability('moodle/course:managescales', $context);
$PAGE->set_pagelayout('admin'); $PAGE->set_pagelayout('admin');
} else { } else {
@ -69,7 +69,7 @@ switch ($action) {
} }
if (empty($scale->courseid)) { if (empty($scale->courseid)) {
require_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM)); require_capability('moodle/course:managescales', context_system::instance());
} else if ($scale->courseid != $courseid) { } else if ($scale->courseid != $courseid) {
print_error('invalidcourseid'); print_error('invalidcourseid');
} }
@ -147,10 +147,10 @@ if ($scales = grade_scale::fetch_all_global()) {
$line[] = $used ? get_string('yes') : get_string('no'); $line[] = $used ? get_string('yes') : get_string('no');
$buttons = ""; $buttons = "";
if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) { if (has_capability('moodle/course:managescales', context_system::instance())) {
$buttons .= grade_button('edit', $courseid, $scale); $buttons .= grade_button('edit', $courseid, $scale);
} }
if (!$used and has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) { if (!$used and has_capability('moodle/course:managescales', context_system::instance())) {
$buttons .= grade_button('delete', $courseid, $scale); $buttons .= grade_button('delete', $courseid, $scale);
} }
$line[] = $buttons; $line[] = $buttons;

View File

@ -39,7 +39,7 @@ class course_settings_form extends moodleform {
$mform =& $this->_form; $mform =& $this->_form;
$systemcontext = get_context_instance(CONTEXT_SYSTEM); $systemcontext = context_system::instance();
$can_view_admin_links = false; $can_view_admin_links = false;
if (has_capability('moodle/grade:manage', $systemcontext)) { if (has_capability('moodle/grade:manage', $systemcontext)) {
$can_view_admin_links = true; $can_view_admin_links = true;

View File

@ -36,7 +36,7 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid'); print_error('nocourseid');
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/grade:manage', $context); require_capability('moodle/grade:manage', $context);

View File

@ -36,7 +36,7 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid'); print_error('nocourseid');
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
// default return url // default return url
$gpr = new grade_plugin_return(); $gpr = new grade_plugin_return();

View File

@ -43,7 +43,7 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/grade:manage', $context); require_capability('moodle/grade:manage', $context);
// default return url // default return url

View File

@ -42,7 +42,7 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/grade:manage', $context); require_capability('moodle/grade:manage', $context);
// default return url // default return url

View File

@ -50,7 +50,7 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
$PAGE->set_pagelayout('incourse'); $PAGE->set_pagelayout('incourse');
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
if (!has_capability('moodle/grade:manage', $context)) { if (!has_capability('moodle/grade:manage', $context)) {
require_capability('moodle/grade:edit', $context); require_capability('moodle/grade:edit', $context);
} }

View File

@ -139,7 +139,7 @@ class edit_grade_form extends moodleform {
function definition_after_data() { function definition_after_data() {
global $CFG, $COURSE, $DB; global $CFG, $COURSE, $DB;
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id); $context = context_course::instance($COURSE->id);
$mform =& $this->_form; $mform =& $this->_form;
$grade_item = $this->_customdata['grade_item']; $grade_item = $this->_customdata['grade_item'];

View File

@ -47,7 +47,7 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/grade:manage', $context); require_capability('moodle/grade:manage', $context);
// todo $PAGE->requires->js_module() should be used here instead // todo $PAGE->requires->js_module() should be used here instead

View File

@ -43,7 +43,7 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/grade:manage', $context); require_capability('moodle/grade:manage', $context);
// default return url // default return url

View File

@ -41,7 +41,7 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/grade:manage', $context); require_capability('moodle/grade:manage', $context);

View File

@ -119,7 +119,7 @@ class grade_export_form extends moodleform {
if ($grade_items = $gseq->items) { if ($grade_items = $gseq->items) {
$needs_multiselect = false; $needs_multiselect = false;
$canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $COURSE->id)); $canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($COURSE->id));
foreach ($grade_items as $grade_item) { foreach ($grade_items as $grade_item) {
// Is the grade_item hidden? If so, can the user see hidden grade_items? // Is the grade_item hidden? If so, can the user see hidden grade_items?

View File

@ -59,7 +59,7 @@ if ($id) {
$key->courseid = $course->id; $key->courseid = $course->id;
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/grade:export', $context); require_capability('moodle/grade:export', $context);
// extra security check // extra security check

View File

@ -35,7 +35,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:export', $context); require_capability('moodle/grade:export', $context);

View File

@ -29,7 +29,7 @@ if (empty($CFG->gradepublishing)) {
print_error('gradepubdisable'); print_error('gradepubdisable');
} }
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('gradeexport/ods:publish', $context); require_capability('gradeexport/ods:publish', $context);
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa // use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa

View File

@ -33,7 +33,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:export', $context); require_capability('moodle/grade:export', $context);
require_capability('gradeexport/ods:view', $context); require_capability('gradeexport/ods:view', $context);

View File

@ -32,7 +32,7 @@ class grade_export_ods extends grade_export {
$strgrades = get_string('grades'); $strgrades = get_string('grades');
$shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id))); $shortname = format_string($this->course->shortname, true, array('context' => context_course::instance($this->course->id)));
// Calculate file name // Calculate file name
$downloadfilename = clean_filename("$shortname $strgrades.ods"); $downloadfilename = clean_filename("$shortname $strgrades.ods");

View File

@ -28,7 +28,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:export', $context); require_capability('moodle/grade:export', $context);
require_capability('gradeexport/ods:view', $context); require_capability('gradeexport/ods:view', $context);

View File

@ -29,7 +29,7 @@ if (empty($CFG->gradepublishing)) {
print_error('gradepubdisable'); print_error('gradepubdisable');
} }
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('gradeexport/txt:publish', $context); require_capability('gradeexport/txt:publish', $context);
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa // use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa

View File

@ -34,7 +34,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:export', $context); require_capability('moodle/grade:export', $context);
require_capability('gradeexport/txt:view', $context); require_capability('gradeexport/txt:view', $context);

View File

@ -74,7 +74,7 @@ class grade_export_txt extends grade_export {
@header('Pragma: no-cache'); @header('Pragma: no-cache');
} }
header("Content-Type: application/download\n"); header("Content-Type: application/download\n");
$shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id))); $shortname = format_string($this->course->shortname, true, array('context' => context_course::instance($this->course->id)));
$downloadfilename = clean_filename("$shortname $strgrades"); $downloadfilename = clean_filename("$shortname $strgrades");
header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\""); header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\"");

View File

@ -28,7 +28,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:export', $context); require_capability('moodle/grade:export', $context);
require_capability('gradeexport/txt:view', $context); require_capability('gradeexport/txt:view', $context);

View File

@ -29,7 +29,7 @@ if (empty($CFG->gradepublishing)) {
print_error('gradepubdisable'); print_error('gradepubdisable');
} }
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('gradeexport/xls:publish', $context); require_capability('gradeexport/xls:publish', $context);
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa // use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa

View File

@ -33,7 +33,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:export', $context); require_capability('moodle/grade:export', $context);
require_capability('gradeexport/xls:view', $context); require_capability('gradeexport/xls:view', $context);

View File

@ -33,7 +33,7 @@ class grade_export_xls extends grade_export {
$strgrades = get_string('grades'); $strgrades = get_string('grades');
// Calculate file name // Calculate file name
$shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id))); $shortname = format_string($this->course->shortname, true, array('context' => context_course::instance($this->course->id)));
$downloadfilename = clean_filename("$shortname $strgrades.xls"); $downloadfilename = clean_filename("$shortname $strgrades.xls");
// Creating a workbook // Creating a workbook
$workbook = new MoodleExcelWorkbook("-"); $workbook = new MoodleExcelWorkbook("-");

View File

@ -28,7 +28,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:export', $context); require_capability('moodle/grade:export', $context);
require_capability('gradeexport/xls:view', $context); require_capability('gradeexport/xls:view', $context);

View File

@ -29,7 +29,7 @@ if (empty($CFG->gradepublishing)) {
print_error('gradepubdisable'); print_error('gradepubdisable');
} }
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('gradeexport/xml:publish', $context); require_capability('gradeexport/xml:publish', $context);
// use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa // use the same page parameters as export.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa

View File

@ -33,7 +33,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:export', $context); require_capability('moodle/grade:export', $context);
require_capability('gradeexport/xml:view', $context); require_capability('gradeexport/xml:view', $context);

View File

@ -38,7 +38,7 @@ class grade_export_xml extends grade_export {
$strgrades = get_string('grades'); $strgrades = get_string('grades');
/// Calculate file name /// Calculate file name
$shortname = format_string($this->course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $this->course->id))); $shortname = format_string($this->course->shortname, true, array('context' => context_course::instance($this->course->id)));
$downloadfilename = clean_filename("$shortname $strgrades.xml"); $downloadfilename = clean_filename("$shortname $strgrades.xml");
make_temp_directory('gradeexport'); make_temp_directory('gradeexport');

View File

@ -28,7 +28,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:export', $context); require_capability('moodle/grade:export', $context);
require_capability('gradeexport/xml:view', $context); require_capability('gradeexport/xml:view', $context);

View File

@ -41,7 +41,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:import', $context); require_capability('moodle/grade:import', $context);
require_capability('gradeimport/csv:view', $context); require_capability('gradeimport/csv:view', $context);

View File

@ -59,7 +59,7 @@ if ($id) {
$key->courseid = $course->id; $key->courseid = $course->id;
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('moodle/grade:import', $context); require_capability('moodle/grade:import', $context);
// extra security check // extra security check

View File

@ -35,7 +35,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:import', $context); require_capability('moodle/grade:import', $context);

View File

@ -161,13 +161,13 @@ function grade_import_commit($courseid, $importcode, $importfeedback=true, $verb
*/ */
function get_unenrolled_users_in_import($importcode, $courseid) { function get_unenrolled_users_in_import($importcode, $courseid) {
global $CFG, $DB; global $CFG, $DB;
$relatedctxcondition = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $courseid)); $relatedctxcondition = get_related_contexts_string(context_course::instance($courseid));
//users with a gradeable role //users with a gradeable role
list($gradebookrolessql, $gradebookrolesparams) = $DB->get_in_or_equal(explode(',', $CFG->gradebookroles), SQL_PARAMS_NAMED, 'grbr'); list($gradebookrolessql, $gradebookrolesparams) = $DB->get_in_or_equal(explode(',', $CFG->gradebookroles), SQL_PARAMS_NAMED, 'grbr');
//enrolled users //enrolled users
$context = get_context_instance(CONTEXT_COURSE, $courseid); $context = context_course::instance($courseid);
list($enrolledsql, $enrolledparams) = get_enrolled_sql($context); list($enrolledsql, $enrolledparams) = get_enrolled_sql($context);
$sql = "SELECT giv.id, u.firstname, u.lastname, u.idnumber AS useridnumber, $sql = "SELECT giv.id, u.firstname, u.lastname, u.idnumber AS useridnumber,

View File

@ -29,7 +29,7 @@ if (empty($CFG->gradepublishing)) {
print_error('gradepubdisable'); print_error('gradepubdisable');
} }
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('gradeimport/xml:publish', $context); require_capability('gradeimport/xml:publish', $context);
// use the same page parameters as import.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa // use the same page parameters as import.php and append &key=sdhakjsahdksahdkjsahksadjksahdkjsadhksa

View File

@ -34,7 +34,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:import', $context); require_capability('moodle/grade:import', $context);
require_capability('gradeimport/xml:view', $context); require_capability('gradeimport/xml:view', $context);

View File

@ -29,7 +29,7 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $id); $context = context_course::instance($id);
require_capability('moodle/grade:import', $context); require_capability('moodle/grade:import', $context);
require_capability('gradeimport/xml:view', $context); require_capability('gradeimport/xml:view', $context);

View File

@ -135,7 +135,7 @@ class graded_users_iterator {
return false; return false;
} }
$coursecontext = get_context_instance(CONTEXT_COURSE, $this->course->id); $coursecontext = context_course::instance($this->course->id);
$relatedcontexts = get_related_contexts_string($coursecontext); $relatedcontexts = get_related_contexts_string($coursecontext);
list($gradebookroles_sql, $params) = list($gradebookroles_sql, $params) =
@ -568,7 +568,7 @@ function grade_print_tabs($active_type, $active_plugin, $plugin_info, $return=fa
function grade_get_plugin_info($courseid, $active_type, $active_plugin) { function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
global $CFG, $SITE; global $CFG, $SITE;
$context = get_context_instance(CONTEXT_COURSE, $courseid); $context = context_course::instance($courseid);
$plugin_info = array(); $plugin_info = array();
$count = 0; $count = 0;
@ -1674,7 +1674,7 @@ class grade_seq extends grade_structure {
global $USER, $CFG; global $USER, $CFG;
$this->courseid = $courseid; $this->courseid = $courseid;
$this->context = get_context_instance(CONTEXT_COURSE, $courseid); $this->context = context_course::instance($courseid);
// get course grade tree // get course grade tree
$top_element = grade_category::fetch_course_tree($courseid, true); $top_element = grade_category::fetch_course_tree($courseid, true);
@ -1828,7 +1828,7 @@ class grade_tree extends grade_structure {
$this->courseid = $courseid; $this->courseid = $courseid;
$this->levels = array(); $this->levels = array();
$this->context = get_context_instance(CONTEXT_COURSE, $courseid); $this->context = context_course::instance($courseid);
if (!empty($COURSE->id) && $COURSE->id == $this->courseid) { if (!empty($COURSE->id) && $COURSE->id == $this->courseid) {
$course = $COURSE; $course = $COURSE;
@ -2459,7 +2459,7 @@ abstract class grade_helper {
if (self::$managesetting !== null) { if (self::$managesetting !== null) {
return self::$managesetting; return self::$managesetting;
} }
$context = get_context_instance(CONTEXT_COURSE, $courseid); $context = context_course::instance($courseid);
if (has_capability('moodle/course:update', $context)) { if (has_capability('moodle/course:update', $context)) {
self::$managesetting = new grade_plugin_info('coursesettings', new moodle_url('/grade/edit/settings/index.php', array('id'=>$courseid)), get_string('course')); self::$managesetting = new grade_plugin_info('coursesettings', new moodle_url('/grade/edit/settings/index.php', array('id'=>$courseid)), get_string('course'));
} else { } else {
@ -2479,7 +2479,7 @@ abstract class grade_helper {
if (self::$gradereports !== null) { if (self::$gradereports !== null) {
return self::$gradereports; return self::$gradereports;
} }
$context = get_context_instance(CONTEXT_COURSE, $courseid); $context = context_course::instance($courseid);
$gradereports = array(); $gradereports = array();
$gradepreferences = array(); $gradepreferences = array();
foreach (get_plugin_list('gradereport') as $plugin => $plugindir) { foreach (get_plugin_list('gradereport') as $plugin => $plugindir) {
@ -2539,7 +2539,7 @@ abstract class grade_helper {
if (self::$scaleinfo !== null) { if (self::$scaleinfo !== null) {
return self::$scaleinfo; return self::$scaleinfo;
} }
if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_COURSE, $courseid))) { if (has_capability('moodle/course:managescales', context_course::instance($courseid))) {
$url = new moodle_url('/grade/edit/scale/index.php', array('id'=>$courseid)); $url = new moodle_url('/grade/edit/scale/index.php', array('id'=>$courseid));
self::$scaleinfo = new grade_plugin_info('scale', $url, get_string('view')); self::$scaleinfo = new grade_plugin_info('scale', $url, get_string('view'));
} else { } else {
@ -2558,7 +2558,7 @@ abstract class grade_helper {
if (self::$outcomeinfo !== null) { if (self::$outcomeinfo !== null) {
return self::$outcomeinfo; return self::$outcomeinfo;
} }
$context = get_context_instance(CONTEXT_COURSE, $courseid); $context = context_course::instance($courseid);
$canmanage = has_capability('moodle/grade:manage', $context); $canmanage = has_capability('moodle/grade:manage', $context);
$canupdate = has_capability('moodle/course:update', $context); $canupdate = has_capability('moodle/course:update', $context);
if (!empty($CFG->enableoutcomes) && ($canmanage || $canupdate)) { if (!empty($CFG->enableoutcomes) && ($canmanage || $canupdate)) {
@ -2593,7 +2593,7 @@ abstract class grade_helper {
if (self::$edittree !== null) { if (self::$edittree !== null) {
return self::$edittree; return self::$edittree;
} }
if (has_capability('moodle/grade:manage', get_context_instance(CONTEXT_COURSE, $courseid))) { if (has_capability('moodle/grade:manage', context_course::instance($courseid))) {
$url = new moodle_url('/grade/edit/tree/index.php', array('sesskey'=>sesskey(), 'showadvanced'=>'0', 'id'=>$courseid)); $url = new moodle_url('/grade/edit/tree/index.php', array('sesskey'=>sesskey(), 'showadvanced'=>'0', 'id'=>$courseid));
self::$edittree = array( self::$edittree = array(
'simpleview' => new grade_plugin_info('simpleview', $url, get_string('simpleview', 'grades')), 'simpleview' => new grade_plugin_info('simpleview', $url, get_string('simpleview', 'grades')),
@ -2613,7 +2613,7 @@ abstract class grade_helper {
if (self::$letterinfo !== null) { if (self::$letterinfo !== null) {
return self::$letterinfo; return self::$letterinfo;
} }
$context = get_context_instance(CONTEXT_COURSE, $courseid); $context = context_course::instance($courseid);
$canmanage = has_capability('moodle/grade:manage', $context); $canmanage = has_capability('moodle/grade:manage', $context);
$canmanageletters = has_capability('moodle/grade:manageletters', $context); $canmanageletters = has_capability('moodle/grade:manageletters', $context);
if ($canmanage || $canmanageletters) { if ($canmanage || $canmanageletters) {
@ -2638,7 +2638,7 @@ abstract class grade_helper {
return self::$importplugins; return self::$importplugins;
} }
$importplugins = array(); $importplugins = array();
$context = get_context_instance(CONTEXT_COURSE, $courseid); $context = context_course::instance($courseid);
if (has_capability('moodle/grade:import', $context)) { if (has_capability('moodle/grade:import', $context)) {
foreach (get_plugin_list('gradeimport') as $plugin => $plugindir) { foreach (get_plugin_list('gradeimport') as $plugin => $plugindir) {
@ -2676,7 +2676,7 @@ abstract class grade_helper {
if (self::$exportplugins !== null) { if (self::$exportplugins !== null) {
return self::$exportplugins; return self::$exportplugins;
} }
$context = get_context_instance(CONTEXT_COURSE, $courseid); $context = context_course::instance($courseid);
$exportplugins = array(); $exportplugins = array();
if (has_capability('moodle/grade:export', $context)) { if (has_capability('moodle/grade:export', $context)) {
foreach (get_plugin_list('gradeexport') as $plugin => $plugindir) { foreach (get_plugin_list('gradeexport') as $plugin => $plugindir) {

View File

@ -39,7 +39,7 @@ $newvalue = optional_param('newvalue', false, PARAM_TEXT);
if (!$course = $DB->get_record('course', array('id' => $courseid))) { if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid'); print_error('nocourseid');
} }
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_login($course); require_login($course);
switch ($action) { switch ($action) {

View File

@ -46,7 +46,7 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid'); print_error('nocourseid');
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('gradereport/grader:view', $context); require_capability('gradereport/grader:view', $context);
require_capability('moodle/grade:viewall', $context); require_capability('moodle/grade:viewall', $context);

View File

@ -107,7 +107,7 @@ class grade_report_grader extends grade_report {
global $CFG; global $CFG;
parent::__construct($courseid, $gpr, $context, $page); parent::__construct($courseid, $gpr, $context, $page);
$this->canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->course->id)); $this->canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($this->course->id));
// load collapsed settings for this report // load collapsed settings for this report
if ($collapsed = get_user_preferences('grade_report_grader_collapsed_categories')) { if ($collapsed = get_user_preferences('grade_report_grader_collapsed_categories')) {

View File

@ -40,8 +40,8 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
$systemcontext = get_context_instance(CONTEXT_SYSTEM); $systemcontext = context_system::instance();
require_capability('gradereport/grader:view', $context); require_capability('gradereport/grader:view', $context);
require('preferences_form.php'); require('preferences_form.php');

View File

@ -40,8 +40,7 @@ class grader_report_preferences_form extends moodleform {
$mform =& $this->_form; $mform =& $this->_form;
$course = $this->_customdata['course']; $course = $this->_customdata['course'];
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$canviewhidden = has_capability('moodle/grade:viewhidden', $context); $canviewhidden = has_capability('moodle/grade:viewhidden', $context);

View File

@ -52,7 +52,7 @@ if (!$item = $DB->get_record('grade_items', array('id' => $itemid))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('gradereport/grader:view', $context); require_capability('gradereport/grader:view', $context);
require_capability('moodle/grade:viewall', $context); require_capability('moodle/grade:viewall', $context);

View File

@ -23,7 +23,7 @@
*/ */
$row = $tabs = array(); $row = $tabs = array();
$tabcontext = get_context_instance(CONTEXT_COURSE, $COURSE->id); $tabcontext = context_course::instance($COURSE->id);
$row[] = new tabobject('graderreport', $row[] = new tabobject('graderreport',
$CFG->wwwroot.'/grade/report/grader/index.php?id='.$courseid, $CFG->wwwroot.'/grade/report/grader/index.php?id='.$courseid,
get_string('pluginname', 'gradereport_grader')); get_string('pluginname', 'gradereport_grader'));

View File

@ -33,7 +33,7 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid'); print_error('nocourseid');
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
/// find all accessible reports /// find all accessible reports
$reports = get_plugin_list('gradereport'); // Get all installed reports $reports = get_plugin_list('gradereport'); // Get all installed reports

View File

@ -35,7 +35,7 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('gradereport/outcomes:view', $context); require_capability('gradereport/outcomes:view', $context);

View File

@ -38,8 +38,8 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
} }
require_login($course); require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
$systemcontext = get_context_instance(CONTEXT_SYSTEM); $systemcontext = context_system::instance();
require_capability('gradereport/overview:view', $context); require_capability('gradereport/overview:view', $context);
if (empty($userid)) { if (empty($userid)) {
@ -64,7 +64,7 @@ if (has_capability('moodle/grade:viewall', $systemcontext)) {
//ok - can view own course grades //ok - can view own course grades
$access = true; $access = true;
} else if (has_capability('moodle/grade:viewall', get_context_instance(CONTEXT_USER, $userid)) and $course->showgrades) { } else if (has_capability('moodle/grade:viewall', context_user::instance($userid)) and $course->showgrades) {
// ok - can view grades of this user- parent most probably // ok - can view grades of this user- parent most probably
$access = true; $access = true;
} }

View File

@ -122,7 +122,7 @@ class grade_report_overview extends grade_report {
continue; continue;
} }
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); $coursecontext = context_course::instance($course->id);
if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) { if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
// The course is hidden and the user isn't allowed to see it // The course is hidden and the user isn't allowed to see it

View File

@ -39,7 +39,7 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
require_login($course); require_login($course);
$PAGE->set_pagelayout('report'); $PAGE->set_pagelayout('report');
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
require_capability('gradereport/user:view', $context); require_capability('gradereport/user:view', $context);
if (empty($userid)) { if (empty($userid)) {
@ -60,7 +60,7 @@ if (has_capability('moodle/grade:viewall', $context)) {
//ok - can view own grades //ok - can view own grades
$access = true; $access = true;
} else if (has_capability('moodle/grade:viewall', get_context_instance(CONTEXT_USER, $userid)) and $course->showgrades) { } else if (has_capability('moodle/grade:viewall', context_user::instance($userid)) and $course->showgrades) {
// ok - can view grades of this user- parent most probably // ok - can view grades of this user- parent most probably
$access = true; $access = true;
} }

View File

@ -203,7 +203,7 @@ class grade_report_user extends grade_report {
$this->tabledata = array(); $this->tabledata = array();
$this->canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->courseid)); $this->canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($this->courseid));
// get the user (for full name) // get the user (for full name)
$this->user = $DB->get_record('user', array('id' => $userid)); $this->user = $DB->get_record('user', array('id' => $userid));
@ -870,7 +870,7 @@ function grade_report_user_profilereport($course, $user) {
global $OUTPUT; global $OUTPUT;
if (!empty($course->showgrades)) { if (!empty($course->showgrades)) {
$context = get_context_instance(CONTEXT_COURSE, $course->id); $context = context_course::instance($course->id);
//first make sure we have proper final grades - this must be done before constructing of the grade tree //first make sure we have proper final grades - this must be done before constructing of the grade tree
grade_regrade_final_grades($course->id); grade_regrade_final_grades($course->id);