From 327c67a9714e8e19a7ee74c7d9facfb8fed40dfd Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 26 Jul 2012 14:57:34 +0800 Subject: [PATCH] MDL-34466 mod_choice Replace all instances of get_context_instance() with respective context_XXXX class in mod/choice --- mod/choice/lib.php | 10 ++++------ mod/choice/report.php | 2 +- mod/choice/view.php | 8 +++----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/mod/choice/lib.php b/mod/choice/lib.php index 2b37b382c48..e961311ab5a 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -200,7 +200,7 @@ function choice_prepare_options($choice, $user, $coursemodule, $allresponses) { $cdisplay = array('options'=>array()); $cdisplay['limitanswers'] = true; - $context = get_context_instance(CONTEXT_MODULE, $coursemodule->id); + $context = context_module::instance($coursemodule->id); foreach ($choice->option as $optionid => $text) { if (isset($text)) { //make sure there are no dud entries in the db with blank text values. @@ -248,7 +248,7 @@ function choice_user_submit_response($formanswer, $choice, $userid, $course, $cm require_once($CFG->libdir.'/completionlib.php'); $current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $userid)); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = context_module::instance($cm->id); $countanswers=0; if($choice->limitanswers) { @@ -368,7 +368,7 @@ function prepare_choice_show_results($choice, $course, $cm, $allresponses, $forc unset($display->maxanswers); $display->numberofuser = $totaluser; - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = context_module::instance($cm->id); $display->viewresponsecapability = has_capability('mod/choice:readresponses', $context); $display->deleterepsonsecapability = has_capability('mod/choice:deleteresponses',$context); $display->fullnamecapability = has_capability('moodle/site:viewfullnames', $context); @@ -386,8 +386,6 @@ function prepare_choice_show_results($choice, $course, $cm, $allresponses, $forc } } - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - $hascapfullnames = has_capability('moodle/site:viewfullnames', $context); $viewresponses = has_capability('mod/choice:readresponses', $context); @@ -708,7 +706,7 @@ function choice_reset_userdata($data) { function choice_get_response_data($choice, $cm, $groupmode) { global $CFG, $USER, $DB; - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = context_module::instance($cm->id); /// Get the current group if ($groupmode > 0) { diff --git a/mod/choice/report.php b/mod/choice/report.php index b1723dd2620..4d6a5b9b3ee 100644 --- a/mod/choice/report.php +++ b/mod/choice/report.php @@ -31,7 +31,7 @@ require_login($course, false, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $context = context_module::instance($cm->id); require_capability('mod/choice:readresponses', $context); diff --git a/mod/choice/view.php b/mod/choice/view.php index 1a222fc87c7..7999f8a917b 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -31,9 +31,7 @@ $strchoice = get_string('modulename', 'choice'); $strchoices = get_string('modulenameplural', 'choice'); - if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) { - print_error('badcontext'); - } + $context = context_module::instance($cm->id); if ($action == 'delchoice' and confirm_sesskey() and is_enrolled($context, NULL, 'mod/choice:choose') and $choice->allowupdate) { if ($answer = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) { @@ -133,7 +131,7 @@ } if (!$choiceformshown) { - $sitecontext = get_context_instance(CONTEXT_SYSTEM); + $sitecontext = context_system::instance(); if (isguestuser()) { // Guest account @@ -144,7 +142,7 @@ $SESSION->wantsurl = qualified_me(); $SESSION->enrolcancel = (!empty($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : ''; - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $coursecontext = context_course::instance($course->id); $courseshortname = format_string($course->shortname, true, array('context' => $coursecontext)); echo $OUTPUT->box_start('generalbox', 'notice');