Differences Between: [Versions 311 and 403] [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]
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 /** 26 * @deprecated since Moodle 3.11 27 */ 28 function data_get_completion_state() { 29 $completionclass = \mod_data\completion\custom_completion::class; 30 throw new coding_exception(__FUNCTION__ . "() has been removed, please use the '{$completionclass}' class instead"); 31 } 32 33 /** 34 * @deprecated since Moodle 4.3. 35 * @global object 36 * @param array $export 37 * @param string $dataname 38 * @param int $count 39 * @return string 40 */ 41 function data_export_xls($export, $dataname, $count) { 42 global $CFG; 43 44 debugging('Function data_export_xls() has been deprecated, because xls export has been dropped.', 45 DEBUG_DEVELOPER); 46 require_once("$CFG->libdir/excellib.class.php"); 47 $filename = clean_filename("{$dataname}-{$count}_record"); 48 if ($count > 1) { 49 $filename .= 's'; 50 } 51 $filename .= clean_filename('-' . gmdate("Ymd_Hi")); 52 $filename .= '.xls'; 53 54 $filearg = '-'; 55 $workbook = new MoodleExcelWorkbook($filearg); 56 $workbook->send($filename); 57 $worksheet = array(); 58 $worksheet[0] = $workbook->add_worksheet(''); 59 $rowno = 0; 60 foreach ($export as $row) { 61 $colno = 0; 62 foreach($row as $col) { 63 $worksheet[0]->write($rowno, $colno, $col); 64 $colno++; 65 } 66 $rowno++; 67 } 68 $workbook->close(); 69 return $filename; 70 } 71 72 /** 73 * @deprecated since Moodle 4.3, exporting is now being done by \mod_data\local\exporter\csv_entries_exporter 74 * @global object 75 * @param array $export 76 * @param string $delimiter_name 77 * @param object $database 78 * @param int $count 79 * @param bool $return 80 * @return string|void 81 */ 82 function data_export_csv($export, $delimiter_name, $database, $count, $return=false) { 83 global $CFG; 84 85 debugging('Function data_export_csv has been deprecated. Exporting is now being done by ' 86 . '\mod_data\local\csv_exporter.', DEBUG_DEVELOPER); 87 require_once($CFG->libdir . '/csvlib.class.php'); 88 89 $filename = $database . '-' . $count . '-record'; 90 if ($count > 1) { 91 $filename .= 's'; 92 } 93 if ($return) { 94 return csv_export_writer::print_array($export, $delimiter_name, '"', true); 95 } else { 96 csv_export_writer::download_array($filename, $export, $delimiter_name); 97 } 98 } 99 100 /** 101 * @deprecated since Moodle 4.3, exporting is now being done by \mod_data\local\exporter\ods_entries_exporter 102 * @global object 103 * @param array $export 104 * @param string $dataname 105 * @param int $count 106 * @param string 107 */ 108 function data_export_ods($export, $dataname, $count) { 109 global $CFG; 110 111 debugging('Function data_export_ods has been deprecated. Exporting is now being done by ' 112 . '\mod_data\local\ods_exporter.', DEBUG_DEVELOPER); 113 require_once("$CFG->libdir/odslib.class.php"); 114 $filename = clean_filename("{$dataname}-{$count}_record"); 115 if ($count > 1) { 116 $filename .= 's'; 117 } 118 $filename .= clean_filename('-' . gmdate("Ymd_Hi")); 119 $filename .= '.ods'; 120 $filearg = '-'; 121 $workbook = new MoodleODSWorkbook($filearg); 122 $workbook->send($filename); 123 $worksheet = array(); 124 $worksheet[0] = $workbook->add_worksheet(''); 125 $rowno = 0; 126 foreach ($export as $row) { 127 $colno = 0; 128 foreach($row as $col) { 129 $worksheet[0]->write($rowno, $colno, $col); 130 $colno++; 131 } 132 $rowno++; 133 } 134 $workbook->close(); 135 return $filename; 136 } 137 138 /** 139 * @deprecated since Moodle 4.3, use \mod_data\local\exporter\utils::data_exportdata with a \mod_data\local\exporter\entries_exporter object 140 * @global object 141 * @param int $dataid 142 * @param array $fields 143 * @param array $selectedfields 144 * @param int $currentgroup group ID of the current group. This is used for 145 * exporting data while maintaining group divisions. 146 * @param object $context the context in which the operation is performed (for capability checks) 147 * @param bool $userdetails whether to include the details of the record author 148 * @param bool $time whether to include time created/modified 149 * @param bool $approval whether to include approval status 150 * @param bool $tags whether to include tags 151 * @return array 152 */ 153 function data_get_exportdata($dataid, $fields, $selectedfields, $currentgroup=0, $context=null, 154 $userdetails=false, $time=false, $approval=false, $tags = false) { 155 global $DB; 156 157 debugging('Function data_get_exportdata has been deprecated. Use ' 158 . '\mod_data\local\exporter_utils::data_exportdata with a \mod_data\local\exporter object instead', 159 DEBUG_DEVELOPER); 160 161 if (is_null($context)) { 162 $context = context_system::instance(); 163 } 164 // exporting user data needs special permission 165 $userdetails = $userdetails && has_capability('mod/data:exportuserinfo', $context); 166 167 $exportdata = array(); 168 169 // populate the header in first row of export 170 foreach($fields as $key => $field) { 171 if (!in_array($field->field->id, $selectedfields)) { 172 // ignore values we aren't exporting 173 unset($fields[$key]); 174 } else { 175 $exportdata[0][] = $field->field->name; 176 } 177 } 178 if ($tags) { 179 $exportdata[0][] = get_string('tags', 'data'); 180 } 181 if ($userdetails) { 182 $exportdata[0][] = get_string('user'); 183 $exportdata[0][] = get_string('username'); 184 $exportdata[0][] = get_string('email'); 185 } 186 if ($time) { 187 $exportdata[0][] = get_string('timeadded', 'data'); 188 $exportdata[0][] = get_string('timemodified', 'data'); 189 } 190 if ($approval) { 191 $exportdata[0][] = get_string('approved', 'data'); 192 } 193 194 $datarecords = $DB->get_records('data_records', array('dataid'=>$dataid)); 195 ksort($datarecords); 196 $line = 1; 197 foreach($datarecords as $record) { 198 // get content indexed by fieldid 199 if ($currentgroup) { 200 $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 = ?'; 201 $where = array($record->id, $currentgroup); 202 } else { 203 $select = 'SELECT fieldid, content, content1, content2, content3, content4 FROM {data_content} WHERE recordid = ?'; 204 $where = array($record->id); 205 } 206 207 if( $content = $DB->get_records_sql($select, $where) ) { 208 foreach($fields as $field) { 209 $contents = ''; 210 if(isset($content[$field->field->id])) { 211 $contents = $field->export_text_value($content[$field->field->id]); 212 } 213 $exportdata[$line][] = $contents; 214 } 215 if ($tags) { 216 $itemtags = \core_tag_tag::get_item_tags_array('mod_data', 'data_records', $record->id); 217 $exportdata[$line][] = implode(', ', $itemtags); 218 } 219 if ($userdetails) { // Add user details to the export data 220 $userdata = get_complete_user_data('id', $record->userid); 221 $exportdata[$line][] = fullname($userdata); 222 $exportdata[$line][] = $userdata->username; 223 $exportdata[$line][] = $userdata->email; 224 } 225 if ($time) { // Add time added / modified 226 $exportdata[$line][] = userdate($record->timecreated); 227 $exportdata[$line][] = userdate($record->timemodified); 228 } 229 if ($approval) { // Add approval status 230 $exportdata[$line][] = (int) $record->approved; 231 } 232 } 233 $line++; 234 } 235 $line--; 236 return $exportdata; 237 } 238 239 /** 240 * @deprecated since Moodle 4.3, importing is now being done by \mod_data\local\importer\csv_importer::import_csv 241 * Import records for a data instance from csv data. 242 * 243 * @param object $cm Course module of the data instance. 244 * @param object $data The data instance. 245 * @param string $csvdata The csv data to be imported. 246 * @param string $encoding The encoding of csv data. 247 * @param string $fielddelimiter The delimiter of the csv data. 248 * @return int Number of records added. 249 */ 250 function data_import_csv($cm, $data, &$csvdata, $encoding, $fielddelimiter) { 251 debugging('Function data_import_csv has been deprecated. ' 252 . 'Importing is now being done by \mod_data\local\csv_importer::import_csv.', 253 DEBUG_DEVELOPER); 254 255 // New function needs a file, not the file content, so we have to temporarily put the content into a file. 256 $tmpdir = make_request_directory(); 257 $tmpfilename = 'tmpfile.csv'; 258 $tmpfilepath = $tmpdir . '/tmpfile.csv'; 259 file_put_contents($tmpfilepath, $csvdata); 260 261 $importer = new \mod_data\local\importer\csv_entries_importer($tmpfilepath, $tmpfilename); 262 $importer->import_csv($cm, $data, $encoding, $fielddelimiter); 263 return 0; 264 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body