diff --git a/mod/assign/lib.php b/mod/assign/lib.php index 71daf6af1da..80f3d49951c 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 05a73fa1464..277b05beaf1 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'); } /** @@ -308,15 +307,6 @@ class assign { return $result; } - /** - * Expose the renderer to plugins - * - * @return assign_renderer - */ - public function get_renderer() { - return $this->output; - } - /** * Display the assignment, used by view.php * @@ -1431,7 +1421,7 @@ class assign { } else { $data->batchusers = $batchusers; } - $o .= $this->output->render(new assign_header($this->get_instance(), + $o .= $this->get_renderer()->render(new assign_header($this->get_instance(), $this->get_context(), $this->show_intro(), $this->get_course_module()->id, @@ -1444,7 +1434,7 @@ class assign { $this->get_instance(), $data)); } - $o .= $this->output->render(new assign_form('extensionform', $mform)); + $o .= $this->get_renderer()->render(new assign_form('extensionform', $mform)); $o .= $this->view_footer(); return $o; } @@ -1644,12 +1634,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_renderer()->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_renderer()->render(new assign_submission_plugin_submission($plugin, $item, assign_submission_plugin_submission::FULL, $this->get_course_module()->id, @@ -1667,12 +1657,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_renderer()->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_renderer()->render(new assign_feedback_plugin_feedback($plugin, $item, assign_feedback_plugin_feedback::FULL, $this->get_course_module()->id, @@ -1738,12 +1728,12 @@ class assign { */ private function view_quickgrading_result($message) { $o = ''; - $o .= $this->output->render(new assign_header($this->get_instance(), + $o .= $this->get_renderer()->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_renderer()->render(new assign_quickgrading_result($message, $this->get_course_module()->id)); $o .= $this->view_footer(); return $o; } @@ -1754,7 +1744,7 @@ class assign { * @return string */ private function view_footer() { - return $this->output->render_footer(); + return $this->get_renderer()->render_footer(); } /** @@ -1869,6 +1859,20 @@ class assign { add_to_log($this->get_course()->id, 'assign', $action, $fullurl, $info, $this->get_course_module()->id, $USER->id); } + /** + * Lazy load the page renderer and expose the renderer to plugins + * + * @return assign_renderer + */ + private function get_renderer() { + 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 * @@ -1990,7 +1994,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_renderer()->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; @@ -2014,7 +2018,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_renderer()->render(new assign_user_summary($user, $this->get_course()->id, has_capability('moodle/site:viewfullnames', $this->get_course_context()), @@ -2054,7 +2058,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_renderer()->render(new assign_submission_status($this->get_instance()->allowsubmissionsfromdate, $this->get_instance()->alwaysshowdescription, $submission, $this->get_instance()->teamsubmission, @@ -2100,7 +2104,7 @@ class assign { '', array('class'=>'gradeform')); } - $o .= $this->output->render(new assign_form('gradingform',$mform)); + $o .= $this->get_renderer()->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); @@ -2120,7 +2124,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_renderer()->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, @@ -2130,7 +2134,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_renderer()->confirm(get_string('revealidentitiesconfirm', 'assign'), $confirmurl, $cancelurl); $o .= $this->view_footer(); $this->add_to_log('view', get_string('viewrevealidentitiesconfirm', 'assign')); return $o; @@ -2153,7 +2157,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_renderer()->single_button(new moodle_url('/mod/assign/view.php', $params), get_string('back'), 'get'); } @@ -2235,8 +2239,8 @@ class assign { $gradingoptionsdata->filter = $filter; $gradingoptionsform->set_data($gradingoptionsdata); - $actionformtext = $this->output->render($gradingactions); - $o .= $this->output->render(new assign_header($this->get_instance(), + $actionformtext = $this->get_renderer()->render($gradingactions); + $o .= $this->get_renderer()->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); @@ -2249,22 +2253,22 @@ class assign { // 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_renderer()->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_renderer()->render(new assign_form('quickgradingform', $quickgradingform)); } else { - $o .= $this->output->render(new assign_grading_table($this, $perpage, $filter, 0, false)); + $o .= $this->get_renderer()->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_renderer()->render(new assign_form('gradingbatchoperationsform', $gradingbatchoperationsform)); } - $o .= $this->output->render(new assign_form('gradingoptionsform', $gradingoptionsform, 'M.mod_assign.init_grading_options')); + $o .= $this->get_renderer()->render(new assign_form('gradingoptionsform', $gradingoptionsform, 'M.mod_assign.init_grading_options')); return $o; } @@ -2321,13 +2325,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_renderer()->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_renderer()->notification(get_string('submissionsclosed', 'assign')); $o .= $this->view_footer(); @@ -2353,7 +2357,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_renderer()->render(new assign_header($this->get_instance(), $this->get_context(), $this->show_intro(), $this->get_course_module()->id, @@ -2365,7 +2369,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_renderer()->render(new assign_form('editsubmissionform',$mform)); $o .= $this->view_footer(); $this->add_to_log('view submit assignment form', get_string('viewownsubmissionform', 'assign')); @@ -2526,8 +2530,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_renderer()->header(); + $o .= $this->get_renderer()->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')); @@ -2589,7 +2593,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_renderer()->render(new assign_submission_status($this->get_instance()->allowsubmissionsfromdate, $this->get_instance()->alwaysshowdescription, $submission, $this->get_instance()->teamsubmission, @@ -2668,7 +2672,7 @@ class assign { $this->get_return_action(), $this->get_return_params()); - $o .= $this->output->render($feedbackstatus); + $o .= $this->get_renderer()->render($feedbackstatus); } } @@ -2684,7 +2688,7 @@ class assign { global $CFG, $DB, $USER, $PAGE; $o = ''; - $o .= $this->output->render(new assign_header($this->get_instance(), + $o .= $this->get_renderer()->render(new assign_header($this->get_instance(), $this->get_context(), $this->show_intro(), $this->get_course_module()->id)); @@ -2701,7 +2705,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_renderer()->render($summary); } else { $summary = new assign_grading_summary($this->count_participants(0), $this->get_instance()->submissiondrafts, @@ -2713,7 +2717,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_renderer()->render($summary); } } $grade = $this->get_user_grade($USER->id, false); @@ -2988,7 +2992,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_renderer()->assign_files($this->context, $submissionid, $area, $component); } @@ -3829,7 +3833,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_renderer()->action_link(new moodle_url('/grade/report/grader/index.php', array('id'=>$this->get_course()->id)), $gradinginfo->items[0]->grades[$userid]->str_grade); } else {