/
course_renderer.php
executable file
·432 lines (357 loc) · 16.6 KB
/
course_renderer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Course renderer.
*
* @package theme_noanme
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace theme_fordson\output\core;
defined('MOODLE_INTERNAL') || die();
use moodle_url;
use lang_string;
use coursecat_helper;
use coursecat;
use stdClass;
use course_in_list;
use context_course;
use pix_url;
use html_writer;
use heading;
use pix_icon;
use image_url;
require_once($CFG->dirroot . '/course/renderer.php');
/**
* Course renderer class.
*
* @package theme_noanme
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (theme_fordson_get_setting('enablefrontpageavailablecoursebox')) {
class course_renderer extends \theme_boost\output\core\course_renderer {
protected $countcategories = 0;
/**
* Renders html to display a course search form.
*
* @param string $value default value to populate the search field
* @param string $format display format - 'plain' (default), 'short' or 'navbar'
* @return string
*/
public function course_search_form($value = '', $format = 'plain') {
static $count = 0;
$formid = 'coursesearch';
if ((++$count) > 1) {
$formid .= $count;
}
switch ($format) {
case 'navbar' :
$formid = 'coursesearchnavbar';
$inputid = 'navsearchbox';
$inputsize = 20;
break;
case 'short' :
$inputid = 'shortsearchbox';
$inputsize = 12;
break;
default :
$inputid = 'coursesearchbox';
$inputsize = 30;
}
$data = (object) [
'searchurl' => (new moodle_url('/course/search.php'))->out(false),
'id' => $formid,
'inputid' => $inputid,
'inputsize' => $inputsize,
'value' => $value
];
return $this->render_from_template('theme_fordson/course_search_form', $data);
}
public function frontpage_available_courses($id=0) {
/* available courses */
global $CFG, $OUTPUT, $PAGE;
require_once($CFG->libdir. '/coursecatlib.php');
$chelper = new coursecat_helper();
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)->set_courses_display_options(array(
'recursive' => true,
'limit' => $CFG->frontpagecourselimit,
'viewmoreurl' => new moodle_url('/course/index.php'),
'viewmoretext' => new lang_string('fulllistofcourses')
));
$chelper->set_attributes(array('class' => 'frontpage-course-list-all'));
$courses = coursecat::get($id)->get_courses($chelper->get_courses_display_options());
$totalcount = coursecat::get($id)->get_courses_count($chelper->get_courses_display_options());
$rcourseids = array_keys($courses);
$acourseids = array_chunk($rcourseids, 3);
$newcourse = get_string('availablecourses');
$header = '
<div id="frontpage-course-list">
<div class="class-list">
<h2>'.$newcourse.'</h2>
</div>
<div class="courses frontpage-course-list-all">';
$content = '';
$footer = '
</div>
</div>';
if (count($rcourseids) > 0) {
foreach ($acourseids as $courseids) {
$content .= '<div class="container-fluid"> <div class="row">';
$rowcontent = '';
foreach ($courseids as $courseid) {
$course = get_course($courseid);
$trimtitlevalue = $PAGE->theme->settings->trimtitle;
$trimtitle = theme_fordson_course_trim_char($course->fullname, $trimtitlevalue);
$noimgurl = $OUTPUT->pix_url('noimg', 'theme');
$courseurl = new moodle_url('/course/view.php', array('id' => $courseid ));
if ($course instanceof stdClass) {
require_once($CFG->libdir. '/coursecatlib.php');
$course = new course_in_list($course);
}
// Load from config if usea a img from course summary file if not exist a img then a default one ore use a fa-icon
$imgurl = '';
$context = context_course::instance($course->id);
foreach ($course->get_course_overviewfiles() as $file) {
$isimage = $file->is_valid_image();
$imgurl = file_encode_url("$CFG->wwwroot/pluginfile.php",
'/'. $file->get_contextid(). '/'. $file->get_component(). '/'.
$file->get_filearea(). $file->get_filepath(). $file->get_filename(), !$isimage);
if (!$isimage) {
$imgurl = $noimgurl;
}
}
if (empty($imgurl)) {
$imgurl = $PAGE->theme->setting_file_url('headerdefaultimage', 'headerdefaultimage', true);
if (!$imgurl) {
$imgurl = $noimgurl;
}
}
$rowcontent .= '
<div class="col-md-4">
<div class="class-box-fp" style="background-image: url('.$imgurl.');background-repeat: no-repeat;background-size:cover; background-position:center;">
';
if ($PAGE->theme->settings->titletooltip) {
$tooltiptext = 'data-toggle="tooltip" data-placement= "top" title="'.$course->fullname.'"';
} else {
$tooltiptext = '';
}
$rowcontent .= '
<div class="course-title">
<h4><a '.$tooltiptext.' href="'.$courseurl.'">'.$trimtitle.'</a></h4>
</div>
</div>
</div>';
}
$content .= $rowcontent;
$content .= '</div> </div>';
}
}
$coursehtml = $header.$content.$footer;
if($id == 0){
echo $coursehtml;
}else{
$coursehtml .= '<br/><br/>';
return $coursehtml;
}
}
public function view_available_courses($id = 0, $courses = NULL, $totalcount = NULL) {
/* available courses */
global $CFG, $OUTPUT, $PAGE;
require_once($CFG->libdir. '/coursecatlib.php');
$chelper = new coursecat_helper();
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)->set_courses_display_options(array(
'recursive' => false,
'limit' => $CFG->frontpagecourselimit,
'viewmoreurl' => new moodle_url('/course/index.php'),
'viewmoretext' => new lang_string('fulllistofcourses')
));
$chelper->set_attributes(array('class' => 'category-course-list-all'));
if (!$courses) {
$courses = coursecat::get($id)->get_courses($chelper->get_courses_display_options());
$totalcount = coursecat::get($id)->get_courses_count($chelper->get_courses_display_options());
}
$rcourseids = array_keys($courses);
$acourseids = array_chunk($rcourseids, 3);
if($id!=0){
$newcourse = get_string('availablecourses');
} else {
$newcourse = NULL;
}
$header = '
<div id="category-course-list">
<div class="class-list">
<h2>'.$newcourse.'</h2>
</div>
<div class="courses category-course-list-all">';
$content = '';
$footer = '
</div>
</div>';
if (count($rcourseids) > 0) {
foreach ($acourseids as $courseids) {
$content .= '<div class="container-fluid"> <div class="row">';
$rowcontent = '';
foreach ($courseids as $courseid) {
$course = get_course($courseid);
$trimtitlevalue = $PAGE->theme->settings->trimtitle;
$trimsummaryvalue = $PAGE->theme->settings->trimsummary;
$summary = theme_fordson_strip_html_tags($course->summary);
$summary = theme_fordson_course_trim_char($summary, $trimsummaryvalue);
$trimtitle = theme_fordson_course_trim_char($course->fullname, $trimtitlevalue);
$noimgurl = $OUTPUT->pix_url('noimg', 'theme');
$courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
if ($course instanceof stdClass) {
require_once($CFG->libdir. '/coursecatlib.php');
$course = new course_in_list($course);
}
// Load from config if usea a img from course summary file if not exist a img then a default one ore use a fa-icon
$imgurl = '';
$context = context_course::instance($course->id);
foreach ($course->get_course_overviewfiles() as $file) {
$isimage = $file->is_valid_image();
$imgurl = file_encode_url("$CFG->wwwroot/pluginfile.php",
'/'. $file->get_contextid(). '/'. $file->get_component(). '/'.
$file->get_filearea(). $file->get_filepath(). $file->get_filename(), !$isimage);
if (!$isimage) {
$imgurl = $noimgurl;
}
}
if (empty($imgurl)) {
$imgurl = $PAGE->theme->setting_file_url('headerdefaultimage', 'headerdefaultimage', true);
if (!$imgurl) {
$imgurl = $noimgurl;
}
}
$rowcontent .= '
<div class="col-md-4">';
$rowcontent .= html_writer::start_tag('div', array('class' => $course->visible ? '' : 'coursedimmed'));
$rowcontent .= '
<div class="class-box">
';
if ($PAGE->theme->settings->titletooltip) {
$tooltiptext = 'data-toggle="tooltip" data-placement= "top" title="'.$course->fullname.'"';
} else {
$tooltiptext = '';
}
$rowcontent .= '
<div class="course-title">
<h4><a '.$tooltiptext.' href="'.$courseurl.'">'.$trimtitle.'</a></h4>
</div>
<a href="'.$courseurl.'">
<div class="course-image-view" style="background-image: url('.$imgurl.');background-repeat: no-repeat;background-size:cover; background-position:center;">
</div>
</a>
<div class="course-summary">
'.$summary.'
</div>
</div>
</div>
</div>';
}
$content .= $rowcontent;
$content .= '</div> </div>';
}
}
$coursehtml = $header.$content.$footer;
$coursehtml .= '<br/><br/>';
return $coursehtml;
}
/**
* Returns HTML to display the subcategories and courses in the given category
*
* This method is re-used by AJAX to expand content of not loaded category
*
* @param coursecat_helper $chelper various display options
* @param coursecat $coursecat
* @param int $depth depth of the category in the current tree
* @return string
*/
protected function coursecat_category(coursecat_helper $chelper, $coursecat, $depth) {
global $CFG, $OUTPUT;
// open category tag
$classes = array('category');
if (empty($coursecat->visible)) {
$classes[] = 'dimmed_category';
}
if ($chelper->get_subcat_depth() > 0 && $depth >= $chelper->get_subcat_depth()) {
// do not load content
$categorycontent = '';
$classes[] = 'notloaded';
if ($coursecat->get_children_count() ||
($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_COLLAPSED && $coursecat->get_courses_count())) {
$classes[] = 'with_children';
$classes[] = 'collapsed';
}
} else {
// load category content
$categorycontent = $this->coursecat_category_content($chelper, $coursecat, $depth);
$classes[] = 'loaded';
if (!empty($categorycontent)) {
$classes[] = 'with_children';
}
}
$totalcount = coursecat::get(0)->get_children_count();
$content = '';
if($this->countcategories == 0 || ($this->countcategories % 3) == 0){
if(($this->countcategories % 3) == 0 && $totalcount != $this->countcategories){
$content .= '</div> </div>';
}
if($totalcount != $this->countcategories || $this->countcategories == 0){
$categoryparam = optional_param('categoryid', 0, PARAM_INT);
if($categoryparam){
$content .= $OUTPUT->heading(get_string('categories'));
}
$content .= '<div class="container-fluid"><div class="row">';
}
}
// ADD HERE GRID OPTIONS AND BOX CSS
$classes[] = 'col-md-3 box-class';
$content = '<div class="'.join(' ', $classes).'" data-categoryid="'.$coursecat->id.'" data-depth="'.$depth.'" data-showcourses="'.$chelper->get_show_courses().'" data-type="'.self::COURSECAT_TYPE_CATEGORY.'">';
$content .= '<div class="cat-icon">';
// LOAD ICON
$val = theme_fordson_get_setting('catsicon');
$url= new moodle_url('/course/index.php', array('categoryid' => $coursecat->id));
$content .= '<a href="'.$url.'">';
$content .= '<i class="fa fa-5x fa-'.$val.'"></i>';
//Cat title
$categoryname = $coursecat->get_formatted_name();
$content .= '<div>';
$content .= '<div class="info-enhanced">';
$content .= '<span class="class-category">'.$categoryname.'</span>';
// ADD HERE A CLASS TO SHOW COURSES COUNT IN A CORNER OR WHERE YOU THINK IS BETTER.
if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_COUNT) {
$coursescount = $coursecat->get_courses_count();
$content .= ' <span class="numberofcourses" title="'.get_string('numberofcourses').'">('.$coursescount.')</span>';
}
$content .= '</div>';
$content .= '</div>';
$content .= '</a>';
$content .= '</div>'; // BORDER DIV END.
$content .= '</div>'; // COL-MD-4 DIV END
if($totalcount == $this->countcategories){
}
++$this->countcategories;
return $content;
}
protected function coursecat_courses(coursecat_helper $chelper, $courses, $totalcount = null) {
$categoryid = optional_param('categoryid', 0, PARAM_INT);
$content = '<div class="clearfix"></div>';
$content .= $this->view_available_courses($categoryid, $courses, $totalcount);
return $content;
}
}
}