/** * Returns course-specific information to be output immediately above content on any course page * (for the current course) * * @param bool $onlyifnotcalledbefore output content only if it has not been output before * @return string */ public function course_content_header($onlyifnotcalledbefore = false) { global $CFG; static $functioncalled = false; if ($functioncalled && $onlyifnotcalledbefore) { // we have already output the content header return ''; } // Output any session notification. $notifications = \core\notification::fetch(); $bodynotifications = ''; foreach ($notifications as $notification) { $bodynotifications .= $this->render_from_template($notification->get_template_name(), $notification->export_for_template($this)); } $output = html_writer::span($bodynotifications, 'notifications', array('id' => 'user-notifications')); if ($this->page->course->id == SITEID) { // return immediately and do not include /course/lib.php if not necessary return $output; } require_once $CFG->dirroot . '/course/lib.php'; $functioncalled = true; $courseformat = course_get_format($this->page->course); if (($obj = $courseformat->course_content_header()) !== null) { $output .= html_writer::div($courseformat->get_renderer($this->page)->render($obj), 'course-content-header'); } return $output; }
/** * Test fetching of notifications from the session. */ public function test_fetch() { // Initially there won't be any notifications. $this->assertCount(0, \core\notification::fetch()); // Adding a notification should make one available to fetch. \core\notification::success('Notification created'); $this->assertCount(1, \core\notification::fetch()); $this->assertCount(0, \core\notification::fetch()); }