From 2cffef9f41d26c1daddc066f4d82479f89351d28 Mon Sep 17 00:00:00 2001
From: Paul Charsley
Date: Thu, 13 Sep 2012 13:44:05 +1200
Subject: [PATCH] MDL-35388 modifications to allow php unit tests to be run
---
mod/assign/lib.php | 2 +-
mod/assign/locallib.php | 86 +++++++++++++++++++++++------------------
2 files changed, 50 insertions(+), 38 deletions(-)
diff --git a/mod/assign/lib.php b/mod/assign/lib.php
index 1636d2e7911..a25b871e8cc 100644
--- a/mod/assign/lib.php
+++ b/mod/assign/lib.php
@@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
* @param mod_assign_mod_form $form
* @return int The instance id of the new assignment
*/
-function assign_add_instance(stdClass $data, mod_assign_mod_form $form) {
+function assign_add_instance(stdClass $data, mod_assign_mod_form $form = null) {
global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php
index 567252f7751..100c4888e6b 100644
--- a/mod/assign/locallib.php
+++ b/mod/assign/locallib.php
@@ -132,7 +132,6 @@ class assign {
$this->submissionplugins = $this->load_plugins('assignsubmission');
$this->feedbackplugins = $this->load_plugins('assignfeedback');
- $this->output = $PAGE->get_renderer('mod_assign');
}
/**
@@ -1417,7 +1416,7 @@ class assign {
} else {
$data->batchusers = $batchusers;
}
- $o .= $this->output->render(new assign_header($this->get_instance(),
+ $o .= $this->get_output()->render(new assign_header($this->get_instance(),
$this->get_context(),
$this->show_intro(),
$this->get_course_module()->id,
@@ -1430,7 +1429,7 @@ class assign {
$this->get_instance(),
$data));
}
- $o .= $this->output->render(new assign_form('extensionform', $mform));
+ $o .= $this->get_output()->render(new assign_form('extensionform', $mform));
$o .= $this->view_footer();
return $o;
}
@@ -1602,12 +1601,12 @@ class assign {
if ($item->userid != $USER->id) {
require_capability('mod/assign:grade', $this->context);
}
- $o .= $this->output->render(new assign_header($this->get_instance(),
+ $o .= $this->get_output()->render(new assign_header($this->get_instance(),
$this->get_context(),
$this->show_intro(),
$this->get_course_module()->id,
$plugin->get_name()));
- $o .= $this->output->render(new assign_submission_plugin_submission($plugin,
+ $o .= $this->get_output()->render(new assign_submission_plugin_submission($plugin,
$item,
assign_submission_plugin_submission::FULL,
$this->get_course_module()->id,
@@ -1625,12 +1624,12 @@ class assign {
if ($item->userid != $USER->id) {
require_capability('mod/assign:grade', $this->context);
}
- $o .= $this->output->render(new assign_header($this->get_instance(),
+ $o .= $this->get_output()->render(new assign_header($this->get_instance(),
$this->get_context(),
$this->show_intro(),
$this->get_course_module()->id,
$plugin->get_name()));
- $o .= $this->output->render(new assign_feedback_plugin_feedback($plugin,
+ $o .= $this->get_output()->render(new assign_feedback_plugin_feedback($plugin,
$item,
assign_feedback_plugin_feedback::FULL,
$this->get_course_module()->id,
@@ -1696,12 +1695,12 @@ class assign {
*/
private function view_quickgrading_result($message) {
$o = '';
- $o .= $this->output->render(new assign_header($this->get_instance(),
+ $o .= $this->get_output()->render(new assign_header($this->get_instance(),
$this->get_context(),
$this->show_intro(),
$this->get_course_module()->id,
get_string('quickgradingresult', 'assign')));
- $o .= $this->output->render(new assign_quickgrading_result($message, $this->get_course_module()->id));
+ $o .= $this->get_output()->render(new assign_quickgrading_result($message, $this->get_course_module()->id));
$o .= $this->view_footer();
return $o;
}
@@ -1712,7 +1711,7 @@ class assign {
* @return string
*/
private function view_footer() {
- return $this->output->render_footer();
+ return $this->get_output()->render_footer();
}
/**
@@ -1814,6 +1813,19 @@ class assign {
add_to_log($this->get_course()->id, 'assign', $action, $fullurl, $info, $this->get_course_module()->id, $USER->id);
}
+
+ /**
+ * Load the page renderer
+ * @return assign_renderer
+ */
+ private function get_output() {
+ global $PAGE;
+ if ($this->output) {
+ return $this->output;
+ }
+ $this->output = $PAGE->get_renderer('mod_assign');
+ return $this->output;
+ }
/**
* Load the submission object for a particular user, optionally creating it if required
@@ -1936,7 +1948,7 @@ class assign {
// Need submit permission to submit an assignment
require_capability('mod/assign:grade', $this->context);
- $o .= $this->output->render(new assign_header($this->get_instance(),
+ $o .= $this->get_output()->render(new assign_header($this->get_instance(),
$this->get_context(), false, $this->get_course_module()->id,get_string('grading', 'assign')));
$rownum = required_param('rownum', PARAM_INT) + $offset;
@@ -1960,7 +1972,7 @@ class assign {
}
$user = $DB->get_record('user', array('id' => $userid));
if ($user) {
- $o .= $this->output->render(new assign_user_summary($user,
+ $o .= $this->get_output()->render(new assign_user_summary($user,
$this->get_course()->id,
has_capability('moodle/site:viewfullnames',
$this->get_course_context()),
@@ -2000,7 +2012,7 @@ class assign {
}
$viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context());
- $o .= $this->output->render(new assign_submission_status($this->get_instance()->allowsubmissionsfromdate,
+ $o .= $this->get_output()->render(new assign_submission_status($this->get_instance()->allowsubmissionsfromdate,
$this->get_instance()->alwaysshowdescription,
$submission,
$this->get_instance()->teamsubmission,
@@ -2045,7 +2057,7 @@ class assign {
'',
array('class'=>'gradeform'));
}
- $o .= $this->output->render(new assign_form('gradingform',$mform));
+ $o .= $this->get_output()->render(new assign_form('gradingform',$mform));
$msg = get_string('viewgradingformforstudent', 'assign', array('id'=>$user->id, 'fullname'=>fullname($user)));
$this->add_to_log('view grading form', $msg);
@@ -2065,7 +2077,7 @@ class assign {
require_capability('mod/assign:revealidentities', $this->get_context());
$o = '';
- $o .= $this->output->render(new assign_header($this->get_instance(),
+ $o .= $this->get_output()->render(new assign_header($this->get_instance(),
$this->get_context(), false, $this->get_course_module()->id));
$confirmurl = new moodle_url('/mod/assign/view.php', array('id'=>$this->get_course_module()->id,
@@ -2075,7 +2087,7 @@ class assign {
$cancelurl = new moodle_url('/mod/assign/view.php', array('id'=>$this->get_course_module()->id,
'action'=>'grading'));
- $o .= $this->output->confirm(get_string('revealidentitiesconfirm', 'assign'), $confirmurl, $cancelurl);
+ $o .= $this->get_output()->confirm(get_string('revealidentitiesconfirm', 'assign'), $confirmurl, $cancelurl);
$o .= $this->view_footer();
$this->add_to_log('view', get_string('viewrevealidentitiesconfirm', 'assign'));
return $o;
@@ -2098,7 +2110,7 @@ class assign {
parse_str($returnparams, $params);
$params = array_merge( array('id' => $this->get_course_module()->id, 'action' => $returnaction), $params);
- return $this->output->single_button(new moodle_url('/mod/assign/view.php', $params), get_string('back'), 'get');
+ return $this->get_output()->single_button(new moodle_url('/mod/assign/view.php', $params), get_string('back'), 'get');
}
@@ -2174,30 +2186,30 @@ class assign {
$o .= plagiarism_update_status($this->get_course(), $this->get_course_module());
}
- $actionformtext = $this->output->render($gradingactions);
- $o .= $this->output->render(new assign_header($this->get_instance(),
+ $actionformtext = $this->get_output()->render($gradingactions);
+ $o .= $this->get_output()->render(new assign_header($this->get_instance(),
$this->get_context(), false, $this->get_course_module()->id, get_string('grading', 'assign'), $actionformtext));
$o .= groups_print_activity_menu($this->get_course_module(), $CFG->wwwroot . '/mod/assign/view.php?id=' . $this->get_course_module()->id.'&action=grading', true);
// load and print the table of submissions
if ($showquickgrading && $quickgrading) {
- $table = $this->output->render(new assign_grading_table($this, $perpage, $filter, 0, true));
+ $table = $this->get_output()->render(new assign_grading_table($this, $perpage, $filter, 0, true));
$quickgradingform = new mod_assign_quick_grading_form(null,
array('cm'=>$this->get_course_module()->id,
'gradingtable'=>$table));
- $o .= $this->output->render(new assign_form('quickgradingform', $quickgradingform));
+ $o .= $this->get_output()->render(new assign_form('quickgradingform', $quickgradingform));
} else {
- $o .= $this->output->render(new assign_grading_table($this, $perpage, $filter, 0, false));
+ $o .= $this->get_output()->render(new assign_grading_table($this, $perpage, $filter, 0, false));
}
$currentgroup = groups_get_activity_group($this->get_course_module(), true);
$users = array_keys($this->list_participants($currentgroup, true));
if (count($users) != 0) {
// if no enrolled user in a course then don't display the batch operations feature
- $o .= $this->output->render(new assign_form('gradingbatchoperationsform', $gradingbatchoperationsform));
+ $o .= $this->get_output()->render(new assign_form('gradingbatchoperationsform', $gradingbatchoperationsform));
}
- $o .= $this->output->render(new assign_form('gradingoptionsform', $gradingoptionsform, 'M.mod_assign.init_grading_options'));
+ $o .= $this->get_output()->render(new assign_form('gradingoptionsform', $gradingoptionsform, 'M.mod_assign.init_grading_options'));
return $o;
}
@@ -2254,13 +2266,13 @@ class assign {
// Need submit permission to submit an assignment
require_capability('mod/assign:submit', $this->context);
- $o .= $this->output->render(new assign_header($this->get_instance(),
+ $o .= $this->get_output()->render(new assign_header($this->get_instance(),
$this->get_context(),
$this->show_intro(),
$this->get_course_module()->id,
get_string('editsubmission', 'assign')));
- $o .= $this->output->notification(get_string('submissionsclosed', 'assign'));
+ $o .= $this->get_output()->notification(get_string('submissionsclosed', 'assign'));
$o .= $this->view_footer();
@@ -2286,7 +2298,7 @@ class assign {
if (!$this->submissions_open()) {
return $this->view_student_error_message();
}
- $o .= $this->output->render(new assign_header($this->get_instance(),
+ $o .= $this->get_output()->render(new assign_header($this->get_instance(),
$this->get_context(),
$this->show_intro(),
$this->get_course_module()->id,
@@ -2298,7 +2310,7 @@ class assign {
$mform = new mod_assign_submission_form(null, array($this, $data));
}
- $o .= $this->output->render(new assign_form('editsubmissionform',$mform));
+ $o .= $this->get_output()->render(new assign_form('editsubmissionform',$mform));
$o .= $this->view_footer();
$this->add_to_log('view submit assignment form', get_string('viewownsubmissionform', 'assign'));
@@ -2419,8 +2431,8 @@ class assign {
$data));
}
$o = '';
- $o .= $this->output->header();
- $o .= $this->output->render(new assign_submit_for_grading_page($notifications, $this->get_course_module()->id, $mform));
+ $o .= $this->get_output()->header();
+ $o .= $this->get_output()->render(new assign_submit_for_grading_page($notifications, $this->get_course_module()->id, $mform));
$o .= $this->view_footer();
$this->add_to_log('view confirm submit assignment form', get_string('viewownsubmissionform', 'assign'));
@@ -2473,7 +2485,7 @@ class assign {
$extensionduedate = $grade->extensionduedate;
}
$viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context());
- $o .= $this->output->render(new assign_submission_status($this->get_instance()->allowsubmissionsfromdate,
+ $o .= $this->get_output()->render(new assign_submission_status($this->get_instance()->allowsubmissionsfromdate,
$this->get_instance()->alwaysshowdescription,
$submission,
$this->get_instance()->teamsubmission,
@@ -2550,7 +2562,7 @@ class assign {
$this->get_return_action(),
$this->get_return_params());
- $o .= $this->output->render($feedbackstatus);
+ $o .= $this->get_output()->render($feedbackstatus);
}
}
@@ -2566,7 +2578,7 @@ class assign {
global $CFG, $DB, $USER, $PAGE;
$o = '';
- $o .= $this->output->render(new assign_header($this->get_instance(),
+ $o .= $this->get_output()->render(new assign_header($this->get_instance(),
$this->get_context(),
$this->show_intro(),
$this->get_course_module()->id));
@@ -2583,7 +2595,7 @@ class assign {
$this->get_course_module()->id,
$this->count_submissions_need_grading(),
$this->get_instance()->teamsubmission);
- $o .= $this->output->render($summary);
+ $o .= $this->get_output()->render($summary);
} else {
$summary = new assign_grading_summary($this->count_participants(0),
$this->get_instance()->submissiondrafts,
@@ -2595,7 +2607,7 @@ class assign {
$this->get_course_module()->id,
$this->count_submissions_need_grading(),
$this->get_instance()->teamsubmission);
- $o .= $this->output->render($summary);
+ $o .= $this->get_output()->render($summary);
}
}
$grade = $this->get_user_grade($USER->id, false);
@@ -2870,7 +2882,7 @@ class assign {
$fs = get_file_storage();
$browser = get_file_browser();
$files = $fs->get_area_files($this->get_context()->id, $component, $area , $submissionid , "timemodified", false);
- return $this->output->assign_files($this->context, $submissionid, $area, $component);
+ return $this->get_output()->assign_files($this->context, $submissionid, $area, $component);
}
@@ -3702,7 +3714,7 @@ class assign {
}
if (has_all_capabilities(array('gradereport/grader:view', 'moodle/grade:viewall'), $this->get_course_context())) {
- $gradestring = $this->output->action_link(new moodle_url('/grade/report/grader/index.php',
+ $gradestring = $this->get_output()->action_link(new moodle_url('/grade/report/grader/index.php',
array('id'=>$this->get_course()->id)),
$gradinginfo->items[0]->grades[$userid]->str_grade);
} else {