96 |
efrain |
1 |
<?php
|
|
|
2 |
|
117 |
ariadna |
3 |
class block_cesa_course_rating extends block_base
|
|
|
4 |
{
|
|
|
5 |
public function init()
|
|
|
6 |
{
|
|
|
7 |
$this->title = get_string('pluginname', 'block_cesa_course_rating');
|
|
|
8 |
}
|
96 |
efrain |
9 |
|
117 |
ariadna |
10 |
public function applicable_formats()
|
|
|
11 |
{
|
|
|
12 |
return [
|
503 |
ariadna |
13 |
'all' => false,
|
|
|
14 |
'my' => false,
|
|
|
15 |
'admin' => false,
|
|
|
16 |
'course' => false,
|
|
|
17 |
'course-view' => true,
|
|
|
18 |
'enrol' => true,
|
117 |
ariadna |
19 |
];
|
|
|
20 |
}
|
|
|
21 |
|
503 |
ariadna |
22 |
function specialization()
|
|
|
23 |
{
|
|
|
24 |
global $CFG, $DB;
|
|
|
25 |
if (empty($this->config)) {
|
619 |
ariadna |
26 |
$this->instance->defaultregion = 'bellow-content';
|
|
|
27 |
$this->instance->region = 'bellow-content';
|
503 |
ariadna |
28 |
$DB->update_record('block_instances', $this->instance);
|
|
|
29 |
|
620 |
ariadna |
30 |
$this->title = 'Puntuación del Curso';
|
503 |
ariadna |
31 |
} else {
|
|
|
32 |
$this->title = get_string('pluginname', 'block_cesa_course_rating');
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
|
117 |
ariadna |
36 |
function instance_allow_multiple()
|
|
|
37 |
{
|
|
|
38 |
return false;
|
|
|
39 |
}
|
96 |
efrain |
40 |
|
117 |
ariadna |
41 |
public function html_attributes()
|
|
|
42 |
{
|
|
|
43 |
global $CFG;
|
|
|
44 |
$attributes = parent::html_attributes();
|
|
|
45 |
return $attributes;
|
|
|
46 |
}
|
96 |
efrain |
47 |
|
117 |
ariadna |
48 |
public function has_config()
|
|
|
49 |
{
|
|
|
50 |
return true;
|
|
|
51 |
}
|
96 |
efrain |
52 |
|
117 |
ariadna |
53 |
public function get_content()
|
|
|
54 |
{
|
|
|
55 |
global $CFG, $COURSE;
|
96 |
efrain |
56 |
|
117 |
ariadna |
57 |
if ($this->content !== null) {
|
621 |
ariadna |
58 |
return $this->content;
|
117 |
ariadna |
59 |
}
|
96 |
efrain |
60 |
|
117 |
ariadna |
61 |
$this->content = new stdClass;
|
96 |
efrain |
62 |
|
117 |
ariadna |
63 |
if (!empty($this->config->title)) {
|
621 |
ariadna |
64 |
$this->content->title = format_text($this->config->title, FORMAT_HTML, array('filter' => true));
|
117 |
ariadna |
65 |
} else {
|
|
|
66 |
$this->content->title = get_string('pluginname', 'block_cesa_course_rating');
|
|
|
67 |
}
|
96 |
efrain |
68 |
|
117 |
ariadna |
69 |
$courseid = $COURSE->id;
|
|
|
70 |
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
96 |
efrain |
71 |
|
117 |
ariadna |
72 |
$canRate = has_capability('block/cesa_course_rating:rate', $context);
|
621 |
ariadna |
73 |
$canRateClass = $canRate ? 'ccn-can-rate' : 'ccn-cannot-rate';
|
96 |
efrain |
74 |
|
117 |
ariadna |
75 |
$ccnSubmitRating = $this->submit_rating();
|
|
|
76 |
$this->content->text = '';
|
96 |
efrain |
77 |
|
621 |
ariadna |
78 |
$ccnRating = number_format($this->overall_rating($COURSE->id), 1);
|
96 |
efrain |
79 |
|
621 |
ariadna |
80 |
$ccnStar = '<li class="list-inline-item"><i class="fa fa-star"></i></li>';
|
|
|
81 |
$ccnStarHalf = '<li class="list-inline-item"><i class="fa fa-star-half-o"></i></li>';
|
|
|
82 |
$ccnStarVoid = '<li class="list-inline-item"><i class="fa fa-star-o"></i></li>';
|
96 |
efrain |
83 |
|
117 |
ariadna |
84 |
if ($ccnRating == 5) {
|
|
|
85 |
$ccnStars = str_repeat($ccnStar, 5);
|
|
|
86 |
} elseif ($ccnRating == 4.5) {
|
|
|
87 |
$ccnStars = str_repeat($ccnStar, 4) . str_repeat($ccnStarHalf, 1);
|
|
|
88 |
} elseif ($ccnRating == 4) {
|
|
|
89 |
$ccnStars = str_repeat($ccnStar, 4) . str_repeat($ccnStarVoid, 1);
|
|
|
90 |
} elseif ($ccnRating == 3.5) {
|
|
|
91 |
$ccnStars = str_repeat($ccnStar, 3) . str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 1);
|
|
|
92 |
} elseif ($ccnRating == 3) {
|
|
|
93 |
$ccnStars = str_repeat($ccnStar, 3) . str_repeat($ccnStarVoid, 2);
|
|
|
94 |
} elseif ($ccnRating == 2.5) {
|
621 |
ariadna |
95 |
$ccnStars = str_repeat($ccnStar, 2) . str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 2);
|
117 |
ariadna |
96 |
} elseif ($ccnRating == 2) {
|
|
|
97 |
$ccnStars = str_repeat($ccnStar, 2) . str_repeat($ccnStarVoid, 3);
|
|
|
98 |
} elseif ($ccnRating == 1.5) {
|
621 |
ariadna |
99 |
$ccnStars = str_repeat($ccnStar, 1) . str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 3);
|
117 |
ariadna |
100 |
} elseif ($ccnRating == 0.5) {
|
|
|
101 |
$ccnStars = str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 4);
|
|
|
102 |
} else {
|
|
|
103 |
$ccnStars = str_repeat($ccnStarVoid, 5);
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
$ccnFive = $this->get_specific_average($COURSE->id, 5);
|
|
|
107 |
$ccnFour = $this->get_specific_average($COURSE->id, 4);
|
|
|
108 |
$ccnThree = $this->get_specific_average($COURSE->id, 3);
|
|
|
109 |
$ccnTwo = $this->get_specific_average($COURSE->id, 2);
|
|
|
110 |
$ccnOne = $this->get_specific_average($COURSE->id, 1);
|
|
|
111 |
|
|
|
112 |
$this->content->text .= '
|
621 |
ariadna |
113 |
<div class="cs_row_five">
|
|
|
114 |
<div class="student_feedback_container">
|
|
|
115 |
<h4 data-ccn="title" class="aii_title">' . $this->content->title . '</h4>
|
|
|
116 |
<div class="s_feeback_content">
|
|
|
117 |
<ul class="skills">
|
|
|
118 |
<li class="list-inline-item">5 estrellas</li>
|
|
|
119 |
<li class="list-inline-item progressbar1" data-width="' . $ccnFive . '" data-target="100">' . $ccnFive . '%</li>
|
|
|
120 |
</ul>
|
|
|
121 |
<ul class="skills">
|
|
|
122 |
<li class="list-inline-item">4 estrellas</li>
|
|
|
123 |
<li class="list-inline-item progressbar2" data-width="' . $ccnFour . '" data-target="100">' . $ccnFour . '%</li>
|
|
|
124 |
</ul>
|
|
|
125 |
<ul class="skills">
|
|
|
126 |
<li class="list-inline-item">3 estrellas</li>
|
|
|
127 |
<li class="list-inline-item progressbar3" data-width="' . $ccnThree . '" data-target="100">' . $ccnThree . '%</li>
|
|
|
128 |
</ul>
|
|
|
129 |
<ul class="skills">
|
|
|
130 |
<li class="list-inline-item">2 estrellas</li>
|
|
|
131 |
<li class="list-inline-item progressbar4" data-width="' . $ccnTwo . '" data-target="100">' . $ccnTwo . '%</li>
|
|
|
132 |
</ul>
|
|
|
133 |
<ul class="skills">
|
|
|
134 |
<li class="list-inline-item">1 estrella</li>
|
|
|
135 |
<li class="list-inline-item progressbar5" data-width="' . $ccnOne . '" data-target="100">' . $ccnOne . '%</li>
|
|
|
136 |
</ul>
|
|
|
137 |
</div>
|
|
|
138 |
<div class="aii_average_review text-center ' . $canRateClass . '">
|
|
|
139 |
<div class="av_content">
|
|
|
140 |
<h2>' . $ccnRating . '</h2>
|
|
|
141 |
<ul class="aii_rive_list mb0">
|
|
|
142 |
' . $ccnStars . '
|
|
|
143 |
</ul>
|
|
|
144 |
<p>' . $this->count_ratings($COURSE->id) . '</p>';
|
117 |
ariadna |
145 |
if ($canRate == 1) {
|
|
|
146 |
$this->content->text .= $ccnSubmitRating;
|
|
|
147 |
}
|
|
|
148 |
$this->content->text .= '
|
621 |
ariadna |
149 |
</div>
|
|
|
150 |
</div>
|
|
|
151 |
</div>
|
|
|
152 |
</div>';
|
117 |
ariadna |
153 |
return $this->content;
|
|
|
154 |
}
|
96 |
efrain |
155 |
}
|