|
| 1 | +<?php |
| 2 | + |
| 3 | +defined('MOODLE_INTERNAL') || die(); |
| 4 | + |
| 5 | +class block_kalturamediagallery extends block_base { |
| 6 | + function init() { |
| 7 | + $this->title = get_string('pluginname', 'local_kalturamediagallery'); |
| 8 | + } |
| 9 | + |
| 10 | + function get_content() { |
| 11 | + if(!is_null($this->content)) { |
| 12 | + return $this->content; |
| 13 | + } |
| 14 | + |
| 15 | + $this->content = new stdClass(); |
| 16 | + $this->content->text = ''; |
| 17 | + $this->content->footer = ''; |
| 18 | + |
| 19 | + if($context = $this->getCourseContext()) { |
| 20 | + $this->content->text = $this->getKalturaMediaGalleryLink($context->instanceid); |
| 21 | + } |
| 22 | + |
| 23 | + return $this->content; |
| 24 | + } |
| 25 | + |
| 26 | + function applicable_formats() |
| 27 | + { |
| 28 | + return array( |
| 29 | + 'course-view' => true |
| 30 | + ); |
| 31 | + } |
| 32 | + |
| 33 | + private function getKalturaMediaGalleryLink($courseId) { |
| 34 | + $mediaGalleryUrl = new moodle_url('/local/kalturamediagallery/index.php', array( |
| 35 | + 'courseid' => $courseId |
| 36 | + )); |
| 37 | + |
| 38 | + $link = html_writer::tag('a', get_string('nav_mediagallery', 'local_kalturamediagallery'), array( |
| 39 | + 'href' => $mediaGalleryUrl->out(false) |
| 40 | + )); |
| 41 | + |
| 42 | + return $link; |
| 43 | + } |
| 44 | + |
| 45 | + private function getCourseContext() { |
| 46 | + // Check the current page context. If the context is not of a course or module then return false. |
| 47 | + $context = context::instance_by_id($this->page->context->id); |
| 48 | + $isCourseContext = $context instanceof context_course; |
| 49 | + if (!$isCourseContext) { |
| 50 | + return false; |
| 51 | + } |
| 52 | + |
| 53 | + // If the context if a module then get the parent context. |
| 54 | + $courseContext = ($context instanceof context_module) ? $context->get_course_context() : $context; |
| 55 | + |
| 56 | + return $courseContext; |
| 57 | + } |
| 58 | +} |
0 commit comments