-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathblock_elisadmin.php
366 lines (301 loc) · 18.3 KB
/
block_elisadmin.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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<?php
/**
* ELIS(TM): Enterprise Learning Intelligence Suite
* Copyright (C) 2008-2014 Remote-Learner.net Inc (http://www.remote-learner.net)
*
* This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
* @package block_elisadmin
* @author Remote-Learner.net Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2008-2014 Remote Learner.net Inc (http://www.remote-learner.net)
*
*/
require_once($CFG->dirroot.'/local/elisprogram/lib/setup.php');
require_once(elispm::lib('lib.php'));
require_once(elis::plugin_file('block_elisadmin', 'lib.php'));
require_once(elispm::lib('menuitem.class.php'));
require_once(elispm::lib('data/userset.class.php'));
require_once(elispm::lib('deprecatedlib.php'));
/// Add curriculum stylesheets...
/*
if (file_exists($CFG->dirroot.'/curriculum/styles.css')) {
// echo '<link style="text/css" REL=StyleSheet HREF="' . $CFG->wwwroot . '/curriculum/styles.css" />';
$CFG->stylesheets[] = $CFG->wwwroot . '/curriculum/styles.css';
}
*/
class block_elisadmin extends block_base {
var $currentdepth;
var $spancounter;
var $tempcontent;
var $pathtosection;
var $expandjavascript;
var $destination;
function init() {
global $PAGE, $CFG, $DB;
$this->title = get_string('blockname', 'block_elisadmin');
$this->release = elispm::$release;
$this->cron = 300;
$this->currentdepth = 0;
$this->spancounter = 1;
$this->tempcontent = '';
$this->section = (isset($PAGE->section) ? $PAGE->section : '');
$this->pathtosection = array();
$this->expandjavascript = '';
$this->lastcron = $DB->get_field('block', 'lastcron', array('name' => 'elisadmin'));
$this->divcounter = 1;
}
function applicable_formats() {
return array(
'my' => true,
'admin' => true,
'site-index' => true
);
}
function preferred_width() {
return 210;
}
/**
* Are you going to allow multiple instances of each block?
* If yes, then it is assumed that the block WILL USE per-instance configuration
* @return boolean
* @todo finish documenting this function by explaining per-instance configuration further
*/
function instance_allow_multiple() {
// Are you going to allow multiple instances of each block?
// If yes, then it is assumed that the block WILL USE per-instance configuration
return false;
}
function get_content() {
global $CFG, $ADMIN, $USER, $HTTPSPAGEREQUIRED, $PAGE, $DB, $SITE;
require_once($CFG->libdir . '/adminlib.php');
//dependencies on page classes
require_once(elispm::file('usersetpage.class.php'));
require_once(elispm::file('curriculumpage.class.php'));
require_once(elispm::file('coursepage.class.php'));
require_once(elispm::file('trackpage.class.php'));
//require_once($CFG->dirroot . '/my/pagelib.php');
/// Determine the users CM access level.
$access = cm_determine_access($USER->id);
//make sure local_elisprogram / custom contexts set up correctly
//to prevent error before the upgrade to ELIS 2
if (empty($access) || $this->content !== NULL || !defined('CONTEXT_ELIS_PROGRAM')) {
return $this->content;
}
//if we are not on a PM page, disable the expansion of
//entities in the curr admin tree (logic in curriculum/index.php)
if (!is_a($PAGE, 'pm_page') && $PAGE->pagetype != 'admin-setting-local_elisprogram_settings') {
unset($USER->currentitypath);
}
// Include Icon CSS.
$PAGE->requires->css('/local/elisprogram/icons.css');
//CM entities for placement at the top of the menu
$cm_entity_pages = array();
$cm_entity_pages[] = new menuitem('root');
$num_block_icons = isset(elis::$config->local_elisprogram->num_block_icons) ? elis::$config->local_elisprogram->num_block_icons : 5;
/*****************************************
* Clusters
*****************************************/
if (!isset(elis::$config->local_elisprogram->display_clusters_at_top_level) || !empty(elis::$config->local_elisprogram->display_clusters_at_top_level)) {
$manageclusters_css_class = block_elisadmin_get_item_css_class('manageclusters');
$cluster_css_class = block_elisadmin_get_item_css_class('cluster_instance');
require_once elispm::lib('contexts.php');
$context_result = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:userset_view', $USER->id);
$extrafilters = array('contexts' => $context_result,'parent' => 0);
$num_records = cluster_count_records('', '', $extrafilters);
if ($clusters = cluster_get_listing('priority, name', 'ASC', 0, $num_block_icons, '', '', $extrafilters)) {
foreach($clusters as $cluster) {
$params = array('id' => $cluster->id,
'action' => 'view');
//count sub-clusters
$cluster_filter = array('contexts' => usersetpage::get_contexts('local/elisprogram:userset_view'));
$cluster_count = cluster_count_records('', '', array('parent' => $cluster->id), $cluster_filter);
//count associated curricula
$curriculum_filter = array('contexts' => curriculumpage::get_contexts('local/elisprogram:program_view'));
$curriculum_count = clustercurriculum::count_curricula($cluster->id, $curriculum_filter);
$isLeaf = empty($cluster_count) &&
empty($curriculum_count);
$cm_entity_pages[] = block_elisadmin_get_menu_item('userset', $cluster, 'root', $manageclusters_css_class, $cluster->id, 0, $params, $isLeaf);
}
}
if ($num_block_icons < $num_records) {
$cm_entity_pages[] = block_elisadmin_get_menu_summary_item('userset', $cluster_css_class, $num_records - $num_block_icons);
}
}
/*****************************************
* Curricula
*****************************************/
if (!empty(elis::$config->local_elisprogram->display_curricula_at_top_level)) {
// We have to track the number of programs that are added to the tree.
$programcount = 0;
// We also have to track the number of records that don't get filtered.
$validprogramcount = 0;
$managecurricula_css_class = block_elisadmin_get_item_css_class('managecurricula');
$curriculum_css_class = block_elisadmin_get_item_css_class('curriculum_instance');
require_once elispm::file('curriculumpage.class.php');
// Get the records from the db, do not limit by number to display, we'll take care of that below.
$curricula = $DB->get_recordset(curriculum::TABLE, null, 'priority ASC, name ASC', '*');
// Iterate through each record and make it a menu item.
foreach ($curricula as $curriculum) {
$params = array('id' => $curriculum->id,
'action' => 'view');
// Count associated courses.
$course_filter = array('contexts' => coursepage::get_contexts('local/elisprogram:course_view'));
$course_count = curriculumcourse_count_records($curriculum->id, '', '', $course_filter);
// Count associated tracks.
$track_contexts = trackpage::get_contexts('local/elisprogram:track_view');
$track_count = track_count_records('', '', $curriculum->id, 0, $track_contexts);
// Count associated clusters.
$cluster_filter = array('contexts' => usersetpage::get_contexts('local/elisprogram:userset_view'));
$cluster_count = clustercurriculum::count_clusters($curriculum->id, 0, $cluster_filter);
$isLeaf = empty($course_count) &&
empty($track_count) &&
empty($cluster_count);
// Get the menu item.
$thismenuitem = block_elisadmin_get_menu_item('curriculum', $curriculum, 'root', $managecurricula_css_class, 0, $curriculum->id, $params, $isLeaf);
// Increment our record count.
$programcount++;
// Make sure this menu item is allowed to be seen by the user.
if ($thismenuitem->page->page_instance->can_do()) {
// Increment the number of valid menu items.
$validprogramcount++;
// Make sure that we have room for another program item in the menu tree.
if ($validprogramcount <= $num_block_icons) {
// If so, then add this menu item to the array of menu items.
$cm_entity_pages[] = $thismenuitem;
}
}
}
unset($curricula);
// After building the program menu tree see if we have more valid records than we have room.
if ($num_block_icons < $validprogramcount) {
// If so, then we need to add a "X - More Programs" Link to the list.
$cm_entity_pages[] = block_elisadmin_get_menu_summary_item('curriculum', $curriculum_css_class, $validprogramcount - $num_block_icons);
}
}
//general cm pages
$pages = array(
//Dashboard
new menuitem('dashboard', new menuitempage('dashboardpage'), 'root', '', block_elisadmin_get_item_css_class('dashboard')),
//Admin
new menuitem('admn', null, 'root', get_string('admin'), block_elisadmin_get_item_css_class('admn', true))
,
new menuitem('bulkuser', new menuitempage('bulkuserpage'), null, get_string('userbulk', 'admin'), block_elisadmin_get_item_css_class('bulkuser')),
new menuitem('resultsconfig', new menuitempage('resultsconfigpage'), null, 'Default Results Engine Score Settings', block_elisadmin_get_item_css_class('resultsconfig'))
);
// ELIS-3208 - commented out this code as the Jasper reports no longer work in ELIS 2
/*
//show the Jasper report server link if applicable
if (cm_jasper_link_enabled()) {
//page action
$jasper_link_params = array('action' => 'reportslist');
//page instance
$jasper_link_page = new menuitempage('jasperreportpage', '', $jasper_link_params);
//styling for the link
$jasper_link_css = block_elisadmin_get_item_css_class('reportslist');
$pages[] = new menuitem('reportslist', $jasper_link_page, null, '', $jasper_link_css);
}
*/
$pages = array_merge($pages, array(
new menuitem('customfields', new menuitempage('customfieldpage', '', array('level' => 'user')), null, '',
block_elisadmin_get_item_css_class('customfields')),
new menuitem('clusterclassification',
new menuitempage('usersetclassificationpage', 'plugins/usetclassify/usersetclassificationpage.class.php'),
null, get_string('userset_classification', 'elisprogram_usetclassify'), block_elisadmin_get_item_css_class('clusterclassification')),
//Users
new menuitem('users', null, 'root', '', block_elisadmin_get_item_css_class('users', true)),
new menuitem('manageusers', new menuitempage('userpage'), null, '',
block_elisadmin_get_item_css_class('manageusers')),
new menuitem('manageclusters', new menuitempage('usersetpage'), null, '',
block_elisadmin_get_item_css_class('manageclusters')),
//Curriculum
new menuitem('curr', null, 'root', get_string('curriculum', 'local_elisprogram'),
block_elisadmin_get_item_css_class('curr', true)),
new menuitem('certificatelist', new menuitempage('certificatelistpage'), null, '',
block_elisadmin_get_item_css_class('certificatelist')),
new menuitem('managecurricula', new menuitempage('curriculumpage'), null, '',
block_elisadmin_get_item_css_class('managecurricula')),
new menuitem('managecourses', new menuitempage('coursepage'), null, '',
block_elisadmin_get_item_css_class('managecourses')),
new menuitem('manageclasses', new menuitempage('pmclasspage'), null, '',
block_elisadmin_get_item_css_class('manageclasses')),
//Learning Plan
new menuitem('crscat', null, 'root', get_string('learningplan', 'local_elisprogram'),
block_elisadmin_get_item_css_class('crscat', true)),
new menuitem('currentcourses', new menuitempage('coursecatalogpage', '', array('action' => 'current')), null, '',
block_elisadmin_get_item_css_class('currentcourses')),
new menuitem('availablecourses', new menuitempage('coursecatalogpage', '', array('action' => 'available')), null, '',
block_elisadmin_get_item_css_class('availablecourses')),
new menuitem('waitlist', new menuitempage('coursecatalogpage', '', array('action' => 'waitlist')), null,
get_string('waitlistcourses', 'local_elisprogram'), block_elisadmin_get_item_css_class('waitlist')),
//Reports
new menuitem('rept', null, 'root', get_string('reports', 'local_elisprogram'), block_elisadmin_get_item_css_class('rept', true))
));
if (has_capability('moodle/course:managegroups', context_course::instance($SITE->id))) {
if (elis::$config->elisprogram_usetgroups->site_course_userset_groups) {
$pages[] = new menuitem('frontpagegroups', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/group/index.php?id={$SITE->id}"), 'admn', get_string('frontpagegroups', 'elisprogram_usetgroups'), block_elisadmin_get_item_css_class('manageclusters'));
}
if (elis::$config->elisprogram_usetgroups->userset_groupings) {
$pages[] = new menuitem('frontpagegroupings', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/group/groupings.php?id={$SITE->id}"), 'admn', get_string('frontpagegroupings', 'elisprogram_usetgroups'), block_elisadmin_get_item_css_class('manageclusters'));
}
}
/**
* This section adds all the necessary PHP reports to the menu
*/
//get all report pages, including categories but not including the
//topmost report element
$report_pages = block_elisadmin_get_report_tree_items();
//merge in the reporting page links
$pages = array_merge($pages, $report_pages);
if (empty(elis::$config->local_elisprogram->userdefinedtrack)) {
$pages[] = new menuitem('managetracks', new menuitempage('trackpage'), null, '', block_elisadmin_get_item_css_class('managetracks'));
}
$syscontext = context_system::instance();
if (has_capability('local/elisprogram:config', $syscontext)) {
$pages[] = new menuitem('configmanager',
new menuitempage('url_page',
'lib/menuitem.class.php',
"{$CFG->wwwroot}/admin/settings.php?section=local_elisprogram_settings"),
'admn', get_string('configuration'),
block_elisadmin_get_item_css_class('configuration')
);
}
$pages[] = new menuitem('notifications', new menuitempage('notifications', 'notificationspage.class.php', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('notifications'));
//$pages[] = new menuitem('dataimport', new menuitempage('dataimportpage', 'elis_ip/elis_ip_page.php', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('integrationpoint'));
$pages[] = new menuitem('defaultcls', new menuitempage('configclsdefaultpage', '', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('defaultcls'));
$pages[] = new menuitem('defaultcrs', new menuitempage('configcrsdefaultpage', '', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('defaultcrs'));
//turn all pages that have no children into leaf nodes
menuitemlisting::flag_leaf_nodes($pages);
//combine the specific entity page listing with the general CM listing
$menuitemlisting = new menuitemlisting(array_merge($cm_entity_pages, $pages));
$tree = new treerepresentation($menuitemlisting);
$this->content = new stdClass;
$this->content->text = $tree->convert_to_markup();
$this->content->footer = '';
if ($this->is_empty() !== true) {
$PAGE->requires->yui_module('moodle-local_elisprogram-menuitem', 'M.local_elisprogram.init_menuitem', array($tree->get_js_object(), $CFG->httpswwwroot), null, true);
}
return $this->content;
}
/**
* Perform all the regularly scheduled tasks, such as grades updating and reporting.
*
*/
function cron() {
global $CFG;
require_once($CFG->dirroot . '/curriculum/lib/lib.php');
$status = true;
return cm_cron();
}
}