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 |
* All backups table.
|
|
|
19 |
*
|
|
|
20 |
* @package report_allbackups
|
|
|
21 |
* @copyright 2020 Catalyst IT
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
namespace report_allbackups\output;
|
|
|
26 |
|
|
|
27 |
defined('MOODLE_INTERNAL') || die();
|
|
|
28 |
|
|
|
29 |
use moodle_url, html_writer, context_system;
|
|
|
30 |
|
|
|
31 |
require_once($CFG->libdir . '/tablelib.php');
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Table to display list backups.
|
|
|
35 |
*
|
|
|
36 |
* @package report_allbackups
|
|
|
37 |
* @copyright 2020 Catalyst IT
|
|
|
38 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
39 |
*/
|
|
|
40 |
class allbackups_table extends \table_sql {
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* User id field.
|
|
|
44 |
*
|
|
|
45 |
* @var string
|
|
|
46 |
*/
|
|
|
47 |
public $useridfield = 'userid';
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Constructor
|
|
|
51 |
* @param int $uniqueid all tables have to have a unique id, this is used
|
|
|
52 |
* as a key when storing table properties like sort order in the session.
|
|
|
53 |
*/
|
|
|
54 |
public function __construct($uniqueid) {
|
|
|
55 |
global $OUTPUT;
|
|
|
56 |
parent::__construct($uniqueid);
|
|
|
57 |
|
|
|
58 |
if (!optional_param('downloadallselectedfiles', 0, PARAM_ALPHA)) {
|
|
|
59 |
// Set Download flag so we can check it before defining columns/headers to show.
|
|
|
60 |
// Don't set if downloading files.
|
|
|
61 |
$this->is_downloading(optional_param('download', '', PARAM_ALPHA), 'allbackups');
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
// Define the list of columns to show.
|
|
|
65 |
$columns = array();
|
|
|
66 |
$headers = array();
|
|
|
67 |
|
|
|
68 |
// Add selector column if not downloading report.
|
|
|
69 |
if (!$this->is_downloading()) {
|
|
|
70 |
// Add selector column to report.
|
|
|
71 |
$columns[] = 'selector';
|
|
|
72 |
|
|
|
73 |
$options = [
|
|
|
74 |
'id' => 'check-items',
|
|
|
75 |
'name' => 'check-items',
|
|
|
76 |
'value' => 1,
|
|
|
77 |
];
|
|
|
78 |
$mastercheckbox = new \core\output\checkbox_toggleall('items', true, $options);
|
|
|
79 |
|
|
|
80 |
$headers[] = $OUTPUT->render($mastercheckbox);
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
$columns = array_merge($columns, array('component', 'filearea', 'filename', 'filesize', 'fullname', 'timecreated'));
|
|
|
84 |
$headers = array_merge($headers, array(get_string('component', 'report_allbackups'),
|
|
|
85 |
get_string('filearea', 'report_allbackups'),
|
|
|
86 |
get_string('name'),
|
|
|
87 |
get_string('size'),
|
|
|
88 |
get_string('user'),
|
|
|
89 |
get_string('date')));
|
|
|
90 |
|
|
|
91 |
// Add actions column if not downloading this report.
|
|
|
92 |
if (!$this->is_downloading()) {
|
|
|
93 |
array_push($columns, 'action');
|
|
|
94 |
array_push($headers, get_string('action'));
|
|
|
95 |
}
|
|
|
96 |
$this->define_columns($columns);
|
|
|
97 |
$this->define_headers($headers);
|
|
|
98 |
$this->no_sorting('action');
|
|
|
99 |
$this->no_sorting('selector');
|
|
|
100 |
$this->initialbars(false);
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/**
|
|
|
104 |
* Function to display the checkbox for bulk actions.
|
|
|
105 |
*
|
|
|
106 |
* @param object $row the data from the db containing all fields from the current row.
|
|
|
107 |
* @return string
|
|
|
108 |
*/
|
|
|
109 |
public function col_selector($row) {
|
|
|
110 |
global $OUTPUT;
|
|
|
111 |
if ($this->is_downloading()) {
|
|
|
112 |
return '';
|
|
|
113 |
}
|
|
|
114 |
$options = [
|
|
|
115 |
'id' => 'item'.$row->id,
|
|
|
116 |
'name' => 'item'.$row->id,
|
|
|
117 |
'value' => $row->id,
|
|
|
118 |
];
|
|
|
119 |
$itemcheckbox = new \core\output\checkbox_toggleall('items', false, $options);
|
|
|
120 |
return $OUTPUT->render($itemcheckbox);
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
/**
|
|
|
124 |
* Function to display the available actions for each record.
|
|
|
125 |
*
|
|
|
126 |
* @param object $row the data from the db containing all fields from the current row.
|
|
|
127 |
* @return string
|
|
|
128 |
*/
|
|
|
129 |
public function col_action($row) {
|
|
|
130 |
$context = \context_system::instance();
|
|
|
131 |
$fileurl = moodle_url::make_pluginfile_url(
|
|
|
132 |
$row->contextid,
|
|
|
133 |
$row->component,
|
|
|
134 |
$row->filearea,
|
|
|
135 |
null,
|
|
|
136 |
$row->filepath,
|
|
|
137 |
$row->filename,
|
|
|
138 |
true
|
|
|
139 |
);
|
|
|
140 |
$output = \html_writer::link($fileurl, get_string('download'));
|
|
|
141 |
|
|
|
142 |
if (has_capability('moodle/restore:restorecourse', $context)) {
|
|
|
143 |
$params = array();
|
|
|
144 |
$params['action'] = 'choosebackupfile';
|
|
|
145 |
$params['filename'] = $row->filename;
|
|
|
146 |
$params['filepath'] = $row->filepath;
|
|
|
147 |
$params['component'] = $row->component;
|
|
|
148 |
$params['filearea'] = $row->filearea;
|
|
|
149 |
$params['filecontextid'] = $row->contextid;
|
|
|
150 |
$params['contextid'] = context_system::instance()->id;
|
|
|
151 |
$params['itemid'] = $row->itemid;
|
|
|
152 |
$restoreurl = new moodle_url('/backup/restorefile.php', $params);
|
|
|
153 |
|
|
|
154 |
$output .= ' | '. html_writer::link($restoreurl, get_string('restore'));
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
if (has_capability('report/allbackups:delete', $context)) {
|
|
|
158 |
$params = array('delete' => $row->id, 'filename' => $row->filename);
|
|
|
159 |
$deleteurl = new moodle_url('/report/allbackups/index.php', $params);
|
|
|
160 |
$output .= ' | '. html_writer::link($deleteurl, get_string('delete'));
|
|
|
161 |
}
|
|
|
162 |
return $output;
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
/**
|
|
|
166 |
* Function to display the human readable filesize of this file.
|
|
|
167 |
*
|
|
|
168 |
* @param object $row the data from the db containing all fields from the current row.
|
|
|
169 |
* @return string
|
|
|
170 |
*/
|
|
|
171 |
public function col_filesize($row) {
|
|
|
172 |
return display_size($row->filesize);
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
/**
|
|
|
176 |
* Function to display the human readable time this file was created.
|
|
|
177 |
*
|
|
|
178 |
* @param object $row the data from the db containing all fields from the current row.
|
|
|
179 |
* @return string
|
|
|
180 |
*/
|
|
|
181 |
public function col_timecreated($row) {
|
|
|
182 |
return userdate($row->timecreated);
|
|
|
183 |
}
|
|
|
184 |
}
|