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 |
* Course summary exporter with a specific purpose.
|
|
|
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 |
namespace block_featured_courses;
|
|
|
26 |
|
|
|
27 |
use core_course\external\course_summary_exporter;
|
|
|
28 |
use core_course_category;
|
|
|
29 |
use moodle_exception;
|
|
|
30 |
use moodle_url;
|
|
|
31 |
use renderer_base;
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Class mini_course_summary_exporter
|
|
|
35 |
*
|
|
|
36 |
* @package block_featured_courses
|
|
|
37 |
* @copyright 2020 - CALL Learning - Laurent David <laurent@call-learning>
|
|
|
38 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
39 |
*
|
|
|
40 |
*/
|
|
|
41 |
class mini_course_summary_exporter extends course_summary_exporter {
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Only a subset of the usual.
|
|
|
45 |
*
|
|
|
46 |
* @return array|array[]
|
|
|
47 |
*/
|
|
|
48 |
public static function define_other_properties(): array {
|
|
|
49 |
return array(
|
|
|
50 |
'fullnamedisplay' => array(
|
|
|
51 |
'type' => PARAM_TEXT,
|
|
|
52 |
),
|
|
|
53 |
'viewurl' => array(
|
|
|
54 |
'type' => PARAM_URL,
|
|
|
55 |
),
|
|
|
56 |
'courseimage' => array(
|
|
|
57 |
'type' => PARAM_RAW,
|
|
|
58 |
),
|
|
|
59 |
'showshortname' => array(
|
|
|
60 |
'type' => PARAM_BOOL
|
|
|
61 |
),
|
|
|
62 |
'coursecategory' => array(
|
|
|
63 |
'type' => PARAM_TEXT
|
|
|
64 |
)
|
|
|
65 |
);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* Define related variables
|
|
|
70 |
*
|
|
|
71 |
* @return string[]
|
|
|
72 |
*/
|
|
|
73 |
protected static function define_related(): array {
|
|
|
74 |
// We cache the context so it does not need to be retrieved from the course.
|
|
|
75 |
return array('context' => '\\context');
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Get other useful values
|
|
|
80 |
*
|
|
|
81 |
* @param renderer_base $output
|
|
|
82 |
* @return array
|
|
|
83 |
* @throws moodle_exception
|
|
|
84 |
*/
|
|
|
85 |
protected function get_other_values(renderer_base $output): array {
|
|
|
86 |
global $CFG;
|
|
|
87 |
$courseimage = self::get_course_image($this->data);
|
|
|
88 |
if (!$courseimage) {
|
|
|
89 |
$courseimage = $output->get_generated_image_for_id($this->data->id);
|
|
|
90 |
}
|
|
|
91 |
$coursecategory = core_course_category::get($this->data->category, MUST_EXIST, true);
|
|
|
92 |
$urlparam = array('id' => $this->data->id);
|
|
|
93 |
$courseurl = new moodle_url('/course/view.php', $urlparam);
|
|
|
94 |
if (!empty($CFG->enablesyllabus) && class_exists('\\local_syllabus\\locallib\utils')) {
|
|
|
95 |
$courseurl = \local_syllabus\locallib\utils::get_syllabus_page_url($urlparam);
|
|
|
96 |
}
|
|
|
97 |
return array(
|
|
|
98 |
'fullnamedisplay' => get_course_display_name_for_list($this->data),
|
|
|
99 |
'viewurl' => $courseurl->out(false),
|
|
|
100 |
'courseimage' => $courseimage,
|
|
|
101 |
'showshortname' => (bool) ($CFG->courselistshortnames ?? false),
|
|
|
102 |
'coursecategory' => $coursecategory->name
|
|
|
103 |
);
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
}
|