2018-09-17 13:12:56 +02:00
|
|
|
<?php
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
require_once($CFG->dirroot.'/grade/querylib.php');
|
|
|
|
require_once($CFG->dirroot.'/blocks/gradelevel/lib.php');
|
|
|
|
|
|
|
|
use block_gradelevel;
|
|
|
|
|
|
|
|
class block_gradelevel extends block_base {
|
|
|
|
|
|
|
|
public $levelset;
|
|
|
|
|
|
|
|
public function init() {
|
|
|
|
global $PAGE;
|
|
|
|
global $COURSE;
|
|
|
|
|
|
|
|
$this->title = get_config('gradelevel', 'blocktitle');
|
|
|
|
if(empty($this->title))
|
|
|
|
{
|
|
|
|
$this->title = get_string('title', 'block_gradelevel');
|
|
|
|
}
|
|
|
|
|
|
|
|
// include javascript and run badge renderer when page loading is complete
|
|
|
|
$PAGE->requires->js_call_amd('block_gradelevel/renderbadge', 'init');
|
|
|
|
|
|
|
|
// find or create the levelset for this course
|
|
|
|
$this->levelset = block_gradelevel_levelset::find_by_course($COURSE->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The PHP tag and the curly bracket for the class definition
|
|
|
|
// will only be closed after there is another function added in the next section.
|
|
|
|
|
|
|
|
public function html_attributes() {
|
|
|
|
$attributes = parent::html_attributes(); // Get default values
|
|
|
|
$attributes['class'] .= ' block_'. $this->name(); // Append our class to class attribute
|
|
|
|
return $attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_content() {
|
2018-09-23 22:06:52 +02:00
|
|
|
global $CFG;
|
2018-09-17 13:12:56 +02:00
|
|
|
global $USER;
|
2018-09-21 22:30:09 +02:00
|
|
|
global $COURSE;
|
2018-09-17 13:12:56 +02:00
|
|
|
|
|
|
|
if ($this->content !== null) {
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->content = new stdClass;
|
|
|
|
|
2018-09-23 22:06:52 +02:00
|
|
|
if(empty($this->levelset))
|
2018-09-17 13:12:56 +02:00
|
|
|
{
|
2018-09-23 22:06:52 +02:00
|
|
|
$this->content->text = "<figure class='dummybadge'><img height='150px' width='150px' src='{$CFG->wwwroot}/blocks/gradelevel/pix/brokenbadge.svg' /></figure>";
|
|
|
|
$this->content->footer = get_string("unattached_course",'block_gradelevel');
|
2018-09-17 13:12:56 +02:00
|
|
|
}
|
2018-09-23 22:06:52 +02:00
|
|
|
else {
|
|
|
|
// below can be a single call to $this->levelset->get_user_leveldata() once the need for debugging (fixed point total) is gone
|
|
|
|
$pointstotal = $this->levelset->get_levelset_grade($USER->id);
|
|
|
|
$level_info = $this->levelset->calculate_level($pointstotal);
|
|
|
|
|
|
|
|
$this->content->text = $this->levelset->render_badge($pointstotal);
|
|
|
|
|
|
|
|
if($level_info->levelup_total > 0)
|
|
|
|
{
|
|
|
|
$this->content->footer = "<div class='pointinfo'>".get_string('levelup_at','block_gradelevel')." <span class='currentpoints'>{$level_info->points_in_level}</span>/<span class='leveluppoints'>{$level_info->levelup_total}</span></div>";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->content->footer = "<div class='pointinfo complete'>".get_string('levelup_done','block_gradelevel')."</div>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$coursecontext = context_course::instance($COURSE->id);
|
2018-09-21 22:30:09 +02:00
|
|
|
|
2018-09-23 22:06:52 +02:00
|
|
|
if(has_capability('block/gradelevel:viewresults', $coursecontext))
|
|
|
|
{
|
2018-09-24 11:05:10 +02:00
|
|
|
$this->content->footer .= "\n<div class='teachermode'><a href='{$CFG->wwwroot}/blocks/gradelevel/view-results.php?courseid={$COURSE->id}'>".get_string('teacher_view_results','block_gradelevel')."</a></div>";
|
2018-09-23 22:06:52 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-17 13:12:56 +02:00
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-21 22:30:09 +02:00
|
|
|
public function hide_header() { return !get_config('gradelevel', 'showtitle'); }
|
2018-09-17 13:12:56 +02:00
|
|
|
|
|
|
|
public function has_config() { return true; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|