From 90636e2b4163aec22c8888b0881f908af159b867 Mon Sep 17 00:00:00 2001 From: Penny Leach Date: Fri, 17 Sep 2010 09:39:56 +0000 Subject: [PATCH] portfolio MDL-24251 make sure $PAGE context is set up properly --- lib/portfolio/caller.php | 14 ++++++++++++++ lib/portfoliolib.php | 12 +++--------- lib/simpletest/portfolio_testclass.php | 3 +++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/portfolio/caller.php b/lib/portfolio/caller.php index 259fb537a9f..4cabcd1d627 100644 --- a/lib/portfolio/caller.php +++ b/lib/portfolio/caller.php @@ -477,6 +477,13 @@ abstract class portfolio_caller_base { */ public static abstract function expected_callbackargs(); + + /** + * return the context for this export. used for $PAGE->set_context + * + * @return stdclass + */ + public abstract function set_context($PAGE); } /** @@ -551,4 +558,11 @@ abstract class portfolio_module_caller_base extends portfolio_caller_base { public function heading_summary() { return get_string('exportingcontentfrom', 'portfolio', $this->display_name() . ': ' . $this->cm->name); } + + /** + * overridden to return the course module context + */ + public function set_context($PAGE) { + $PAGE->set_cm($this->cm); + } } diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php index 00b23d39535..7409fca53bf 100644 --- a/lib/portfoliolib.php +++ b/lib/portfoliolib.php @@ -1119,19 +1119,13 @@ function portfolio_insane_notify_admins($insane, $instances=false) { } function portfolio_export_pagesetup($PAGE, $caller) { - // for build navigation - if (!$course = $caller->get('course')) { - $course = $courseid; - } - - // set up the course so that build_navigation works nice - $PAGE->set_course($course); + // set up the context so that build_navigation works nice + $caller->set_context($PAGE); list($extranav, $cm) = $caller->get_navigation(); // and now we know the course for sure and maybe the cm, call require_login with it - // todo this will have to change when we have things exporting content outside the course context (eg blogs) - require_login($course, false, $cm); + require_login($PAGE->course, false, $cm); foreach ($extranav as $navitem) { $PAGE->navbar->add($navitem['name']); diff --git a/lib/simpletest/portfolio_testclass.php b/lib/simpletest/portfolio_testclass.php index 8e1cddc94b6..4135c182c54 100644 --- a/lib/simpletest/portfolio_testclass.php +++ b/lib/simpletest/portfolio_testclass.php @@ -108,6 +108,9 @@ class portfolio_caller_test extends portfolio_caller_base { public static function base_supported_formats() { return array(PORTFOLIO_FORMAT_RICH, PORTFOLIO_FORMAT_FILE); } + public function set_context($PAGE) { + $PAGE->set_context(get_system_context()); + } } class portfolio_exporter_test extends portfolio_exporter {