-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_achievement.php
87 lines (76 loc) · 3.61 KB
/
block_achievement.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
<?php
// This file is part of the achievement plugin for Moodle
// This plugin is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This plugin is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this plugin. If not, see <http://www.gnu.org/licenses/>.
/**
*
* @package achievement
* @copyright 2012 Andil
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_achievement extends block_base {
function init() {
$this->title = get_string('blockname', 'block_achievement');
}
function has_config() {
return true;
}
function get_content() {
global $CFG, $USER;
$nbloop = 0;
require_once($CFG->dirroot.'/blocks/achievement/achievement.php');
/*
* Achievement init
*/
if($USER->id==0) return NULL;
$achievementprocessor = new achievement();
$achievementprocessor->load_achievementlist();
$achievementprocessor->compute_achievement_for_user($USER);
$achievementlist = $achievementprocessor->get_achievementlist();
$this->content = new stdClass;
$this->content->footer = '<a href="'.$CFG->wwwroot.'/blocks/achievement/personal.php">'.
get_string('fulllistofachievements', 'block_achievement').'</a>...';
if ((count($USER->achievementdone)>0) &&
($USER->achievementdone != false)) {
$this->content->text = '<ul class="list">';
foreach ($USER->achievementdone as $currentachdone) {
$currentachievement = $achievementlist[$currentachdone->achievementid];
if (++$nbloop <= $CFG->block_achievement_nbachievementinblock) {
$itemclass = '';
if ($achievementprocessor->has_update() &&
($achievementprocessor->achievementdone_search($achievementprocessor->get_newachievementdonelist(),
$currentachievement)!==false)){
$itemclass = ' new';
}
$content = '
<div class="icon column c0" style="float:left;">
<img
src="'.$CFG->wwwroot.'/blocks/achievement/pix/'.$achievementprocessor->get_achievement_pix($currentachievement).'"
class="icon '.$achievementprocessor->build_achievement_shortname($currentachievement).'"
alt="'.$achievementprocessor->get_achievement_string($currentachievement).'" />
</div>';
$content .= '<div class="column">'.
$achievementprocessor->get_achievement_string($currentachievement).
'</div>';
$this->content->text .= '
<li class="achievementitem'.$itemclass.'">'.$content.'</li>';
}
}
$this->content->text .='</ul>';
}
else {
$this->content->text = get_string('no_achievement', 'block_achievement');
}
return $this->content;
}
}