-
Notifications
You must be signed in to change notification settings - Fork 7
/
resultsstatuspage.class.php
422 lines (372 loc) · 13.2 KB
/
resultsstatuspage.class.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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<?php
/**
* Common page class for role assignments
*
* ELIS(TM): Enterprise Learning Intelligence Suite
* Copyright (C) 2008-2010 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 elis
* @subpackage curriculummanagement
* @author Remote-Learner.net Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2008-2010 Remote Learner.net Inc http://www.remote-learner.net
*/
defined('MOODLE_INTERNAL') || die();
require_once elispm::lib('lib.php');
require_once elispm::lib('page.class.php');
require_once elispm::file('resultspage.class.php');
require_once($CFG->libdir .'/tablelib.php');
/**
* New table class to extend table_sql
*
* We're extending the table so we can format class name and student name columns
*
* @author Remote Learner http://www.remote-learner.net
*/
class table_engine_status extends table_sql {
public $elisurl;
/**
* Standard Constructor
*
* @param string $uniqueid A unique id for the table
* @param string $url The base url for the page
*/
function __construct($uniqueid, $url) {
$this->elisurl = $url;
parent::__construct($uniqueid);
}
/**
* Format the idnumber with a link to the class results
*
* @param object $row A row of data
* @return string The formatted idnumber
*/
function col_idnumber($row) {
$idnumber = $row->idnumber;
if (!$this->download && !empty($row->daterun)) {
$params = array('s' => 'clsenginestatus', 'id' => $row->id);
$url = new moodle_url($this->elisurl, $params);
$idnumber = html_writer::link($url, $row->idnumber);
}
return $idnumber;
}
/**
* Format the actions with each action on a separate line
*
* @param object $row A row of data
* @return string The formatted actions
*/
function col_actions($row) {
$actions = $row->actions;
if (!$this->download) {
$rows = explode(',', $row->actions);
$actions = implode("<br />\n", $rows);
}
return $actions;
}
/**
* Format the run date column to be human readable
*
* @param object $row A row of data
* @return string The formatted date
*/
function col_daterun($row) {
$date = '';
if (! empty($row->daterun)) {
if (is_numeric($row->daterun)) {
$format = get_string('strftimedate');
$date = userdate($row->daterun, $format);
} else {
$date = $row->daterun;
}
}
return $date;
}
/**
* Fullname is treated as a special columname in tablelib and should always
* be treated the same as the fullname of a user.
* @uses $this->useridfield if the userid field is not expected to be id
* then you need to override $this->useridfield to point at the correct
* field for the user id.
*
* ELIS version.
*
*/
function col_fullname($row) {
global $COURSE, $CFG;
if (!$this->download) {
$params = array('s' => 'usr', 'id' => $row->{$this->useridfield}, 'action' => 'view');
$url = new moodle_url($this->elisurl, $params);
if ($COURSE->id != SITEID) {
$url->param('course', $COURSE->id);
}
return html_writer::link($url, elis_fullname($row));
} else {
return elis_fullname($row);
}
}
}
/**
* Abstract class to define engine status pages.
*
* @author Remote Learner http://www.remote-learner.net
*/
abstract class enginestatuspage extends enginepage {
protected $headers = array();
/**
* Build the default navigation bar
*
* @see enginepage::build_navbar_default()
*/
public function build_navbar_default($who = null) {
parent::build_navbar_default();
$id = $this->required_param('id', PARAM_INT);
$page = $this->get_new_page(array('id' => $id), true);
$this->navbar->add(get_string('results_status_report', self::LANG_FILE), $page->url);
}
/**
* Display the default page
*
* @uses $CFG;
*/
function display_default() {
global $CFG;
$id = required_param('id', PARAM_INT);
$title = get_string('results_status_report', self::LANG_FILE);
$params = array($id);
$page = $this->get_new_page(array('id' => $id), true);
$table = new table_engine_status($this->tableid, $this->_get_page_url());
$table->define_columns($this->columns);
$table->define_headers($this->headers);
$table->define_baseurl($page->url);
if (method_exists($this, 'table_filter')) {
$filter = $this->table_filter();
if (isset($filter['where'])) {
$this->where = $filter['where'].' AND '.$this->where;
$params = array_merge($filter['where_parameters'], $params);
}
}
$table->set_sql($this->fields, $this->from, $this->where, $params);
$table->set_count_sql($this->count, $params);
$table->sortable(true, $this->sort);
print('<div class="results enginestatus">');
print_string('results_status_'. $this->type .'_title', self::LANG_FILE, $this->get_title_data());
$table->out(50, false);
print('</div>');
}
/**
* Do the default action
*
* @see enginestatuspage::display_default
*/
function do_default() {
$this->display('default');
}
}
/**
* Engine status page for courses
*
* @author Tyler Bannister <[email protected]>
*/
class course_enginestatuspage extends enginestatuspage {
public $pagename = 'crsenginestatus';
public $type = 'course';
protected $tableid = 'results_engine_course_status';
protected $columns = array('idnumber', 'datescheduled', 'daterun');
protected $fields = 'cc.id, cc.idnumber, MAX(crcl.datescheduled) as datescheduled, MAX(crcl.daterun) as daterun';
protected $from = '{local_elisprogram_cls} cc LEFT JOIN {local_elisprogram_res_clslog} crcl ON crcl.classid=cc.id';
protected $where = 'cc.courseid=? GROUP BY cc.id, cc.idnumber';
protected $count = 'SELECT COUNT(1) FROM {local_elisprogram_cls} WHERE courseid=?';
protected $sort = 'idnumber';
/**
* Constructor
*
* Sets up the language strings for table headers
*
* @param array $params Parameters for parent classes
*/
function __construct($params = null) {
$daterun = get_string('results_date_run', self::LANG_FILE);
$classinstance = get_string('results_class_instance', self::LANG_FILE);
$datescheduled = get_string('results_date_scheduled', self::LANG_FILE);
$this->headers = array($classinstance, $datescheduled, $daterun);
parent::__construct($params);
}
/**
* Return the context that the page is related to. Used by the constructor
* for calling $this->set_context().
* @return object The page context
*/
protected function _get_page_context() {
$id = $this->required_param('id', PARAM_INT);
return \local_elisprogram\context\course::instance($id);
}
/**
* This function returns the page context object
* @return object Course description context ojbect
*/
public function get_context() {
return $this->context;
}
/**
* Get the course id.
*
* @return int The course id
*/
protected function get_course_id() {
return $this->required_param('id', PARAM_INT);
}
/**
* Get parent page object
*
* @return object An object of the same type as the parent page
* @uses $CFG
* @uses $CURMAN
*/
protected function get_parent_page() {
if (!isset($this->parent_page)) {
global $CFG, $CURMAN;
require_once elispm::file('coursepage.class.php');
$id = $this->required_param('id', PARAM_INT);
$this->parent_page = new coursepage(array('id' => $id, 'action' => 'view'));
}
return $this->parent_page;
}
/**
* Get data object for title
*
* @return object An object of the same type as the parent page
* @uses $DB
*/
protected function get_title_data() {
global $DB;
$params = array('id' => $this->required_param('id', PARAM_INT));
$course = $DB->get_record('local_elisprogram_crs', $params, 'id, name');
return $course;
}
/**
* Check if the user can do the default action
*
* @return bool True if the user has permission to use the default action
*/
function can_do_default() {
return has_capability('local/elisprogram:course_view', $this->get_context());
}
/**
* Method to return sql filter for table
* @return array the filter sql and sql parameters
*/
public function table_filter() {
$contexts = pmclasspage::get_contexts('local/elisprogram:class_view');
if ($contexts != null) {
$filterobj = $contexts->get_filter('id', 'class');
return $filterobj->get_sql(false, 'cc');
}
return array('FALSE', array());
}
}
/**
* Engine page for classes
*
* Classes have an extra form field that courses don't have.
*
* @author Tyler Bannister <[email protected]>
*/
class class_enginestatuspage extends enginestatuspage {
public $pagename = 'clsenginestatus';
public $type = 'class';
protected $tableid = 'results_engine_class_status';
protected $columns = array('fullname', 'actions', 'daterun');
protected $fields = 'cu.id, cu.firstname, cu.lastname, GROUP_CONCAT(crsl.action) as actions, MAX(crsl.daterun) as daterun';
protected $from = '{local_elisprogram_cls_enrol} cce JOIN {local_elisprogram_usr} cu ON cu.id=cce.userid LEFT JOIN {local_elisprogram_res_clslog} crcl ON crcl.classid=cce.classid LEFT JOIN {local_elisprogram_res_stulog} crsl ON crsl.userid=cce.userid AND crsl.classlogid=crcl.id';
protected $where = 'cce.classid=? GROUP BY cu.id, cu.firstname, cu.lastname';
protected $count = 'SELECT COUNT(1) FROM {local_elisprogram_cls_enrol} WHERE classid=?';
protected $sort = 'lastname';
/**
* Constructor
*
* Sets up the language strings for table headers
*
* @param array $params Parameters for parent classes
*/
function __construct($params = null) {
$daterun = get_string('results_date_run', self::LANG_FILE);
$student = get_string('defaultcoursestudent');
$actions = get_string('results_actions_performed', self::LANG_FILE);
$this->headers = array($student, $actions, $daterun);
parent::__construct($params);
}
/**
* Return the context that the page is related to. Used by the constructor
* for calling $this->set_context().
* @return object The page context
*/
protected function _get_page_context() {
$id = $this->required_param('id', PARAM_INT);
return \local_elisprogram\context\pmclass::instance($id);
}
/**
* This function returns the page context object
* @return object pmclass context ojbect
*/
public function get_context() {
return $this->context;
}
/**
* Get the course id.
*
* @return int The course id
* @uses $DB
*/
protected function get_course_id() {
global $DB;
$classid = $this->required_param('id', PARAM_INT);
$courseid = $DB->get_field('local_elisprogram_cls', 'courseid', array('id' => $classid));
return $courseid;
}
/**
* Get parent page object
*
* @return object An object of the same type as the parent page
* @uses $CFG
* @uses $CURMAN
*/
protected function get_parent_page() {
if (!isset($this->parent_page)) {
global $CFG, $CURMAN;
require_once elispm::file('pmclasspage.class.php');
$id = $this->required_param('id');
$this->parent_page = new pmclasspage(array('id' => $id, 'action' => 'view'));
}
return $this->parent_page;
}
/**
* Get data object for title
*
* @return object An object of the same type as the parent page
* @uses $DB
*/
protected function get_title_data() {
global $DB;
$sql = 'SELECT cls.id, cls.idnumber, crs.name'
.' FROM {local_elisprogram_cls} cls'
.' JOIN {local_elisprogram_crs} crs ON crs.id = cls.courseid'
.' WHERE cls.id=?';
$params = array('id' => $this->required_param('id', PARAM_INT));
$class = $DB->get_record_sql($sql, $params);
return $class;
}
}