Skip to content

Commit

Permalink
MDL-32322 quiz reports: get_context_instance -> new classes.
Browse files Browse the repository at this point in the history
Also, eliminate unnecessary use of global $COURSE.
  • Loading branch information
timhunt committed Apr 20, 2012
1 parent ead4f18 commit 26aded5
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 28 deletions.
2 changes: 1 addition & 1 deletion mod/quiz/report/attemptsreport.php
Expand Up @@ -346,7 +346,7 @@ public function col_checkbox($attempt) {
}

public function col_picture($attempt) {
global $COURSE, $OUTPUT;
global $OUTPUT;
$user = new stdClass();
$user->id = $attempt->userid;
$user->lastname = $attempt->lastname;
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/report/grading/report.php
Expand Up @@ -84,7 +84,7 @@ public function display($quiz, $cm, $course) {
}

// Check permissions
$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
$this->context = context_module::instance($cm->id);
require_capability('mod/quiz:grade', $this->context);
$shownames = has_capability('quiz/grading:viewstudentnames', $this->context);
$showidnumbers = has_capability('quiz/grading:viewidnumber', $this->context);
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/report/overview/overviewgraph.php
Expand Up @@ -37,7 +37,7 @@
$cm = get_coursemodule_from_instance('quiz', $quizid);

require_login($course, false, $cm);
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$modcontext = context_module::instance($cm->id);
require_capability('mod/quiz:viewreports', $modcontext);

if ($groupid && $groupmode = groups_get_activity_groupmode($cm)) {
Expand Down
17 changes: 6 additions & 11 deletions mod/quiz/report/overview/report.php
Expand Up @@ -40,9 +40,9 @@
class quiz_overview_report extends quiz_attempt_report {

public function display($quiz, $cm, $course) {
global $CFG, $COURSE, $DB, $OUTPUT;
global $CFG, $DB, $OUTPUT;

$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
$this->context = context_module::instance($cm->id);

$download = optional_param('download', '', PARAM_ALPHA);

Expand Down Expand Up @@ -117,24 +117,19 @@ public function display($quiz, $cm, $course) {
$allowed = array();
}

$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$courseshortname = format_string($course->shortname, true,
array('context' => $coursecontext));

$displaycoursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$displaycourseshortname = format_string($COURSE->shortname, true,
array('context' => $displaycoursecontext));

// Load the required questions.
$questions = quiz_report_get_significant_questions($quiz);

// Prepare for downloading, if applicable.
$courseshortname = format_string($course->shortname, true,
array('context' => context_course::instance($course->id)));
$table = new quiz_overview_table($quiz, $this->context, $qmsubselect,
$qmfilter, $attemptsmode, $groupstudents, $students, $detailedmarks,
$questions, $includecheckboxes, $reporturl, $displayoptions);
$filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'),
$courseshortname, $quiz->name);
$table->is_downloading($download, $filename,
$displaycourseshortname . ' ' . format_string($quiz->name, true));
$courseshortname . ' ' . format_string($quiz->name, true));
if ($table->is_downloading()) {
raise_memory_limit(MEMORY_EXTRA);
}
Expand Down
14 changes: 4 additions & 10 deletions mod/quiz/report/responses/report.php
Expand Up @@ -48,9 +48,9 @@
class quiz_responses_report extends quiz_attempt_report {

public function display($quiz, $cm, $course) {
global $CFG, $COURSE, $DB, $PAGE, $OUTPUT;
global $CFG, $DB, $PAGE, $OUTPUT;

$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
$this->context = context_module::instance($cm->id);

$download = optional_param('download', '', PARAM_ALPHA);

Expand Down Expand Up @@ -137,21 +137,15 @@ public function display($quiz, $cm, $course) {
// Load the required questions.
$questions = quiz_report_get_significant_questions($quiz);

$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$courseshortname = format_string($course->shortname, true,
array('context' => $coursecontext));

$displaycoursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$displaycourseshortname = format_string($COURSE->shortname, true,
array('context' => $displaycoursecontext));

array('context' => context_course::instance($course->id)));
$table = new quiz_responses_table($quiz, $this->context, $qmsubselect,
$qmfilter, $attemptsmode, $groupstudents, $students, $questions,
$includecheckboxes, $reporturl, $displayoptions);
$filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'),
$courseshortname, $quiz->name);
$table->is_downloading($download, $filename,
$displaycourseshortname . ' ' . format_string($quiz->name, true));
$courseshortname . ' ' . format_string($quiz->name, true));
if ($table->is_downloading()) {
raise_memory_limit(MEMORY_EXTRA);
}
Expand Down
5 changes: 2 additions & 3 deletions mod/quiz/report/statistics/report.php
Expand Up @@ -54,7 +54,7 @@ class quiz_statistics_report extends quiz_default_report {
public function display($quiz, $cm, $course) {
global $CFG, $DB, $OUTPUT, $PAGE;

$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
$this->context = context_module::instance($cm->id);

// Work out the display options.
$download = optional_param('download', '', PARAM_ALPHA);
Expand Down Expand Up @@ -118,9 +118,8 @@ public function display($quiz, $cm, $course) {
} else {
$report = get_string('questionstatsfilename', 'quiz_statistics');
}
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$courseshortname = format_string($course->shortname, true,
array('context' => $coursecontext));
array('context' => context_course::instance($course->id)));
$filename = quiz_report_download_filename($report, $courseshortname, $quiz->name);
$this->table->is_downloading($download, $filename,
get_string('quizstructureanalysis', 'quiz_statistics'));
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/report/statistics/statistics_graph.php
Expand Up @@ -62,7 +62,7 @@ function graph_get_new_colour() {

// Check access.
require_login($quiz->course, false, $cm);
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$modcontext = context_module::instance($cm->id);
require_capability('quiz/statistics:view', $modcontext);

if (groups_get_activity_groupmode($cm)) {
Expand Down

0 comments on commit 26aded5

Please sign in to comment.