This repository has been archived by the owner on May 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
block_ajax_marking.php
executable file
·336 lines (300 loc) · 13.1 KB
/
block_ajax_marking.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<?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/>.
/**
* Main block file
*
* @package block
* @subpackage ajax_marking
* @copyright 2008 Matt Gibson
* @author Matt Gibson {@link http://moodle.org/user/view.php?id=81450}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/blocks/ajax_marking/lib.php');
/**
* This class builds a marking block on the front page which loads assignments and submissions
* dynamically into a tree structure using AJAX. All marking occurs in pop-up windows and each node
* removes itself from the tree after its pop up is graded.
*
* @copyright 2008-2010 Matt Gibson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_ajax_marking extends block_base {
/**
* Standard init function, sets block title and version number
*
* @return void
*/
public function init() {
$this->title = get_string('ajaxmarking', 'block_ajax_marking');
}
/**
* Standard specialization function
*
* @return void
*/
public function specialization() {
$this->title = get_string('marking', 'block_ajax_marking');
}
/**
* Standard function to determine where block can be placed
*
* @return array
*/
public function applicable_formats() {
return array(
'site-index' => false,
'course-view' => true,
'course-view-social' => false,
'mod' => true,
'my' => false
);
}
/**
* Standard get content function returns $this->content containing the block HTML etc
*
* @return bool|\stdClass
*/
public function get_content() {
global $CFG, $PAGE;
if (!isloggedin()) {
// Save all the DB stuff for the non-logged in front page.
return false;
}
$modclasses = block_ajax_marking_get_module_classes();
// If the user has switched role, we want to hide the block if the role would not normally
// see the block. Normally, we don't check at this level so that we can have overrides
// at module level.
if (!empty($PAGE->course->id) && is_role_switched($PAGE->course->id)) {
$canseeblock = false;
foreach ($modclasses as $mod) {
if (has_capability($mod->get_capability(), $PAGE->context)) {
$canseeblock = true;
}
if (!$canseeblock) {
return false;
}
}
}
if ($this->content !== null) {
return $this->content;
}
require_once($CFG->dirroot.'/blocks/ajax_marking/lib.php');
$courses = block_ajax_marking_get_my_teacher_courses();
// Grading permissions exist in at least one course, so display.
if (count($courses) > 0 || block_ajax_marking_admin_see_all()) {
$this->content = new stdClass();
// Start building content output.
$this->content->footer = '';
$this->content->text = '<div id="block_ajax_marking">';
// Add a style to hide the HTML list and prevent flicker.
$this->content->text .= $this->anti_flicker_js();
// Add the basic HTML for the rest of the stuff to fit into.
$divs = '
<div id="block_ajax_marking_hidden">
<div id="dynamicicons">';
$divs .= $this->get_dynamic_icons_html();
$divs .= '
</div>
</div>
<div id="treetabs"></div>
<div id="block_ajax_marking_error"></div>';
$this->content->text .= $divs;
// Don't warn about javascript if the screenreader option is set - it was deliberate.
$noscript = '<noscript>
<p>'.
get_string('nojavascript', 'block_ajax_marking').
'</p>
</noscript>';
$this->content->text .= $noscript;
$this->content->text .= ' <div class="block_ajax_marking_spacer"></div>'.
'</div>'; // End of #block_ajax_marking container.
// Set things going.
$PAGE->requires->js_init_call('M.block_ajax_marking.init_block', array(), true,
$this->js_module());
// We need to append all of the plugin specific javascript. This file will be
// requested as part of a separate http request after the PHP has all been finished
// with, so we do this cheaply to keep overheads low by not using setup.php and
// having the js in static functions.
foreach (array_keys($modclasses) as $modname) {
$filename = '/blocks/ajax_marking/modules/'.$modname.'/'.$modname.'.js';
if (file_exists($CFG->dirroot.$filename)) {
$PAGE->requires->js($filename);
}
}
} else {
// No grading permissions in any courses - don't display the block (student). Exception.
// for when the block is just installed and the user can edit. Might look broken
// otherwise.
if (has_capability('moodle/course:manageactivities', $PAGE->context)) {
$this->content = new stdClass();
$this->content->text .= get_string('nogradedassessments', 'block_ajax_marking');
} else {
// This will stop the other functions like has_content() from running all the way
// through this again.
$this->content = false;
}
}
return $this->content;
}
/**
* Standard function - does the block allow configuration for specific instances of itself
* rather than site-wide?
*
* @return bool false
*/
public function instance_allow_config() {
return false;
}
/**
*
* We need a rendered icon for each node type. We can't rely on CSS to do this
* as there is no mechanism for generating it dynamically, i.e. having an arbitrary
* number of CSS rules generated, one for each module plugin. These icons are
* transplanted using JS to the nodes as needed.
*
* @return string HTML
*/
private function get_dynamic_icons_html() {
global $OUTPUT;
$modclasses = block_ajax_marking_get_module_classes();
$html = '';
foreach (array_keys($modclasses) as $modname) {
$html .= '<img id="block_ajax_marking_'.$modname.'_icon"
class="dynamicicon"
src="'.$OUTPUT->pix_url('icon', $modname).'"
alt="'.$modname.'"
title="'.$modname.'" />';
}
$html .= '<img id="block_ajax_marking_course_icon" class="dynamicicon"
src="'.$OUTPUT->pix_url('c/course').'"
alt="'.get_string('course').'"
title="'.get_string('course').'" />';
$html .= '<img id="block_ajax_marking_group_icon" class="dynamicicon"
src="'.$OUTPUT->pix_url('c/group').'"
alt="'.get_string('group').'"
title="'.get_string('group').'" />';
$html .= '<img id="block_ajax_marking_cohort_icon" class="dynamicicon"
src="'.$OUTPUT->pix_url('c/group').'"
alt="'.get_string('cohort', 'cohort').'"
title="'.get_string('cohort', 'cohort').'" />';
$html .= '<img id="block_ajax_marking_hide_icon" class="dynamicicon"
src="'.$OUTPUT->pix_url('t/hide').'"
alt="'.get_string('hide').'"
title="'.get_string('hide').'" />';
$html .= '<img id="block_ajax_marking_show_icon" class="dynamicicon"
src="'.$OUTPUT->pix_url('t/show').'"
alt="'.get_string('show').'"
title="'.get_string('show').'" />';
$html .= '<img id="block_ajax_marking_showgroups_icon" class="dynamicicon"
src="'.$OUTPUT->pix_url('group-disabled', 'block_ajax_marking').'"
alt="'.get_string('showgroups', 'block_ajax_marking').'"
title="'.get_string('showgroups', 'block_ajax_marking').'" />';
$html .= '<img id="block_ajax_marking_hidegroups_icon" class="dynamicicon"
src="'.$OUTPUT->pix_url('group', 'block_ajax_marking').'"
alt="'.get_string('hidegroups', 'block_ajax_marking').'"
title="'.get_string('hidegroups', 'block_ajax_marking').'" />';
return $html;
}
/**
* Provides the inline javascript to hide stuff whilst the page is loading, preventing
* flicker.
*
* @return string Script tag
*/
private function anti_flicker_js() {
return '<script type="text/javascript" defer="defer">
/* <![CDATA[ */
var styleElement = document.createElement("style");
styleElement.type = "text/css";
var hidehtml = "#block_ajax_marking_html_list, "+
"#treetabs, "+
"#totalmessage {display: none;}";
if (styleElement.styleSheet) {
styleElement.styleSheet.cssText = hidehtml;
} else {
styleElement.appendChild(document.createTextNode(hidehtml));
}
document.getElementsByTagName("head")[0].appendChild(styleElement);
/* ]]> */</script>';
}
/**
* Provides the definition for the javascript module for the page to include
*
* @return array
*/
private function js_module() {
// Set up the javascript module, with any data that the JS will need.
return array(
'name' => 'block_ajax_marking',
'fullpath' => '/blocks/ajax_marking/yui/mainwidget/mainwidget.js',
'requires' => array(
'moodle-block_ajax_marking-mainwidget'
),
'strings' => array(
array('totaltomark',
'block_ajax_marking'),
array('nogradedassessments',
'block_ajax_marking'),
array('nothingtomark',
'block_ajax_marking'),
array('refresh',
'block_ajax_marking'),
array('configure',
'block_ajax_marking'),
array('connectfail',
'block_ajax_marking'),
array('connecttimeout',
'block_ajax_marking'),
array('nogroups',
'block_ajax_marking'),
array('showthisactivity',
'block_ajax_marking'),
array('showthiscourse',
'block_ajax_marking'),
array('showwithgroups',
'block_ajax_marking'),
array('hidethisactivity',
'block_ajax_marking'),
array('hidethiscourse',
'block_ajax_marking'),
array('hidethiscourse',
'block_ajax_marking'),
array('show',
'block_ajax_marking'),
array('showgroups',
'block_ajax_marking'),
array('choosegroups',
'block_ajax_marking'),
array('recentitems',
'block_ajax_marking'),
array('mediumitems',
'block_ajax_marking'),
array('overdueitems',
'block_ajax_marking'),
array('errorcontactadmin',
'block_ajax_marking'),
array('recentitem',
'block_ajax_marking'),
array('mediumitem',
'block_ajax_marking'),
array('overdueitem',
'block_ajax_marking')
)
);
}
}