From 3584d60abedc259496a35e54ef9cbb1136b07694 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Thu, 15 Nov 2012 15:00:48 +0800 Subject: [PATCH] MDL-28583 Redirect in Scorm course format before output --- course/format/scorm/lib.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/course/format/scorm/lib.php b/course/format/scorm/lib.php index 0bb518d80c1..60e9a2648f8 100644 --- a/course/format/scorm/lib.php +++ b/course/format/scorm/lib.php @@ -74,4 +74,28 @@ class format_scorm extends format_base { BLOCK_POS_RIGHT => array('news_items', 'recent_activity', 'calendar_upcoming') ); } + + /** + * Allows course format to execute code on moodle_page::set_course() + * + * If user is on course view page and there is no scorm module added to the course + * and the user has 'moodle/course:update' capability, redirect to create module + * form. This function is executed before the output starts + * + * @param moodle_page $page instance of page calling set_course + */ + public function page_set_course(moodle_page $page) { + global $PAGE; + if ($PAGE == $page && $page->has_set_url() && + $page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) { + $modinfo = get_fast_modinfo($this->courseid); + if (empty($modinfo->instances['scorm']) + && has_capability('moodle/course:update', context_course::instance($this->courseid))) { + // Redirect to create a new activity + $url = new moodle_url('/course/modedit.php', + array('course' => $this->courseid, 'section' => 0, 'add' => 'scorm')); + redirect($url); + } + } + } } -- 2.43.0