Skip to content

Commit

Permalink
MDL-36317 Execute course format callback when course or module is set…
Browse files Browse the repository at this point in the history
… on page
  • Loading branch information
marinaglancy committed Nov 2, 2012
1 parent 6109f21 commit 695705f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
18 changes: 18 additions & 0 deletions course/format/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,24 @@ public function get_default_blocks() {
);
return $blocknames;
}

/**
* Allows course format to execute code on moodle_page::set_course()
*
* @param moodle_page $page instance of page calling set_course
*/
public function page_set_course(moodle_page $page) {
}

/**
* Allows course format to execute code on moodle_page::set_cm()
*
* Current module can be accessed as $page->cm (returns instance of cm_info)
*
* @param moodle_page $page instance of page calling set_cm
*/
public function page_set_cm(moodle_page $page) {
}
}

/**
Expand Down
16 changes: 14 additions & 2 deletions lib/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ public function set_state($state) {
* @param stdClass $course the course to set as the global course.
*/
public function set_course($course) {
global $COURSE, $PAGE;
global $COURSE, $PAGE, $CFG, $SITE;

if (empty($course->id)) {
throw new coding_exception('$course passed to moodle_page::set_course does not look like a proper course object.');
Expand All @@ -867,6 +867,12 @@ public function set_course($course) {
if (!$this->_context) {
$this->set_context(context_course::instance($this->_course->id));
}

// notify course format that this page is set for the course
if ($this->_course->id != $SITE->id) {
require_once($CFG->dirroot.'/course/lib.php');
course_get_format($this->_course)->page_set_course($this);
}
}

/**
Expand Down Expand Up @@ -911,7 +917,7 @@ public function set_context($context) {
* @return void
*/
public function set_cm($cm, $course = null, $module = null) {
global $DB;
global $DB, $CFG, $SITE;

if (!isset($cm->id) || !isset($cm->course)) {
throw new coding_exception('Invalid $cm parameter for $PAGE object, it has to be instance of cm_info or record from the course_modules table.');
Expand Down Expand Up @@ -943,6 +949,12 @@ public function set_cm($cm, $course = null, $module = null) {
if ($module) {
$this->set_activity_record($module);
}

// notify course format that this page is set for the course module
if ($this->_course->id != $SITE->id) {
require_once($CFG->dirroot.'/course/lib.php');
course_get_format($this->_course)->page_set_cm($this);
}
}

/**
Expand Down

0 comments on commit 695705f

Please sign in to comment.