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 renderer.
|
|
|
19 |
*
|
|
|
20 |
* @package theme_universe
|
|
|
21 |
* @copyright 2023 Marcin Czaja (https://rosea.io)
|
|
|
22 |
* @license Commercial https://themeforest.net/licenses
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
namespace theme_universe\output\core;
|
|
|
26 |
|
|
|
27 |
use moodle_url;
|
|
|
28 |
use html_writer;
|
|
|
29 |
use core_course_category;
|
|
|
30 |
use coursecat_helper;
|
|
|
31 |
use stdClass;
|
|
|
32 |
use core_course_list_element;
|
|
|
33 |
use lang_string;
|
|
|
34 |
use theme_universe\util\course;
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* @package theme_universe
|
|
|
38 |
* @copyright 2023 Marcin Czaja - Rosea Themes - rosea.io
|
|
|
39 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
40 |
*/
|
1441 |
ariadna |
41 |
class course_renderer extends \core_course_renderer {
|
1 |
efrain |
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Renders html to display a course search form
|
|
|
45 |
*
|
|
|
46 |
* @param string $value default value to populate the search field
|
|
|
47 |
* @return string
|
|
|
48 |
*/
|
1441 |
ariadna |
49 |
public function course_search_form($value = '') {
|
1 |
efrain |
50 |
|
|
|
51 |
$data = [
|
|
|
52 |
'action' => \core_search\manager::get_course_search_url(),
|
|
|
53 |
'btnclass' => 'btn-primary',
|
|
|
54 |
'inputname' => 'q',
|
|
|
55 |
'searchstring' => get_string('searchcourses'),
|
|
|
56 |
'hiddenfields' => (object) ['name' => 'areaids', 'value' => 'core_course-course'],
|
|
|
57 |
'query' => $value
|
|
|
58 |
];
|
|
|
59 |
|
|
|
60 |
return $this->render_from_template('core/search_input_fw', $data);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* Renders the list of courses
|
|
|
65 |
*
|
|
|
66 |
* This is internal function, please use core_course_renderer::courses_list() or another public
|
|
|
67 |
* method from outside of the class
|
|
|
68 |
*
|
|
|
69 |
* If list of courses is specified in $courses; the argument $chelper is only used
|
|
|
70 |
* to retrieve display options and attributes, only methods get_show_courses(),
|
|
|
71 |
* get_courses_display_option() and get_and_erase_attributes() are called.
|
|
|
72 |
*
|
|
|
73 |
* @param coursecat_helper $chelper various display options
|
|
|
74 |
* @param array $courses the list of courses to display
|
|
|
75 |
* @param int|null $totalcount total number of courses (affects display mode if it is AUTO or pagination if applicable),
|
|
|
76 |
* defaulted to count($courses)
|
|
|
77 |
* @return string
|
|
|
78 |
*
|
|
|
79 |
* @throws \coding_exception
|
|
|
80 |
* @throws \dml_exception
|
|
|
81 |
* @throws \moodle_exception
|
|
|
82 |
*/
|
1441 |
ariadna |
83 |
protected function coursecat_courses(coursecat_helper $chelper, $courses, $totalcount = null) {
|
|
|
84 |
global $CFG;
|
1 |
efrain |
85 |
|
|
|
86 |
|
|
|
87 |
if ($totalcount === null) {
|
|
|
88 |
$totalcount = count($courses);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
if (!$totalcount) {
|
|
|
92 |
// Courses count is cached during courses retrieval.
|
|
|
93 |
return '';
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO) {
|
|
|
97 |
// In 'auto' course display mode we analyse if number of courses is more or less than $CFG->courseswithsummarieslimit.
|
|
|
98 |
if ($totalcount <= $CFG->courseswithsummarieslimit) {
|
|
|
99 |
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED);
|
|
|
100 |
} else {
|
|
|
101 |
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED);
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
// Prepare content of paging bar if it is needed.
|
|
|
106 |
$paginationurl = $chelper->get_courses_display_option('paginationurl');
|
|
|
107 |
$paginationallowall = $chelper->get_courses_display_option('paginationallowall');
|
|
|
108 |
if ($totalcount > count($courses)) {
|
|
|
109 |
// There are more results that can fit on one page.
|
|
|
110 |
if ($paginationurl) {
|
|
|
111 |
// The option paginationurl was specified, display pagingbar.
|
|
|
112 |
$perpage = $chelper->get_courses_display_option('limit', $CFG->coursesperpage);
|
|
|
113 |
$page = $chelper->get_courses_display_option('offset') / $perpage;
|
|
|
114 |
$pagingbar = $this->paging_bar(
|
|
|
115 |
$totalcount,
|
|
|
116 |
$page,
|
|
|
117 |
$perpage,
|
|
|
118 |
$paginationurl->out(false, array('perpage' => $perpage))
|
|
|
119 |
);
|
|
|
120 |
if ($paginationallowall) {
|
|
|
121 |
$pagingbar .= html_writer::tag('div', html_writer::link(
|
|
|
122 |
$paginationurl->out(false, array('perpage' => 'all')),
|
|
|
123 |
get_string('showall', '', $totalcount)
|
|
|
124 |
), array('class' => 'paging paging-showall'));
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
} else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) {
|
|
|
128 |
// There are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode.
|
|
|
129 |
$pagingbar = html_writer::tag(
|
|
|
130 |
'div',
|
|
|
131 |
html_writer::link(
|
|
|
132 |
$paginationurl->out(
|
|
|
133 |
false,
|
|
|
134 |
array('perpage' => $CFG->coursesperpage)
|
|
|
135 |
),
|
|
|
136 |
get_string('showperpage', '', $CFG->coursesperpage)
|
|
|
137 |
),
|
|
|
138 |
array('class' => 'paging paging-showperpage')
|
|
|
139 |
);
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
// Display list of courses.
|
|
|
143 |
$attributes = $chelper->get_and_erase_attributes('courses');
|
|
|
144 |
$content = html_writer::start_tag('div', $attributes);
|
|
|
145 |
|
|
|
146 |
if (!empty($pagingbar)) {
|
|
|
147 |
$content .= $pagingbar;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
$coursecount = 1;
|
|
|
151 |
|
1441 |
ariadna |
152 |
$content .= html_writer::start_tag('div', array('class' => 'rui-course-card-deck mt-2'));
|
1 |
efrain |
153 |
|
|
|
154 |
foreach ($courses as $course) {
|
|
|
155 |
$content .= $this->coursecat_coursebox($chelper, $course);
|
|
|
156 |
|
|
|
157 |
$coursecount++;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
$content .= html_writer::end_tag('div');
|
|
|
161 |
|
|
|
162 |
if (!empty($pagingbar)) {
|
|
|
163 |
$content .= $pagingbar;
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
if (!empty($morelink)) {
|
|
|
167 |
$content .= $morelink;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
$content .= html_writer::end_tag('div'); // End courses.
|
|
|
171 |
|
|
|
172 |
return $content;
|
|
|
173 |
}
|
|
|
174 |
|
1441 |
ariadna |
175 |
protected function coursecat_subcategories(coursecat_helper $chelper, $coursecat, $depth) {
|
1 |
efrain |
176 |
global $CFG;
|
1441 |
ariadna |
177 |
$subcategories = [];
|
1 |
efrain |
178 |
if (!$chelper->get_categories_display_option('nodisplay')) {
|
|
|
179 |
$subcategories = $coursecat->get_children($chelper->get_categories_display_options());
|
|
|
180 |
}
|
|
|
181 |
$totalcount = $coursecat->get_children_count();
|
|
|
182 |
if (!$totalcount) {
|
|
|
183 |
// Note that we call core_course_category::get_children_count() AFTER core_course_category::get_children().
|
|
|
184 |
// To avoid extra DB requests.
|
|
|
185 |
// Categories count is cached during children categories retrieval.
|
|
|
186 |
return '';
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
// Prepare content of paging bar or more link if it is needed.
|
|
|
190 |
$paginationurl = $chelper->get_categories_display_option('paginationurl');
|
|
|
191 |
$paginationallowall = $chelper->get_categories_display_option('paginationallowall');
|
|
|
192 |
if ($totalcount > count($subcategories)) {
|
|
|
193 |
if ($paginationurl) {
|
|
|
194 |
// The option 'paginationurl was specified, display pagingbar.
|
|
|
195 |
$perpage = $chelper->get_categories_display_option('limit', $CFG->coursesperpage);
|
|
|
196 |
$page = $chelper->get_categories_display_option('offset') / $perpage;
|
|
|
197 |
$pagingbar = $this->paging_bar(
|
|
|
198 |
$totalcount,
|
|
|
199 |
$page,
|
|
|
200 |
$perpage,
|
|
|
201 |
$paginationurl->out(false, array('perpage' => $perpage))
|
|
|
202 |
);
|
|
|
203 |
if ($paginationallowall) {
|
|
|
204 |
$pagingbar .= html_writer::tag('div', html_writer::link(
|
|
|
205 |
$paginationurl->out(false, array('perpage' => 'all')),
|
|
|
206 |
get_string('showall', '', $totalcount)
|
1441 |
ariadna |
207 |
), ['class' => 'paging paging-showall']);
|
1 |
efrain |
208 |
}
|
|
|
209 |
} else if ($viewmoreurl = $chelper->get_categories_display_option('viewmoreurl')) {
|
|
|
210 |
// The option 'viewmoreurl' was specified, display more link (if it is link to category view page, add category id).
|
|
|
211 |
if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) {
|
|
|
212 |
$viewmoreurl->param('categoryid', $coursecat->id);
|
|
|
213 |
}
|
|
|
214 |
$viewmoretext = $chelper->get_categories_display_option('viewmoretext', new lang_string('viewmore'));
|
|
|
215 |
$morelink = html_writer::tag(
|
|
|
216 |
'div',
|
|
|
217 |
html_writer::link($viewmoreurl, $viewmoretext, array('class' => 'btn btn-secondary w-100')),
|
|
|
218 |
array('class' => 'paging paging-morelink wrapper-fw')
|
|
|
219 |
);
|
|
|
220 |
}
|
|
|
221 |
} else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) {
|
|
|
222 |
// There are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode.
|
|
|
223 |
$pagingbar = html_writer::tag('div', html_writer::link(
|
|
|
224 |
$paginationurl->out(false, array('perpage' => $CFG->coursesperpage)),
|
|
|
225 |
get_string('showperpage', '', $CFG->coursesperpage)
|
|
|
226 |
), array('class' => 'paging paging-showperpage'));
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
// Display list of subcategories.
|
|
|
230 |
$content = html_writer::start_tag('div', array('class' => 'subcategories'));
|
|
|
231 |
|
|
|
232 |
if (!empty($pagingbar)) {
|
|
|
233 |
$content .= $pagingbar;
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
foreach ($subcategories as $subcategory) {
|
|
|
237 |
$content .= $this->coursecat_category($chelper, $subcategory, $depth);
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
if (!empty($pagingbar)) {
|
|
|
241 |
$content .= $pagingbar;
|
|
|
242 |
}
|
|
|
243 |
if (!empty($morelink)) {
|
|
|
244 |
$content .= $morelink;
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
$content .= html_writer::end_tag('div');
|
|
|
248 |
return $content;
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
/**
|
|
|
252 |
* Returns HTML to display course content (summary, course contacts and optionally category name)
|
|
|
253 |
*
|
|
|
254 |
* This method is called from coursecat_coursebox() and may be re-used in AJAX
|
|
|
255 |
*
|
|
|
256 |
* @param coursecat_helper $chelper various display options
|
|
|
257 |
* @param stdClass|core_course_list_element $course
|
|
|
258 |
*
|
|
|
259 |
* @return string
|
|
|
260 |
*
|
|
|
261 |
* @throws \coding_exception
|
|
|
262 |
* @throws \dml_exception
|
|
|
263 |
* @throws \moodle_exception
|
|
|
264 |
*/
|
1441 |
ariadna |
265 |
protected function coursecat_coursebox_content(coursecat_helper $chelper, $course) {
|
1 |
efrain |
266 |
$theme = \theme_config::load('universe');
|
|
|
267 |
|
|
|
268 |
if ($course instanceof stdClass) {
|
|
|
269 |
$course = new core_course_list_element($course);
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
$cccteachers = $theme->settings->cccteachers;
|
|
|
273 |
$cccsummary = $theme->settings->cccsummary;
|
|
|
274 |
$coursecarddesclimit = $theme->settings->coursecarddesclimit;
|
1441 |
ariadna |
275 |
|
|
|
276 |
if ($coursecarddesclimit == null) {
|
|
|
277 |
$coursecarddesclimit = 100;
|
|
|
278 |
}
|
|
|
279 |
|
1 |
efrain |
280 |
$courseprogressbar = $theme->settings->courseprogressbar;
|
|
|
281 |
|
|
|
282 |
$courseutil = new course($course);
|
|
|
283 |
$coursecontacts = $courseutil->get_course_contacts();
|
1441 |
ariadna |
284 |
$metacoursecontacts = $courseutil->get_meta_course_contacts();
|
|
|
285 |
$metacourselang = $courseutil->get_meta_course_lang();
|
1 |
efrain |
286 |
|
1441 |
ariadna |
287 |
$showfilter1 = ($theme->settings->showfilter1 == '1') ? true : false;
|
|
|
288 |
$showfilter2 = ($theme->settings->showfilter2 == '1') ? true : false;
|
|
|
289 |
$showfilter3 = ($theme->settings->showfilter3 == '1') ? true : false;
|
|
|
290 |
$showfilter4 = ($theme->settings->showfilter4 == '1') ? true : false;
|
|
|
291 |
$showfilter5 = ($theme->settings->showfilter5 == '1') ? true : false;
|
|
|
292 |
$showfilter6 = ($theme->settings->showfilter6 == '1') ? true : false;
|
|
|
293 |
|
|
|
294 |
$customfiltertitle1 = $theme->settings->customfilter1;
|
|
|
295 |
$customfiltertitle2 = $theme->settings->customfilter2;
|
|
|
296 |
$customfiltertitle3 = $theme->settings->customfilter3;
|
|
|
297 |
$customfiltertitle4 = $theme->settings->customfilter4;
|
|
|
298 |
$customfiltertitle5 = $theme->settings->customfilter5;
|
|
|
299 |
$customfiltertitle6 = $theme->settings->customfilter6;
|
|
|
300 |
|
|
|
301 |
$metacoursecustomfilter1 = format_string($courseutil->get_meta_course_customfilter1());
|
|
|
302 |
$metacoursecustomfilter2 = format_string($courseutil->get_meta_course_customfilter2());
|
|
|
303 |
$metacoursecustomfilter3 = format_string($courseutil->get_meta_course_customfilter3());
|
|
|
304 |
$metacoursecustomfilter4 = format_string($courseutil->get_meta_course_customfilter4());
|
|
|
305 |
$metacoursecustomfilter5 = format_string($courseutil->get_meta_course_customfilter5());
|
|
|
306 |
$metacoursecustomfilter6 = format_string($courseutil->get_meta_course_customfilter6());
|
|
|
307 |
|
1 |
efrain |
308 |
$courseenrolmenticons = $courseutil->get_enrolment_icons();
|
|
|
309 |
$courseenrolmenticons = !empty($courseenrolmenticons) ? $this->render_enrolment_icons($courseenrolmenticons) : false;
|
|
|
310 |
$courseprogress = $courseutil->get_progress();
|
|
|
311 |
$hasprogress = $courseprogress != null;
|
|
|
312 |
|
1441 |
ariadna |
313 |
if ($courseprogressbar == 0) {
|
|
|
314 |
$hasprogress = false;
|
|
|
315 |
$courseprogress = false;
|
1 |
efrain |
316 |
}
|
1441 |
ariadna |
317 |
|
|
|
318 |
$forcedlanguage = ($theme->settings->courselangbadge == 1) ? strval($course->lang) : null;
|
|
|
319 |
$showcustomfields = ($theme->settings->showcustomfields == 1) ? true : false;
|
1 |
efrain |
320 |
|
1441 |
ariadna |
321 |
$coursedates = '';
|
1 |
efrain |
322 |
|
1441 |
ariadna |
323 |
if ($this->page->theme->settings->ipcoursedates == 1) {
|
|
|
324 |
$coursedates .= html_writer::start_div('rui-custom-field-box');
|
|
|
325 |
$coursedates .= html_writer::tag('span', get_string('startdate', 'moodle'), ['class' => 'rui-custom-field-name']);
|
|
|
326 |
$coursedates .= html_writer::tag('span', userdate($course->startdate, get_string('strftimedaydate', 'core_langconfig')), ['class' => 'rui-custom-field-value']);
|
|
|
327 |
$coursedates .= html_writer::end_div(); // .rui-custom-field-box.
|
1093 |
ariadna |
328 |
|
1441 |
ariadna |
329 |
// Course End date.
|
|
|
330 |
$courseenddate = $course->enddate;
|
|
|
331 |
if ($courseenddate != '0') {
|
|
|
332 |
$coursedates .= html_writer::start_div('rui-custom-field-box');
|
|
|
333 |
$coursedates .= html_writer::tag('span', get_string('enddate', 'moodle'), ['class' => 'rui-custom-field-name rui-course-enddate-label']);
|
|
|
334 |
$coursedates .= html_writer::tag('span', userdate($courseenddate, get_string('strftimedaydate', 'core_langconfig')), ['class' => 'rui-course-enddate rui-custom-field-value']);
|
|
|
335 |
$coursedates .= html_writer::end_div(); // .rui-custom-field-box.
|
|
|
336 |
}
|
1093 |
ariadna |
337 |
}
|
1441 |
ariadna |
338 |
|
1 |
efrain |
339 |
$data = [
|
|
|
340 |
'id' => $course->id,
|
|
|
341 |
'fullname' => $chelper->get_course_formatted_name($course),
|
|
|
342 |
'visible' => $course->visible,
|
|
|
343 |
'image' => $courseutil->get_summary_image(),
|
|
|
344 |
'summary' => $courseutil->get_summary($chelper),
|
|
|
345 |
'category' => $courseutil->get_category(),
|
1441 |
ariadna |
346 |
'showcustomfields' => $showcustomfields,
|
1 |
efrain |
347 |
'customfields' => $courseutil->course_get_taux(),
|
1441 |
ariadna |
348 |
'coursedates' => $coursedates,
|
1 |
efrain |
349 |
'hasprogress' => $hasprogress,
|
|
|
350 |
'progress' => (int) $courseprogress,
|
|
|
351 |
'hasenrolmenticons' => $courseenrolmenticons != false,
|
|
|
352 |
'enrolmenticons' => $courseenrolmenticons,
|
|
|
353 |
'hascontacts' => !empty($coursecontacts),
|
|
|
354 |
'contacts' => $coursecontacts,
|
1441 |
ariadna |
355 |
'metacontacts' => $metacoursecontacts,
|
|
|
356 |
'metalang' => $metacourselang,
|
|
|
357 |
'metacoursecatid' => $course->category,
|
|
|
358 |
'metacoursecustomfilter1' => $metacoursecustomfilter1,
|
|
|
359 |
'metacoursecustomfilter2' => $metacoursecustomfilter2,
|
|
|
360 |
'metacoursecustomfilter3' => $metacoursecustomfilter3,
|
|
|
361 |
'metacoursecustomfilter4' => $metacoursecustomfilter4,
|
|
|
362 |
'metacoursecustomfilter5' => $metacoursecustomfilter5,
|
|
|
363 |
'metacoursecustomfilter6' => $metacoursecustomfilter6,
|
|
|
364 |
'showfilter1' => $showfilter1,
|
|
|
365 |
'showfilter2' => $showfilter2,
|
|
|
366 |
'showfilter3' => $showfilter3,
|
|
|
367 |
'showfilter4' => $showfilter4,
|
|
|
368 |
'showfilter5' => $showfilter5,
|
|
|
369 |
'showfilter6' => $showfilter6,
|
|
|
370 |
'customfiltertitle1' => $customfiltertitle1,
|
|
|
371 |
'customfiltertitle2' => $customfiltertitle2,
|
|
|
372 |
'customfiltertitle3' => $customfiltertitle3,
|
|
|
373 |
'customfiltertitle4' => $customfiltertitle4,
|
|
|
374 |
'customfiltertitle5' => $customfiltertitle5,
|
|
|
375 |
'customfiltertitle6' => $customfiltertitle6,
|
1 |
efrain |
376 |
'courseprogressbar' => $courseprogressbar,
|
|
|
377 |
'cccteachers' => $cccteachers,
|
|
|
378 |
'cccsummary' => $cccsummary,
|
|
|
379 |
'coursecarddesclimit' => $coursecarddesclimit,
|
1441 |
ariadna |
380 |
'forcedlanguage' => $forcedlanguage
|
1 |
efrain |
381 |
];
|
|
|
382 |
|
1441 |
ariadna |
383 |
return $this->render_from_template('theme_universe/custom_coursecard', $data);
|
1 |
efrain |
384 |
}
|
|
|
385 |
|
|
|
386 |
/**
|
|
|
387 |
* Displays one course in the list of courses.
|
|
|
388 |
*
|
|
|
389 |
* This is an internal function, to display an information about just one course
|
|
|
390 |
* please use core_course_renderer::course_info_box()
|
|
|
391 |
*
|
|
|
392 |
* @param coursecat_helper $chelper various display options
|
|
|
393 |
* @param core_course_list_element|stdClass $course
|
|
|
394 |
* @param string $additionalclasses additional classes to add to the main <div> tag (usually
|
|
|
395 |
* depend on the course position in list - first/last/even/odd)
|
|
|
396 |
* @return string
|
|
|
397 |
*/
|
1441 |
ariadna |
398 |
protected function coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '') {
|
1 |
efrain |
399 |
if (!isset($this->strings->summary)) {
|
|
|
400 |
$this->strings->summary = get_string('summary');
|
|
|
401 |
}
|
|
|
402 |
|
|
|
403 |
if ($chelper->get_show_courses() <= self::COURSECAT_SHOW_COURSES_COUNT) {
|
|
|
404 |
return '';
|
|
|
405 |
}
|
|
|
406 |
|
|
|
407 |
if ($course instanceof stdClass) {
|
|
|
408 |
$course = new core_course_list_element($course);
|
|
|
409 |
}
|
|
|
410 |
|
|
|
411 |
return $this->coursecat_coursebox_content($chelper, $course);
|
|
|
412 |
}
|
|
|
413 |
|
|
|
414 |
/**
|
|
|
415 |
* Returns HTML to display a tree of subcategories and courses in the given category
|
|
|
416 |
*
|
|
|
417 |
* @param coursecat_helper $chelper various display options
|
|
|
418 |
* @param core_course_category $coursecat top category (this category's name and description will NOT be added to the tree)
|
|
|
419 |
* @return string
|
|
|
420 |
*/
|
1441 |
ariadna |
421 |
protected function coursecat_tree(coursecat_helper $chelper, $coursecat) {
|
|
|
422 |
// // Reset the category expanded flag for this course category tree first.
|
|
|
423 |
// $this->categoryexpandedonload = false;
|
|
|
424 |
$categorycontent = $this->coursecat_category_content($chelper, $coursecat, 0);
|
1 |
efrain |
425 |
if (empty($categorycontent)) {
|
|
|
426 |
return '';
|
|
|
427 |
}
|
|
|
428 |
|
|
|
429 |
// Start content generation.
|
|
|
430 |
$content = '';
|
|
|
431 |
$attributes = $chelper->get_and_erase_attributes('course_category_tree clearfix');
|
1441 |
ariadna |
432 |
|
1 |
efrain |
433 |
$content .= html_writer::start_tag('div', $attributes);
|
1441 |
ariadna |
434 |
$content .= html_writer::tag('div', $categorycontent, ['class' => 'content']);
|
1 |
efrain |
435 |
$content .= html_writer::end_tag('div'); // End course_category_tree.
|
|
|
436 |
|
|
|
437 |
return $content;
|
|
|
438 |
}
|
|
|
439 |
|
|
|
440 |
/**
|
|
|
441 |
* Returns HTML to display a course category as a part of a tree
|
|
|
442 |
*
|
|
|
443 |
* This is an internal function, to display a particular category and all its contents
|
|
|
444 |
* use {@link core_course_renderer::course_category()}
|
|
|
445 |
*
|
|
|
446 |
* @param coursecat_helper $chelper various display options
|
|
|
447 |
* @param core_course_category $coursecat
|
|
|
448 |
* @param int $depth depth of this category in the current tree
|
|
|
449 |
* @return string
|
|
|
450 |
*/
|
1441 |
ariadna |
451 |
protected function coursecat_category(coursecat_helper $chelper, $coursecat, $depth) {
|
|
|
452 |
global $DB, $CFG;
|
|
|
453 |
|
1 |
efrain |
454 |
// Open category tag.
|
1441 |
ariadna |
455 |
$classes = ['category'];
|
1 |
efrain |
456 |
if (empty($coursecat->visible)) {
|
|
|
457 |
$classes[] = 'dimmed_category';
|
|
|
458 |
}
|
|
|
459 |
|
1441 |
ariadna |
460 |
$categorycontent = '';
|
|
|
461 |
|
1 |
efrain |
462 |
// Make sure JS file to expand category content is included.
|
|
|
463 |
|
1441 |
ariadna |
464 |
$content = html_writer::start_tag('div', [
|
1 |
efrain |
465 |
'class' => join(' ', $classes),
|
|
|
466 |
'data-categoryid' => $coursecat->id,
|
|
|
467 |
'data-depth' => $depth,
|
1441 |
ariadna |
468 |
// 'data-showcourses' => $chelper->get_show_courses(),
|
|
|
469 |
// 'data-type' => self::COURSECAT_TYPE_CATEGORY,
|
|
|
470 |
]);
|
1 |
efrain |
471 |
|
1441 |
ariadna |
472 |
// Number of courses.
|
|
|
473 |
$a = $coursecat->get_courses_count();
|
|
|
474 |
$b = $coursecat->get_children_count();
|
|
|
475 |
$coursesum = $a + $b;
|
|
|
476 |
// End.
|
|
|
477 |
|
1 |
efrain |
478 |
// Category name.
|
|
|
479 |
$categoryname = html_writer::link(
|
|
|
480 |
new moodle_url(
|
|
|
481 |
'/course/index.php',
|
1441 |
ariadna |
482 |
['categoryid' => $coursecat->id]
|
1 |
efrain |
483 |
),
|
|
|
484 |
$coursecat->get_formatted_name(),
|
1441 |
ariadna |
485 |
['class' => 'rui-category-link text-decoration-none']
|
1 |
efrain |
486 |
);
|
|
|
487 |
|
1441 |
ariadna |
488 |
$html = null;
|
1 |
efrain |
489 |
|
1441 |
ariadna |
490 |
// Path for links.
|
|
|
491 |
$siteurl = $CFG->wwwroot;
|
|
|
492 |
$catpath = "/course/index.php?categoryid=";
|
1 |
efrain |
493 |
|
1441 |
ariadna |
494 |
// // DB: List all records.
|
|
|
495 |
// $records = $DB->get_records('course_categories');
|
1 |
efrain |
496 |
|
1441 |
ariadna |
497 |
// // List of all categories.
|
|
|
498 |
// foreach ($records as $value) {
|
|
|
499 |
// $caturl = "{$siteurl}{$catpath}{$value->id}";
|
|
|
500 |
// $classcatdepth = "rui-subcat-badge categories-depth-{$value->depth}";
|
|
|
501 |
|
|
|
502 |
// $attributes = ['class' => $classcatdepth];
|
|
|
503 |
// $catname = $value->name;
|
|
|
504 |
|
|
|
505 |
// // Depth.
|
|
|
506 |
// if ($value->parent > 0 && $value->parent == $coursecat->id) {
|
|
|
507 |
// $html .= html_writer::link($caturl, $catname, $attributes);
|
|
|
508 |
// }
|
|
|
509 |
|
|
|
510 |
// }
|
|
|
511 |
|
|
|
512 |
$content .= html_writer::start_tag('div', ['class' => 'rui-categorybox-wrapper']);
|
|
|
513 |
|
|
|
514 |
// Category Title.
|
|
|
515 |
$content .= html_writer::start_tag('h3', ['class' => 'rui-categoryname aabtn']);
|
1 |
efrain |
516 |
$content .= $categoryname;
|
1441 |
ariadna |
517 |
$content .= html_writer::end_tag('h3');
|
|
|
518 |
|
|
|
519 |
$content .= html_writer::start_tag('h5', ['class' => 'rui-no-courses-title']);
|
|
|
520 |
switch ($coursesum) {
|
|
|
521 |
case '1':
|
|
|
522 |
$content .= $coursesum . ' ' . get_string('course', 'moodle');
|
|
|
523 |
break;
|
|
|
524 |
default:
|
|
|
525 |
$content .= $coursesum . ' ' . get_string('courses', 'moodle');
|
|
|
526 |
break;
|
1 |
efrain |
527 |
}
|
|
|
528 |
$content .= html_writer::end_tag('h5');
|
|
|
529 |
|
|
|
530 |
|
1441 |
ariadna |
531 |
// Category desc.
|
|
|
532 |
// $content .= $chelper->get_category_formatted_description($coursecat);
|
|
|
533 |
$content .= html_writer::end_tag('div'); // End .rui-categorybox-wrapper.
|
|
|
534 |
|
|
|
535 |
// Display subcategories if exists.
|
|
|
536 |
if($html != null) {
|
|
|
537 |
$content .= html_writer::tag('div', $html, ['class' => 'rui-category-box-subcat']);
|
|
|
538 |
}
|
|
|
539 |
|
1 |
efrain |
540 |
// Add category content to the output.
|
1441 |
ariadna |
541 |
$content .= html_writer::tag('div', $categorycontent, ['class' => 'rui-categorybox-wrapper']);
|
1 |
efrain |
542 |
|
|
|
543 |
$content .= html_writer::end_tag('div'); // End .category.
|
|
|
544 |
|
|
|
545 |
// Return the course category tree HTML.
|
|
|
546 |
return $content;
|
|
|
547 |
}
|
|
|
548 |
|
|
|
549 |
/**
|
|
|
550 |
* Returns enrolment icons
|
|
|
551 |
*
|
|
|
552 |
* @param array $icons
|
|
|
553 |
*
|
|
|
554 |
* @return array
|
|
|
555 |
*/
|
1441 |
ariadna |
556 |
protected function render_enrolment_icons(array $icons): array {
|
1 |
efrain |
557 |
$data = [];
|
|
|
558 |
|
|
|
559 |
foreach ($icons as $icon) {
|
|
|
560 |
$data[] = $this->render($icon);
|
|
|
561 |
}
|
|
|
562 |
|
|
|
563 |
return $data;
|
|
|
564 |
}
|
1441 |
ariadna |
565 |
|
1 |
efrain |
566 |
}
|