Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
use block_featured_courses\output\featured_courses;
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
     * Update the block title from config values
46
     */
47
    public function specialization() {
48
        if (!empty($this->config->title)) {
49
            $this->title = $this->config->title;
50
        }
51
    }
52
 
53
    /**
54
     * Content for the block
55
     *
56
     * @return stdClass|string|null
57
     * @throws coding_exception
58
     * @throws dml_exception
59
     */
60
    public function get_content() {
61
 
62
        if ($this->content !== null) {
63
            return $this->content;
64
        }
65
 
66
        if (empty($this->instance)) {
67
            $this->content = '';
68
            return $this->content;
69
        }
70
        $this->content = '';
71
 
72
        if ($this->config && !empty($this->config->selectedcourses)) {
73
            $this->content = new stdClass();
74
            $this->content->footer = '';
75
            $renderer = $this->page->get_renderer('core');
76
            $this->content->text = $renderer->render(
77
                new featured_courses(
78
                    $this->config->selectedcourses
79
                ));
80
        }
81
        return $this->content;
82
    }
83
 
84
    /**
85
     * All applicable formats
86
     *
87
     * @return array
88
     */
89
    public function applicable_formats(): array {
90
        return array('all' => true);
91
    }
92
 
93
    /**
94
     * Multiple blocks ?
95
     *
96
     * @return bool
97
     */
98
    public function instance_allow_multiple(): bool {
99
        return true;
100
    }
101
 
102
    /**
103
     * Has configuration ?
104
     *
105
     * @return bool
106
     */
107
    public function has_config(): bool {
108
        return false;
109
    }
110
}