Permalink
Browse files

MDL-34468 quiz: Replace all instances of get_context_instance() with …

…respective context_XXXX class in mod/quiz
  • Loading branch information...
1 parent 1c96911 commit c492a78ee23028f9b181d52f8dc98130b6fca71e @ankitagarwal ankitagarwal committed Jul 24, 2012
@@ -87,7 +87,7 @@ public function __construct($quiz, $cm, $course, $getcontext = true) {
$this->quiz->cmid = $this->cm->id;
$this->course = $course;
if ($getcontext && !empty($cm->id)) {
- $this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $this->context = context_module::instance($cm->id);
}
$questionids = quiz_questions_in_quiz($this->quiz->questions);
if ($questionids) {
@@ -744,7 +744,7 @@ function quiz_print_pagecontrols($quiz, $pageurl, $page, $hasattempts,
echo '<div class="pagecontrols">';
// Get the current context.
- $thiscontext = get_context_instance(CONTEXT_COURSE, $quiz->course);
+ $thiscontext = context_course::instance($quiz->course);
$contexts = new question_edit_contexts($thiscontext);
// Get the default category.
View
@@ -32,7 +32,7 @@
if (!$course = $DB->get_record('course', array('id' => $id))) {
print_error('invalidcourseid');
}
-$coursecontext = get_context_instance(CONTEXT_COURSE, $id);
+$coursecontext = context_course::instance($id);
require_login($course);
$PAGE->set_pagelayout('incourse');
@@ -124,7 +124,7 @@
$currentsection = '';
foreach ($quizzes as $quiz) {
$cm = get_coursemodule_from_instance('quiz', $quiz->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$data = array();
// Section number if necessary.
View
@@ -839,7 +839,7 @@ function quiz_get_recent_mod_activity(&$activities, &$index, $timestart,
return;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
$accessallgroups = has_capability('moodle/site:accessallgroups', $context);
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
$grader = has_capability('mod/quiz:viewreports', $context);
@@ -1075,7 +1075,7 @@ function quiz_after_add_or_update($quiz) {
// We need to use context now, so we need to make sure all needed info is already in db.
$DB->set_field('course_modules', 'instance', $quiz->id, array('id'=>$cmid));
- $context = get_context_instance(CONTEXT_MODULE, $cmid);
+ $context = context_module::instance($cmid);
// Save the feedback.
$DB->delete_records('quiz_feedback', array('quizid' => $quiz->id));
@@ -1378,7 +1378,7 @@ function quiz_check_file_access($attemptuniqueid, $questionid, $context = null)
if ($context === null) {
$quiz = $DB->get_record('quiz', array('id' => $attempt->quiz));
$cm = get_coursemodule_from_id('quiz', $quiz->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
}
// Load those questions and the associated states.
@@ -1439,7 +1439,7 @@ function quiz_print_overview($courses, &$htmlarray) {
userdate($quiz->timeclose)) . '</div>';
// Now provide more information depending on the uers's role.
- $context = get_context_instance(CONTEXT_MODULE, $quiz->coursemodule);
+ $context = context_module::instance($quiz->coursemodule);
if (has_capability('mod/quiz:viewreports', $context)) {
// For teacher-like people, show a summary of the number of student attempts.
// The $quiz objects returned by get_all_instances_in_course have the necessary $cm
@@ -1590,7 +1590,7 @@ function quiz_get_extra_capabilities() {
function quiz_extend_navigation($quiznode, $course, $module, $cm) {
global $CFG;
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $context = context_module::instance($cm->id);
if (has_capability('mod/quiz:view', $context)) {
$url = new moodle_url('/mod/quiz/view.php', array('id'=>$cm->id));
@@ -1416,7 +1416,7 @@ function quiz_attempt_submitted_handler($event) {
}
return quiz_send_notification_messages($course, $quiz, $attempt,
- get_context_instance(CONTEXT_MODULE, $cm->id), $cm);
+ context_module::instance($cm->id), $cm);
}
/**
@@ -1442,7 +1442,7 @@ function quiz_attempt_overdue_handler($event) {
}
return quiz_send_overdue_message($course, $quiz, $attempt,
- get_context_instance(CONTEXT_MODULE, $cm->id), $cm);
+ context_module::instance($cm->id), $cm);
}
/**
@@ -42,7 +42,7 @@
}
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_login($course, false, $cm);
@@ -74,7 +74,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
// Add or edit an override.
require_capability('mod/quiz:manageoverrides', $context);
@@ -62,7 +62,7 @@
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
// Check the user has the required capabilities to list overrides.
require_capability('mod/quiz:manageoverrides', $context);
View
@@ -63,7 +63,7 @@
$PAGE->set_url($url);
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
$PAGE->set_pagelayout('report');
$reportlist = quiz_report_list($context);
View
@@ -54,7 +54,7 @@
// Check login and get context.
require_login($course, false, $cm);
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+$context = context_module::instance($cm->id);
require_capability('mod/quiz:view', $context);
// Cache some other capabilities we use several times.

0 comments on commit c492a78

Please sign in to comment.