15
15
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
16
17
17
/**
18
- * Thumblinks Action block renderable.
18
+ * Featured courses renderable
19
19
*
20
- * @package block_thumblinks_action
20
+ * @package block_featured_courses
21
21
* @copyright 2020 - CALL Learning - Laurent David <laurent@call-learning>
22
22
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
23
*/
24
24
25
25
namespace block_featured_courses \output ;
26
- global $ CFG ;
27
-
28
26
defined ('MOODLE_INTERNAL ' ) || die ();
29
27
28
+ use block_featured_courses \mini_course_summary_exporter ;
30
29
use context_course ;
31
30
use context_helper ;
32
- use core_course \external \course_summary_exporter ;
33
- use moodle_url ;
34
31
use renderable ;
35
32
use renderer_base ;
36
33
use templatable ;
37
34
38
- class mini_course_summary_exporter extends course_summary_exporter {
39
-
40
- /**
41
- * Only a subset of the usual.
42
- *
43
- * @return array|array[]
44
- */
45
- public static function define_other_properties () {
46
- return array (
47
- 'fullnamedisplay ' => array (
48
- 'type ' => PARAM_TEXT ,
49
- ),
50
- 'viewurl ' => array (
51
- 'type ' => PARAM_URL ,
52
- ),
53
- 'courseimage ' => array (
54
- 'type ' => PARAM_RAW ,
55
- ),
56
- 'showshortname ' => array (
57
- 'type ' => PARAM_BOOL
58
- ),
59
- 'coursecategory ' => array (
60
- 'type ' => PARAM_TEXT
61
- )
62
- );
63
- }
64
-
65
- /**
66
- * Constructor - saves the persistent object, and the related objects.
67
- *
68
- * @param mixed $data - Either an stdClass or an array of values.
69
- * @param array $related - An optional list of pre-loaded objects related to this object.
70
- */
71
- public function __construct ($ data , $ related = array ()) {
72
- \core \external \exporter::__construct ($ data , $ related );
73
- }
74
-
75
- protected static function define_related () {
76
- // We cache the context so it does not need to be retrieved from the course.
77
- return array ('context ' => '\\context ' );
78
- }
79
-
80
- protected function get_other_values (renderer_base $ output ) {
81
- global $ CFG ;
82
- $ courseimage = self ::get_course_image ($ this ->data );
83
- if (!$ courseimage ) {
84
- $ courseimage = $ output ->get_generated_image_for_id ($ this ->data ->id );
85
- }
86
- $ coursecategory = \core_course_category::get ($ this ->data ->category , MUST_EXIST , true );
87
- $ urlparam = array ('id ' => $ this ->data ->id );
88
- $ courseurl = new moodle_url ('/course/view.php ' , $ urlparam );
89
- if (class_exists ('\\local_syllabus \\locallib\utils ' )) {
90
- $ courseurl = \local_syllabus \locallib \utils::get_syllabus_page_url ($ urlparam );
91
- }
92
- return array (
93
- 'fullnamedisplay ' => get_course_display_name_for_list ($ this ->data ),
94
- 'viewurl ' => $ courseurl ->out (false ),
95
- 'courseimage ' => $ courseimage ,
96
- 'showshortname ' => $ CFG ->courselistshortnames ? true : false ,
97
- 'coursecategory ' => $ coursecategory ->name
98
- );
99
- }
100
-
101
- }
102
-
103
35
/**
104
36
* Class containing data for featured_courses block.
105
37
*
106
- * @package block_mcms
38
+ * @package block_featured_courses
107
39
* @copyright 2020 - CALL Learning - Laurent David <laurent@call-learning>
108
40
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
109
41
*/
@@ -118,7 +50,7 @@ class featured_courses implements renderable, templatable {
118
50
* featured_courses constructor.
119
51
* Retrieve matchin courses
120
52
*
121
- * @param $coursesid
53
+ * @param int $coursesid
122
54
* @throws \coding_exception
123
55
* @throws \dml_exception
124
56
*/
@@ -128,6 +60,13 @@ public function __construct($coursesid) {
128
60
$ this ->courses = $ DB ->get_records_select ('course ' , 'id ' . $ sql , $ params );
129
61
}
130
62
63
+ /**
64
+ * Export the renderable for template
65
+ *
66
+ * @param renderer_base $renderer
67
+ * @return array
68
+ * @throws \coding_exception
69
+ */
131
70
public function export_for_template (renderer_base $ renderer ) {
132
71
$ formattedcourses = array_map (function ($ course ) use ($ renderer ) {
133
72
context_helper::preload_from_record ($ course );
0 commit comments