-
Notifications
You must be signed in to change notification settings - Fork 54
/
block_progress.php
167 lines (150 loc) · 5.72 KB
/
block_progress.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
<?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/>.
/**
* Progress Bar block definition
*
* @package contrib
* @subpackage block_progress
* @copyright 2010 Michael de Raadt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot.'/blocks/progress/lib.php');
/**
* Progress Bar block class
*
* @copyright 2010 Michael de Raadt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_progress extends block_base {
/**
* Sets the block title
*
* @return void
*/
public function init() {
$this->title = get_string('config_default_title', 'block_progress');
}
/**
* Constrols the block title based on instance configuration
*
* @return bool
*/
public function specialization() {
if (isset($this->config->progressTitle) && trim($this->config->progressTitle)!='') {
$this->title = format_string($this->config->progressTitle);
}
}
/**
* Controls whether multiple instances of the block are allowed on a page
*
* @return bool
*/
public function instance_allow_multiple() {
return true;
}
/**
* Defines where the block can be added
*
* @return array
*/
public function applicable_formats() {
return array(
'course-view' => true,
'site' => false,
'mod' => false,
'my' => false
);
}
/**
* Creates the blocks main content
*
* @return string
*/
public function get_content() {
// Access to settings needed
global $USER, $COURSE, $CFG, $DB, $OUTPUT;
// If content has already been generated, don't waste time generating it again
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass;
$this->content->text = '';
$this->content->footer = '';
// Check if any activities/resources have been created
$modules = modules_in_use();
if (empty($modules)) {
if (has_capability('moodle/block:edit', $this->context)) {
$this->content->text .= get_string('no_events_config_message', 'block_progress');
}
return $this->content;
}
// Check if activities/resources have been selected in config
$events = event_information($this->config, $modules);
if ($events===null || $events===0) {
if (has_capability('moodle/block:edit', $this->context)) {
$this->content->text .= get_string('no_events_message', 'block_progress');
if($USER->editing) {
$parameters = array('id'=>$COURSE->id, 'sesskey'=>sesskey(),
'bui_editid'=>$this->instance->id);
$url = new moodle_url('/course/view.php', $parameters);
$label = get_string('selectitemstobeadded', 'block_progress');
$this->content->text .= $OUTPUT->single_button($url, $label);
if ($events===0) {
$url->param('turnallon', '1');
$label = get_string('addallcurrentitems', 'block_progress');
$this->content->text .= $OUTPUT->single_button($url, $label);
}
}
}
return $this->content;
}
else if (empty($events)) {
if (has_capability('moodle/block:edit', $this->context)) {
$this->content->text .= get_string('no_visible_events_message', 'block_progress');
}
return $this->content;
}
// Display progress bar
else {
$attempts = get_attempts($modules, $this->config, $events, $USER->id,
$this->instance->id);
$this->content->text =
progress_bar($modules, $this->config, $events, $USER->id,
$this->instance->id, $attempts);
}
// Organise access to JS
$jsmodule = array(
'name' => 'block_progress',
'fullpath' => '/blocks/progress/module.js',
'requires' => array(),
'strings' => array(
array('time_expected', 'block_progress'),
),
);
$displaydate = !isset($this->config->displayNow) || $this->config->displayNow==1;
$arguments = array($CFG->wwwroot, array_keys($modules), $displaydate);
$this->page->requires->js_init_call('M.block_progress.init', $arguments, false, $jsmodule);
// Allow teachers to access the overview page
if (has_capability('block/progress:overview', $this->context)) {
$parameters = array('id' => $this->instance->id, 'courseid' => $COURSE->id);
$url = new moodle_url('/blocks/progress/overview.php', $parameters);
$label = get_string('overview', 'block_progress');
$this->content->text .= $OUTPUT->single_button($url, $label);
}
return $this->content;
}
}