Skip to content

Commit

Permalink
MDL-34468 quiz: Replace all instances of get_context_instance() with …
Browse files Browse the repository at this point in the history
…respective context_XXXX class in mod/quiz
  • Loading branch information
ankitagarwal committed Jul 24, 2012
1 parent 1c96911 commit c492a78
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion mod/quiz/attemptlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/editlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions mod/quiz/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions mod/quiz/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions mod/quiz/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/overridedelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/overrideedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c492a78

Please sign in to comment.