1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* this file contains the status table class to display certain users statusses.
|
|
|
19 |
*
|
|
|
20 |
* File logtable.php
|
|
|
21 |
* Encoding UTF-8
|
|
|
22 |
* @copyright Sebsoft.nl
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace tool_usersuspension;
|
|
|
27 |
|
|
|
28 |
defined('MOODLE_INTERNAL') || die;
|
|
|
29 |
require_once($CFG->libdir . '/tablelib.php');
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* tool_usersuspension\logtable
|
|
|
33 |
*
|
|
|
34 |
* @package tool_usersuspension
|
|
|
35 |
*
|
|
|
36 |
* @copyright Sebsoft.nl
|
|
|
37 |
* @author R.J. van Dongen <rogier@sebsoft.nl>
|
|
|
38 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
39 |
*/
|
|
|
40 |
class logtable extends \table_sql {
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Localised 'suspended' string
|
|
|
44 |
*
|
|
|
45 |
* @var string
|
|
|
46 |
*/
|
|
|
47 |
protected $strsuspended;
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Localised 'unsuspended' string
|
|
|
51 |
*
|
|
|
52 |
* @var string
|
|
|
53 |
*/
|
|
|
54 |
protected $strunsuspended;
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Localised 'deleted' string
|
|
|
58 |
*
|
|
|
59 |
* @var string
|
|
|
60 |
*/
|
|
|
61 |
protected $strdeleted;
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* Do we render the history or the current status?
|
|
|
65 |
*
|
|
|
66 |
* @var bool
|
|
|
67 |
*/
|
|
|
68 |
protected $showhistory;
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* Create a new instance of the logtable
|
|
|
72 |
*
|
|
|
73 |
* @param bool $showhistory if true, shows historic statusses. If false shows current statusses
|
|
|
74 |
*/
|
|
|
75 |
public function __construct($showhistory = true) {
|
|
|
76 |
global $USER;
|
|
|
77 |
parent::__construct(__CLASS__. '-' . $USER->id . '-' . ((int)$showhistory));
|
|
|
78 |
$this->showhistory = (bool)$showhistory;
|
|
|
79 |
$this->strsuspended = get_string('status:suspended', 'tool_usersuspension');
|
|
|
80 |
$this->strunsuspended = get_string('status:unsuspended', 'tool_usersuspension');
|
|
|
81 |
$this->strdeleted = get_string('status:deleted', 'tool_usersuspension');
|
|
|
82 |
$this->no_sorting('action');
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* Set the sql to query the db.
|
|
|
87 |
* This method is disabled for this class, since we use internal queries
|
|
|
88 |
*
|
|
|
89 |
* @param string $fields
|
|
|
90 |
* @param string $from
|
|
|
91 |
* @param string $where
|
|
|
92 |
* @param array $params
|
|
|
93 |
* @throws exception
|
|
|
94 |
*/
|
|
|
95 |
public function set_sql($fields, $from, $where, array $params = null) {
|
|
|
96 |
// We'll disable this method.
|
|
|
97 |
throw new exception('err:statustable:set_sql');
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* Display the general status log table.
|
|
|
102 |
*
|
|
|
103 |
* @param int $pagesize
|
|
|
104 |
* @param bool $useinitialsbar
|
|
|
105 |
*/
|
|
|
106 |
public function render_log($pagesize, $useinitialsbar = true) {
|
|
|
107 |
global $DB;
|
|
|
108 |
$this->define_columns(array('userid', 'name', 'status', 'mailsent', 'mailedto', 'timecreated', 'action'));
|
|
|
109 |
$this->define_headers(array(
|
|
|
110 |
get_string('thead:userid', 'tool_usersuspension'),
|
|
|
111 |
get_string('thead:name', 'tool_usersuspension'),
|
|
|
112 |
get_string('thead:status', 'tool_usersuspension'),
|
|
|
113 |
get_string('thead:mailsent', 'tool_usersuspension'),
|
|
|
114 |
get_string('thead:mailedto', 'tool_usersuspension'),
|
|
|
115 |
get_string('thead:timecreated', 'tool_usersuspension'),
|
|
|
116 |
get_string('thead:action', 'tool_usersuspension'))
|
|
|
117 |
);
|
|
|
118 |
$fields = 'l.id,l.userid,' . $DB->sql_fullname('u.firstname', 'u.lastname') .
|
|
|
119 |
' AS name,l.status,l.mailsent,l.mailedto,l.timecreated,NULL AS action';
|
|
|
120 |
$table = ($this->showhistory ? 'tool_usersuspension_log' : 'tool_usersuspension_status');
|
|
|
121 |
$from = '{' . $table . '} l LEFT JOIN {user} u ON l.userid=u.id';
|
|
|
122 |
$where = '1 = 1';
|
|
|
123 |
$params = []; // Moodle3.8: _must_ be array now?
|
|
|
124 |
parent::set_sql($fields, $from, $where, $params);
|
|
|
125 |
$this->out($pagesize, $useinitialsbar);
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
/**
|
|
|
129 |
* Render visual representation of the 'timecreated' column for use in the table
|
|
|
130 |
*
|
|
|
131 |
* @param \stdClass $row
|
|
|
132 |
* @return string time string
|
|
|
133 |
*/
|
|
|
134 |
public function col_timecreated($row) {
|
|
|
135 |
return userdate($row->timecreated);
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
/**
|
|
|
139 |
* Render visual representation of the 'status' column for use in the table
|
|
|
140 |
*
|
|
|
141 |
* @param \stdClass $row
|
|
|
142 |
* @return string time string
|
|
|
143 |
*/
|
|
|
144 |
public function col_status($row) {
|
|
|
145 |
$var = 'str' . $row->status;
|
|
|
146 |
return isset($this->{$var}) ? $this->{$var} : $row->status;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
* Render visual representation of the 'action' column for use in the table
|
|
|
151 |
*
|
|
|
152 |
* @param \stdClass $row
|
|
|
153 |
* @return string actions
|
|
|
154 |
*/
|
|
|
155 |
public function col_action($row) {
|
|
|
156 |
$actions = array();
|
|
|
157 |
return implode('', $actions);
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
/**
|
|
|
161 |
* Return the image tag representing an action image
|
|
|
162 |
*
|
|
|
163 |
* @param string $action
|
|
|
164 |
* @return string HTML image tag
|
|
|
165 |
*/
|
|
|
166 |
protected function get_action_image($action) {
|
|
|
167 |
global $OUTPUT;
|
|
|
168 |
return '<img src="' . $OUTPUT->image_url($action, 'tool_usersuspension') . '"/>';
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
/**
|
|
|
172 |
* Return a string containing the link to an action
|
|
|
173 |
*
|
|
|
174 |
* @param \stdClass $row
|
|
|
175 |
* @param string $action
|
|
|
176 |
* @return string link representing the action with an image
|
|
|
177 |
*/
|
|
|
178 |
protected function get_action($row, $action) {
|
|
|
179 |
$actionstr = 'str' . $action;
|
|
|
180 |
return '<a href="' . new \moodle_url($this->baseurl,
|
|
|
181 |
array('action' => $action, 'id' => $row->id, 'sesskey' => sesskey())) .
|
|
|
182 |
'" alt="' . $this->{$actionstr} .
|
|
|
183 |
'">' . $this->get_action_image($action) . '</a>';
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
}
|