Internal api update to allow rendering demo badges with a specific level

This commit is contained in:
PM 2019-08-21 23:13:23 +02:00
parent ed70b0de2c
commit e46f7e2d30
3 changed files with 33 additions and 10 deletions

View File

@ -366,7 +366,7 @@ class block_gradelevel_levelset {
$levelup_points = $next_at - $current_at;
$points_in_level = $points - $current_at;
if($levelup_points == 0){ // at max level
if($levelup_points <= 0){ // at max level
$progress = 0;
$points_in_level = 0;
}
@ -379,9 +379,9 @@ class block_gradelevel_levelset {
$result->level = $level;
$result->badge_color = $badge_color;
$result->progress = $progress;
$result->next_at = $next_at;
$result->levelup_total = $levelup_points;
$result->points_in_level = $points_in_level;
$result->next_at = round($next_at);
$result->levelup_total = round($levelup_points);
$result->points_in_level = round($points_in_level);
return $result;
}
@ -480,12 +480,19 @@ class block_gradelevel_levelset {
return $html;
}
public function render_demo_badge(int $size=100)
public function render_demo_badge(int $size=100, $level=null)
{
$levels = $this->badgelevels();
$maxpoints = array_pop(array_keys($levels));
if($level == null || $level > count($levels))
{
$points = array_pop(array_keys($levels));
}
else
{
$points = array_keys($levels)[$level - 1];
}
return $this->render_badge($maxpoints, $size);
return $this->render_badge($points, $size);
}

View File

@ -1,4 +1,4 @@
<?php
$plugin->component = 'block_gradelevel'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494)
$plugin->version = 2018112400; // YYYYMMDDHH (year, month, day, iteration)
$plugin->version = 2019082100; // YYYYMMDDHH (year, month, day, iteration)
$plugin->requires = 2018050800; // YYYYMMDDHH (This is the release version for Moodle 3.5)

View File

@ -57,7 +57,16 @@ if(count($course_groups > 0))
print "<li class='result_badge'>";
print $skill->render_badge($pointstotal,BADGE_SIZE);
print "<figcaption><span class='namepart'>{$usr->firstname}</span> <span class='namepart'>{$usr->lastname}</span></figcaption>";
print "<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>";
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>";
}
print "</li>";
unset($remaining_users[$usr->id]);
}
@ -79,7 +88,14 @@ foreach($remaining_users as $usr)
print "<li class='result_badge'>";
print $skill->render_badge($pointstotal,BADGE_SIZE);
print "<figcaption><span class='namepart'>{$usr->firstname}</span> <span class='namepart'>{$usr->lastname}</span></figcaption>";
print "<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>";
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>";
}
print "</li>";
}