Rev 620 | Rev 622 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
class block_cesa_course_rating extends block_base
{
public function init()
{
$this->title = get_string('pluginname', 'block_cesa_course_rating');
}
public function applicable_formats()
{
return [
'all' => false,
'my' => false,
'admin' => false,
'course' => false,
'course-view' => true,
'enrol' => true,
];
}
function specialization()
{
global $CFG, $DB;
if (empty($this->config)) {
$this->instance->defaultregion = 'bellow-content';
$this->instance->region = 'bellow-content';
$DB->update_record('block_instances', $this->instance);
$this->title = 'Puntuación del Curso';
} else {
$this->title = get_string('pluginname', 'block_cesa_course_rating');
}
}
function instance_allow_multiple()
{
return false;
}
public function html_attributes()
{
global $CFG;
$attributes = parent::html_attributes();
return $attributes;
}
public function has_config()
{
return true;
}
public function get_content()
{
global $CFG, $COURSE;
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass;
if (!empty($this->config->title)) {
$this->content->title = format_text($this->config->title, FORMAT_HTML, array('filter' => true));
} else {
$this->content->title = get_string('pluginname', 'block_cesa_course_rating');
}
$courseid = $COURSE->id;
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$canRate = has_capability('block/cesa_course_rating:rate', $context);
$canRateClass = $canRate ? 'ccn-can-rate' : 'ccn-cannot-rate';
$ccnSubmitRating = $this->submit_rating();
$this->content->text = '';
$ccnRating = number_format($this->overall_rating($COURSE->id), 1);
$ccnStar = '<li class="list-inline-item"><i class="fa fa-star"></i></li>';
$ccnStarHalf = '<li class="list-inline-item"><i class="fa fa-star-half-o"></i></li>';
$ccnStarVoid = '<li class="list-inline-item"><i class="fa fa-star-o"></i></li>';
if ($ccnRating == 5) {
$ccnStars = str_repeat($ccnStar, 5);
} elseif ($ccnRating == 4.5) {
$ccnStars = str_repeat($ccnStar, 4) . str_repeat($ccnStarHalf, 1);
} elseif ($ccnRating == 4) {
$ccnStars = str_repeat($ccnStar, 4) . str_repeat($ccnStarVoid, 1);
} elseif ($ccnRating == 3.5) {
$ccnStars = str_repeat($ccnStar, 3) . str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 1);
} elseif ($ccnRating == 3) {
$ccnStars = str_repeat($ccnStar, 3) . str_repeat($ccnStarVoid, 2);
} elseif ($ccnRating == 2.5) {
$ccnStars = str_repeat($ccnStar, 2) . str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 2);
} elseif ($ccnRating == 2) {
$ccnStars = str_repeat($ccnStar, 2) . str_repeat($ccnStarVoid, 3);
} elseif ($ccnRating == 1.5) {
$ccnStars = str_repeat($ccnStar, 1) . str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 3);
} elseif ($ccnRating == 0.5) {
$ccnStars = str_repeat($ccnStarHalf, 1) . str_repeat($ccnStarVoid, 4);
} else {
$ccnStars = str_repeat($ccnStarVoid, 5);
}
$ccnFive = $this->get_specific_average($COURSE->id, 5);
$ccnFour = $this->get_specific_average($COURSE->id, 4);
$ccnThree = $this->get_specific_average($COURSE->id, 3);
$ccnTwo = $this->get_specific_average($COURSE->id, 2);
$ccnOne = $this->get_specific_average($COURSE->id, 1);
$this->content->text .= '
<div class="cs_row_five">
<div class="student_feedback_container">
<h4 data-ccn="title" class="aii_title">' . $this->content->title . '</h4>
<div class="s_feeback_content">
<ul class="skills">
<li class="list-inline-item">5 estrellas</li>
<li class="list-inline-item progressbar1" data-width="' . $ccnFive . '" data-target="100">' . $ccnFive . '%</li>
</ul>
<ul class="skills">
<li class="list-inline-item">4 estrellas</li>
<li class="list-inline-item progressbar2" data-width="' . $ccnFour . '" data-target="100">' . $ccnFour . '%</li>
</ul>
<ul class="skills">
<li class="list-inline-item">3 estrellas</li>
<li class="list-inline-item progressbar3" data-width="' . $ccnThree . '" data-target="100">' . $ccnThree . '%</li>
</ul>
<ul class="skills">
<li class="list-inline-item">2 estrellas</li>
<li class="list-inline-item progressbar4" data-width="' . $ccnTwo . '" data-target="100">' . $ccnTwo . '%</li>
</ul>
<ul class="skills">
<li class="list-inline-item">1 estrella</li>
<li class="list-inline-item progressbar5" data-width="' . $ccnOne . '" data-target="100">' . $ccnOne . '%</li>
</ul>
</div>
<div class="aii_average_review text-center ' . $canRateClass . '">
<div class="av_content">
<h2>' . $ccnRating . '</h2>
<ul class="aii_rive_list mb0">
' . $ccnStars . '
</ul>
<p>' . $this->count_ratings($COURSE->id) . '</p>';
if ($canRate == 1) {
$this->content->text .= $ccnSubmitRating;
}
$this->content->text .= '
</div>
</div>
</div>
</div>';
return $this->content;
}
}