|
| 1 | +<?php |
| 2 | +// This file is part of Moodle - http://moodle.org/ |
| 3 | +// |
| 4 | +// Moodle is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// Moodle is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +/** |
| 18 | + * Newblock block caps. |
| 19 | + * |
| 20 | + * @package block_featured_courses |
| 21 | + * @copyright 2020 - CALL Learning - Laurent David <laurent@call-learning> |
| 22 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 23 | + */ |
| 24 | + |
| 25 | +defined('MOODLE_INTERNAL') || die(); |
| 26 | + |
| 27 | +/** |
| 28 | + * Class block_featured_courses |
| 29 | + * |
| 30 | + * @copyright 2020 - CALL Learning - Laurent David <laurent@call-learning> |
| 31 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 32 | + */ |
| 33 | +class block_featured_courses extends block_base { |
| 34 | + |
| 35 | + /** |
| 36 | + * Init function |
| 37 | + * |
| 38 | + * @throws coding_exception |
| 39 | + */ |
| 40 | + public function init() { |
| 41 | + $this->title = get_string('pluginname', 'block_featured_courses'); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Content for the block |
| 46 | + * |
| 47 | + * @return \stdClass|string|null |
| 48 | + * @throws coding_exception |
| 49 | + */ |
| 50 | + public function get_content() { |
| 51 | + |
| 52 | + if ($this->content !== null) { |
| 53 | + return $this->content; |
| 54 | + } |
| 55 | + |
| 56 | + if (empty($this->instance)) { |
| 57 | + $this->content = ''; |
| 58 | + return $this->content; |
| 59 | + } |
| 60 | + |
| 61 | + $this->content = new stdClass(); |
| 62 | + $this->content->items = array(); |
| 63 | + $this->content->icons = array(); |
| 64 | + $this->content->footer = ''; |
| 65 | + |
| 66 | + // User/index.php expect course context, so get one if page has module context. |
| 67 | + $currentcontext = $this->page->context->get_course_context(false); |
| 68 | + |
| 69 | + if (!empty($this->config->text)) { |
| 70 | + $this->content->text = $this->config->text; |
| 71 | + } |
| 72 | + |
| 73 | + $this->content = ''; |
| 74 | + if (empty($currentcontext)) { |
| 75 | + return $this->content; |
| 76 | + } |
| 77 | + if ($this->page->course->id == SITEID) { |
| 78 | + $this->context->text .= "site context"; |
| 79 | + } |
| 80 | + |
| 81 | + if (!empty($this->config->text)) { |
| 82 | + $this->content->text .= $this->config->text; |
| 83 | + } |
| 84 | + |
| 85 | + return $this->content; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * All applicable formats |
| 90 | + * |
| 91 | + * @return array |
| 92 | + */ |
| 93 | + public function applicable_formats() { |
| 94 | + return array('all' => true); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Multiple blocks ? |
| 99 | + * |
| 100 | + * @return bool |
| 101 | + */ |
| 102 | + public function instance_allow_multiple() { |
| 103 | + return true; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Has configuration ? |
| 108 | + * |
| 109 | + * @return bool |
| 110 | + */ |
| 111 | + public function has_config() { |
| 112 | + return true; |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Cron Job |
| 117 | + * |
| 118 | + * @return bool |
| 119 | + */ |
| 120 | + public function cron() { |
| 121 | + mtrace("Hey, my cron script is running"); |
| 122 | + |
| 123 | + // Do something. |
| 124 | + |
| 125 | + return true; |
| 126 | + } |
| 127 | +} |
0 commit comments