-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.php
120 lines (94 loc) · 3.93 KB
/
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
<?php
/**
* testimonials block renderer
*
* @package block_testimonials
* @copyright 2015 Thomas Threadgold <tj.threadgold@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
class block_testimonials_renderer extends plugin_renderer_base {
/**
* Construct contents of testimonials block
*
* @param array $products The list of products to be output
* @return string html to be displayed in testimonials block
*/
public function output_testimonials($config, $context) {
$html = '';
$html = sprintf(
'<ul class="testimonial__list %s">',
(int) $config->enable_rotation === 1 ? 'autoplay' : ''
);
for($i = 1; $i <= (int)$config->testimonials_shown; $i++) {
$quote = 'testimonial_quote_'.$i;
$image = 'testimonial_photo_'.$i;
$name = 'testimonial_name_'.$i;
$position = 'testimonial_position_'.$i;
$html .= sprintf(
'<li class="testimonial__item %s" data-id="%d">',
$i === 1 ? 'active' : '',
$i
);
// Output quote
if(0 < strlen($config->$quote)) {
$html .= sprintf(
'<div class="testimonial__quote">%s</div>',
$config->$quote
);
}
$html .= '<div class="testimonial__person">';
// Output image
if((bool)$config->show_image) {
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'block_testimonials', 'photo', $config->$image);
foreach ($files as $file) {
$filename = $file->get_filename();
if($filename !== '.') {
$url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $filename);
if(!!$url) {
$html .= sprintf(
'<img class="testimonial__photo" src="%s" alt="%s">',
$url,
$config->$name
);
}
}
}
}
$html .= '<div class="testimonial__info">';
// Output title
if((bool)$config->show_name) {
$html .= sprintf(
'<h3 class="testimonial__name">%s</h3>',
$config->$name
);
}
// Output description
if((bool)$config->show_position) {
$html .= sprintf(
'<h4 class="testimonial__position">%s</h4>',
$config->$position
);
}
$html .= '</div>';
$html .= '</div>';
$html .= '</li>';
}
$html .= '</ul>';
// output pagination
if((bool)$config->show_pagination) {
$html .= '<ul class="pagination">';
for($i = 1; $i <= (int)$config->testimonials_shown; $i++) {
$html .= sprintf(
'<li class="pagination__item %1$s"><a class="pagination__link" data-id="%2$d">%2$d</a></li>',
$i === 1 ? 'active' : '',
$i
);
}
$html .= '</ul>';
}
return $html;
}
}
?>