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 |
* List of deprecated mod_data functions.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_data
|
|
|
21 |
* @copyright 2021 Jun Pataleta
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
1441 |
ariadna |
26 |
* @deprecated since Moodle 4.1 MDL-75146 - please do not use this function any more.
|
1 |
efrain |
27 |
*/
|
1441 |
ariadna |
28 |
#[\core\attribute\deprecated(
|
|
|
29 |
'mod_data\manager::get_template and mod_data\template::parse_entries',
|
|
|
30 |
since: '4.1',
|
|
|
31 |
mdl: 'MDL-75146',
|
|
|
32 |
final: true,
|
|
|
33 |
)]
|
|
|
34 |
function data_print_template(): void {
|
|
|
35 |
\core\deprecation::emit_deprecation(__FUNCTION__);
|
1 |
efrain |
36 |
}
|
|
|
37 |
|
|
|
38 |
/**
|
1441 |
ariadna |
39 |
* @deprecated since Moodle 4.1 MDL-75148 - please, use the preset::get_name_from_plugin() function instead.
|
|
|
40 |
*/
|
|
|
41 |
#[\core\attribute\deprecated('mod_data\preset::get_name_from_plugin()', since: '4.1', mdl: 'MDL-75148', final: true)]
|
|
|
42 |
function data_preset_name(): void {
|
|
|
43 |
\core\deprecation::emit_deprecation(__FUNCTION__);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* @deprecated since Moodle 4.1 MDL-75148 - please, use the manager::get_available_presets() function instead.
|
|
|
48 |
*/
|
|
|
49 |
#[\core\attribute\deprecated('mod_data\manager::get_available_presets()', since: '4.1', mdl: 'MDL-75148', final: true)]
|
|
|
50 |
function data_get_available_presets(): void {
|
|
|
51 |
\core\deprecation::emit_deprecation(__FUNCTION__);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* @deprecated since Moodle 4.1 MDL-75148 - please, use the manager::get_available_saved_presets() function instead.
|
|
|
56 |
*/
|
|
|
57 |
#[\core\attribute\deprecated('mod_data\manager::get_available_saved_presets()', since: '4.1', mdl: 'MDL-75148', final: true)]
|
|
|
58 |
function data_get_available_site_presets(): void {
|
|
|
59 |
\core\deprecation::emit_deprecation(__FUNCTION__);
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* @deprecated since Moodle 4.1 MDL-75187 - please, use the preset::delete() function instead.
|
|
|
64 |
*/
|
|
|
65 |
#[\core\attribute\deprecated('mod_data\preset::delete()', since: '4.1', mdl: 'MDL-75187', final: true)]
|
|
|
66 |
function data_delete_site_preset(): void {
|
|
|
67 |
\core\deprecation::emit_deprecation(__FUNCTION__);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* @deprecated since Moodle 4.1 MDL-75142 - please, use the preset::save() function instead.
|
|
|
72 |
*/
|
|
|
73 |
#[\core\attribute\deprecated('mod_data\preset::save()', since: '4.1', mdl: 'MDL-75142', final: true)]
|
|
|
74 |
function data_presets_save(): void {
|
|
|
75 |
\core\deprecation::emit_deprecation(__FUNCTION__);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* @deprecated since Moodle 4.1 MDL-75142 - please, use the protected preset::generate_preset_xml() function instead.
|
|
|
80 |
*/
|
|
|
81 |
#[\core\attribute\deprecated('mod_data\preset::generate_preset_xml()', since: '4.1', mdl: 'MDL-75142', final: true)]
|
|
|
82 |
function data_presets_generate_xml(): void {
|
|
|
83 |
\core\deprecation::emit_deprecation(__FUNCTION__);
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
* @deprecated since Moodle 4.1 MDL-75142 - please, use the preset::export() function instead.
|
|
|
88 |
*/
|
|
|
89 |
#[\core\attribute\deprecated('mod_data\preset::export()', since: '4.1', mdl: 'MDL-75142', final: true)]
|
|
|
90 |
function data_presets_export(): void {
|
|
|
91 |
\core\deprecation::emit_deprecation(__FUNCTION__);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* @deprecated since Moodle 4.1 MDL-75187 - please, use the preset::can_manage() function instead.
|
|
|
96 |
*/
|
|
|
97 |
#[\core\attribute\deprecated('mod_data\preset::can_manage()', since: '4.1', mdl: 'MDL-75187', final: true)]
|
|
|
98 |
function data_user_can_delete_preset(): void {
|
|
|
99 |
\core\deprecation::emit_deprecation(__FUNCTION__);
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
/**
|
|
|
103 |
* @deprecated since Moodle 4.1 MDL-75146 - please do not use this function any more.
|
|
|
104 |
*/
|
|
|
105 |
#[\core\attribute\deprecated('mod_data\manager::set_module_viewed', since: '4.1', mdl: 'MDL-75146', final: true)]
|
|
|
106 |
function data_view(): void {
|
|
|
107 |
\core\deprecation::emit_deprecation(__FUNCTION__);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* @deprecated since Moodle 4.1 MDL-75148 - please, use the preset::is_directory_a_preset() function instead.
|
|
|
112 |
*/
|
|
|
113 |
#[\core\attribute\deprecated('mod_data\preset::is_directory_a_preset()', since: '4.1', mdl: 'MDL-75148', final: true)]
|
|
|
114 |
function is_directory_a_preset(): void {
|
|
|
115 |
\core\deprecation::emit_deprecation(__FUNCTION__);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
/**
|
1 |
efrain |
119 |
* @deprecated since Moodle 4.3.
|
|
|
120 |
* @global object
|
|
|
121 |
* @param array $export
|
|
|
122 |
* @param string $dataname
|
|
|
123 |
* @param int $count
|
|
|
124 |
* @return string
|
|
|
125 |
*/
|
|
|
126 |
function data_export_xls($export, $dataname, $count) {
|
|
|
127 |
global $CFG;
|
|
|
128 |
|
|
|
129 |
debugging('Function data_export_xls() has been deprecated, because xls export has been dropped.',
|
|
|
130 |
DEBUG_DEVELOPER);
|
|
|
131 |
require_once("$CFG->libdir/excellib.class.php");
|
|
|
132 |
$filename = clean_filename("{$dataname}-{$count}_record");
|
|
|
133 |
if ($count > 1) {
|
|
|
134 |
$filename .= 's';
|
|
|
135 |
}
|
|
|
136 |
$filename .= clean_filename('-' . gmdate("Ymd_Hi"));
|
|
|
137 |
$filename .= '.xls';
|
|
|
138 |
|
|
|
139 |
$filearg = '-';
|
|
|
140 |
$workbook = new MoodleExcelWorkbook($filearg);
|
|
|
141 |
$workbook->send($filename);
|
|
|
142 |
$worksheet = array();
|
|
|
143 |
$worksheet[0] = $workbook->add_worksheet('');
|
|
|
144 |
$rowno = 0;
|
|
|
145 |
foreach ($export as $row) {
|
|
|
146 |
$colno = 0;
|
|
|
147 |
foreach($row as $col) {
|
|
|
148 |
$worksheet[0]->write($rowno, $colno, $col);
|
|
|
149 |
$colno++;
|
|
|
150 |
}
|
|
|
151 |
$rowno++;
|
|
|
152 |
}
|
|
|
153 |
$workbook->close();
|
|
|
154 |
return $filename;
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
/**
|
|
|
158 |
* @deprecated since Moodle 4.3, exporting is now being done by \mod_data\local\exporter\csv_entries_exporter
|
|
|
159 |
* @global object
|
|
|
160 |
* @param array $export
|
|
|
161 |
* @param string $delimiter_name
|
|
|
162 |
* @param object $database
|
|
|
163 |
* @param int $count
|
|
|
164 |
* @param bool $return
|
|
|
165 |
* @return string|void
|
|
|
166 |
*/
|
|
|
167 |
function data_export_csv($export, $delimiter_name, $database, $count, $return=false) {
|
|
|
168 |
global $CFG;
|
|
|
169 |
|
|
|
170 |
debugging('Function data_export_csv has been deprecated. Exporting is now being done by '
|
|
|
171 |
. '\mod_data\local\csv_exporter.', DEBUG_DEVELOPER);
|
|
|
172 |
require_once($CFG->libdir . '/csvlib.class.php');
|
|
|
173 |
|
|
|
174 |
$filename = $database . '-' . $count . '-record';
|
|
|
175 |
if ($count > 1) {
|
|
|
176 |
$filename .= 's';
|
|
|
177 |
}
|
|
|
178 |
if ($return) {
|
|
|
179 |
return csv_export_writer::print_array($export, $delimiter_name, '"', true);
|
|
|
180 |
} else {
|
|
|
181 |
csv_export_writer::download_array($filename, $export, $delimiter_name);
|
|
|
182 |
}
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
/**
|
|
|
186 |
* @deprecated since Moodle 4.3, exporting is now being done by \mod_data\local\exporter\ods_entries_exporter
|
|
|
187 |
* @global object
|
|
|
188 |
* @param array $export
|
|
|
189 |
* @param string $dataname
|
|
|
190 |
* @param int $count
|
|
|
191 |
* @param string
|
|
|
192 |
*/
|
|
|
193 |
function data_export_ods($export, $dataname, $count) {
|
|
|
194 |
global $CFG;
|
|
|
195 |
|
|
|
196 |
debugging('Function data_export_ods has been deprecated. Exporting is now being done by '
|
|
|
197 |
. '\mod_data\local\ods_exporter.', DEBUG_DEVELOPER);
|
|
|
198 |
require_once("$CFG->libdir/odslib.class.php");
|
|
|
199 |
$filename = clean_filename("{$dataname}-{$count}_record");
|
|
|
200 |
if ($count > 1) {
|
|
|
201 |
$filename .= 's';
|
|
|
202 |
}
|
|
|
203 |
$filename .= clean_filename('-' . gmdate("Ymd_Hi"));
|
|
|
204 |
$filename .= '.ods';
|
|
|
205 |
$filearg = '-';
|
|
|
206 |
$workbook = new MoodleODSWorkbook($filearg);
|
|
|
207 |
$workbook->send($filename);
|
|
|
208 |
$worksheet = array();
|
|
|
209 |
$worksheet[0] = $workbook->add_worksheet('');
|
|
|
210 |
$rowno = 0;
|
|
|
211 |
foreach ($export as $row) {
|
|
|
212 |
$colno = 0;
|
|
|
213 |
foreach($row as $col) {
|
|
|
214 |
$worksheet[0]->write($rowno, $colno, $col);
|
|
|
215 |
$colno++;
|
|
|
216 |
}
|
|
|
217 |
$rowno++;
|
|
|
218 |
}
|
|
|
219 |
$workbook->close();
|
|
|
220 |
return $filename;
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
/**
|
|
|
224 |
* @deprecated since Moodle 4.3, use \mod_data\local\exporter\utils::data_exportdata with a \mod_data\local\exporter\entries_exporter object
|
|
|
225 |
* @global object
|
|
|
226 |
* @param int $dataid
|
|
|
227 |
* @param array $fields
|
|
|
228 |
* @param array $selectedfields
|
|
|
229 |
* @param int $currentgroup group ID of the current group. This is used for
|
|
|
230 |
* exporting data while maintaining group divisions.
|
|
|
231 |
* @param object $context the context in which the operation is performed (for capability checks)
|
|
|
232 |
* @param bool $userdetails whether to include the details of the record author
|
|
|
233 |
* @param bool $time whether to include time created/modified
|
|
|
234 |
* @param bool $approval whether to include approval status
|
|
|
235 |
* @param bool $tags whether to include tags
|
|
|
236 |
* @return array
|
|
|
237 |
*/
|
|
|
238 |
function data_get_exportdata($dataid, $fields, $selectedfields, $currentgroup=0, $context=null,
|
|
|
239 |
$userdetails=false, $time=false, $approval=false, $tags = false) {
|
|
|
240 |
global $DB;
|
|
|
241 |
|
|
|
242 |
debugging('Function data_get_exportdata has been deprecated. Use '
|
|
|
243 |
. '\mod_data\local\exporter_utils::data_exportdata with a \mod_data\local\exporter object instead',
|
|
|
244 |
DEBUG_DEVELOPER);
|
|
|
245 |
|
|
|
246 |
if (is_null($context)) {
|
|
|
247 |
$context = context_system::instance();
|
|
|
248 |
}
|
|
|
249 |
// exporting user data needs special permission
|
|
|
250 |
$userdetails = $userdetails && has_capability('mod/data:exportuserinfo', $context);
|
|
|
251 |
|
|
|
252 |
$exportdata = array();
|
|
|
253 |
|
|
|
254 |
// populate the header in first row of export
|
|
|
255 |
foreach($fields as $key => $field) {
|
|
|
256 |
if (!in_array($field->field->id, $selectedfields)) {
|
|
|
257 |
// ignore values we aren't exporting
|
|
|
258 |
unset($fields[$key]);
|
|
|
259 |
} else {
|
|
|
260 |
$exportdata[0][] = $field->field->name;
|
|
|
261 |
}
|
|
|
262 |
}
|
|
|
263 |
if ($tags) {
|
|
|
264 |
$exportdata[0][] = get_string('tags', 'data');
|
|
|
265 |
}
|
|
|
266 |
if ($userdetails) {
|
|
|
267 |
$exportdata[0][] = get_string('user');
|
|
|
268 |
$exportdata[0][] = get_string('username');
|
|
|
269 |
$exportdata[0][] = get_string('email');
|
|
|
270 |
}
|
|
|
271 |
if ($time) {
|
|
|
272 |
$exportdata[0][] = get_string('timeadded', 'data');
|
|
|
273 |
$exportdata[0][] = get_string('timemodified', 'data');
|
|
|
274 |
}
|
|
|
275 |
if ($approval) {
|
|
|
276 |
$exportdata[0][] = get_string('approved', 'data');
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
$datarecords = $DB->get_records('data_records', array('dataid'=>$dataid));
|
|
|
280 |
ksort($datarecords);
|
|
|
281 |
$line = 1;
|
|
|
282 |
foreach($datarecords as $record) {
|
|
|
283 |
// get content indexed by fieldid
|
|
|
284 |
if ($currentgroup) {
|
|
|
285 |
$select = 'SELECT c.fieldid, c.content, c.content1, c.content2, c.content3, c.content4 FROM {data_content} c, {data_records} r WHERE c.recordid = ? AND r.id = c.recordid AND r.groupid = ?';
|
|
|
286 |
$where = array($record->id, $currentgroup);
|
|
|
287 |
} else {
|
|
|
288 |
$select = 'SELECT fieldid, content, content1, content2, content3, content4 FROM {data_content} WHERE recordid = ?';
|
|
|
289 |
$where = array($record->id);
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
if( $content = $DB->get_records_sql($select, $where) ) {
|
|
|
293 |
foreach($fields as $field) {
|
|
|
294 |
$contents = '';
|
|
|
295 |
if(isset($content[$field->field->id])) {
|
|
|
296 |
$contents = $field->export_text_value($content[$field->field->id]);
|
|
|
297 |
}
|
|
|
298 |
$exportdata[$line][] = $contents;
|
|
|
299 |
}
|
|
|
300 |
if ($tags) {
|
|
|
301 |
$itemtags = \core_tag_tag::get_item_tags_array('mod_data', 'data_records', $record->id);
|
|
|
302 |
$exportdata[$line][] = implode(', ', $itemtags);
|
|
|
303 |
}
|
|
|
304 |
if ($userdetails) { // Add user details to the export data
|
|
|
305 |
$userdata = get_complete_user_data('id', $record->userid);
|
|
|
306 |
$exportdata[$line][] = fullname($userdata);
|
|
|
307 |
$exportdata[$line][] = $userdata->username;
|
|
|
308 |
$exportdata[$line][] = $userdata->email;
|
|
|
309 |
}
|
|
|
310 |
if ($time) { // Add time added / modified
|
|
|
311 |
$exportdata[$line][] = userdate($record->timecreated);
|
|
|
312 |
$exportdata[$line][] = userdate($record->timemodified);
|
|
|
313 |
}
|
|
|
314 |
if ($approval) { // Add approval status
|
|
|
315 |
$exportdata[$line][] = (int) $record->approved;
|
|
|
316 |
}
|
|
|
317 |
}
|
|
|
318 |
$line++;
|
|
|
319 |
}
|
|
|
320 |
$line--;
|
|
|
321 |
return $exportdata;
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
/**
|
|
|
325 |
* @deprecated since Moodle 4.3, importing is now being done by \mod_data\local\importer\csv_importer::import_csv
|
|
|
326 |
* Import records for a data instance from csv data.
|
|
|
327 |
*
|
|
|
328 |
* @param object $cm Course module of the data instance.
|
|
|
329 |
* @param object $data The data instance.
|
|
|
330 |
* @param string $csvdata The csv data to be imported.
|
|
|
331 |
* @param string $encoding The encoding of csv data.
|
|
|
332 |
* @param string $fielddelimiter The delimiter of the csv data.
|
|
|
333 |
* @return int Number of records added.
|
|
|
334 |
*/
|
|
|
335 |
function data_import_csv($cm, $data, &$csvdata, $encoding, $fielddelimiter) {
|
|
|
336 |
debugging('Function data_import_csv has been deprecated. '
|
|
|
337 |
. 'Importing is now being done by \mod_data\local\csv_importer::import_csv.',
|
|
|
338 |
DEBUG_DEVELOPER);
|
|
|
339 |
|
|
|
340 |
// New function needs a file, not the file content, so we have to temporarily put the content into a file.
|
|
|
341 |
$tmpdir = make_request_directory();
|
|
|
342 |
$tmpfilename = 'tmpfile.csv';
|
|
|
343 |
$tmpfilepath = $tmpdir . '/tmpfile.csv';
|
|
|
344 |
file_put_contents($tmpfilepath, $csvdata);
|
|
|
345 |
|
|
|
346 |
$importer = new \mod_data\local\importer\csv_entries_importer($tmpfilepath, $tmpfilename);
|
|
|
347 |
$importer->import_csv($cm, $data, $encoding, $fielddelimiter);
|
|
|
348 |
return 0;
|
|
|
349 |
}
|