/
completion_table.php
133 lines (121 loc) · 4.54 KB
/
completion_table.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
<?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/>.
/**
* This table displays the user's completions.
* @package block_ps_selfstudy
* @copyright 2015 Andres Ramos
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_table extends table_sql {
/**
* Constructor
* @param int $uniqueid all tables have to have a unique id, this is used
* as a key when storing table properties like sort order in the session.
*/
public function __construct($uniqueid) {
parent::__construct($uniqueid);
// Define the list of columns to show.
$columns = array(
'course_code',
'course_name',
'empctry',
'email',
'firstname',
'completion_date',
'completion_status'
);
// Define the titles of columns to show in header.
$headers = array(
get_string('coursecode', 'block_ps_selfstudy'),
get_string('title', 'block_ps_selfstudy'),
get_string('empserial', 'block_ps_selfstudy'),
get_string('email', 'block_ps_selfstudy'),
get_string('name', 'block_ps_selfstudy'),
get_string('completiondate', 'block_ps_selfstudy'),
get_string('completionstatus', 'block_ps_selfstudy')
);
$this->sortable(true, 'course_code', SORT_ASC);
$this->collapsible(false);
$this->define_columns($columns);
$this->define_headers($headers);
}
/**
* Generate the display of the user's full name column.
* @param object $values the table row being output.
* @return string HTML content to go inside the td.
*/
public function col_firstname($values) {
global $CFG;
// If the data is being downloaded than we don't want to show HTML.
if ($this->is_downloading()) {
$fullname = "$values->firstname $values->lastname";
return $fullname;
} else {
return '<a href="' . $CFG->wwwroot . '/../../../user/profile.php?id='.$values->student_id.'">
'.$values->firstname." ".$values->lastname.'</a>';
}
}
/**
* Generate the display of the user's custom profile field EmpSerialCC.
* @param object $values the table row being output.
* @return string HTML content to go inside the td.
*/
public function col_empctry($values) {
global $DB;
// If the data is being downloaded than we don't want to show HTML.
$empctryid = $DB->get_record(
'user_info_field',
array('shortname' => 'empctry'),
$fields = 'id'
);
if (!empty($empctryid)) {
$empctry = $DB->get_record(
'user_info_data',
array(
'userid' => $values->student_id,
'fieldid' => $empctryid->id
),
$fields = 'data'
);
if (!empty($empctry)) {
return $empctry->data;
} else {
return "";
}
}
}
/**
* Generate the display of the user's completion status.
* @param object $values the table row being output.
* @return string HTML content to go inside the td.
*/
public function col_completion_status($values) {
// If the value is 0, show Pending status.
if ($values->completion_status == "completed") {
return get_string('completed', 'block_ps_selfstudy');
}
}
/**
* Generate the display of the user's completion date.
* @param object $values the table row being output.
* @return string HTML content to go inside the td.
*/
public function col_completion_date($values) {
// Show readable date from timestamp.
$date = $values->completion_date;
return date("m/d/Y", $date);
}
}