-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_fn_myprogress.php
184 lines (154 loc) · 7.01 KB
/
block_fn_myprogress.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package block_fn_myprogress
* @copyright Michael Gardener <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/completionlib.php');
require_once($CFG->dirroot . '/blocks/fn_myprogress/lib.php');
/**
*
* base class for block
* @author MoodleFn
*/
class block_fn_myprogress extends block_list {
public function init() {
$this->title = get_string('blocktitle', 'block_fn_myprogress');
}
/**
* Constrols the block title based on instance configuration
*
* @return bool
*/
public function specialization() {
global $course;
// Need the bigger course object.
$this->course = $course;
if (empty($this->config->title)) {
$this->title = get_string('blocktitle', 'block_fn_myprogress');
} else {
$this->title = $this->config->title;
}
}
/**
* Return the block content *
* @return block content
* @todo Finish documenting this function
*/
public function get_content() {
global $CFG, $SESSION, $COURSE, $USER, $OUTPUT;
if ($this->content !== null) {
return $this->content;
}
$context = context_course::instance($COURSE->id);
if (isset($SESSION->completioncache)) {
unset($SESSION->completioncache);
}
$this->content = new stdClass;
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
if (!has_capability('block/fn_myprogress:viewblock', $context) || is_siteadmin($USER)) {
return $this->content;
}
$completedactivities = 0;
$incompletedactivities = 0;
$savedactivities = 0;
$notattemptedactivities = 0;
$waitingforgradeactivities = 0;
$course = $this->page->course;
$activities = block_fn_myprogress_get_gradable_activities($course->id, $USER->id);
// Draft config.
if (isset($this->config->showdraft)) {
$showdraft = $this->config->showdraft;
} else {
$showdraft = get_config('block_fn_myprogress', 'showdraft');
}
if ($activities) {
list($completedactivities,
$incompletedactivities,
$savedactivities,
$notattemptedactivities,
$waitingforgradeactivities,
$status
) = block_fn_myprogress_get_activity_status_numbers($activities);
if (has_capability('block/fn_myprogress:viewblock', $context) && !is_siteadmin($USER)) {
// Completed.
if ($incompletedactivities) {
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/blocks/fn_myprogress/listactivities.php?id=' .
$course->id . '&show=completed' .
'&navlevel=top">' . $completedactivities . ' '.
get_string('completedsuccessful', 'block_fn_myprogress').'</a>';
} else {
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/blocks/fn_myprogress/listactivities.php?id=' .
$course->id . '&show=completed' .
'&navlevel=top">' . $completedactivities . ' '.
get_string('completed', 'block_fn_myprogress').'</a>';
}
$this->content->icons[] = '<img src="'.
$OUTPUT->pix_url('completed', 'block_fn_myprogress').'" class="icon" alt="">';
// Incomplete.
if ($incompletedactivities) {
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/blocks/fn_myprogress/listactivities.php?id=' .
$course->id . '&show=incompleted' .
'&navlevel=top">' . $incompletedactivities . ' ' .
get_string('completedunsuccessful', 'block_fn_myprogress') . '</a>';
$this->content->icons[] = '<img src="' .
$OUTPUT->pix_url('incomplete', 'block_fn_myprogress') . '" class="icon" alt="">';
}
// Draft.
if ($showdraft && $savedactivities) {
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/blocks/fn_myprogress/listactivities.php?id=' .
$course->id . '&show=draft' .
'&navlevel=top">' . $savedactivities . ' '.
get_string('draft', 'block_fn_myprogress').'</a>';
$this->content->icons[] = '<img src="' .
$OUTPUT->pix_url('saved', 'block_fn_myprogress') . '" class="icon" alt="">';
}
// Not Attempted.
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/blocks/fn_myprogress/listactivities.php?id=' .
$course->id . '&show=notattempted' .
'&navlevel=top">' . $notattemptedactivities . ' '.
get_string('notattempted', 'block_fn_myprogress').'</a>';
$this->content->icons[] = '<img src="'.
$OUTPUT->pix_url('notattempted', 'block_fn_myprogress').'" class="icon" alt="">';
// Waiting for grade.
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/blocks/fn_myprogress/listactivities.php?id=' .
$course->id . '&show=waitingforgrade' .
'&navlevel=top">' . $waitingforgradeactivities . ' '.
get_string('waitingforgrade', 'block_fn_myprogress').'</a>';
$this->content->icons[] = '<img src="'.
$OUTPUT->pix_url('unmarked', 'block_fn_myprogress').'" class="icon" alt="">';
}
} else {
$this->content->items[] = get_string('disabledviewmessage', 'block_fn_myprogress');
$this->content->icons[] = '<img src="'.
$OUTPUT->pix_url('warning', 'block_fn_myprogress').'" class="icon" alt="">';
}
return $this->content;
}
public function applicable_formats() {
return array('all' => false, 'course-*' => true);
}
public function has_config() {
return true;
}
public function instance_allow_config() {
return true;
}
}