Commit | Line | Data |
---|---|---|
c861fe2f | 1 | <?php |
2 | ||
a5cb8d69 | 3 | // This file is part of Moodle - http://moodle.org/ |
4 | // | |
c861fe2f | 5 | // Moodle is free software: you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
a5cb8d69 | 14 | // |
c861fe2f | 15 | // You should have received a copy of the GNU General Public License |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
c4d0753b | 17 | |
18 | /** | |
19 | * deprecatedlib.php - Old functions retained only for backward compatibility | |
20 | * | |
21 | * Old functions retained only for backward compatibility. New code should not | |
22 | * use any of these functions. | |
23 | * | |
78bfb562 | 24 | * @package core |
c861fe2f | 25 | * @subpackage deprecated |
78bfb562 PS |
26 | * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} |
27 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
c861fe2f | 28 | * @deprecated |
c4d0753b | 29 | */ |
30 | ||
78bfb562 PS |
31 | defined('MOODLE_INTERNAL') || die(); |
32 | ||
33c46db5 AA |
33 | /* === Functions that needs to be kept longer in deprecated lib than normal time period === */ |
34 | ||
35 | /** | |
36 | * Add an entry to the legacy log table. | |
37 | * | |
38 | * @deprecated since 2.7 use new events instead | |
39 | * | |
40 | * @param int $courseid The course id | |
41 | * @param string $module The module name e.g. forum, journal, resource, course, user etc | |
42 | * @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify. | |
43 | * @param string $url The file and parameters used to see the results of the action | |
44 | * @param string $info Additional description information | |
45 | * @param int $cm The course_module->id if there is one | |
46 | * @param int|stdClass $user If log regards $user other than $USER | |
47 | * @return void | |
48 | */ | |
49 | function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0) { | |
50 | debugging('add_to_log() has been deprecated, please rewrite your code to the new events API', DEBUG_DEVELOPER); | |
51 | ||
52 | // This is a nasty hack that allows us to put all the legacy stuff into legacy storage, | |
53 | // this way we may move all the legacy settings there too. | |
54 | $manager = get_log_manager(); | |
55 | if (method_exists($manager, 'legacy_add_to_log')) { | |
56 | $manager->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user); | |
57 | } | |
58 | } | |
59 | ||
60 | /** | |
61 | * Function to call all event handlers when triggering an event | |
62 | * | |
63 | * @deprecated since 2.6 | |
64 | * | |
65 | * @param string $eventname name of the event | |
66 | * @param mixed $eventdata event data object | |
67 | * @return int number of failed events | |
68 | */ | |
69 | function events_trigger($eventname, $eventdata) { | |
70 | debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER); | |
71 | return events_trigger_legacy($eventname, $eventdata); | |
72 | } | |
73 | ||
74 | /** | |
75 | * List all core subsystems and their location | |
76 | * | |
77 | * This is a whitelist of components that are part of the core and their | |
78 | * language strings are defined in /lang/en/<<subsystem>>.php. If a given | |
79 | * plugin is not listed here and it does not have proper plugintype prefix, | |
80 | * then it is considered as course activity module. | |
81 | * | |
82 | * The location is optionally dirroot relative path. NULL means there is no special | |
83 | * directory for this subsystem. If the location is set, the subsystem's | |
84 | * renderer.php is expected to be there. | |
85 | * | |
86 | * @deprecated since 2.6, use core_component::get_core_subsystems() | |
87 | * | |
88 | * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons | |
89 | * @return array of (string)name => (string|null)location | |
90 | */ | |
91 | function get_core_subsystems($fullpaths = false) { | |
92 | global $CFG; | |
93 | ||
94 | // NOTE: do not add any other debugging here, keep forever. | |
95 | ||
96 | $subsystems = core_component::get_core_subsystems(); | |
97 | ||
98 | if ($fullpaths) { | |
99 | return $subsystems; | |
100 | } | |
101 | ||
102 | debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER); | |
103 | ||
104 | $dlength = strlen($CFG->dirroot); | |
105 | ||
106 | foreach ($subsystems as $k => $v) { | |
107 | if ($v === null) { | |
108 | continue; | |
109 | } | |
110 | $subsystems[$k] = substr($v, $dlength+1); | |
111 | } | |
112 | ||
113 | return $subsystems; | |
114 | } | |
115 | ||
116 | /** | |
117 | * Lists all plugin types. | |
118 | * | |
119 | * @deprecated since 2.6, use core_component::get_plugin_types() | |
120 | * | |
121 | * @param bool $fullpaths false means relative paths from dirroot | |
122 | * @return array Array of strings - name=>location | |
123 | */ | |
124 | function get_plugin_types($fullpaths = true) { | |
125 | global $CFG; | |
126 | ||
127 | // NOTE: do not add any other debugging here, keep forever. | |
128 | ||
129 | $types = core_component::get_plugin_types(); | |
130 | ||
131 | if ($fullpaths) { | |
132 | return $types; | |
133 | } | |
134 | ||
135 | debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER); | |
136 | ||
137 | $dlength = strlen($CFG->dirroot); | |
138 | ||
139 | foreach ($types as $k => $v) { | |
140 | if ($k === 'theme') { | |
141 | $types[$k] = 'theme'; | |
142 | continue; | |
143 | } | |
144 | $types[$k] = substr($v, $dlength+1); | |
145 | } | |
146 | ||
147 | return $types; | |
148 | } | |
149 | ||
150 | /** | |
151 | * Use when listing real plugins of one type. | |
152 | * | |
153 | * @deprecated since 2.6, use core_component::get_plugin_list() | |
154 | * | |
155 | * @param string $plugintype type of plugin | |
156 | * @return array name=>fulllocation pairs of plugins of given type | |
157 | */ | |
158 | function get_plugin_list($plugintype) { | |
159 | ||
160 | // NOTE: do not add any other debugging here, keep forever. | |
161 | ||
162 | if ($plugintype === '') { | |
163 | $plugintype = 'mod'; | |
164 | } | |
165 | ||
166 | return core_component::get_plugin_list($plugintype); | |
167 | } | |
168 | ||
169 | /** | |
170 | * Get a list of all the plugins of a given type that define a certain class | |
171 | * in a certain file. The plugin component names and class names are returned. | |
172 | * | |
173 | * @deprecated since 2.6, use core_component::get_plugin_list_with_class() | |
174 | * | |
175 | * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'. | |
176 | * @param string $class the part of the name of the class after the | |
177 | * frankenstyle prefix. e.g 'thing' if you are looking for classes with | |
178 | * names like report_courselist_thing. If you are looking for classes with | |
179 | * the same name as the plugin name (e.g. qtype_multichoice) then pass ''. | |
180 | * @param string $file the name of file within the plugin that defines the class. | |
181 | * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum') | |
182 | * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice'). | |
183 | */ | |
184 | function get_plugin_list_with_class($plugintype, $class, $file) { | |
185 | ||
186 | // NOTE: do not add any other debugging here, keep forever. | |
187 | ||
188 | return core_component::get_plugin_list_with_class($plugintype, $class, $file); | |
189 | } | |
190 | ||
191 | /** | |
192 | * Returns the exact absolute path to plugin directory. | |
193 | * | |
194 | * @deprecated since 2.6, use core_component::get_plugin_directory() | |
195 | * | |
196 | * @param string $plugintype type of plugin | |
197 | * @param string $name name of the plugin | |
198 | * @return string full path to plugin directory; NULL if not found | |
199 | */ | |
200 | function get_plugin_directory($plugintype, $name) { | |
201 | ||
202 | // NOTE: do not add any other debugging here, keep forever. | |
203 | ||
204 | if ($plugintype === '') { | |
205 | $plugintype = 'mod'; | |
206 | } | |
207 | ||
208 | return core_component::get_plugin_directory($plugintype, $name); | |
209 | } | |
210 | ||
211 | /** | |
212 | * Normalize the component name using the "frankenstyle" names. | |
213 | * | |
214 | * @deprecated since 2.6, use core_component::normalize_component() | |
215 | * | |
216 | * @param string $component | |
6b6a2ec4 | 217 | * @return array two-items list of [(string)type, (string|null)name] |
33c46db5 AA |
218 | */ |
219 | function normalize_component($component) { | |
220 | ||
221 | // NOTE: do not add any other debugging here, keep forever. | |
222 | ||
223 | return core_component::normalize_component($component); | |
224 | } | |
225 | ||
226 | /** | |
227 | * Return exact absolute path to a plugin directory. | |
228 | * | |
229 | * @deprecated since 2.6, use core_component::normalize_component() | |
230 | * | |
231 | * @param string $component name such as 'moodle', 'mod_forum' | |
232 | * @return string full path to component directory; NULL if not found | |
233 | */ | |
234 | function get_component_directory($component) { | |
235 | ||
236 | // NOTE: do not add any other debugging here, keep forever. | |
237 | ||
238 | return core_component::get_component_directory($component); | |
239 | } | |
240 | ||
241 | /** | |
242 | * Get the context instance as an object. This function will create the | |
243 | * context instance if it does not exist yet. | |
244 | * | |
245 | * @deprecated since 2.2, use context_course::instance() or other relevant class instead | |
246 | * @todo This will be deleted in Moodle 2.8, refer MDL-34472 | |
247 | * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE. | |
248 | * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id, | |
249 | * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0 | |
250 | * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; | |
251 | * MUST_EXIST means throw exception if no record or multiple records found | |
252 | * @return context The context object. | |
253 | */ | |
254 | function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) { | |
255 | ||
256 | debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER); | |
257 | ||
258 | $instances = (array)$instance; | |
259 | $contexts = array(); | |
260 | ||
261 | $classname = context_helper::get_class_for_level($contextlevel); | |
262 | ||
263 | // we do not load multiple contexts any more, PAGE should be responsible for any preloading | |
264 | foreach ($instances as $inst) { | |
265 | $contexts[$inst] = $classname::instance($inst, $strictness); | |
266 | } | |
267 | ||
268 | if (is_array($instance)) { | |
269 | return $contexts; | |
270 | } else { | |
271 | return $contexts[$instance]; | |
272 | } | |
273 | } | |
274 | /* === End of long term deprecated api list === */ | |
275 | ||
114e3209 PŠ |
276 | /** |
277 | * Adds a file upload to the log table so that clam can resolve the filename to the user later if necessary | |
278 | * | |
279 | * @deprecated since 2.7 - use new file picker instead | |
280 | * | |
114e3209 PŠ |
281 | */ |
282 | function clam_log_upload($newfilepath, $course=null, $nourl=false) { | |
6dd7175a | 283 | throw new coding_exception('clam_log_upload() can not be used any more, please use file picker instead'); |
114e3209 PŠ |
284 | } |
285 | ||
286 | /** | |
287 | * This function logs to error_log and to the log table that an infected file has been found and what's happened to it. | |
288 | * | |
289 | * @deprecated since 2.7 - use new file picker instead | |
290 | * | |
114e3209 PŠ |
291 | */ |
292 | function clam_log_infected($oldfilepath='', $newfilepath='', $userid=0) { | |
6dd7175a | 293 | throw new coding_exception('clam_log_infected() can not be used any more, please use file picker instead'); |
114e3209 PŠ |
294 | } |
295 | ||
296 | /** | |
297 | * Some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path. | |
298 | * | |
299 | * @deprecated since 2.7 - use new file picker instead | |
300 | * | |
114e3209 PŠ |
301 | */ |
302 | function clam_change_log($oldpath, $newpath, $update=true) { | |
6dd7175a | 303 | throw new coding_exception('clam_change_log() can not be used any more, please use file picker instead'); |
114e3209 PŠ |
304 | } |
305 | ||
306 | /** | |
307 | * Replaces the given file with a string. | |
308 | * | |
309 | * @deprecated since 2.7 - infected files are now deleted in file picker | |
310 | * | |
114e3209 PŠ |
311 | */ |
312 | function clam_replace_infected_file($file) { | |
6dd7175a | 313 | throw new coding_exception('clam_replace_infected_file() can not be used any more, please use file picker instead'); |
114e3209 PŠ |
314 | } |
315 | ||
7293a1aa DP |
316 | /** |
317 | * Deals with an infected file - either moves it to a quarantinedir | |
318 | * (specified in CFG->quarantinedir) or deletes it. | |
319 | * | |
320 | * If moving it fails, it deletes it. | |
321 | * | |
322 | * @deprecated since 2.7 | |
323 | */ | |
324 | function clam_handle_infected_file($file, $userid=0, $basiconly=false) { | |
325 | throw new coding_exception('clam_handle_infected_file() can not be used any more, please use file picker instead'); | |
326 | } | |
327 | ||
328 | /** | |
329 | * If $CFG->runclamonupload is set, we scan a given file. (called from {@link preprocess_files()}) | |
330 | * | |
331 | * @deprecated since 2.7 | |
332 | */ | |
333 | function clam_scan_moodle_file(&$file, $course) { | |
334 | throw new coding_exception('clam_scan_moodle_file() can not be used any more, please use file picker instead'); | |
335 | } | |
336 | ||
337 | ||
6780a1d3 PŠ |
338 | /** |
339 | * Checks whether the password compatibility library will work with the current | |
340 | * version of PHP. This cannot be done using PHP version numbers since the fix | |
341 | * has been backported to earlier versions in some distributions. | |
342 | * | |
343 | * See https://github.com/ircmaxell/password_compat/issues/10 for more details. | |
344 | * | |
345 | * @deprecated since 2.7 PHP 5.4.x should be always compatible. | |
346 | * | |
6780a1d3 PŠ |
347 | */ |
348 | function password_compat_not_supported() { | |
1ac1d29b | 349 | throw new coding_exception('Do not use password_compat_not_supported() - bcrypt is now always available'); |
6780a1d3 PŠ |
350 | } |
351 | ||
d79d5ac2 PS |
352 | /** |
353 | * Factory method that was returning moodle_session object. | |
354 | * | |
355 | * @deprecated since 2.6 | |
d79d5ac2 PS |
356 | */ |
357 | function session_get_instance() { | |
2149326b | 358 | throw new coding_exception('session_get_instance() is removed, use \core\session\manager instead'); |
d79d5ac2 PS |
359 | } |
360 | ||
361 | /** | |
362 | * Returns true if legacy session used. | |
363 | * | |
364 | * @deprecated since 2.6 | |
d79d5ac2 PS |
365 | */ |
366 | function session_is_legacy() { | |
2149326b | 367 | throw new coding_exception('session_is_legacy() is removed, do not use any more'); |
d79d5ac2 PS |
368 | } |
369 | ||
370 | /** | |
371 | * Terminates all sessions, auth hooks are not executed. | |
d79d5ac2 PS |
372 | * |
373 | * @deprecated since 2.6 | |
374 | */ | |
375 | function session_kill_all() { | |
2149326b | 376 | throw new coding_exception('session_kill_all() is removed, use \core\session\manager::kill_all_sessions() instead'); |
d79d5ac2 PS |
377 | } |
378 | ||
379 | /** | |
380 | * Mark session as accessed, prevents timeouts. | |
381 | * | |
382 | * @deprecated since 2.6 | |
d79d5ac2 PS |
383 | */ |
384 | function session_touch($sid) { | |
2149326b | 385 | throw new coding_exception('session_touch() is removed, use \core\session\manager::touch_session() instead'); |
d79d5ac2 PS |
386 | } |
387 | ||
388 | /** | |
389 | * Terminates one sessions, auth hooks are not executed. | |
390 | * | |
391 | * @deprecated since 2.6 | |
d79d5ac2 PS |
392 | */ |
393 | function session_kill($sid) { | |
2149326b | 394 | throw new coding_exception('session_kill() is removed, use \core\session\manager::kill_session() instead'); |
d79d5ac2 PS |
395 | } |
396 | ||
397 | /** | |
398 | * Terminates all sessions of one user, auth hooks are not executed. | |
d79d5ac2 PS |
399 | * |
400 | * @deprecated since 2.6 | |
d79d5ac2 PS |
401 | */ |
402 | function session_kill_user($userid) { | |
2149326b | 403 | throw new coding_exception('session_kill_user() is removed, use \core\session\manager::kill_user_sessions() instead'); |
d79d5ac2 PS |
404 | } |
405 | ||
d79d5ac2 PS |
406 | /** |
407 | * Setup $USER object - called during login, loginas, etc. | |
408 | * | |
409 | * Call sync_user_enrolments() manually after log-in, or log-in-as. | |
410 | * | |
411 | * @deprecated since 2.6 | |
d79d5ac2 PS |
412 | */ |
413 | function session_set_user($user) { | |
2149326b | 414 | throw new coding_exception('session_set_user() is removed, use \core\session\manager::set_user() instead'); |
d79d5ac2 PS |
415 | } |
416 | ||
417 | /** | |
418 | * Is current $USER logged-in-as somebody else? | |
419 | * @deprecated since 2.6 | |
d79d5ac2 PS |
420 | */ |
421 | function session_is_loggedinas() { | |
2149326b | 422 | throw new coding_exception('session_is_loggedinas() is removed, use \core\session\manager::is_loggedinas() instead'); |
d79d5ac2 PS |
423 | } |
424 | ||
425 | /** | |
426 | * Returns the $USER object ignoring current login-as session | |
427 | * @deprecated since 2.6 | |
d79d5ac2 PS |
428 | */ |
429 | function session_get_realuser() { | |
2149326b | 430 | throw new coding_exception('session_get_realuser() is removed, use \core\session\manager::get_realuser() instead'); |
d79d5ac2 PS |
431 | } |
432 | ||
433 | /** | |
434 | * Login as another user - no security checks here. | |
435 | * @deprecated since 2.6 | |
d79d5ac2 PS |
436 | */ |
437 | function session_loginas($userid, $context) { | |
2149326b | 438 | throw new coding_exception('session_loginas() is removed, use \core\session\manager::loginas() instead'); |
d79d5ac2 PS |
439 | } |
440 | ||
6b32d6bc PS |
441 | /** |
442 | * Minify JavaScript files. | |
443 | * | |
444 | * @deprecated since 2.6 | |
6b32d6bc PS |
445 | */ |
446 | function js_minify($files) { | |
2149326b | 447 | throw new coding_exception('js_minify() is removed, use core_minify::js_files() or core_minify::js() instead.'); |
6b32d6bc PS |
448 | } |
449 | ||
450 | /** | |
451 | * Minify CSS files. | |
452 | * | |
453 | * @deprecated since 2.6 | |
6b32d6bc PS |
454 | */ |
455 | function css_minify_css($files) { | |
2149326b | 456 | throw new coding_exception('css_minify_css() is removed, use core_minify::css_files() or core_minify::css() instead.'); |
6b32d6bc PS |
457 | } |
458 | ||
9e19a0f0 PS |
459 | // === Deprecated before 2.6.0 === |
460 | ||
689096bc PS |
461 | /** |
462 | * Hack to find out the GD version by parsing phpinfo output | |
2a723541 JP |
463 | * |
464 | * @deprecated | |
689096bc PS |
465 | */ |
466 | function check_gd_version() { | |
2149326b | 467 | throw new coding_exception('check_gd_version() is removed, GD extension is always available now'); |
689096bc PS |
468 | } |
469 | ||
b28247fe PS |
470 | /** |
471 | * Not used any more, the account lockout handling is now | |
472 | * part of authenticate_user_login(). | |
473 | * @deprecated | |
474 | */ | |
475 | function update_login_count() { | |
2149326b | 476 | throw new coding_exception('update_login_count() is removed, all calls need to be removed'); |
b28247fe PS |
477 | } |
478 | ||
479 | /** | |
480 | * Not used any more, replaced by proper account lockout. | |
481 | * @deprecated | |
482 | */ | |
483 | function reset_login_count() { | |
2149326b | 484 | throw new coding_exception('reset_login_count() is removed, all calls need to be removed'); |
b28247fe PS |
485 | } |
486 | ||
c6d75bff | 487 | /** |
c6d75bff | 488 | * @deprecated |
c6d75bff PS |
489 | */ |
490 | function update_log_display_entry($module, $action, $mtable, $field) { | |
c6d75bff | 491 | |
2149326b | 492 | throw new coding_exception('The update_log_display_entry() is removed, please use db/log.php description file instead.'); |
c6d75bff PS |
493 | } |
494 | ||
35716b86 | 495 | /** |
05226d76 | 496 | * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions) |
35716b86 | 497 | * this was abused mostly for embedding of attachments |
35716b86 PS |
498 | */ |
499 | function filter_text($text, $courseid = NULL) { | |
e4d9185e | 500 | throw new coding_exception('filter_text() can not be used anymore, use format_text(), format_string() etc instead.'); |
35716b86 PS |
501 | } |
502 | ||
17c70aa0 | 503 | /** |
17c70aa0 PS |
504 | * @deprecated use $PAGE->https_required() instead |
505 | */ | |
506 | function httpsrequired() { | |
e4d9185e | 507 | throw new coding_exception('httpsrequired() can not be used any more use $PAGE->https_required() instead.'); |
17c70aa0 PS |
508 | } |
509 | ||
50a8bd6c PS |
510 | /** |
511 | * Given a physical path to a file, returns the URL through which it can be reached in Moodle. | |
512 | * | |
11d4bea2 SL |
513 | * @deprecated since 3.1 - replacement legacy file API methods can be found on the moodle_url class, for example: |
514 | * The moodle_url::make_legacyfile_url() method can be used to generate a legacy course file url. To generate | |
515 | * course module file.php url the moodle_url::make_file_url() should be used. | |
50a8bd6c PS |
516 | * |
517 | * @param string $path Physical path to a file | |
518 | * @param array $options associative array of GET variables to append to the URL | |
519 | * @param string $type (questionfile|rssfile|httpscoursefile|coursefile) | |
520 | * @return string URL to file | |
521 | */ | |
522 | function get_file_url($path, $options=null, $type='coursefile') { | |
11d4bea2 | 523 | debugging('Function get_file_url() is deprecated, please use moodle_url factory methods instead.', DEBUG_DEVELOPER); |
17c70aa0 | 524 | global $CFG; |
50a8bd6c PS |
525 | |
526 | $path = str_replace('//', '/', $path); | |
527 | $path = trim($path, '/'); // no leading and trailing slashes | |
528 | ||
529 | // type of file | |
530 | switch ($type) { | |
531 | case 'questionfile': | |
532 | $url = $CFG->wwwroot."/question/exportfile.php"; | |
533 | break; | |
534 | case 'rssfile': | |
535 | $url = $CFG->wwwroot."/rss/file.php"; | |
536 | break; | |
537 | case 'httpscoursefile': | |
538 | $url = $CFG->httpswwwroot."/file.php"; | |
539 | break; | |
540 | case 'coursefile': | |
541 | default: | |
542 | $url = $CFG->wwwroot."/file.php"; | |
543 | } | |
544 | ||
545 | if ($CFG->slasharguments) { | |
546 | $parts = explode('/', $path); | |
547 | foreach ($parts as $key => $part) { | |
548 | /// anchor dash character should not be encoded | |
549 | $subparts = explode('#', $part); | |
550 | $subparts = array_map('rawurlencode', $subparts); | |
551 | $parts[$key] = implode('#', $subparts); | |
552 | } | |
553 | $path = implode('/', $parts); | |
554 | $ffurl = $url.'/'.$path; | |
555 | $separator = '?'; | |
556 | } else { | |
557 | $path = rawurlencode('/'.$path); | |
558 | $ffurl = $url.'?file='.$path; | |
559 | $separator = '&'; | |
560 | } | |
561 | ||
562 | if ($options) { | |
563 | foreach ($options as $name=>$value) { | |
564 | $ffurl = $ffurl.$separator.$name.'='.$value; | |
565 | $separator = '&'; | |
566 | } | |
567 | } | |
568 | ||
569 | return $ffurl; | |
570 | } | |
571 | ||
613bbd7c | 572 | /** |
05226d76 | 573 | * @deprecated use get_enrolled_users($context) instead. |
613bbd7c | 574 | */ |
4f0c2d00 | 575 | function get_course_participants($courseid) { |
e4d9185e | 576 | throw new coding_exception('get_course_participants() can not be used any more, use get_enrolled_users() instead.'); |
613bbd7c | 577 | } |
578 | ||
613bbd7c | 579 | /** |
05226d76 | 580 | * @deprecated use is_enrolled($context, $userid) instead. |
613bbd7c | 581 | */ |
4f0c2d00 | 582 | function is_course_participant($userid, $courseid) { |
e4d9185e | 583 | throw new coding_exception('is_course_participant() can not be used any more, use is_enrolled() instead.'); |
613bbd7c | 584 | } |
585 | ||
586 | /** | |
1ac1d29b | 587 | * @deprecated |
613bbd7c | 588 | */ |
589 | function get_recent_enrolments($courseid, $timestart) { | |
2149326b | 590 | throw new coding_exception('get_recent_enrolments() is removed as it returned inaccurate results.'); |
613bbd7c | 591 | } |
592 | ||
ed5dd29f | 593 | /** |
05226d76 | 594 | * @deprecated use clean_param($string, PARAM_FILE) instead. |
ed5dd29f | 595 | */ |
596 | function detect_munged_arguments($string, $allowdots=1) { | |
e4d9185e | 597 | throw new coding_exception('detect_munged_arguments() can not be used any more, please use clean_param(,PARAM_FILE) instead.'); |
ed5dd29f | 598 | } |
599 | ||
9152fc99 | 600 | |
0c6d2dd4 | 601 | /** |
602 | * Unzip one zip file to a destination dir | |
603 | * Both parameters must be FULL paths | |
604 | * If destination isn't specified, it will be the | |
605 | * SAME directory where the zip file resides. | |
c861fe2f | 606 | * |
607 | * @global object | |
608 | * @param string $zipfile The zip file to unzip | |
609 | * @param string $destination The location to unzip to | |
610 | * @param bool $showstatus_ignored Unused | |
2c2f4f17 | 611 | * @deprecated since 2.0 MDL-15919 |
0c6d2dd4 | 612 | */ |
613 | function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) { | |
2c2f4f17 AN |
614 | debugging(__FUNCTION__ . '() is deprecated. ' |
615 | . 'Please use the application/zip file_packer implementation instead.', DEBUG_DEVELOPER); | |
0c6d2dd4 | 616 | |
2c2f4f17 | 617 | // Extract everything from zipfile. |
0c6d2dd4 | 618 | $path_parts = pathinfo(cleardoubleslashes($zipfile)); |
619 | $zippath = $path_parts["dirname"]; //The path of the zip file | |
620 | $zipfilename = $path_parts["basename"]; //The name of the zip file | |
621 | $extension = $path_parts["extension"]; //The extension of the file | |
622 | ||
623 | //If no file, error | |
624 | if (empty($zipfilename)) { | |
625 | return false; | |
626 | } | |
627 | ||
628 | //If no extension, error | |
629 | if (empty($extension)) { | |
630 | return false; | |
631 | } | |
632 | ||
633 | //Clear $zipfile | |
634 | $zipfile = cleardoubleslashes($zipfile); | |
635 | ||
636 | //Check zipfile exists | |
637 | if (!file_exists($zipfile)) { | |
638 | return false; | |
639 | } | |
640 | ||
641 | //If no destination, passed let's go with the same directory | |
642 | if (empty($destination)) { | |
643 | $destination = $zippath; | |
644 | } | |
645 | ||
646 | //Clear $destination | |
647 | $destpath = rtrim(cleardoubleslashes($destination), "/"); | |
648 | ||
649 | //Check destination path exists | |
650 | if (!is_dir($destpath)) { | |
651 | return false; | |
652 | } | |
653 | ||
0b0bfa93 | 654 | $packer = get_file_packer('application/zip'); |
655 | ||
656 | $result = $packer->extract_to_pathname($zipfile, $destpath); | |
0c6d2dd4 | 657 | |
658 | if ($result === false) { | |
659 | return false; | |
660 | } | |
661 | ||
662 | foreach ($result as $status) { | |
663 | if ($status !== true) { | |
664 | return false; | |
665 | } | |
666 | } | |
667 | ||
668 | return true; | |
669 | } | |
670 | ||
ed94cb66 | 671 | /** |
672 | * Zip an array of files/dirs to a destination zip file | |
673 | * Both parameters must be FULL paths to the files/dirs | |
c861fe2f | 674 | * |
675 | * @global object | |
676 | * @param array $originalfiles Files to zip | |
677 | * @param string $destination The destination path | |
678 | * @return bool Outcome | |
56b9e796 AN |
679 | * |
680 | * @deprecated since 2.0 MDL-15919 | |
ed94cb66 | 681 | */ |
56b9e796 AN |
682 | function zip_files($originalfiles, $destination) { |
683 | debugging(__FUNCTION__ . '() is deprecated. ' | |
684 | . 'Please use the application/zip file_packer implementation instead.', DEBUG_DEVELOPER); | |
ed94cb66 | 685 | |
56b9e796 | 686 | // Extract everything from destination. |
ed94cb66 | 687 | $path_parts = pathinfo(cleardoubleslashes($destination)); |
688 | $destpath = $path_parts["dirname"]; //The path of the zip file | |
689 | $destfilename = $path_parts["basename"]; //The name of the zip file | |
690 | $extension = $path_parts["extension"]; //The extension of the file | |
691 | ||
692 | //If no file, error | |
693 | if (empty($destfilename)) { | |
694 | return false; | |
695 | } | |
696 | ||
697 | //If no extension, add it | |
698 | if (empty($extension)) { | |
699 | $extension = 'zip'; | |
700 | $destfilename = $destfilename.'.'.$extension; | |
701 | } | |
702 | ||
703 | //Check destination path exists | |
704 | if (!is_dir($destpath)) { | |
705 | return false; | |
706 | } | |
707 | ||
708 | //Check destination path is writable. TODO!! | |
709 | ||
710 | //Clean destination filename | |
711 | $destfilename = clean_filename($destfilename); | |
712 | ||
713 | //Now check and prepare every file | |
714 | $files = array(); | |
715 | $origpath = NULL; | |
716 | ||
717 | foreach ($originalfiles as $file) { //Iterate over each file | |
718 | //Check for every file | |
719 | $tempfile = cleardoubleslashes($file); // no doubleslashes! | |
720 | //Calculate the base path for all files if it isn't set | |
721 | if ($origpath === NULL) { | |
722 | $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/"); | |
723 | } | |
724 | //See if the file is readable | |
725 | if (!is_readable($tempfile)) { //Is readable | |
726 | continue; | |
727 | } | |
728 | //See if the file/dir is in the same directory than the rest | |
729 | if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) { | |
730 | continue; | |
731 | } | |
732 | //Add the file to the array | |
733 | $files[] = $tempfile; | |
734 | } | |
735 | ||
736 | $zipfiles = array(); | |
737 | $start = strlen($origpath)+1; | |
738 | foreach($files as $file) { | |
739 | $zipfiles[substr($file, $start)] = $file; | |
740 | } | |
741 | ||
0b0bfa93 | 742 | $packer = get_file_packer('application/zip'); |
ed94cb66 | 743 | |
3ed22f1a | 744 | return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename); |
ed94cb66 | 745 | } |
746 | ||
5bf243d1 | 747 | /** |
05226d76 | 748 | * @deprecated use groups_get_all_groups() instead. |
5bf243d1 | 749 | */ |
750 | function mygroupid($courseid) { | |
e4d9185e | 751 | throw new coding_exception('mygroupid() can not be used any more, please use groups_get_all_groups() instead.'); |
5bf243d1 | 752 | } |
753 | ||
5bf243d1 | 754 | /** |
d494100e | 755 | * @deprecated since Moodle 2.0 MDL-14617 - please do not use this function any more. |
5bf243d1 | 756 | */ |
757 | function groupmode($course, $cm=null) { | |
53ca9cc8 | 758 | throw new coding_exception('groupmode() can not be used any more, please use groups_get_* instead.'); |
5bf243d1 | 759 | } |
760 | ||
c584346c | 761 | /** |
d494100e | 762 | * @deprecated Since year 2006 - please do not use this function any more. |
c584346c | 763 | */ |
764 | function set_current_group($courseid, $groupid) { | |
53ca9cc8 | 765 | throw new coding_exception('set_current_group() can not be used anymore, please use $SESSION->currentgroup[$courseid] instead'); |
c584346c | 766 | } |
767 | ||
5bf243d1 | 768 | /** |
d494100e | 769 | * @deprecated Since year 2006 - please do not use this function any more. |
5bf243d1 | 770 | */ |
771 | function get_current_group($courseid, $full = false) { | |
53ca9cc8 | 772 | throw new coding_exception('get_current_group() can not be used any more, please use groups_get_* instead'); |
5bf243d1 | 773 | } |
774 | ||
061e6b28 | 775 | /** |
061e6b28 | 776 | * @deprecated Since Moodle 2.8 |
777 | */ | |
778 | function groups_filter_users_by_course_module_visible($cm, $users) { | |
2149326b | 779 | throw new coding_exception('groups_filter_users_by_course_module_visible() is removed. ' . |
061e6b28 | 780 | 'Replace with a call to \core_availability\info_module::filter_user_list(), ' . |
781 | 'which does basically the same thing but includes other restrictions such ' . | |
1ac1d29b | 782 | 'as profile restrictions.'); |
061e6b28 | 783 | } |
784 | ||
785 | /** | |
061e6b28 | 786 | * @deprecated Since Moodle 2.8 |
787 | */ | |
788 | function groups_course_module_visible($cm, $userid=null) { | |
2149326b AA |
789 | throw new coding_exception('groups_course_module_visible() is removed, use $cm->uservisible to decide whether the current |
790 | user can ' . 'access an activity.', DEBUG_DEVELOPER); | |
061e6b28 | 791 | } |
5bf243d1 | 792 | |
8ec50604 | 793 | /** |
1ac1d29b | 794 | * @deprecated since 2.0 |
8ec50604 | 795 | */ |
245ac557 | 796 | function error($message, $link='') { |
2149326b | 797 | throw new coding_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a removed, please call |
1ac1d29b | 798 | print_error() instead of error()'); |
251387d0 | 799 | } |
8ec50604 | 800 | |
8ec50604 | 801 | |
b7009474 | 802 | /** |
803 | * @deprecated use $PAGE->theme->name instead. | |
b7009474 | 804 | */ |
805 | function current_theme() { | |
e4d9185e | 806 | throw new coding_exception('current_theme() can not be used any more, please use $PAGE->theme->name instead'); |
b7009474 | 807 | } |
808 | ||
8954245a | 809 | /** |
8954245a | 810 | * @deprecated |
8954245a | 811 | */ |
812 | function formerr($error) { | |
2149326b | 813 | throw new coding_exception('formerr() is removed. Please change your code to use $OUTPUT->error_text($string).'); |
8954245a | 814 | } |
815 | ||
34a2777c | 816 | /** |
34a2777c | 817 | * @deprecated use $OUTPUT->skip_link_target() in instead. |
34a2777c | 818 | */ |
819 | function skip_main_destination() { | |
e4d9185e | 820 | throw new coding_exception('skip_main_destination() can not be used any more, please use $OUTPUT->skip_link_target() instead.'); |
34a2777c | 821 | } |
822 | ||
34a2777c | 823 | /** |
05226d76 | 824 | * @deprecated use $OUTPUT->container() instead. |
34a2777c | 825 | */ |
826 | function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) { | |
e4d9185e | 827 | throw new coding_exception('print_container() can not be used any more. Please use $OUTPUT->container() instead.'); |
34a2777c | 828 | } |
829 | ||
830 | /** | |
05226d76 | 831 | * @deprecated use $OUTPUT->container_start() instead. |
34a2777c | 832 | */ |
833 | function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) { | |
e4d9185e | 834 | throw new coding_exception('print_container_start() can not be used any more. Please use $OUTPUT->container_start() instead.'); |
34a2777c | 835 | } |
836 | ||
837 | /** | |
05226d76 | 838 | * @deprecated use $OUTPUT->container_end() instead. |
34a2777c | 839 | */ |
840 | function print_container_end($return=false) { | |
e4d9185e | 841 | throw new coding_exception('print_container_end() can not be used any more. Please use $OUTPUT->container_end() instead.'); |
34a2777c | 842 | } |
843 | ||
844 | /** | |
845 | * Print a bold message in an optional color. | |
846 | * | |
ef53650e | 847 | * @deprecated since Moodle 2.0 MDL-19077 - use $OUTPUT->notification instead. |
c917b53a | 848 | * @todo MDL-50469 This will be deleted in Moodle 3.3. |
34a2777c | 849 | * @param string $message The message to print out |
c917b53a | 850 | * @param string $classes Optional style to display message text in |
34a2777c | 851 | * @param string $align Alignment option |
852 | * @param bool $return whether to return an output string or echo now | |
a5cb8d69 | 853 | * @return string|bool Depending on $result |
34a2777c | 854 | */ |
24346803 | 855 | function notify($message, $classes = 'error', $align = 'center', $return = false) { |
34a2777c | 856 | global $OUTPUT; |
857 | ||
c917b53a AA |
858 | debugging('notify() is deprecated, please use $OUTPUT->notification() instead', DEBUG_DEVELOPER); |
859 | ||
34a2777c | 860 | if ($classes == 'green') { |
24346803 AN |
861 | debugging('Use of deprecated class name "green" in notify. Please change to "success".', DEBUG_DEVELOPER); |
862 | $classes = 'success'; // Backward compatible with old color system. | |
34a2777c | 863 | } |
864 | ||
865 | $output = $OUTPUT->notification($message, $classes); | |
866 | if ($return) { | |
867 | return $output; | |
868 | } else { | |
869 | echo $output; | |
870 | } | |
871 | } | |
872 | ||
873 | /** | |
05226d76 | 874 | * @deprecated use $OUTPUT->continue_button() instead. |
34a2777c | 875 | */ |
876 | function print_continue($link, $return = false) { | |
e4d9185e | 877 | throw new coding_exception('print_continue() can not be used any more. Please use $OUTPUT->continue_button() instead.'); |
34a2777c | 878 | } |
879 | ||
34a2777c | 880 | /** |
05226d76 | 881 | * @deprecated use $PAGE methods instead. |
34a2777c | 882 | */ |
883 | function print_header($title='', $heading='', $navigation='', $focus='', | |
e120c61d | 884 | $meta='', $cache=true, $button=' ', $menu=null, |
34a2777c | 885 | $usexml=false, $bodytags='', $return=false) { |
34a2777c | 886 | |
e4d9185e | 887 | throw new coding_exception('print_header() can not be used any more. Please use $PAGE methods instead.'); |
34a2777c | 888 | } |
889 | ||
47a1aa45 | 890 | /** |
05226d76 | 891 | * @deprecated use $PAGE methods instead. |
47a1aa45 | 892 | */ |
893 | function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='', | |
894 | $cache=true, $button=' ', $menu='', $usexml=false, $bodytags='', $return=false) { | |
895 | ||
e4d9185e | 896 | throw new coding_exception('print_header_simple() can not be used any more. Please use $PAGE methods instead.'); |
47a1aa45 | 897 | } |
898 | ||
a5cb8d69 | 899 | /** |
05226d76 | 900 | * @deprecated use $OUTPUT->block() instead. |
a5cb8d69 | 901 | */ |
902 | function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') { | |
e4d9185e | 903 | throw new coding_exception('print_side_block() can not be used any more, please use $OUTPUT->block() instead.'); |
a5cb8d69 | 904 | } |
905 | ||
f8065dd2 | 906 | /** |
907 | * Prints a basic textarea field. | |
908 | * | |
909 | * @deprecated since Moodle 2.0 | |
910 | * | |
911 | * When using this function, you should | |
912 | * | |
913 | * @global object | |
3d27180e | 914 | * @param bool $unused No longer used. |
f8065dd2 | 915 | * @param int $rows Number of rows to display (minimum of 10 when $height is non-null) |
916 | * @param int $cols Number of columns to display (minimum of 65 when $width is non-null) | |
917 | * @param null $width (Deprecated) Width of the element; if a value is passed, the minimum value for $cols will be 65. Value is otherwise ignored. | |
918 | * @param null $height (Deprecated) Height of the element; if a value is passe, the minimum value for $rows will be 10. Value is otherwise ignored. | |
919 | * @param string $name Name to use for the textarea element. | |
920 | * @param string $value Initial content to display in the textarea. | |
921 | * @param int $obsolete deprecated | |
922 | * @param bool $return If false, will output string. If true, will return string value. | |
923 | * @param string $id CSS ID to add to the textarea element. | |
924 | * @return string|void depending on the value of $return | |
925 | */ | |
3d27180e | 926 | function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') { |
f8065dd2 | 927 | /// $width and height are legacy fields and no longer used as pixels like they used to be. |
928 | /// However, you can set them to zero to override the mincols and minrows values below. | |
929 | ||
3d8a479b MD |
930 | // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used |
931 | // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.'); | |
f8065dd2 | 932 | |
933 | global $CFG; | |
934 | ||
935 | $mincols = 65; | |
936 | $minrows = 10; | |
937 | $str = ''; | |
938 | ||
939 | if ($id === '') { | |
940 | $id = 'edit-'.$name; | |
941 | } | |
942 | ||
3d27180e DW |
943 | if ($height && ($rows < $minrows)) { |
944 | $rows = $minrows; | |
f8065dd2 | 945 | } |
3d27180e DW |
946 | if ($width && ($cols < $mincols)) { |
947 | $cols = $mincols; | |
f8065dd2 | 948 | } |
949 | ||
3d27180e DW |
950 | editors_head_setup(); |
951 | $editor = editors_get_preferred_editor(FORMAT_HTML); | |
988592c5 | 952 | $editor->set_text($value); |
3d27180e DW |
953 | $editor->use_editor($id, array('legacy'=>true)); |
954 | ||
0ac97084 | 955 | $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n"; |
3d27180e | 956 | $str .= htmlspecialchars($value); // needed for editing of cleaned text! |
f8065dd2 | 957 | $str .= '</textarea>'."\n"; |
958 | ||
959 | if ($return) { | |
960 | return $str; | |
961 | } | |
962 | echo $str; | |
963 | } | |
964 | ||
f8065dd2 | 965 | /** |
966 | * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please | |
967 | * provide this function with the language strings for sortasc and sortdesc. | |
968 | * | |
05226d76 | 969 | * @deprecated use $OUTPUT->arrow() instead. |
e4d9185e | 970 | * @todo final deprecation of this function once MDL-45448 is resolved |
f8065dd2 | 971 | * |
f8065dd2 | 972 | * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned. |
973 | * | |
974 | * @global object | |
975 | * @param string $direction 'up' or 'down' | |
976 | * @param string $strsort The language string used for the alt attribute of this image | |
977 | * @param bool $return Whether to print directly or return the html string | |
978 | * @return string|void depending on $return | |
979 | * | |
980 | */ | |
981 | function print_arrow($direction='up', $strsort=null, $return=false) { | |
f8065dd2 | 982 | global $OUTPUT; |
983 | ||
05226d76 DP |
984 | debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER); |
985 | ||
f8065dd2 | 986 | if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) { |
987 | return null; | |
988 | } | |
989 | ||
990 | $return = null; | |
991 | ||
992 | switch ($direction) { | |
993 | case 'up': | |
994 | $sortdir = 'asc'; | |
995 | break; | |
996 | case 'down': | |
997 | $sortdir = 'desc'; | |
998 | break; | |
999 | case 'move': | |
1000 | $sortdir = 'asc'; | |
1001 | break; | |
1002 | default: | |
1003 | $sortdir = null; | |
1004 | break; | |
1005 | } | |
1006 | ||
1007 | // Prepare language string | |
1008 | $strsort = ''; | |
1009 | if (empty($strsort) && !empty($sortdir)) { | |
1010 | $strsort = get_string('sort' . $sortdir, 'grades'); | |
1011 | } | |
1012 | ||
663640f5 | 1013 | $return = ' ' . $OUTPUT->pix_icon('t/' . $direction, $strsort) . ' '; |
f8065dd2 | 1014 | |
1015 | if ($return) { | |
1016 | return $return; | |
1017 | } else { | |
1018 | echo $return; | |
1019 | } | |
1020 | } | |
1021 | ||
8100c169 | 1022 | /** |
8100c169 | 1023 | * @deprecated since Moodle 2.0 |
8100c169 | 1024 | */ |
1025 | function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='', | |
1026 | $nothingvalue='0', $return=false, $disabled=false, $tabindex=0, | |
1027 | $id='', $listbox=false, $multiple=false, $class='') { | |
2149326b | 1028 | throw new coding_exception('choose_from_menu() is removed. Please change your code to use html_writer::select().'); |
053203a8 | 1029 | |
053203a8 | 1030 | } |
1031 | ||
c68e4098 | 1032 | /** |
05226d76 | 1033 | * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead. |
c68e4098 | 1034 | */ |
1035 | function print_scale_menu_helpbutton($courseid, $scale, $return=false) { | |
e4d9185e DP |
1036 | throw new coding_exception('print_scale_menu_helpbutton() can not be used any more. '. |
1037 | 'Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.'); | |
c68e4098 | 1038 | } |
1039 | ||
49c8c8d2 | 1040 | /** |
05226d76 | 1041 | * @deprecated use html_writer::checkbox() instead. |
49c8c8d2 | 1042 | */ |
916276fc | 1043 | function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) { |
e4d9185e | 1044 | throw new coding_exception('print_checkbox() can not be used any more. Please use html_writer::checkbox() instead.'); |
49c8c8d2 | 1045 | } |
6a5c71b9 | 1046 | |
d3932d2b JP |
1047 | /** |
1048 | * Prints the 'update this xxx' button that appears on module pages. | |
1049 | * | |
1050 | * @deprecated since Moodle 3.2 | |
1051 | * | |
1052 | * @param string $cmid the course_module id. | |
1053 | * @param string $ignored not used any more. (Used to be courseid.) | |
1054 | * @param string $string the module name - get_string('modulename', 'xxx') | |
1055 | * @return string the HTML for the button, if this user has permission to edit it, else an empty string. | |
1056 | */ | |
1057 | function update_module_button($cmid, $ignored, $string) { | |
1058 | global $CFG, $OUTPUT; | |
1059 | ||
1060 | debugging('update_module_button() has been deprecated and should not be used anymore. Activity modules should not add the ' . | |
1061 | 'edit module button, the link is already available in the Administration block. Themes can choose to display the link ' . | |
1062 | 'in the buttons row consistently for all module types.', DEBUG_DEVELOPER); | |
1063 | ||
1064 | if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) { | |
1065 | $string = get_string('updatethis', '', $string); | |
1066 | ||
1067 | $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey())); | |
1068 | return $OUTPUT->single_button($url, $string); | |
1069 | } else { | |
1070 | return ''; | |
1071 | } | |
1072 | } | |
1073 | ||
7d2a0492 | 1074 | /** |
05226d76 | 1075 | * @deprecated use $OUTPUT->navbar() instead |
7d2a0492 | 1076 | */ |
1077 | function print_navigation ($navigation, $separator=0, $return=false) { | |
e4d9185e | 1078 | throw new coding_exception('print_navigation() can not be used any more, please update use $OUTPUT->navbar() instead.'); |
7d2a0492 | 1079 | } |
1080 | ||
1081 | /** | |
05226d76 | 1082 | * @deprecated Please use $PAGE->navabar methods instead. |
7d2a0492 | 1083 | */ |
1084 | function build_navigation($extranavlinks, $cm = null) { | |
e4d9185e | 1085 | throw new coding_exception('build_navigation() can not be used any more, please use $PAGE->navbar methods instead.'); |
7d2a0492 | 1086 | } |
1087 | ||
1088 | /** | |
05226d76 | 1089 | * @deprecated not relevant with global navigation in Moodle 2.x+ |
7d2a0492 | 1090 | */ |
1091 | function navmenu($course, $cm=NULL, $targetwindow='self') { | |
e4d9185e | 1092 | throw new coding_exception('navmenu() can not be used any more, it is no longer relevant with global navigation.'); |
f43cdceb | 1093 | } |
76d9df3f SH |
1094 | |
1095 | /// CALENDAR MANAGEMENT //////////////////////////////////////////////////////////////// | |
1096 | ||
1097 | ||
1098 | /** | |
e1cd93ce | 1099 | * @deprecated please use calendar_event::create() instead. |
76d9df3f | 1100 | */ |
34c6ec18 | 1101 | function add_event($event) { |
e1cd93ce | 1102 | throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.'); |
76d9df3f SH |
1103 | } |
1104 | ||
1105 | /** | |
e1cd93ce | 1106 | * @deprecated please calendar_event->update() instead. |
76d9df3f SH |
1107 | */ |
1108 | function update_event($event) { | |
e1cd93ce | 1109 | throw new coding_exception('update_event() is removed, please use calendar_event->update() instead.'); |
76d9df3f SH |
1110 | } |
1111 | ||
1112 | /** | |
e1cd93ce | 1113 | * @deprecated please use calendar_event->delete() instead. |
76d9df3f SH |
1114 | */ |
1115 | function delete_event($id) { | |
e4d9185e | 1116 | throw new coding_exception('delete_event() can not be used any more, please use '. |
e1cd93ce | 1117 | 'calendar_event->delete() instead.'); |
76d9df3f SH |
1118 | } |
1119 | ||
1120 | /** | |
e1cd93ce | 1121 | * @deprecated please use calendar_event->toggle_visibility(false) instead. |
76d9df3f SH |
1122 | */ |
1123 | function hide_event($event) { | |
e4d9185e | 1124 | throw new coding_exception('hide_event() can not be used any more, please use '. |
e1cd93ce | 1125 | 'calendar_event->toggle_visibility(false) instead.'); |
76d9df3f SH |
1126 | } |
1127 | ||
1128 | /** | |
e1cd93ce | 1129 | * @deprecated please use calendar_event->toggle_visibility(true) instead. |
76d9df3f SH |
1130 | */ |
1131 | function show_event($event) { | |
e4d9185e | 1132 | throw new coding_exception('show_event() can not be used any more, please use '. |
e1cd93ce | 1133 | 'calendar_event->toggle_visibility(true) instead.'); |
0189bf77 | 1134 | } |
6f3451e5 | 1135 | |
3fed29a7 | 1136 | /** |
6b61c2c4 FM |
1137 | * @deprecated since Moodle 2.2 use core_text::xxxx() instead. |
1138 | * @see core_text | |
3fed29a7 PS |
1139 | */ |
1140 | function textlib_get_instance() { | |
6b61c2c4 FM |
1141 | throw new coding_exception('textlib_get_instance() can not be used any more, please use '. |
1142 | 'core_text::functioname() instead.'); | |
3fed29a7 PS |
1143 | } |
1144 | ||
ee7084e9 | 1145 | /** |
ee7084e9 MG |
1146 | * @deprecated since 2.4 |
1147 | * @see get_section_name() | |
1148 | * @see format_base::get_section_name() | |
1ac1d29b | 1149 | |
ee7084e9 MG |
1150 | */ |
1151 | function get_generic_section_name($format, stdClass $section) { | |
1ac1d29b | 1152 | throw new coding_exception('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base'); |
ee7084e9 | 1153 | } |
99e9f9a6 MG |
1154 | |
1155 | /** | |
1156 | * Returns an array of sections for the requested course id | |
1157 | * | |
1158 | * It is usually not recommended to display the list of sections used | |
1159 | * in course because the course format may have it's own way to do it. | |
1160 | * | |
1161 | * If you need to just display the name of the section please call: | |
1162 | * get_section_name($course, $section) | |
1163 | * {@link get_section_name()} | |
1164 | * from 2.4 $section may also be just the field course_sections.section | |
1165 | * | |
1166 | * If you need the list of all sections it is more efficient to get this data by calling | |
b46be6ad | 1167 | * $modinfo = get_fast_modinfo($courseorid); |
99e9f9a6 MG |
1168 | * $sections = $modinfo->get_section_info_all() |
1169 | * {@link get_fast_modinfo()} | |
1170 | * {@link course_modinfo::get_section_info_all()} | |
1171 | * | |
1172 | * Information about one section (instance of section_info): | |
b46be6ad | 1173 | * get_fast_modinfo($courseorid)->get_sections_info($section) |
99e9f9a6 MG |
1174 | * {@link course_modinfo::get_section_info()} |
1175 | * | |
1176 | * @deprecated since 2.4 | |
99e9f9a6 MG |
1177 | */ |
1178 | function get_all_sections($courseid) { | |
1ac1d29b | 1179 | |
2149326b | 1180 | throw new coding_exception('get_all_sections() is removed. See phpdocs for this function'); |
99e9f9a6 | 1181 | } |
722e6ba9 MG |
1182 | |
1183 | /** | |
722e6ba9 MG |
1184 | * This function is deprecated, please use {@link course_add_cm_to_section()} |
1185 | * Note that course_add_cm_to_section() also updates field course_modules.section and | |
1186 | * calls rebuild_course_cache() | |
1187 | * | |
1188 | * @deprecated since 2.4 | |
722e6ba9 | 1189 | */ |
44aa854e | 1190 | function add_mod_to_section($mod, $beforemod = null) { |
2149326b | 1191 | throw new coding_exception('Function add_mod_to_section() is removed, please use course_add_cm_to_section()'); |
722e6ba9 | 1192 | } |
d57aa283 MG |
1193 | |
1194 | /** | |
1195 | * Returns a number of useful structures for course displays | |
1196 | * | |
1197 | * Function get_all_mods() is deprecated in 2.4 | |
1198 | * Instead of: | |
1199 | * <code> | |
b46be6ad | 1200 | * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused); |
d57aa283 MG |
1201 | * </code> |
1202 | * please use: | |
1203 | * <code> | |
b46be6ad | 1204 | * $mods = get_fast_modinfo($courseorid)->get_cms(); |
d57aa283 MG |
1205 | * $modnames = get_module_types_names(); |
1206 | * $modnamesplural = get_module_types_names(true); | |
b46be6ad | 1207 | * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names(); |
d57aa283 MG |
1208 | * </code> |
1209 | * | |
1210 | * @deprecated since 2.4 | |
d57aa283 MG |
1211 | */ |
1212 | function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { | |
2149326b | 1213 | throw new coding_exception('Function get_all_mods() is removed. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details'); |
d57aa283 | 1214 | } |
4ede27b2 MG |
1215 | |
1216 | /** | |
1217 | * Returns course section - creates new if does not exist yet | |
1218 | * | |
1219 | * This function is deprecated. To create a course section call: | |
b46be6ad | 1220 | * course_create_sections_if_missing($courseorid, $sections); |
4ede27b2 | 1221 | * to get the section call: |
b46be6ad | 1222 | * get_fast_modinfo($courseorid)->get_section_info($sectionnum); |
4ede27b2 MG |
1223 | * |
1224 | * @see course_create_sections_if_missing() | |
1225 | * @see get_fast_modinfo() | |
1226 | * @deprecated since 2.4 | |
4ede27b2 MG |
1227 | */ |
1228 | function get_course_section($section, $courseid) { | |
2149326b | 1229 | throw new coding_exception('Function get_course_section() is removed. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.'); |
4ede27b2 | 1230 | } |
1b2581f4 MG |
1231 | |
1232 | /** | |
1b2581f4 MG |
1233 | * @deprecated since 2.4 |
1234 | * @see format_weeks::get_section_dates() | |
1b2581f4 MG |
1235 | */ |
1236 | function format_weeks_get_section_dates($section, $course) { | |
2149326b | 1237 | throw new coding_exception('Function format_weeks_get_section_dates() is removed. It is not recommended to'. |
1ac1d29b | 1238 | ' use it outside of format_weeks plugin'); |
1b2581f4 | 1239 | } |
9a36be73 MG |
1240 | |
1241 | /** | |
9a36be73 MG |
1242 | * Deprecated. Instead of: |
1243 | * list($content, $name) = get_print_section_cm_text($cm, $course); | |
1244 | * use: | |
1245 | * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)); | |
1246 | * $name = $cm->get_formatted_name(); | |
1247 | * | |
1248 | * @deprecated since 2.5 | |
1249 | * @see cm_info::get_formatted_content() | |
1250 | * @see cm_info::get_formatted_name() | |
9a36be73 MG |
1251 | */ |
1252 | function get_print_section_cm_text(cm_info $cm, $course) { | |
2149326b | 1253 | throw new coding_exception('Function get_print_section_cm_text() is removed. Please use '. |
1ac1d29b | 1254 | 'cm_info::get_formatted_content() and cm_info::get_formatted_name()'); |
9a36be73 MG |
1255 | } |
1256 | ||
1257 | /** | |
9a36be73 MG |
1258 | * Deprecated. Please use: |
1259 | * $courserenderer = $PAGE->get_renderer('core', 'course'); | |
1260 | * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn, | |
1261 | * array('inblock' => $vertical)); | |
188458a6 | 1262 | * echo $output; |
9a36be73 MG |
1263 | * |
1264 | * @deprecated since 2.5 | |
1265 | * @see core_course_renderer::course_section_add_cm_control() | |
9a36be73 MG |
1266 | */ |
1267 | function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) { | |
2149326b | 1268 | throw new coding_exception('Function print_section_add_menus() is removed. Please use course renderer '. |
1ac1d29b | 1269 | 'function course_section_add_cm_control()'); |
9a36be73 MG |
1270 | } |
1271 | ||
1272 | /** | |
9a36be73 MG |
1273 | * Deprecated. Please use: |
1274 | * $courserenderer = $PAGE->get_renderer('core', 'course'); | |
1275 | * $actions = course_get_cm_edit_actions($mod, $indent, $section); | |
1276 | * return ' ' . $courserenderer->course_section_cm_edit_actions($actions); | |
1277 | * | |
1278 | * @deprecated since 2.5 | |
1279 | * @see course_get_cm_edit_actions() | |
1280 | * @see core_course_renderer->course_section_cm_edit_actions() | |
9a36be73 MG |
1281 | */ |
1282 | function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) { | |
2149326b | 1283 | throw new coding_exception('Function make_editing_buttons() is removed, please see PHPdocs in '. |
1ac1d29b | 1284 | 'lib/deprecatedlib.php on how to replace it'); |
9a36be73 MG |
1285 | } |
1286 | ||
1287 | /** | |
9a36be73 MG |
1288 | * Deprecated. Please use: |
1289 | * $courserenderer = $PAGE->get_renderer('core', 'course'); | |
1290 | * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, | |
1291 | * array('hidecompletion' => $hidecompletion)); | |
1292 | * | |
1293 | * @deprecated since 2.5 | |
1294 | * @see core_course_renderer::course_section_cm_list() | |
9a36be73 MG |
1295 | */ |
1296 | function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) { | |
2149326b | 1297 | throw new coding_exception('Function print_section() is removed. Please use course renderer function '. |
1ac1d29b | 1298 | 'course_section_cm_list() instead.'); |
9a36be73 | 1299 | } |
00ba185d | 1300 | |
ff233851 | 1301 | /** |
ff233851 | 1302 | * @deprecated since 2.5 |
ff233851 MG |
1303 | */ |
1304 | function print_overview($courses, array $remote_courses=array()) { | |
2149326b | 1305 | throw new coding_exception('Function print_overview() is removed. Use block course_overview to display this information'); |
ff233851 | 1306 | } |
a3f66bde MG |
1307 | |
1308 | /** | |
a3f66bde | 1309 | * @deprecated since 2.5 |
a3f66bde MG |
1310 | */ |
1311 | function print_recent_activity($course) { | |
2149326b | 1312 | throw new coding_exception('Function print_recent_activity() is removed. It is not recommended to'. |
1ac1d29b | 1313 | ' use it outside of block_recent_activity'); |
a3f66bde | 1314 | } |
a347aee3 MN |
1315 | |
1316 | /** | |
a347aee3 | 1317 | * @deprecated since 2.5 |
a347aee3 MN |
1318 | */ |
1319 | function delete_course_module($id) { | |
2149326b | 1320 | throw new coding_exception('Function delete_course_module() is removed. Please use course_delete_module() instead.'); |
a347aee3 | 1321 | } |
2c49fb4c MG |
1322 | |
1323 | /** | |
2c49fb4c | 1324 | * @deprecated since 2.5 |
2c49fb4c MG |
1325 | */ |
1326 | function update_category_button($categoryid = 0) { | |
2149326b | 1327 | throw new coding_exception('Function update_category_button() is removed. Pages to view '. |
1ac1d29b | 1328 | 'and edit courses are now separate and no longer depend on editing mode.'); |
2c49fb4c | 1329 | } |
4e0b6025 MG |
1330 | |
1331 | /** | |
4e0b6025 MG |
1332 | * This function is deprecated! For list of categories use |
1333 | * coursecat::make_all_categories($requiredcapability, $excludeid, $separator) | |
1334 | * For parents of one particular category use | |
1335 | * coursecat::get($id)->get_parents() | |
1336 | * | |
1337 | * @deprecated since 2.5 | |
4e0b6025 MG |
1338 | */ |
1339 | function make_categories_list(&$list, &$parents, $requiredcapability = '', | |
1340 | $excludeid = 0, $category = NULL, $path = "") { | |
2149326b | 1341 | throw new coding_exception('Global function make_categories_list() is removed. Please use '. |
1ac1d29b | 1342 | 'coursecat::make_categories_list() and coursecat::get_parents()'); |
4e0b6025 | 1343 | } |
deb65ced MG |
1344 | |
1345 | /** | |
deb65ced | 1346 | * @deprecated since 2.5 |
deb65ced MG |
1347 | */ |
1348 | function category_delete_move($category, $newparentid, $showfeedback=true) { | |
2149326b | 1349 | throw new coding_exception('Function category_delete_move() is removed. Please use coursecat::delete_move() instead.'); |
deb65ced MG |
1350 | } |
1351 | ||
1352 | /** | |
deb65ced | 1353 | * @deprecated since 2.5 |
deb65ced MG |
1354 | */ |
1355 | function category_delete_full($category, $showfeedback=true) { | |
2149326b | 1356 | throw new coding_exception('Function category_delete_full() is removed. Please use coursecat::delete_full() instead.'); |
deb65ced | 1357 | } |
6e1d1ee0 MG |
1358 | |
1359 | /** | |
6e1d1ee0 MG |
1360 | * This function is deprecated. Please use |
1361 | * $coursecat = coursecat::get($category->id); | |
1362 | * if ($coursecat->can_change_parent($newparentcat->id)) { | |
1363 | * $coursecat->change_parent($newparentcat->id); | |
1364 | * } | |
1365 | * | |
1366 | * Alternatively you can use | |
1367 | * $coursecat->update(array('parent' => $newparentcat->id)); | |
1368 | * | |
6e1d1ee0 MG |
1369 | * @see coursecat::change_parent() |
1370 | * @see coursecat::update() | |
1371 | * @deprecated since 2.5 | |
6e1d1ee0 MG |
1372 | */ |
1373 | function move_category($category, $newparentcat) { | |
2149326b | 1374 | throw new coding_exception('Function move_category() is removed. Please use coursecat::change_parent() instead.'); |
6e1d1ee0 MG |
1375 | } |
1376 | ||
1377 | /** | |
6e1d1ee0 MG |
1378 | * This function is deprecated. Please use |
1379 | * coursecat::get($category->id)->hide(); | |
1380 | * | |
1381 | * @see coursecat::hide() | |
1382 | * @deprecated since 2.5 | |
6e1d1ee0 MG |
1383 | */ |
1384 | function course_category_hide($category) { | |
2149326b | 1385 | throw new coding_exception('Function course_category_hide() is removed. Please use coursecat::hide() instead.'); |
6e1d1ee0 MG |
1386 | } |
1387 | ||
1388 | /** | |
6e1d1ee0 MG |
1389 | * This function is deprecated. Please use |
1390 | * coursecat::get($category->id)->show(); | |
1391 | * | |
1392 | * @see coursecat::show() | |
1393 | * @deprecated since 2.5 | |
6e1d1ee0 MG |
1394 | */ |
1395 | function course_category_show($category) { | |
2149326b | 1396 | throw new coding_exception('Function course_category_show() is removed. Please use coursecat::show() instead.'); |
6e1d1ee0 | 1397 | } |
2d8a275b MG |
1398 | |
1399 | /** | |
2d8a275b MG |
1400 | * This function is deprecated. |
1401 | * To get the category with the specified it please use: | |
1402 | * coursecat::get($catid, IGNORE_MISSING); | |
1403 | * or | |
1404 | * coursecat::get($catid, MUST_EXIST); | |
1405 | * | |
1406 | * To get the first available category please use | |
1407 | * coursecat::get_default(); | |
1408 | * | |
2d8a275b | 1409 | * @deprecated since 2.5 |
2d8a275b MG |
1410 | */ |
1411 | function get_course_category($catid=0) { | |
2149326b | 1412 | throw new coding_exception('Function get_course_category() is removed. Please use coursecat::get(), see phpdocs for more details'); |
2d8a275b | 1413 | } |
9bad61db MG |
1414 | |
1415 | /** | |
9bad61db MG |
1416 | * This function is deprecated. It is replaced with the method create() in class coursecat. |
1417 | * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action | |
1418 | * | |
1419 | * @deprecated since 2.5 | |
9bad61db MG |
1420 | */ |
1421 | function create_course_category($category) { | |
2149326b | 1422 | throw new coding_exception('Function create_course_category() is removed. Please use coursecat::create(), see phpdocs for more details'); |
9bad61db | 1423 | } |
bc81b006 MG |
1424 | |
1425 | /** | |
bc81b006 MG |
1426 | * This function is deprecated. |
1427 | * | |
1428 | * To get visible children categories of the given category use: | |
1429 | * coursecat::get($categoryid)->get_children(); | |
1430 | * This function will return the array or coursecat objects, on each of them | |
1431 | * you can call get_children() again | |
1432 | * | |
1433 | * @see coursecat::get() | |
1434 | * @see coursecat::get_children() | |
1435 | * | |
1436 | * @deprecated since 2.5 | |
bc81b006 MG |
1437 | */ |
1438 | function get_all_subcategories($catid) { | |
2149326b | 1439 | throw new coding_exception('Function get_all_subcategories() is removed. Please use appropriate methods() of coursecat |
1ac1d29b | 1440 | class. See phpdocs for more details'); |
bc81b006 | 1441 | } |
8db5dcb7 MG |
1442 | |
1443 | /** | |
8db5dcb7 MG |
1444 | * This function is deprecated. Please use functions in class coursecat: |
1445 | * - coursecat::get($parentid)->has_children() | |
1446 | * tells if the category has children (visible or not to the current user) | |
1447 | * | |
1448 | * - coursecat::get($parentid)->get_children() | |
1449 | * returns an array of coursecat objects, each of them represents a children category visible | |
1450 | * to the current user (i.e. visible=1 or user has capability to view hidden categories) | |
1451 | * | |
1452 | * - coursecat::get($parentid)->get_children_count() | |
1453 | * returns number of children categories visible to the current user | |
1454 | * | |
1455 | * - coursecat::count_all() | |
1456 | * returns total count of all categories in the system (both visible and not) | |
1457 | * | |
1458 | * - coursecat::get_default() | |
1459 | * returns the first category (usually to be used if count_all() == 1) | |
1460 | * | |
1461 | * @deprecated since 2.5 | |
8db5dcb7 MG |
1462 | */ |
1463 | function get_child_categories($parentid) { | |
2149326b | 1464 | throw new coding_exception('Function get_child_categories() is removed. Use coursecat::get_children() or see phpdocs for |
1ac1d29b | 1465 | more details.'); |
8db5dcb7 | 1466 | } |
e1d54562 MG |
1467 | |
1468 | /** | |
e1d54562 MG |
1469 | * |
1470 | * @deprecated since 2.5 | |
1471 | * | |
1472 | * This function is deprecated. Use appropriate functions from class coursecat. | |
1473 | * Examples: | |
1474 | * | |
1475 | * coursecat::get($categoryid)->get_children() | |
1476 | * - returns all children of the specified category as instances of class | |
0198b4a5 MG |
1477 | * coursecat, which means on each of them method get_children() can be called again. |
1478 | * Only categories visible to the current user are returned. | |
e1d54562 | 1479 | * |
0198b4a5 MG |
1480 | * coursecat::get(0)->get_children() |
1481 | * - returns all top-level categories visible to the current user. | |
e1d54562 MG |
1482 | * |
1483 | * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()} | |
1484 | * | |
0198b4a5 MG |
1485 | * coursecat::make_categories_list() |
1486 | * - returns an array of all categories id/names in the system. | |
1487 | * Also only returns categories visible to current user and can additionally be | |
1488 | * filetered by capability, see phpdocs to {@link coursecat::make_categories_list()} | |
1489 | * | |
1490 | * make_categories_options() | |
1491 | * - Returns full course categories tree to be used in html_writer::select() | |
1492 | * | |
e1d54562 MG |
1493 | * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()}, |
1494 | * {@link coursecat::get_default()} | |
e1d54562 MG |
1495 | */ |
1496 | function get_categories($parent='none', $sort=NULL, $shallow=true) { | |
2149326b | 1497 | throw new coding_exception('Function get_categories() is removed. Please use coursecat::get_children() or see phpdocs for other alternatives'); |
e1d54562 | 1498 | } |
a8d683ca MG |
1499 | |
1500 | /** | |
a8d683ca MG |
1501 | * This function is deprecated, please use course renderer: |
1502 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
1503 | * echo $renderer->course_search_form($value, $format); | |
1504 | * | |
1505 | * @deprecated since 2.5 | |
a8d683ca MG |
1506 | */ |
1507 | function print_course_search($value="", $return=false, $format="plain") { | |
2149326b | 1508 | throw new coding_exception('Function print_course_search() is removed, please use course renderer'); |
a8d683ca | 1509 | } |
09ae7ee0 MG |
1510 | |
1511 | /** | |
09ae7ee0 MG |
1512 | * This function is deprecated, please use: |
1513 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
1514 | * echo $renderer->frontpage_my_courses() | |
1515 | * | |
1516 | * @deprecated since 2.5 | |
1517 | */ | |
1518 | function print_my_moodle() { | |
2149326b | 1519 | throw new coding_exception('Function print_my_moodle() is removed, please use course renderer function frontpage_my_courses()'); |
09ae7ee0 MG |
1520 | } |
1521 | ||
1522 | /** | |
09ae7ee0 MG |
1523 | * This function is deprecated, it is replaced with protected function |
1524 | * {@link core_course_renderer::frontpage_remote_course()} | |
1525 | * It is only used from function {@link core_course_renderer::frontpage_my_courses()} | |
1526 | * | |
1527 | * @deprecated since 2.5 | |
1528 | */ | |
1529 | function print_remote_course($course, $width="100%") { | |
2149326b | 1530 | throw new coding_exception('Function print_remote_course() is removed, please use course renderer'); |
09ae7ee0 MG |
1531 | } |
1532 | ||
1533 | /** | |
09ae7ee0 MG |
1534 | * This function is deprecated, it is replaced with protected function |
1535 | * {@link core_course_renderer::frontpage_remote_host()} | |
1536 | * It is only used from function {@link core_course_renderer::frontpage_my_courses()} | |
1537 | * | |
1538 | * @deprecated since 2.5 | |
1539 | */ | |
1540 | function print_remote_host($host, $width="100%") { | |
2149326b | 1541 | throw new coding_exception('Function print_remote_host() is removed, please use course renderer'); |
09ae7ee0 MG |
1542 | } |
1543 | ||
1544 | /** | |
09ae7ee0 MG |
1545 | * @deprecated since 2.5 |
1546 | * | |
1547 | * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 | |
1548 | */ | |
1549 | function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) { | |
2149326b | 1550 | throw new coding_exception('Function print_whole_category_list() is removed, please use course renderer'); |
09ae7ee0 MG |
1551 | } |
1552 | ||
1553 | /** | |
09ae7ee0 | 1554 | * @deprecated since 2.5 |
09ae7ee0 MG |
1555 | */ |
1556 | function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) { | |
2149326b | 1557 | throw new coding_exception('Function print_category_info() is removed, please use course renderer'); |
09ae7ee0 MG |
1558 | } |
1559 | ||
1560 | /** | |
09ae7ee0 MG |
1561 | * @deprecated since 2.5 |
1562 | * | |
1563 | * This function is not used any more in moodle core and course renderer does not have render function for it. | |
1564 | * Combo list on the front page is displayed as: | |
1565 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
1566 | * echo $renderer->frontpage_combo_list() | |
1567 | * | |
1568 | * The new class {@link coursecat} stores the information about course category tree | |
1569 | * To get children categories use: | |
1570 | * coursecat::get($id)->get_children() | |
1571 | * To get list of courses use: | |
1572 | * coursecat::get($id)->get_courses() | |
1573 | * | |
1574 | * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 | |
09ae7ee0 MG |
1575 | */ |
1576 | function get_course_category_tree($id = 0, $depth = 0) { | |
2149326b | 1577 | throw new coding_exception('Function get_course_category_tree() is removed, please use course renderer or coursecat class, |
1ac1d29b | 1578 | see function phpdocs for more info'); |
09ae7ee0 MG |
1579 | } |
1580 | ||
1581 | /** | |
09ae7ee0 MG |
1582 | * @deprecated since 2.5 |
1583 | * | |
1584 | * To print a generic list of courses use: | |
1585 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
1586 | * echo $renderer->courses_list($courses); | |
1587 | * | |
1588 | * To print list of all courses: | |
1589 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
1590 | * echo $renderer->frontpage_available_courses(); | |
1591 | * | |
1592 | * To print list of courses inside category: | |
1593 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
1594 | * echo $renderer->course_category($category); // this will also print subcategories | |
09ae7ee0 MG |
1595 | */ |
1596 | function print_courses($category) { | |
2149326b | 1597 | throw new coding_exception('Function print_courses() is removed, please use course renderer'); |
09ae7ee0 MG |
1598 | } |
1599 | ||
1600 | /** | |
09ae7ee0 MG |
1601 | * @deprecated since 2.5 |
1602 | * | |
1603 | * Please use course renderer to display a course information box. | |
1604 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
1605 | * echo $renderer->courses_list($courses); // will print list of courses | |
1606 | * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox | |
09ae7ee0 MG |
1607 | */ |
1608 | function print_course($course, $highlightterms = '') { | |
2149326b | 1609 | throw new coding_exception('Function print_course() is removed, please use course renderer'); |
09ae7ee0 MG |
1610 | } |
1611 | ||
1612 | /** | |
09ae7ee0 MG |
1613 | * @deprecated since 2.5 |
1614 | * | |
1615 | * This function is not used any more in moodle core and course renderer does not have render function for it. | |
1616 | * Combo list on the front page is displayed as: | |
1617 | * $renderer = $PAGE->get_renderer('core', 'course'); | |
1618 | * echo $renderer->frontpage_combo_list() | |
1619 | * | |
1620 | * The new class {@link coursecat} stores the information about course category tree | |
1621 | * To get children categories use: | |
1622 | * coursecat::get($id)->get_children() | |
1623 | * To get list of courses use: | |
1624 | * coursecat::get($id)->get_courses() | |
09ae7ee0 MG |
1625 | */ |
1626 | function get_category_courses_array($categoryid = 0) { | |
2149326b | 1627 | throw new coding_exception('Function get_category_courses_array() is removed, please use methods of coursecat class'); |
09ae7ee0 MG |
1628 | } |
1629 | ||
1630 | /** | |
09ae7ee0 | 1631 | * @deprecated since 2.5 |
09ae7ee0 MG |
1632 | */ |
1633 | function get_category_courses_array_recursively(array &$flattened, $category) { | |
2149326b | 1634 | throw new coding_exception('Function get_category_courses_array_recursively() is removed, please use methods of coursecat class', DEBUG_DEVELOPER); |
09ae7ee0 MG |
1635 | } |
1636 | ||
7ac18cf9 | 1637 | /** |
7ac18cf9 | 1638 | * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more. |
7ac18cf9 AA |
1639 | */ |
1640 | function blog_get_context_url($context=null) { | |
2149326b | 1641 | throw new coding_exception('Function blog_get_context_url() is removed, getting params from context is not reliable for blogs.'); |
7ac18cf9 AA |
1642 | } |
1643 | ||
09ae7ee0 | 1644 | /** |
09ae7ee0 MG |
1645 | * @deprecated since 2.5 |
1646 | * | |
1647 | * To get list of all courses with course contacts ('managers') use | |
1648 | * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true)); | |
1649 | * | |
1650 | * To get list of courses inside particular category use | |
1651 | * coursecat::get($id)->get_courses(array('coursecontacts' => true)); | |
1652 | * | |
1653 | * Additionally you can specify sort order, offset and maximum number of courses, | |
1654 | * see {@link coursecat::get_courses()} | |
09ae7ee0 MG |
1655 | */ |
1656 | function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) { | |
2149326b | 1657 | throw new coding_exception('Function get_courses_wmanagers() is removed, please use coursecat::get_courses()'); |
09ae7ee0 | 1658 | } |
c269b9d1 MG |
1659 | |
1660 | /** | |
c269b9d1 | 1661 | * @deprecated since 2.5 |
c269b9d1 MG |
1662 | */ |
1663 | function convert_tree_to_html($tree, $row=0) { | |
2149326b | 1664 | throw new coding_exception('Function convert_tree_to_html() is removed. Consider using class tabtree and core_renderer::render_tabtree()'); |
c269b9d1 MG |
1665 | } |
1666 | ||
1667 | /** | |
c269b9d1 | 1668 | * @deprecated since 2.5 |
c269b9d1 MG |
1669 | */ |
1670 | function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) { | |
2149326b | 1671 | throw new coding_exception('Function convert_tabrows_to_tree() is removed. Consider using class tabtree'); |
c269b9d1 | 1672 | } |
9052fc44 | 1673 | |
8ef3a222 | 1674 | /** |
8ef3a222 | 1675 | * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically |
8ef3a222 DP |
1676 | */ |
1677 | function can_use_rotated_text() { | |
2149326b | 1678 | debugging('can_use_rotated_text() is removed. JS feature detection is used automatically.'); |
8ef3a222 | 1679 | } |
61a0299a | 1680 | |
ce2b2150 | 1681 | /** |
ce2b2150 | 1682 | * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more. |
ce2b2150 | 1683 | * @see context::instance_by_id($id) |
ce2b2150 RT |
1684 | */ |
1685 | function get_context_instance_by_id($id, $strictness = IGNORE_MISSING) { | |
f9b7be4f | 1686 | throw new coding_exception('get_context_instance_by_id() is now removed, please use context::instance_by_id($id) instead.'); |
ce2b2150 | 1687 | } |
85b2e46f | 1688 | |
492ba9de AA |
1689 | /** |
1690 | * Returns system context or null if can not be created yet. | |
1691 | * | |
1692 | * @see context_system::instance() | |
01546175 | 1693 | * @deprecated since 2.2 |
492ba9de AA |
1694 | * @param bool $cache use caching |
1695 | * @return context system context (null if context table not created yet) | |
1696 | */ | |
1697 | function get_system_context($cache = true) { | |
1698 | debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER); | |
1699 | return context_system::instance(0, IGNORE_MISSING, $cache); | |
1700 | } | |
8e8891b7 FM |
1701 | |
1702 | /** | |
8e8891b7 FM |
1703 | * @see context::get_parent_context_ids() |
1704 | * @deprecated since 2.2, use $context->get_parent_context_ids() instead | |
8e8891b7 FM |
1705 | */ |
1706 | function get_parent_contexts(context $context, $includeself = false) { | |
2149326b | 1707 | throw new coding_exception('get_parent_contexts() is removed, please use $context->get_parent_context_ids() instead.'); |
8e8891b7 | 1708 | } |
766fd0d9 AD |
1709 | |
1710 | /** | |
7f5b51c4 RT |
1711 | * @deprecated since Moodle 2.2 |
1712 | * @see context::get_parent_context() | |
766fd0d9 | 1713 | */ |
7f5b51c4 | 1714 | function get_parent_contextid(context $context) { |
2149326b | 1715 | throw new coding_exception('get_parent_contextid() is removed, please use $context->get_parent_context() instead.'); |
766fd0d9 | 1716 | } |
f9aa8016 FM |
1717 | |
1718 | /** | |
f9aa8016 FM |
1719 | * @see context::get_child_contexts() |
1720 | * @deprecated since 2.2 | |
f9aa8016 FM |
1721 | */ |
1722 | function get_child_contexts(context $context) { | |
2149326b | 1723 | throw new coding_exception('get_child_contexts() is removed, please use $context->get_child_contexts() instead.'); |
f9aa8016 | 1724 | } |
9fdbf620 FM |
1725 | |
1726 | /** | |
9fdbf620 FM |
1727 | * @see context_helper::create_instances() |
1728 | * @deprecated since 2.2 | |
9fdbf620 FM |
1729 | */ |
1730 | function create_contexts($contextlevel = null, $buildpaths = true) { | |
2149326b | 1731 | throw new coding_exception('create_contexts() is removed, please use context_helper::create_instances() instead.'); |
9fdbf620 | 1732 | } |
84378a57 FM |
1733 | |
1734 | /** | |
84378a57 FM |
1735 | * @see context_helper::cleanup_instances() |
1736 | * @deprecated since 2.2 | |
84378a57 FM |
1737 | */ |
1738 | function cleanup_contexts() { | |
2149326b | 1739 | throw new coding_exception('cleanup_contexts() is removed, please use context_helper::cleanup_instances() instead.'); |
84378a57 | 1740 | } |
79f6b384 FM |
1741 | |
1742 | /** | |
1743 | * Populate context.path and context.depth where missing. | |
1744 | * | |
79f6b384 | 1745 | * @deprecated since 2.2 |
79f6b384 FM |
1746 | */ |
1747 | function build_context_path($force = false) { | |
2149326b | 1748 | throw new coding_exception('build_context_path() is removed, please use context_helper::build_all_paths() instead.'); |
79f6b384 | 1749 | } |
cc4de415 FM |
1750 | |
1751 | /** | |
cc4de415 | 1752 | * @deprecated since 2.2 |
cc4de415 FM |
1753 | */ |
1754 | function rebuild_contexts(array $fixcontexts) { | |
2149326b | 1755 | throw new coding_exception('rebuild_contexts() is removed, please use $context->reset_paths(true) instead.'); |
cc4de415 | 1756 | } |
8f7d3d12 RT |
1757 | |
1758 | /** | |
8f7d3d12 RT |
1759 | * @deprecated since Moodle 2.2 |
1760 | * @see context_helper::preload_course() | |
8f7d3d12 RT |
1761 | */ |
1762 | function preload_course_contexts($courseid) { | |
2149326b | 1763 | throw new coding_exception('preload_course_contexts() is removed, please use context_helper::preload_course() instead.'); |
8f7d3d12 | 1764 | } |
2c5b0eb7 RT |
1765 | |
1766 | /** | |
2c5b0eb7 RT |
1767 | * @deprecated since Moodle 2.2 |
1768 | * @see context::update_moved() | |
2c5b0eb7 RT |
1769 | */ |
1770 | function context_moved(context $context, context $newparent) { | |
2149326b | 1771 | throw new coding_exception('context_moved() is removed, please use context::update_moved() instead.'); |
c5dcd25d AA |
1772 | } |
1773 | ||
a439b2f9 | 1774 | /** |
a439b2f9 FM |
1775 | * @see context::get_capabilities() |
1776 | * @deprecated since 2.2 | |
a439b2f9 FM |
1777 | */ |
1778 | function fetch_context_capabilities(context $context) { | |
2149326b | 1779 | throw new coding_exception('fetch_context_capabilities() is removed, please use $context->get_capabilities() instead.'); |
a439b2f9 FM |
1780 | } |
1781 | ||
c5dcd25d | 1782 | /** |
c5dcd25d AA |
1783 | * @deprecated since 2.2 |
1784 | * @see context_helper::preload_from_record() | |
c5dcd25d AA |
1785 | */ |
1786 | function context_instance_preload(stdClass $rec) { | |
2149326b | 1787 | throw new coding_exception('context_instance_preload() is removed, please use context_helper::preload_from_record() instead.'); |
c5dcd25d | 1788 | } |
b4482dfe AG |
1789 | |
1790 | /** | |
1791 | * Returns context level name | |
1792 | * | |
1793 | * @deprecated since 2.2 | |
1794 | * @see context_helper::get_level_name() | |
b4482dfe AG |
1795 | */ |
1796 | function get_contextlevel_name($contextlevel) { | |
2149326b | 1797 | throw new coding_exception('get_contextlevel_name() is removed, please use context_helper::get_level_name() instead.'); |
b4482dfe | 1798 | } |
329846f1 AG |
1799 | |
1800 | /** | |
329846f1 AG |
1801 | * @deprecated since 2.2 |
1802 | * @see context::get_context_name() | |
329846f1 AG |
1803 | */ |
1804 | function print_context_name(context $context, $withprefix = true, $short = false) { | |
2149326b | 1805 | throw new coding_exception('print_context_name() is removed, please use $context->get_context_name() instead.'); |
329846f1 | 1806 | } |
1de02d62 AG |
1807 | |
1808 | /** | |
1de02d62 AG |
1809 | * @deprecated since 2.2, use $context->mark_dirty() instead |
1810 | * @see context::mark_dirty() | |
1de02d62 AG |
1811 | */ |
1812 | function mark_context_dirty($path) { | |
2149326b | 1813 | throw new coding_exception('mark_context_dirty() is removed, please use $context->mark_dirty() instead.'); |
1de02d62 | 1814 | } |
c592eea2 RT |
1815 | |
1816 | /** | |
c592eea2 RT |
1817 | * @deprecated since Moodle 2.2 |
1818 | * @see context_helper::delete_instance() or context::delete_content() | |
c592eea2 RT |
1819 | */ |
1820 | function delete_context($contextlevel, $instanceid, $deleterecord = true) { | |
1821 | if ($deleterecord) { | |
2149326b | 1822 | throw new coding_exception('delete_context() is removed, please use context_helper::delete_instance() instead.'); |
c592eea2 | 1823 | } else { |
2149326b | 1824 | throw new coding_exception('delete_context() is removed, please use $context->delete_content() instead.'); |
c592eea2 | 1825 | } |
c592eea2 | 1826 | } |
6c89d4e1 MN |
1827 | |
1828 | /** | |
6c89d4e1 MN |
1829 | * @deprecated since 2.2 |
1830 | * @see context::get_url() | |
6c89d4e1 MN |
1831 | */ |
1832 | function get_context_url(context $context) { | |
2149326b | 1833 | throw new coding_exception('get_context_url() is removed, please use $context->get_url() instead.'); |
6c89d4e1 MN |
1834 | } |
1835 | ||
dd33f4af | 1836 | /** |
dd33f4af MN |
1837 | * @deprecated since 2.2 |
1838 | * @see context::get_course_context() | |
dd33f4af MN |
1839 | */ |
1840 | function get_course_context(context $context) { | |
2149326b | 1841 | throw new coding_exception('get_course_context() is removed, please use $context->get_course_context(true) instead.'); |
dd33f4af | 1842 | } |
6acc54b3 AA |
1843 | |
1844 | /** | |
6acc54b3 AA |
1845 | * @deprecated since 2.2 |
1846 | * @see enrol_get_users_courses() | |
6acc54b3 AA |
1847 | */ |
1848 | function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) { | |
1849 | ||
2149326b | 1850 | throw new coding_exception('get_user_courses_bycap() is removed, please use enrol_get_users_courses() instead.'); |
6acc54b3 | 1851 | } |
ae38dcb1 RT |
1852 | |
1853 | /** | |
ae38dcb1 | 1854 | * @deprecated since Moodle 2.2 |
ae38dcb1 RT |
1855 | */ |
1856 | function get_role_context_caps($roleid, context $context) { | |
2149326b | 1857 | throw new coding_exception('get_role_context_caps() is removed, it is really slow. Don\'t use it.'); |
ae38dcb1 | 1858 | } |
b123a543 FM |
1859 | |
1860 | /** | |
b123a543 FM |
1861 | * @see context::get_course_context() |
1862 | * @deprecated since 2.2 | |
b123a543 FM |
1863 | */ |
1864 | function get_courseid_from_context(context $context) { | |
2149326b | 1865 | throw new coding_exception('get_courseid_from_context() is removed, please use $context->get_course_context(false) instead.'); |
6a30b48d | 1866 | } |
2e4c0c91 FM |
1867 | |
1868 | /** | |
2e4c0c91 FM |
1869 | * If you are using this methid, you should have something like this: |
1870 | * | |
1871 | * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); | |
1872 | * | |
1873 | * To prevent the use of this deprecated function, replace the line above with something similar to this: | |
1874 | * | |
1875 | * $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx'); | |
1876 | * ^ | |
1877 | * $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)"; | |
1878 | * ^ ^ ^ ^ | |
1879 | * $params = array('contextlevel' => CONTEXT_COURSE); | |
1880 | * ^ | |
1881 | * @see context_helper:;get_preload_record_columns_sql() | |
1882 | * @deprecated since 2.2 | |
2e4c0c91 FM |
1883 | */ |
1884 | function context_instance_preload_sql($joinon, $contextlevel, $tablealias) { | |
2149326b | 1885 | throw new coding_exception('context_instance_preload_sql() is removed, please use context_helper::get_preload_record_columns_sql() instead.'); |
b123a543 | 1886 | } |
b6452844 MN |
1887 | |
1888 | /** | |
b6452844 MN |
1889 | * @deprecated since 2.2 |
1890 | * @see context::get_parent_context_ids() | |
b6452844 MN |
1891 | */ |
1892 | function get_related_contexts_string(context $context) { | |
2149326b | 1893 | throw new coding_exception('get_related_contexts_string() is removed, please use $context->get_parent_context_ids(true) instead.'); |
b6452844 | 1894 | } |
0142523d | 1895 | |
d0cac8b5 | 1896 | /** |
d0cac8b5 FM |
1897 | * @deprecated since 2.6 |
1898 | * @see core_component::get_plugin_list_with_file() | |
1899 | */ | |
1900 | function get_plugin_list_with_file($plugintype, $file, $include = false) { | |
2149326b | 1901 | throw new coding_exception('get_plugin_list_with_file() is removed, please use core_component::get_plugin_list_with_file() instead.'); |
d0cac8b5 | 1902 | } |
c3d2fbf9 SH |
1903 | |
1904 | /** | |
c3d2fbf9 | 1905 | * @deprecated since 2.6 |
c3d2fbf9 SH |
1906 | */ |
1907 | function check_browser_operating_system($brand) { | |
2149326b | 1908 | throw new coding_exception('check_browser_operating_system is removed, please update your code to use core_useragent instead.'); |
c3d2fbf9 SH |
1909 | } |
1910 | ||
1911 | /** | |
c3d2fbf9 | 1912 | * @deprecated since 2.6 |
c3d2fbf9 SH |
1913 | */ |
1914 | function check_browser_version($brand, $version = null) { | |
2149326b | 1915 | throw new coding_exception('check_browser_version is removed, please update your code to use core_useragent instead.'); |
c3d2fbf9 SH |
1916 | } |
1917 | ||
1918 | /** | |
c3d2fbf9 | 1919 | * @deprecated since 2.6 |
c3d2fbf9 SH |
1920 | */ |
1921 | function get_device_type() { | |
2149326b | 1922 | throw new coding_exception('get_device_type is removed, please update your code to use core_useragent instead.'); |
c3d2fbf9 SH |
1923 | } |
1924 | ||
1925 | /** | |
c3d2fbf9 | 1926 | * @deprecated since 2.6 |
c3d2fbf9 SH |
1927 | */ |
1928 | function get_device_type_list($incusertypes = true) { | |
2149326b | 1929 | throw new coding_exception('get_device_type_list is removed, please update your code to use core_useragent instead.'); |
c3d2fbf9 SH |
1930 | } |
1931 | ||
1932 | /** | |
c3d2fbf9 | 1933 | * @deprecated since 2.6 |
c3d2fbf9 SH |
1934 | */ |
1935 | function get_selected_theme_for_device_type($devicetype = null) { | |
2149326b | 1936 | throw new coding_exception('get_selected_theme_for_device_type is removed, please update your code to use core_useragent instead.'); |
c3d2fbf9 SH |
1937 | } |
1938 | ||
1939 | /** | |
c3d2fbf9 | 1940 | * @deprecated since 2.6 |
c3d2fbf9 SH |
1941 | */ |
1942 | function get_device_cfg_var_name($devicetype = null) { | |
2149326b | 1943 | throw new coding_exception('get_device_cfg_var_name is removed, please update your code to use core_useragent instead.'); |
c3d2fbf9 SH |
1944 | } |
1945 | ||
1946 | /** | |
c3d2fbf9 | 1947 | * @deprecated since 2.6 |
c3d2fbf9 SH |
1948 | */ |
1949 | function set_user_device_type($newdevice) { | |
2149326b | 1950 | throw new coding_exception('set_user_device_type is removed, please update your code to use core_useragent instead.'); |
c3d2fbf9 SH |
1951 | } |
1952 | ||
1953 | /** | |
c3d2fbf9 | 1954 | * @deprecated since 2.6 |
c3d2fbf9 SH |
1955 | */ |
1956 | function get_user_device_type() { | |
2149326b | 1957 | throw new coding_exception('get_user_device_type is removed, please update your code to use core_useragent instead.'); |
c3d2fbf9 SH |
1958 | } |
1959 | ||
1960 | /** | |
c3d2fbf9 | 1961 | * @deprecated since 2.6 |
c3d2fbf9 SH |
1962 | */ |
1963 | function get_browser_version_classes() { | |
2149326b | 1964 | throw new coding_exception('get_browser_version_classes is removed, please update your code to use core_useragent instead.'); |
2b503e40 RT |
1965 | } |
1966 | ||
1967 | /** | |
2b503e40 RT |
1968 | * @deprecated since Moodle 2.6 |
1969 | * @see core_user::get_support_user() | |
2b503e40 RT |
1970 | */ |
1971 | function generate_email_supportuser() { | |
2149326b | 1972 | throw new coding_exception('generate_email_supportuser is removed, please use core_user::get_support_user'); |
853e506a Y |
1973 | } |
1974 | ||
1975 | /** | |
853e506a | 1976 | * @deprecated since Moodle 2.6 |
853e506a Y |
1977 | */ |
1978 | function badges_get_issued_badge_info($hash) { | |
2149326b | 1979 | throw new coding_exception('Function badges_get_issued_badge_info() is removed. Please use core_badges_assertion class and methods to generate badge assertion.'); |
853e506a | 1980 | } |
3d27180e DW |
1981 | |
1982 | /** | |
3d27180e | 1983 | * @deprecated since 2.6 |
3d27180e DW |
1984 | */ |
1985 | function can_use_html_editor() { | |
2149326b | 1986 | throw new coding_exception('can_use_html_editor is removed, please update your code to assume it returns true.'); |
3d27180e | 1987 | } |
52dc1de7 AA |
1988 | |
1989 | ||
1990 | /** | |
26e4b0ca | 1991 | * @deprecated since Moodle 2.7, use {@link user_count_login_failures()} instead. |
52dc1de7 AA |
1992 | */ |
1993 | function count_login_failures($mode, $username, $lastlogin) { | |
26e4b0ca | 1994 | throw new coding_exception('count_login_failures() can not be used any more, please use user_count_login_failures().'); |
52dc1de7 | 1995 | } |
de878a38 | 1996 | |
6538153b | 1997 | /** |
44ab05b3 | 1998 | * @deprecated since 2.7 MDL-33099/MDL-44088 - please do not use this function any more. |
6538153b FM |
1999 | */ |
2000 | function ajaxenabled(array $browsers = null) { | |
44ab05b3 | 2001 | throw new coding_exception('ajaxenabled() can not be used anymore. Update your code to work with JS at all times.'); |
6538153b | 2002 | } |
8d1f33e1 | 2003 | |
2004 | /** | |
e56e8e3a | 2005 | * @deprecated Since Moodle 2.7 MDL-44070 |
8d1f33e1 | 2006 | */ |
2007 | function coursemodule_visible_for_user($cm, $userid=0) { | |
e56e8e3a AA |
2008 | throw new coding_exception('coursemodule_visible_for_user() can not be used any more, |
2009 | please use \core_availability\info_module::is_user_visible()'); | |
8d1f33e1 | 2010 | } |
80f98467 MG |
2011 | |
2012 | /** | |
58b5b04d | 2013 | * @deprecated since Moodle 2.8 MDL-36014, MDL-35618 this functionality is removed |
80f98467 MG |
2014 | */ |
2015 | function enrol_cohort_get_cohorts(course_enrolment_manager $manager) { | |
2149326b | 2016 | throw new coding_exception('Function enrol_cohort_get_cohorts() is removed, use enrol_cohort_search_cohorts() or '. |
1ac1d29b | 2017 | 'cohort_get_available_cohorts() instead'); |
80f98467 MG |
2018 | } |
2019 | ||
2020 | /** | |
80f98467 MG |
2021 | * This function is deprecated, use {@link cohort_can_view_cohort()} instead since it also |
2022 | * takes into account current context | |
2023 | * | |
2024 | * @deprecated since Moodle 2.8 MDL-36014 please use cohort_can_view_cohort() | |
80f98467 MG |
2025 | */ |
2026 | function enrol_cohort_can_view_cohort($cohortid) { | |
2149326b | 2027 | throw new coding_exception('Function enrol_cohort_can_view_cohort() is removed, use cohort_can_view_cohort() instead'); |
80f98467 MG |
2028 | } |
2029 | ||
2030 | /** | |
80f98467 MG |
2031 | * It is advisable to use {@link cohort_get_available_cohorts()} instead. |
2032 | * | |
2033 | * @deprecated since Moodle 2.8 MDL-36014 use cohort_get_available_cohorts() instead | |
80f98467 MG |
2034 | */ |
2035 | function cohort_get_visible_list($course, $onlyenrolled=true) { | |
2149326b | 2036 | throw new coding_exception('Function cohort_get_visible_list() is removed. Please use function cohort_get_available_cohorts() ". |
1ac1d29b | 2037 | "that correctly checks capabilities.'); |
80f98467 | 2038 | } |
58b5b04d MG |
2039 | |
2040 | /** | |
58b5b04d | 2041 | * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed |
58b5b04d MG |
2042 | */ |
2043 | function enrol_cohort_enrol_all_users(course_enrolment_manager $manager, $cohortid, $roleid) { | |
2149326b | 2044 | throw new coding_exception('enrol_cohort_enrol_all_users() is removed. This functionality is moved to enrol_manual.'); |
58b5b04d MG |
2045 | } |
2046 | ||
2047 | /** | |
58b5b04d | 2048 | * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed |
58b5b04d MG |
2049 | */ |
2050 | function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset = 0, $limit = 25, $search = '') { | |
2149326b | 2051 | throw new coding_exception('enrol_cohort_search_cohorts() is removed. This functionality is moved to enrol_manual.'); |
58b5b04d | 2052 | } |
bdc83277 | 2053 | |
8322ed4a AA |
2054 | /* === Apis deprecated in since Moodle 2.9 === */ |
2055 | ||
bdc83277 DM |
2056 | /** |
2057 | * Is $USER one of the supplied users? | |
2058 | * | |
2059 | * $user2 will be null if viewing a user's recent conversations | |
2060 | * | |
2061 | * @deprecated since Moodle 2.9 MDL-49371 - please do not use this function any more. | |
bdc83277 DM |
2062 | */ |
2063 | function message_current_user_is_involved($user1, $user2) { | |
be43ad0d | 2064 | throw new coding_exception('message_current_user_is_involved() can not be used any more.'); |
bdc83277 | 2065 | } |
b19cc4ef AA |
2066 | |
2067 | /** | |
2068 | * Print badges on user profile page. | |
2069 | * | |
2070 | * @deprecated since Moodle 2.9 MDL-45898 - please do not use this function any more. | |
b19cc4ef AA |
2071 | */ |
2072 | function profile_display_badges($userid, $courseid = 0) { | |
a77e0611 | 2073 | throw new coding_exception('profile_display_badges() can not be used any more.'); |
b19cc4ef | 2074 | } |
efd32edb AG |
2075 | |
2076 | /** | |
2077 | * Adds user preferences elements to user edit form. | |
2078 | * | |
2079 | * @deprecated since Moodle 2.9 MDL-45774 - Please do not use this function any more. | |
efd32edb AG |
2080 | */ |
2081 | function useredit_shared_definition_preferences($user, &$mform, $editoroptions = null, $filemanageroptions = null) { | |
ab2d9b34 | 2082 | throw new coding_exception('useredit_shared_definition_preferences() can not be used any more.'); |
efd32edb | 2083 | } |
8322ed4a AA |
2084 | |
2085 | ||
2086 | /** | |
2087 | * Convert region timezone to php supported timezone | |
2088 | * | |
2089 | * @deprecated since Moodle 2.9 | |
8322ed4a AA |
2090 | */ |
2091 | function calendar_normalize_tz($tz) { | |
678b315f | 2092 | throw new coding_exception('calendar_normalize_tz() can not be used any more, please use core_date::normalise_timezone() instead.'); |
8322ed4a AA |
2093 | } |
2094 | ||
2095 | /** | |
2096 | * Returns a float which represents the user's timezone difference from GMT in hours | |
2097 | * Checks various settings and picks the most dominant of those which have a value | |
2098 | * @deprecated since Moodle 2.9 | |
8322ed4a AA |
2099 | */ |
2100 | function get_user_timezone_offset($tz = 99) { | |
a77e0611 SL |
2101 | throw new coding_exception('get_user_timezone_offset() can not be used any more, please use standard PHP DateTimeZone class instead'); |
2102 | ||
8322ed4a AA |
2103 | } |
2104 | ||
2105 | /** | |
2106 | * Returns an int which represents the systems's timezone difference from GMT in seconds | |
2107 | * @deprecated since Moodle 2.9 | |
8322ed4a AA |
2108 | */ |
2109 | function get_timezone_offset($tz) { | |
a77e0611 | 2110 | throw new coding_exception('get_timezone_offset() can not be used any more, please use standard PHP DateTimeZone class instead'); |
8322ed4a AA |
2111 | } |
2112 | ||
2113 | /** | |
2114 | * Returns a list of timezones in the current language. | |
2115 | * @deprecated since Moodle 2.9 | |
8322ed4a AA |
2116 | */ |
2117 | function get_list_of_timezones() { | |
a77e0611 | 2118 | throw new coding_exception('get_list_of_timezones() can not be used any more, please use core_date::get_list_of_timezones() instead'); |
8322ed4a AA |
2119 | } |
2120 | ||
2121 | /** | |
2122 | * Previous internal API, it was not supposed to be used anywhere. | |
2123 | * @deprecated since Moodle 2.9 | |
8322ed4a AA |
2124 | */ |
2125 | function update_timezone_records($timezones) { | |
a77e0611 | 2126 | throw new coding_exception('update_timezone_records() can not be used any more, please use standard PHP DateTime class instead'); |
8322ed4a AA |
2127 | } |
2128 | ||
2129 | /** | |
2130 | * Previous internal API, it was not supposed to be used anywhere. | |
2131 | * @deprecated since Moodle 2.9 | |
8322ed4a AA |
2132 | */ |
2133 | function calculate_user_dst_table($fromyear = null, $toyear = null, $strtimezone = null) { | |
a77e0611 | 2134 | throw new coding_exception('calculate_user_dst_table() can not be used any more, please use standard PHP DateTime class instead'); |
8322ed4a AA |
2135 | } |
2136 | ||
2137 | /** | |
2138 | * Previous internal API, it was not supposed to be used anywhere. | |
2139 | * @deprecated since Moodle 2.9 | |
8322ed4a AA |
2140 | */ |
2141 | function dst_changes_for_year($year, $timezone) { | |
a77e0611 | 2142 | throw new coding_exception('dst_changes_for_year() can not be used any more, please use standard DateTime class instead'); |
8322ed4a AA |
2143 | } |
2144 | ||
2145 | /** | |
2146 | * Previous internal API, it was not supposed to be used anywhere. | |
2147 | * @deprecated since Moodle 2.9 | |
8322ed4a AA |
2148 | */ |
2149 | function get_timezone_record($timezonename) { | |
a77e0611 | 2150 | throw new coding_exception('get_timezone_record() can not be used any more, please use standard PHP DateTime class instead'); |
8322ed4a AA |
2151 | } |
2152 | ||
2149326b | 2153 | /* === Apis deprecated since Moodle 3.0 === */ |
f4864c1c | 2154 | /** |
f4864c1c | 2155 | * @deprecated since Moodle 3.0 MDL-49360 - please do not use this function any more. |
f4864c1c SL |
2156 | */ |
2157 | function get_referer($stripquery = true) { | |
e4f4d341 | 2158 | throw new coding_exception('get_referer() can not be used any more. Please use get_local_referer() instead.'); |
988592c5 | 2159 | } |
25d9ae9a | 2160 | |
34c6ec18 | 2161 | /** |
34c6ec18 AN |
2162 | * @deprecated since Moodle 3.0 use \core_useragent::is_web_crawler instead. |
2163 | */ | |
2164 | function is_web_crawler() { | |
e4f4d341 | 2165 | throw new coding_exception('is_web_crawler() can not be used any more. Please use core_useragent::is_web_crawler() instead.'); |
34c6ec18 | 2166 | } |
ebdfde76 | 2167 | |
0628925b | 2168 | /** |
0628925b | 2169 | * @deprecated since Moodle 3.0 MDL-50287 - please do not use this function any more. |
0628925b DP |
2170 | */ |
2171 | function completion_cron() { | |
e4f4d341 | 2172 | throw new coding_exception('completion_cron() can not be used any more. Functionality has been moved to scheduled tasks.'); |
0628925b | 2173 | } |
9e66dff0 | 2174 | |
0d1e5456 | 2175 | /** |
0d1e5456 | 2176 | * @deprecated since 3.0 |
0d1e5456 MG |
2177 | */ |
2178 | function coursetag_get_tags($courseid, $userid=0, $tagtype='', $numtags=0, $unused = '') { | |
e4f4d341 | 2179 | throw new coding_exception('Function coursetag_get_tags() can not be used any more. Userid is no longer used for tagging courses.'); |
0d1e5456 MG |
2180 | } |
2181 | ||
2182 | /** | |
0d1e5456 | 2183 | * @deprecated since 3.0 |
0d1e5456 MG |
2184 | */ |
2185 | function coursetag_get_all_tags($unused='', $numtags=0) { | |
e4f4d341 | 2186 | throw new coding_exception('Function coursetag_get_all_tag() can not be used any more. Userid is no longer used for tagging courses.'); |
0d1e5456 MG |
2187 | } |
2188 | ||
2189 | /** | |
0d1e5456 | 2190 | * @deprecated since 3.0 |
0d1e5456 MG |
2191 | */ |
2192 | function coursetag_get_jscript() { | |
e4f4d341 | 2193 | throw new coding_exception('Function coursetag_get_jscript() can not be used any more and is obsolete.'); |
0d1e5456 MG |
2194 | } |
2195 | ||
2196 | /** | |
0d1e5456 | 2197 | * @deprecated since 3.0 |
0d1e5456 MG |
2198 | */ |
2199 | function coursetag_get_jscript_links($elementid, $coursetagslinks) { | |
e4f4d341 | 2200 | throw new coding_exception('Function coursetag_get_jscript_links() can not be used any more and is obsolete.'); |
0d1e5456 MG |
2201 | } |
2202 | ||
2203 | /** | |
0d1e5456 | 2204 | * @deprecated since 3.0 |
0d1e5456 MG |
2205 | */ |
2206 | function coursetag_get_records($courseid, $userid) { | |
e4f4d341 | 2207 | throw new coding_exception('Function coursetag_get_records() can not be used any more. Userid is no longer used for tagging courses.'); |
0d1e5456 MG |
2208 | } |
2209 | ||
2210 | /** | |
0d1e5456 | 2211 | * @deprecated since 3.0 |
0d1e5456 MG |
2212 | */ |
2213 | function coursetag_store_keywords($tags, $courseid, $userid=0, $tagtype='official', $myurl='') { | |
e4f4d341 | 2214 | throw new coding_exception('Function coursetag_store_keywords() can not be used any more. Userid is no longer used for tagging courses.'); |
0d1e5456 MG |
2215 | } |
2216 | ||
2217 | /** | |
0d1e5456 | 2218 | * @deprecated since 3.0 |
0d1e5456 MG |
2219 | */ |
2220 | function coursetag_delete_keyword($tagid, $userid, $courseid) { | |
e4f4d341 | 2221 | throw new coding_exception('Function coursetag_delete_keyword() can not be used any more. Userid is no longer used for tagging courses.'); |
0d1e5456 MG |
2222 | } |
2223 | ||
2224 | /** | |
0d1e5456 | 2225 | * @deprecated since 3.0 |
0d1e5456 MG |
2226 | */ |
2227 | function coursetag_get_tagged_courses($tagid) { | |
e4f4d341 | 2228 | throw new coding_exception('Function coursetag_get_tagged_courses() can not be used any more. Userid is no longer used for tagging courses.'); |
0d1e5456 MG |
2229 | } |
2230 | ||
2231 | /** | |
0d1e5456 | 2232 | * @deprecated since 3.0 |
0d1e5456 MG |
2233 | */ |
2234 | function coursetag_delete_course_tags($courseid, $showfeedback=false) { | |
e4f4d341 | 2235 | throw new coding_exception('Function coursetag_delete_course_tags() is deprecated. Use core_tag_tag::remove_all_item_tags().'); |
c026a28d | 2236 | } |
0d1e5456 | 2237 | |
c026a28d MG |
2238 | /** |
2239 | * Set the type of a tag. At this time (version 2.2) the possible values are 'default' or 'official'. Official tags will be | |
2240 | * displayed separately "at tagging time" (while selecting the tags to apply to a record). | |
2241 | * | |
2242 | * @package core_tag | |
2243 | * @deprecated since 3.1 | |
2244 | * @param string $tagid tagid to modify | |
2245 | * @param string $type either 'default' or 'official' | |
2246 | * @return bool true on success, false otherwise | |
2247 | */ | |
2248 | function tag_type_set($tagid, $type) { | |
2249 | debugging('Function tag_type_set() is deprecated and can be replaced with use core_tag_tag::get($tagid)->update().', DEBUG_DEVELOPER); | |
2250 | if ($tag = core_tag_tag::get($tagid, '*')) { | |
e11d7380 | 2251 | return $tag->update(array('isstandard' => ($type === 'official') ? 1 : 0)); |
c026a28d MG |
2252 | } |
2253 | return false; | |
2254 | } | |
0d1e5456 | 2255 | |
c026a28d MG |
2256 | /** |
2257 | * Set the description of a tag | |
2258 | * | |
2259 | * @package core_tag | |
2260 | * @deprecated since 3.1 | |
2261 | * @param int $tagid the id of the tag | |
2262 | * @param string $description the tag's description string to be set | |
2263 | * @param int $descriptionformat the moodle text format of the description | |
2264 | * {@link http://docs.moodle.org/dev/Text_formats_2.0#Database_structure} | |
2265 | * @return bool true on success, false otherwise | |
2266 | */ | |
2267 | function tag_description_set($tagid, $description, $descriptionformat) { | |
2268 | debugging('Function tag_type_set() is deprecated and can be replaced with core_tag_tag::get($tagid)->update().', DEBUG_DEVELOPER); | |
2269 | if ($tag = core_tag_tag::get($tagid, '*')) { | |
2270 | return $tag->update(array('description' => $description, 'descriptionformat' => $descriptionformat)); | |
2271 | } | |
2272 | return false; | |
2273 | } | |
2274 | ||
2275 | /** | |
2276 | * Get the array of db record of tags associated to a record (instances). | |
2277 | * | |
2278 | * @package core_tag | |
2279 | * @deprecated since 3.1 | |
2280 | * @param string $record_type the record type for which we want to get the tags | |
2281 | * @param int $record_id the record id for which we want to get the tags | |
2282 | * @param string $type the tag type (either 'default' or 'official'). By default, all tags are returned. | |
2283 | * @param int $userid (optional) only required for course tagging | |
2284 | * @return array the array of tags | |
2285 | */ | |
2286 | function tag_get_tags($record_type, $record_id, $type=null, $userid=0) { | |
2287 | debugging('Method tag_get_tags() is deprecated and replaced with core_tag_tag::get_item_tags(). ' . | |
2288 | 'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER); | |
e11d7380 MG |
2289 | $standardonly = ($type === 'official' ? core_tag_tag::STANDARD_ONLY : |
2290 | (!empty($type) ? core_tag_tag::NOT_STANDARD_ONLY : core_tag_tag::BOTH_STANDARD_AND_NOT)); | |
2291 | $tags = core_tag_tag::get_item_tags(null, $record_type, $record_id, $standardonly, $userid); | |
c026a28d MG |
2292 | $rv = array(); |
2293 | foreach ($tags as $id => $t) { | |
2294 | $rv[$id] = $t->to_object(); | |
2295 | } | |
2296 | return $rv; | |
2297 | } | |
2298 | ||
2299 | /** | |
2300 | * Get the array of tags display names, indexed by id. | |
2301 | * | |
2302 | * @package core_tag | |
2303 | * @deprecated since 3.1 | |
2304 | * @param string $record_type the record type for which we want to get the tags | |
2305 | * @param int $record_id the record id for which we want to get the tags | |
2306 | * @param string $type the tag type (either 'default' or 'official'). By default, all tags are returned. | |
2307 | * @return array the array of tags (with the value returned by core_tag_tag::make_display_name), indexed by id | |
2308 | */ | |
2309 | function tag_get_tags_array($record_type, $record_id, $type=null) { | |
2310 | debugging('Method tag_get_tags_array() is deprecated and replaced with core_tag_tag::get_item_tags_array(). ' . | |
2311 | 'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER); | |
e11d7380 MG |
2312 | $standardonly = ($type === 'official' ? core_tag_tag::STANDARD_ONLY : |
2313 | (!empty($type) ? core_tag_tag::NOT_STANDARD_ONLY : core_tag_tag::BOTH_STANDARD_AND_NOT)); | |
2314 | return core_tag_tag::get_item_tags_array('', $record_type, $record_id, $standardonly); | |
c026a28d MG |
2315 | } |
2316 | ||
2317 | /** | |
2318 | * Get a comma-separated string of tags associated to a record. | |
2319 | * | |
2320 | * Use {@link tag_get_tags()} to get the same information in an array. | |
2321 | * | |
2322 | * @package core_tag | |
2323 | * @deprecated since 3.1 | |
2324 | * @param string $record_type the record type for which we want to get the tags | |
2325 | * @param int $record_id the record id for which we want to get the tags | |
2326 | * @param int $html either TAG_RETURN_HTML or TAG_RETURN_TEXT, depending on the type of output desired | |
2327 | * @param string $type either 'official' or 'default', if null, all tags are returned | |
2328 | * @return string the comma-separated list of tags. | |
2329 | */ | |
2330 | function tag_get_tags_csv($record_type, $record_id, $html=null, $type=null) { | |
2331 | global $CFG, $OUTPUT; | |
2332 | debugging('Method tag_get_tags_csv() is deprecated. Instead you should use either ' . | |
2333 | 'core_tag_tag::get_item_tags_array() or $OUTPUT->tag_list(core_tag_tag::get_item_tags()). ' . | |
2334 | 'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER); | |
e11d7380 MG |
2335 | $standardonly = ($type === 'official' ? core_tag_tag::STANDARD_ONLY : |
2336 | (!empty($type) ? core_tag_tag::NOT_STANDARD_ONLY : core_tag_tag::BOTH_STANDARD_AND_NOT)); | |
c026a28d | 2337 | if ($html != TAG_RETURN_TEXT) { |
e11d7380 | 2338 | return $OUTPUT->tag_list(core_tag_tag::get_item_tags('', $record_type, $record_id, $standardonly), ''); |
c026a28d | 2339 | } else { |
e11d7380 | 2340 | return join(', ', core_tag_tag::get_item_tags_array('', $record_type, $record_id, $standardonly, 0, false)); |
c026a28d MG |
2341 | } |
2342 | } | |
2343 | ||
2344 | /** | |
2345 | * Get an array of tag ids associated to a record. | |
2346 | * | |
2347 | * @package core_tag | |
2348 | * @deprecated since 3.1 | |
2349 | * @param string $record_type the record type for which we want to get the tags | |
2350 | * @param int $record_id the record id for which we want to get the tags | |
2351 | * @return array tag ids, indexed and sorted by 'ordering' | |
2352 | */ | |
2353 | function tag_get_tags_ids($record_type, $record_id) { | |
2354 | debugging('Method tag_get_tags_ids() is deprecated. Please consider using core_tag_tag::get_item_tags() or similar methods.', DEBUG_DEVELOPER); | |
2355 | $tag_ids = array(); | |
2356 | $tagobjects = core_tag_tag::get_item_tags(null, $record_type, $record_id); | |
2357 | foreach ($tagobjects as $tagobject) { | |
2358 | $tag = $tagobject->to_object(); | |
2359 | if ( array_key_exists($tag->ordering, $tag_ids) ) { | |
2360 | $tag->ordering++; | |
0d1e5456 | 2361 | } |
c026a28d | 2362 | $tag_ids[$tag->ordering] = $tag->id; |
0d1e5456 | 2363 | } |
c026a28d MG |
2364 | ksort($tag_ids); |
2365 | return $tag_ids; | |
2366 | } | |
0d1e5456 | 2367 | |
c026a28d MG |
2368 | /** |
2369 | * Returns the database ID of a set of tags. | |
2370 | * | |
2371 | * @deprecated since 3.1 | |
2372 | * @param mixed $tags one tag, or array of tags, to look for. | |
2373 | * @param bool $return_value specify the type of the returned value. Either TAG_RETURN_OBJECT, or TAG_RETURN_ARRAY (default). | |
2374 | * If TAG_RETURN_ARRAY is specified, an array will be returned even if only one tag was passed in $tags. | |
2375 | * @return mixed tag-indexed array of ids (or objects, if second parameter is TAG_RETURN_OBJECT), or only an int, if only one tag | |
2376 | * is given *and* the second parameter is null. No value for a key means the tag wasn't found. | |
2377 | */ | |
2378 | function tag_get_id($tags, $return_value = null) { | |
2379 | global $CFG, $DB; | |
2380 | debugging('Method tag_get_id() is deprecated and can be replaced with core_tag_tag::get_by_name() or core_tag_tag::get_by_name_bulk(). ' . | |
2381 | 'You need to specify tag collection when retrieving tag by name', DEBUG_DEVELOPER); | |
2382 | ||
2383 | if (!is_array($tags)) { | |
2384 | if(is_null($return_value) || $return_value == TAG_RETURN_OBJECT) { | |
2385 | if ($tagobject = core_tag_tag::get_by_name(core_tag_collection::get_default(), $tags)) { | |
2386 | return $tagobject->id; | |
2387 | } else { | |
2388 | return 0; | |
2389 | } | |
2390 | } | |
2391 | $tags = array($tags); | |
2392 | } | |
2393 | ||
2394 | $records = core_tag_tag::get_by_name_bulk(core_tag_collection::get_default(), $tags, | |
2395 | $return_value == TAG_RETURN_OBJECT ? '*' : 'id, name'); | |
2396 | foreach ($records as $name => $record) { | |
2397 | if ($return_value != TAG_RETURN_OBJECT) { | |
2398 | $records[$name] = $record->id ? $record->id : null; | |
2399 | } else { | |
2400 | $records[$name] = $record->to_object(); | |
2401 | } | |
2402 | } | |
2403 | return $records; | |
2404 | } | |
2405 | ||
2406 | /** | |
2407 | * Change the "value" of a tag, and update the associated 'name'. | |
2408 | * | |
2409 | * @package core_tag | |
2410 | * @deprecated since 3.1 | |
2411 | * @param int $tagid the id of the tag to modify | |
2412 | * @param string $newrawname the new rawname | |
2413 | * @return bool true on success, false otherwise | |
2414 | */ | |
2415 | function tag_rename($tagid, $newrawname) { | |
2416 | debugging('Function tag_rename() is deprecated and may be replaced with core_tag_tag::get($tagid)->update().', DEBUG_DEVELOPER); | |
2417 | if ($tag = core_tag_tag::get($tagid, '*')) { | |
2418 | return $tag->update(array('rawname' => $newrawname)); | |
2419 | } | |
2420 | return false; | |
2421 | } | |
2422 | ||
2423 | /** | |
2424 | * Delete one instance of a tag. If the last instance was deleted, it will also delete the tag, unless its type is 'official'. | |
2425 | * | |
2426 | * @package core_tag | |
2427 | * @deprecated since 3.1 | |
2428 | * @param string $record_type the type of the record for which to remove the instance | |
2429 | * @param int $record_id the id of the record for which to remove the instance | |
2430 | * @param int $tagid the tagid that needs to be removed | |
2431 | * @param int $userid (optional) the userid | |
2432 | * @return bool true on success, false otherwise | |
2433 | */ | |
2434 | function tag_delete_instance($record_type, $record_id, $tagid, $userid = null) { | |
2435 | debugging('Function tag_delete_instance() is deprecated and replaced with core_tag_tag::remove_item_tag() instead. ' . | |
2436 | 'Component is required for retrieving instances', DEBUG_DEVELOPER); | |
2437 | $tag = core_tag_tag::get($tagid); | |
2438 | core_tag_tag::remove_item_tag('', $record_type, $record_id, $tag->rawname, $userid); | |
2439 | } | |
2440 | ||
2441 | /** | |
2442 | * Find all records tagged with a tag of a given type ('post', 'user', etc.) | |
2443 | * | |
2444 | * @package core_tag | |
2a723541 | 2445 | * @deprecated since 3.1 |
c026a28d MG |
2446 | * @category tag |
2447 | * @param string $tag tag to look for | |
2448 | * @param string $type type to restrict search to. If null, every matching record will be returned | |
2449 | * @param int $limitfrom (optional, required if $limitnum is set) return a subset of records, starting at this point. | |
2450 | * @param int $limitnum (optional, required if $limitfrom is set) return a subset comprising this many records. | |
2451 | * @return array of matching objects, indexed by record id, from the table containing the type requested | |
2452 | */ | |
2453 | function tag_find_records($tag, $type, $limitfrom='', $limitnum='') { | |
2454 | debugging('Function tag_find_records() is deprecated and replaced with core_tag_tag::get_by_name()->get_tagged_items(). '. | |
2455 | 'You need to specify tag collection when retrieving tag by name', DEBUG_DEVELOPER); | |
2456 | ||
2457 | if (!$tag || !$type) { | |
2458 | return array(); | |
2459 | } | |
2460 | ||
2461 | $tagobject = core_tag_tag::get_by_name(core_tag_area::get_collection('', $type), $tag); | |
2462 | return $tagobject->get_tagged_items('', $type, $limitfrom, $limitnum); | |
2463 | } | |
2464 | ||
2465 | /** | |
2466 | * Adds one or more tag in the database. This function should not be called directly : you should | |
2467 | * use tag_set. | |
2468 | * | |
2469 | * @package core_tag | |
2470 | * @deprecated since 3.1 | |
2471 | * @param mixed $tags one tag, or an array of tags, to be created | |
2472 | * @param string $type type of tag to be created ("default" is the default value and "official" is the only other supported | |
2473 | * value at this time). An official tag is kept even if there are no records tagged with it. | |
2474 | * @return array $tags ids indexed by their lowercase normalized names. Any boolean false in the array indicates an error while | |
2475 | * adding the tag. | |
2476 | */ | |
2477 | function tag_add($tags, $type="default") { | |
2478 | debugging('Function tag_add() is deprecated. You can use core_tag_tag::create_if_missing(), however it should not be necessary ' . | |
2479 | 'since tags are created automatically when assigned to items', DEBUG_DEVELOPER); | |
2480 | if (!is_array($tags)) { | |
2481 | $tags = array($tags); | |
2482 | } | |
e11d7380 MG |
2483 | $objects = core_tag_tag::create_if_missing(core_tag_collection::get_default(), $tags, |
2484 | $type === 'official'); | |
c026a28d MG |
2485 | |
2486 | // New function returns the tags in different format, for BC we keep the format that this function used to have. | |
2487 | $rv = array(); | |
2488 | foreach ($objects as $name => $tagobject) { | |
2489 | if (isset($tagobject->id)) { | |
2490 | $rv[$tagobject->name] = $tagobject->id; | |
2491 | } else { | |
2492 | $rv[$name] = false; | |
2493 | } | |
2494 | } | |
2495 | return $rv; | |
2496 | } | |
2497 | ||
2498 | /** | |
2499 | * Assigns a tag to a record; if the record already exists, the time and ordering will be updated. | |
2500 | * | |
2501 | * @package core_tag | |
2502 | * @deprecated since 3.1 | |
2503 | * @param string $record_type the type of the record that will be tagged | |
2504 | * @param int $record_id the id of the record that will be tagged | |
2505 | * @param string $tagid the tag id to set on the record. | |
2506 | * @param int $ordering the order of the instance for this record | |
2507 | * @param int $userid (optional) only required for course tagging | |
2508 | * @param string|null $component the component that was tagged | |
2509 | * @param int|null $contextid the context id of where this tag was assigned | |
2510 | * @return bool true on success, false otherwise | |
2511 | */ | |
2512 | function tag_assign($record_type, $record_id, $tagid, $ordering, $userid = 0, $component = null, $contextid = null) { | |
2513 | global $DB; | |
2514 | $message = 'Function tag_assign() is deprecated. Use core_tag_tag::set_item_tags() or core_tag_tag::add_item_tag() instead. ' . | |
2515 | 'Tag instance ordering should not be set manually'; | |
2516 | if ($component === null || $contextid === null) { | |
2517 | $message .= '. You should specify the component and contextid of the item being tagged in your call to tag_assign.'; | |
2518 | } | |
2519 | debugging($message, DEBUG_DEVELOPER); | |
2520 | ||
2521 | if ($contextid) { | |
2522 | $context = context::instance_by_id($contextid); | |
2523 | } else { | |
2524 | $context = context_system::instance(); | |
2525 | } | |
2526 | ||
2527 | // Get the tag. | |
2528 | $tag = $DB->get_record('tag', array('id' => $tagid), 'name, rawname', MUST_EXIST); | |
2529 | ||
2530 | $taginstanceid = core_tag_tag::add_item_tag($component, $record_type, $record_id, $context, $tag->rawname, $userid); | |
2531 | ||
2532 | // Alter the "ordering" of tag_instance. This should never be done manually and only remains here for the backward compatibility. | |
2533 | $taginstance = new stdClass(); | |
2534 | $taginstance->id = $taginstanceid; | |
2535 | $taginstance->ordering = $ordering; | |
2536 | $taginstance->timemodified = time(); | |
2537 | ||
2538 | $DB->update_record('tag_instance', $taginstance); | |
2539 | ||
2540 | return true; | |
2541 | } | |
2542 | ||
2543 | /** | |
2544 | * Count how many records are tagged with a specific tag. | |
2545 | * | |
2546 | * @package core_tag | |
2547 | * @deprecated since 3.1 | |
2548 | * @param string $record_type record to look for ('post', 'user', etc.) | |
2549 | * @param int $tagid is a single tag id | |
2550 | * @return int number of mathing tags. | |
2551 | */ | |
2552 | function tag_record_count($record_type, $tagid) { | |
2553 | debugging('Method tag_record_count() is deprecated and replaced with core_tag_tag::get($tagid)->count_tagged_items(). '. | |
2554 | 'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER); | |
2555 | return core_tag_tag::get($tagid)->count_tagged_items('', $record_type); | |
2556 | } | |
2557 | ||
2558 | /** | |
2559 | * Determine if a record is tagged with a specific tag | |
2560 | * | |
2561 | * @package core_tag | |
2562 | * @deprecated since 3.1 | |
2563 | * @param string $record_type the record type to look for | |
2564 | * @param int $record_id the record id to look for | |
2565 | * @param string $tag a tag name | |
2566 | * @return bool/int true if it is tagged, 0 (false) otherwise | |
2567 | */ | |
2568 | function tag_record_tagged_with($record_type, $record_id, $tag) { | |
2569 | debugging('Method tag_record_tagged_with() is deprecated and replaced with core_tag_tag::get($tagid)->is_item_tagged_with(). '. | |
2570 | 'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER); | |
2571 | return core_tag_tag::is_item_tagged_with('', $record_type, $record_id, $tag); | |
2572 | } | |
2573 | ||
2574 | /** | |
2575 | * Flag a tag as inappropriate. | |
2576 | * | |
2577 | * @deprecated since 3.1 | |
2578 | * @param int|array $tagids a single tagid, or an array of tagids | |
2579 | */ | |
2580 | function tag_set_flag($tagids) { | |
2581 | debugging('Function tag_set_flag() is deprecated and replaced with core_tag_tag::get($tagid)->flag().', DEBUG_DEVELOPER); | |
2582 | $tagids = (array) $tagids; | |
2583 | foreach ($tagids as $tagid) { | |
2584 | if ($tag = core_tag_tag::get($tagid, '*')) { | |
2585 | $tag->flag(); | |
2586 | } | |
2587 | } | |
2588 | } | |
2589 | ||
2590 | /** | |
2591 | * Remove the inappropriate flag on a tag. | |
2592 | * | |
2593 | * @deprecated since 3.1 | |
2594 | * @param int|array $tagids a single tagid, or an array of tagids | |
2595 | */ | |
2596 | function tag_unset_flag($tagids) { | |
2597 | debugging('Function tag_unset_flag() is deprecated and replaced with core_tag_tag::get($tagid)->reset_flag().', DEBUG_DEVELOPER); | |
2598 | $tagids = (array) $tagids; | |
2599 | foreach ($tagids as $tagid) { | |
2600 | if ($tag = core_tag_tag::get($tagid, '*')) { | |
2601 | $tag->reset_flag(); | |
2602 | } | |
2603 | } | |
2604 | } | |
2605 | ||
2606 | /** | |
2607 | * Prints or returns a HTML tag cloud with varying classes styles depending on the popularity and type of each tag. | |
2608 | * | |
2609 | * @deprecated since 3.1 | |
2610 | * | |
2611 | * @param array $tagset Array of tags to display | |
2612 | * @param int $nr_of_tags Limit for the number of tags to return/display, used if $tagset is null | |
2613 | * @param bool $return if true the function will return the generated tag cloud instead of displaying it. | |
2614 | * @param string $sort (optional) selected sorting, default is alpha sort (name) also timemodified or popularity | |
2615 | * @return string|null a HTML string or null if this function does the output | |
2616 | */ | |
2617 | function tag_print_cloud($tagset=null, $nr_of_tags=150, $return=false, $sort='') { | |
2618 | global $OUTPUT; | |
2619 | ||
2620 | debugging('Function tag_print_cloud() is deprecated and replaced with function core_tag_collection::get_tag_cloud(), ' | |
2621 | . 'templateable core_tag\output\tagcloud and template core_tag/tagcloud.', DEBUG_DEVELOPER); | |
2622 | ||
2623 | // Set up sort global - used to pass sort type into core_tag_collection::cloud_sort through usort() avoiding multiple sort functions. | |
2624 | if ($sort == 'popularity') { | |
2625 | $sort = 'count'; | |
2626 | } else if ($sort == 'date') { | |
2627 | $sort = 'timemodified'; | |
2628 | } else { | |
2629 | $sort = 'name'; | |
2630 | } | |
2631 | ||
2632 | if (is_null($tagset)) { | |
2633 | // No tag set received, so fetch tags from database. | |
2634 | // Always add query by tagcollid even when it's not known to make use of the table index. | |
e11d7380 | 2635 | $tagcloud = core_tag_collection::get_tag_cloud(0, false, $nr_of_tags, $sort); |
c026a28d MG |
2636 | } else { |
2637 | $tagsincloud = $tagset; | |
2638 | ||
2639 | $etags = array(); | |
2640 | foreach ($tagsincloud as $tag) { | |
2641 | $etags[] = $tag; | |
2642 | } | |
2643 | ||
2644 | core_tag_collection::$cloudsortfield = $sort; | |
2645 | usort($tagsincloud, "core_tag_collection::cloud_sort"); | |
2646 | ||
2647 | $tagcloud = new \core_tag\output\tagcloud($tagsincloud); | |
2648 | } | |
2649 | ||
2650 | $output = $OUTPUT->render_from_template('core_tag/tagcloud', $tagcloud->export_for_template($OUTPUT)); | |
2651 | if ($return) { | |
2652 | return $output; | |
2653 | } else { | |
2654 | echo $output; | |
0d1e5456 MG |
2655 | } |
2656 | } | |
a27c42ee MG |
2657 | |
2658 | /** | |
2659 | * Function that returns tags that start with some text, for use by the autocomplete feature | |
2660 | * | |
2661 | * @package core_tag | |
2662 | * @deprecated since 3.0 | |
2663 | * @access private | |
2664 | * @param string $text string that the tag names will be matched against | |
2665 | * @return mixed an array of objects, or false if no records were found or an error occured. | |
2666 | */ | |
2667 | function tag_autocomplete($text) { | |
2668 | debugging('Function tag_autocomplete() is deprecated without replacement. ' . | |
2669 | 'New form element "tags" does proper autocomplete.', DEBUG_DEVELOPER); | |
2670 | global $DB; | |
2671 | return $DB->get_records_sql("SELECT tg.id, tg.name, tg.rawname | |
2672 | FROM {tag} tg | |
2673 | WHERE tg.name LIKE ?", array(core_text::strtolower($text)."%")); | |
2674 | } | |
c026a28d MG |
2675 | |
2676 | /** | |
2677 | * Prints a box with the description of a tag and its related tags | |
2678 | * | |
2679 | * @package core_tag | |
2680 | * @deprecated since 3.1 | |
2681 | * @param stdClass $tag_object | |
2682 | * @param bool $return if true the function will return the generated tag cloud instead of displaying it. | |
2683 | * @return string/null a HTML box showing a description of the tag object and it's relationsips or null if output is done directly | |
2684 | * in the function. | |
2685 | */ | |
2686 | function tag_print_description_box($tag_object, $return=false) { | |
2687 | global $USER, $CFG, $OUTPUT; | |
2688 | require_once($CFG->libdir.'/filelib.php'); | |
2689 | ||
2690 | debugging('Function tag_print_description_box() is deprecated without replacement. ' . | |
2691 | 'See core_tag_renderer for similar code.', DEBUG_DEVELOPER); | |
2692 | ||
2693 | $relatedtags = array(); | |
2694 | if ($tag = core_tag_tag::get($tag_object->id)) { | |
2695 | $relatedtags = $tag->get_related_tags(); | |
2696 | } | |
2697 | ||
2698 | $content = !empty($tag_object->description); | |
2699 | $output = ''; | |
2700 | ||
2701 | if ($content) { | |
2702 | $output .= $OUTPUT->box_start('generalbox tag-description'); | |
2703 | } | |
2704 | ||
2705 | if (!empty($tag_object->description)) { | |
2706 | $options = new stdClass(); | |
2707 | $options->para = false; | |
2708 | $options->overflowdiv = true; | |
2709 | $tag_object->description = file_rewrite_pluginfile_urls($tag_object->description, 'pluginfile.php', context_system::instance()->id, 'tag', 'description', $tag_object->id); | |
2710 | $output .= format_text($tag_object->description, $tag_object->descriptionformat, $options); | |
2711 | } | |
2712 | ||
2713 | if ($content) { | |
2714 | $output .= $OUTPUT->box_end(); | |
2715 | } | |
2716 | ||
2717 | if ($relatedtags) { | |
2718 | $output .= $OUTPUT->tag_list($relatedtags, get_string('relatedtags', 'tag'), 'tag-relatedtags'); | |
2719 | } | |
2720 | ||
2721 | if ($return) { | |
2722 | return $output; | |
2723 | } else { | |
2724 | echo $output; | |
2725 | } | |
2726 | } | |
2727 | ||
2728 | /** | |
2729 | * Prints a box that contains the management links of a tag | |
2730 | * | |
2731 | * @deprecated since 3.1 | |
2732 | * @param core_tag_tag|stdClass $tag_object | |
2733 | * @param bool $return if true the function will return the generated tag cloud instead of displaying it. | |
2734 | * @return string|null a HTML string or null if this function does the output | |
2735 | */ | |
2736 | function tag_print_management_box($tag_object, $return=false) { | |
2737 | global $USER, $CFG, $OUTPUT; | |
2738 | ||
2739 | debugging('Function tag_print_description_box() is deprecated without replacement. ' . | |
2740 | 'See core_tag_renderer for similar code.', DEBUG_DEVELOPER); | |
2741 | ||
2742 | $tagname = core_tag_tag::make_display_name($tag_object); | |
2743 | $output = ''; | |
2744 | ||
2745 | if (!isguestuser()) { | |
2746 | $output .= $OUTPUT->box_start('box','tag-management-box'); | |
2747 | $systemcontext = context_system::instance(); | |
2748 | $links = array(); | |
2749 | ||
2750 | // Add a link for users to add/remove this from their interests | |
2751 | if (core_tag_tag::is_enabled('core', 'user') && core_tag_area::get_collection('core', 'user') == $tag_object->tagcollid) { | |
2752 | if (core_tag_tag::is_item_tagged_with('core', 'user', $USER->id, $tag_object->name)) { | |
2753 | $links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=removeinterest&sesskey='. sesskey() . | |
2754 | '&tag='. rawurlencode($tag_object->name) .'">'. | |
2755 | get_string('removetagfrommyinterests', 'tag', $tagname) .'</a>'; | |
2756 | } else { | |
2757 | $links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=addinterest&sesskey='. sesskey() . | |
2758 | '&tag='. rawurlencode($tag_object->name) .'">'. | |
2759 | get_string('addtagtomyinterests', 'tag', $tagname) .'</a>'; | |
2760 | } | |
2761 | } | |
2762 | ||
2763 | // Flag as inappropriate link. Only people with moodle/tag:flag capability. | |
2764 | if (has_capability('moodle/tag:flag', $systemcontext)) { | |
2765 | $links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=flaginappropriate&sesskey='. | |
2766 | sesskey() . '&id='. $tag_object->id . '">'. get_string('flagasinappropriate', | |
2767 | 'tag', rawurlencode($tagname)) .'</a>'; | |
2768 | } | |
2769 | ||
2770 | // Edit tag: Only people with moodle/tag:edit capability who either have it as an interest or can manage tags | |
2771 | if (has_capability('moodle/tag:edit', $systemcontext) || | |
2772 | has_capability('moodle/tag:manage', $systemcontext)) { | |
2773 | $links[] = '<a href="' . $CFG->wwwroot . '/tag/edit.php?id=' . $tag_object->id . '">' . | |
2774 | get_string('edittag', 'tag') . '</a>'; | |
2775 | } | |
2776 | ||
2777 | $output .= implode(' | ', $links); | |
2778 | $output .= $OUTPUT->box_end(); | |
2779 | } | |
2780 | ||
2781 | if ($return) { | |
2782 | return $output; | |
2783 | } else { | |
2784 | echo $output; | |
2785 | } | |
2786 | } | |
2787 | ||
2788 | /** | |
2789 | * Prints the tag search box | |
2790 | * | |
2791 | * @deprecated since 3.1 | |
2792 | * @param bool $return if true return html string | |
2793 | * @return string|null a HTML string or null if this function does the output | |
2794 | */ | |
2795 | function tag_print_search_box($return=false) { | |
2796 | global $CFG, $OUTPUT; | |
2797 | ||
2798 | debugging('Function tag_print_search_box() is deprecated without replacement. ' . | |
2799 | 'See core_tag_renderer for similar code.', DEBUG_DEVELOPER); | |
2800 | ||
2801 | $query = optional_param('query', '', PARAM_RAW); | |
2802 | ||
2803 | $output = $OUTPUT->box_start('','tag-search-box'); | |
2804 | $output .= '<form action="'.$CFG->wwwroot.'/tag/search.php" style="display:inline">'; | |
2805 | $output .= '<div>'; | |
2806 | $output .= '<label class="accesshide" for="searchform_search">'.get_string('searchtags', 'tag').'</label>'; | |
2807 | $output .= '<input id="searchform_search" name="query" type="text" size="40" value="'.s($query).'" />'; | |
2808 | $output .= '<button id="searchform_button" type="submit">'. get_string('search', 'tag') .'</button><br />'; | |
2809 | $output .= '</div>'; | |
2810 | $output .= '</form>'; | |
2811 | $output .= $OUTPUT->box_end(); | |
2812 | ||
2813 | if ($return) { | |
2814 | return $output; | |
2815 | } | |
2816 | else { | |
2817 | echo $output; | |
2818 | } | |
2819 | } | |
2820 | ||
2821 | /** | |
2822 | * Prints the tag search results | |
2823 | * | |
2824 | * @deprecated since 3.1 | |
2825 | * @param string $query text that tag names will be matched against | |
2826 | * @param int $page current page | |
2827 | * @param int $perpage nr of users displayed per page | |
2828 | * @param bool $return if true return html string | |
2829 | * @return string|null a HTML string or null if this function does the output | |
2830 | */ | |
2831 | function tag_print_search_results($query, $page, $perpage, $return=false) { | |
2832 | global $CFG, $USER, $OUTPUT; | |
2833 | ||
2834 | debugging('Function tag_print_search_results() is deprecated without replacement. ' . | |
2835 | 'In /tag/search.php the search results are printed using the core_tag/tagcloud template.', DEBUG_DEVELOPER); | |
2836 | ||
2837 | $query = clean_param($query, PARAM_TAG); | |
2838 | ||
2839 | $count = count(tag_find_tags($query, false)); | |
2840 | $tags = array(); | |
2841 | ||
2842 | if ( $found_tags = tag_find_tags($query, true, $page * $perpage, $perpage) ) { | |
2843 | $tags = array_values($found_tags); | |
2844 | } | |
2845 | ||
2846 | $baseurl = $CFG->wwwroot.'/tag/search.php?query='. rawurlencode($query); | |
2847 | $output = ''; | |
2848 | ||
2849 | // link "Add $query to my interests" | |
2850 | $addtaglink = ''; | |
2851 | if (core_tag_tag::is_enabled('core', 'user') && !core_tag_tag::is_item_tagged_with('core', 'user', $USER->id, $query)) { | |
2852 | $addtaglink = html_writer::link(new moodle_url('/tag/user.php', array('action' => 'addinterest', 'sesskey' => sesskey(), | |
2853 | 'tag' => $query)), get_string('addtagtomyinterests', 'tag', s($query))); | |
2854 | } | |
2855 | ||
2856 | if ( !empty($tags) ) { // there are results to display!! | |
2857 | $output .= $OUTPUT->heading(get_string('searchresultsfor', 'tag', htmlspecialchars($query)) ." : {$count}", 3, 'main'); | |
2858 | ||
2859 | //print a link "Add $query to my interests" | |
2860 | if (!empty($addtaglink)) { | |
2861 | $output .= $OUTPUT->box($addtaglink, 'box', 'tag-management-box'); | |
2862 | } | |
2863 | ||
2864 | $nr_of_lis_per_ul = 6; | |
2865 | $nr_of_uls = ceil( sizeof($tags) / $nr_of_lis_per_ul ); | |
2866 | ||
2867 | $output .= '<ul id="tag-search-results">'; | |
2868 | for($i = 0; $i < $nr_of_uls; $i++) { | |
2869 | foreach (array_slice($tags, $i * $nr_of_lis_per_ul, $nr_of_lis_per_ul) as $tag) { | |
2870 | $output .= '<li>'; | |
2871 | $tag_link = html_writer::link(core_tag_tag::make_url($tag->tagcollid, $tag->rawname), | |
2872 | core_tag_tag::make_display_name($tag)); | |
2873 | $output .= $tag_link; | |
2874 | $output .= '</li>'; | |
2875 | } | |
2876 | } | |
2877 | $output .= '</ul>'; | |
2878 | $output .= '<div> </div>'; // <-- small layout hack in order to look good in Firefox | |
2879 | ||
2880 | $output .= $OUTPUT->paging_bar($count, $page, $perpage, $baseurl); | |
2881 | } | |
2882 | else { //no results were found!! | |
2883 | $output .= $OUTPUT->heading(get_string('noresultsfor', 'tag', htmlspecialchars($query)), 3, 'main'); | |
2884 | ||
2885 | //print a link "Add $query to my interests" | |
2886 | if (!empty($addtaglink)) { | |
2887 | $output .= $OUTPUT->box($addtaglink, 'box', 'tag-management-box'); | |
2888 | } | |
2889 | } | |
2890 | ||
2891 | if ($return) { | |
2892 | return $output; | |
2893 | } | |
2894 | else { | |
2895 | echo $output; | |
2896 | } | |
2897 | } | |
2898 | ||
2899 | /** | |
2900 | * Prints a table of the users tagged with the tag passed as argument | |
2901 | * | |
2902 | * @deprecated since 3.1 | |
2903 | * @param stdClass $tagobject the tag we wish to return data for | |
2904 | * @param int $limitfrom (optional, required if $limitnum is set) prints users starting at this point. | |
2905 | * @param int $limitnum (optional, required if $limitfrom is set) prints this many users. | |
2906 | * @param bool $return if true return html string | |
2907 | * @return string|null a HTML string or null if this function does the output | |
2908 | */ | |
2909 | function tag_print_tagged_users_table($tagobject, $limitfrom='', $limitnum='', $return=false) { | |
2910 | ||
2911 | debugging('Function tag_print_tagged_users_table() is deprecated without replacement. ' . | |
2912 | 'See core_user_renderer for similar code.', DEBUG_DEVELOPER); | |
2913 | ||
2914 | //List of users with this tag | |
2915 | $tagobject = core_tag_tag::get($tagobject->id); | |
2916 | $userlist = $tagobject->get_tagged_items('core', 'user', $limitfrom, $limitnum); | |
2917 | ||
2918 | $output = tag_print_user_list($userlist, true); | |
2919 | ||
2920 | if ($return) { | |
2921 | return $output; | |
2922 | } | |
2923 | else { | |
2924 | echo $output; | |
2925 | } | |
2926 | } | |
2927 | ||
2928 | /** | |
2929 | * Prints an individual user box | |
2930 | * | |
2931 | * @deprecated since 3.1 | |
2932 | * @param user_object $user (contains the following fields: id, firstname, lastname and picture) | |
2933 | * @param bool $return if true return html string | |
2934 | * @return string|null a HTML string or null if this function does the output | |
2935 | */ | |
2936 | function tag_print_user_box($user, $return=false) { | |
2937 | global $CFG, $OUTPUT; | |
2938 | ||
2939 | debugging('Function tag_print_user_box() is deprecated without replacement. ' . | |
2940 | 'See core_user_renderer for similar code.', DEBUG_DEVELOPER); | |
2941 | ||
2942 | $usercontext = context_user::instance($user->id); | |
2943 | $profilelink = ''; | |
2944 | ||
2945 | if ($usercontext and (has_capability('moodle/user:viewdetails', $usercontext) || has_coursecontact_role($user->id))) { | |
2946 | $profilelink = $CFG->wwwroot .'/user/view.php?id='. $user->id; | |
2947 | } | |
2948 | ||
2949 | $output = $OUTPUT->box_start('user-box', 'user'. $user->id); | |
2950 | $fullname = fullname($user); | |
2951 | $alt = ''; | |
2952 | ||
2953 | if (!empty($profilelink)) { | |
2954 | $output .= '<a href="'. $profilelink .'">'; | |
2955 | $alt = $fullname; | |
2956 | } | |
2957 | ||
2958 | $output .= $OUTPUT->user_picture($user, array('size'=>100)); | |
2959 | $output .= '<br />'; | |
2960 | ||
2961 | if (!empty($profilelink)) { | |
2962 | $output .= '</a>'; | |
2963 | } | |
2964 | ||
2965 | //truncate name if it's too big | |
2966 | if (core_text::strlen($fullname) > 26) { | |
2967 | $fullname = core_text::substr($fullname, 0, 26) .'...'; | |
2968 | } | |
2969 | ||
2970 | $output .= '<strong>'. $fullname .'</strong>'; | |
2971 | $output .= $OUTPUT->box_end(); | |
2972 | ||
2973 | if ($return) { | |
2974 | return $output; | |
2975 | } | |
2976 | else { | |
2977 | echo $output; | |
2978 | } | |
2979 | } | |
2980 | ||
2981 | /** | |
2982 | * Prints a list of users | |
2983 | * | |
2984 | * @deprecated since 3.1 | |
2985 | * @param array $userlist an array of user objects | |
2986 | * @param bool $return if true return html string, otherwise output the result | |
2987 | * @return string|null a HTML string or null if this function does the output | |
2988 | */ | |
2989 | function tag_print_user_list($userlist, $return=false) { | |
2990 | ||
2991 | debugging('Function tag_print_user_list() is deprecated without replacement. ' . | |
2992 | 'See core_user_renderer for similar code.', DEBUG_DEVELOPER); | |
2993 | ||
2994 | $output = '<div><ul class="inline-list">'; | |
2995 | ||
2996 | foreach ($userlist as $user){ | |
2997 | $output .= '<li>'. tag_print_user_box($user, true) ."</li>\n"; | |
2998 | } | |
2999 | $output .= "</ul></div>\n"; | |
3000 | ||
3001 | if ($return) { | |
3002 | return $output; | |
3003 | } | |
3004 | else { | |
3005 | echo $output; | |
3006 | } | |
3007 | } | |
3008 | ||
3009 | /** | |
3010 | * Function that returns the name that should be displayed for a specific tag | |
3011 | * | |
3012 | * @package core_tag | |
3013 | * @category tag | |
3014 | * @deprecated since 3.1 | |
3015 | * @param stdClass|core_tag_tag $tagobject a line out of tag table, as returned by the adobd functions | |
3016 | * @param int $html TAG_RETURN_HTML (default) will return htmlspecialchars encoded string, TAG_RETURN_TEXT will not encode. | |
3017 | * @return string | |
3018 | */ | |
3019 | function tag_display_name($tagobject, $html=TAG_RETURN_HTML) { | |
3020 | debugging('Function tag_display_name() is deprecated. Use core_tag_tag::make_display_name().', DEBUG_DEVELOPER); | |
3021 | if (!isset($tagobject->name)) { | |
3022 | return ''; | |
3023 | } | |
3024 | return core_tag_tag::make_display_name($tagobject, $html != TAG_RETURN_TEXT); | |
3025 | } | |
3026 | ||
3027 | /** | |
3028 | * Function that normalizes a list of tag names. | |
3029 | * | |
3030 | * @package core_tag | |
3031 | * @deprecated since 3.1 | |
3032 | * @param array/string $rawtags array of tags, or a single tag. | |
3033 | * @param int $case case to use for returned value (default: lower case). Either TAG_CASE_LOWER (default) or TAG_CASE_ORIGINAL | |
3034 | * @return array lowercased normalized tags, indexed by the normalized tag, in the same order as the original array. | |
3035 | * (Eg: 'Banana' => 'banana'). | |
3036 | */ | |
3037 | function tag_normalize($rawtags, $case = TAG_CASE_LOWER) { | |
3038 | debugging('Function tag_normalize() is deprecated. Use core_tag_tag::normalize().', DEBUG_DEVELOPER); | |
3039 | ||
3040 | if ( !is_array($rawtags) ) { | |
3041 | $rawtags = array($rawtags); | |
3042 | } | |
3043 | ||
3044 | return core_tag_tag::normalize($rawtags, $case == TAG_CASE_LOWER); | |
3045 | } | |
3046 | ||
3047 | /** | |
3048 | * Get a comma-separated list of tags related to another tag. | |
3049 | * | |
3050 | * @package core_tag | |
3051 | * @deprecated since 3.1 | |
3052 | * @param array $related_tags the array returned by tag_get_related_tags | |
3053 | * @param int $html either TAG_RETURN_HTML (default) or TAG_RETURN_TEXT : return html links, or just text. | |
3054 | * @return string comma-separated list | |
3055 | */ | |
3056 | function tag_get_related_tags_csv($related_tags, $html=TAG_RETURN_HTML) { | |
3057 | global $OUTPUT; | |
3058 | debugging('Method tag_get_related_tags_csv() is deprecated. Consider ' | |
3059 | . 'looping through array or using $OUTPUT->tag_list(core_tag_tag::get_item_tags())', | |
3060 | DEBUG_DEVELOPER); | |
3061 | if ($html != TAG_RETURN_TEXT) { | |
3062 | return $OUTPUT->tag_list($related_tags, ''); | |
3063 | } | |
3064 | ||
3065 | $tagsnames = array(); | |
3066 | foreach ($related_tags as $tag) { | |
3067 | $tagsnames[] = core_tag_tag::make_display_name($tag, false); | |
3068 | } | |
3069 | return implode(', ', $tagsnames); | |
3070 | } | |
3071 | ||
3072 | /** | |
3073 | * Used to require that the return value from a function is an array. | |
3074 | * Only used in the deprecated function {@link tag_get_id()} | |
3075 | * @deprecated since 3.1 | |
3076 | */ | |
3077 | define('TAG_RETURN_ARRAY', 0); | |
3078 | /** | |
3079 | * Used to require that the return value from a function is an object. | |
3080 | * Only used in the deprecated function {@link tag_get_id()} | |
3081 | * @deprecated since 3.1 | |
3082 | */ | |
3083 | define('TAG_RETURN_OBJECT', 1); | |
3084 | /** | |
3085 | * Use to specify that HTML free text is expected to be returned from a function. | |
3086 | * Only used in deprecated functions {@link tag_get_tags_csv()}, {@link tag_display_name()}, | |
3087 | * {@link tag_get_related_tags_csv()} | |
3088 | * @deprecated since 3.1 | |
3089 | */ | |
3090 | define('TAG_RETURN_TEXT', 2); | |
3091 | /** | |
3092 | * Use to specify that encoded HTML is expected to be returned from a function. | |
3093 | * Only used in deprecated functions {@link tag_get_tags_csv()}, {@link tag_display_name()}, | |
3094 | * {@link tag_get_related_tags_csv()} | |
3095 | * @deprecated since 3.1 | |
3096 | */ | |
3097 | define('TAG_RETURN_HTML', 3); | |
3098 | ||
3099 | /** | |
3100 | * Used to specify that we wish a lowercased string to be returned | |
3101 | * Only used in deprecated function {@link tag_normalize()} | |
3102 | * @deprecated since 3.1 | |
3103 | */ | |
3104 | define('TAG_CASE_LOWER', 0); | |
3105 | /** | |
3106 | * Used to specify that we do not wish the case of the returned string to change | |
3107 | * Only used in deprecated function {@link tag_normalize()} | |
3108 | * @deprecated since 3.1 | |
3109 | */ | |
3110 | define('TAG_CASE_ORIGINAL', 1); | |
3111 | ||
3112 | /** | |
3113 | * Used to specify that we want all related tags returned, no matter how they are related. | |
3114 | * Only used in deprecated function {@link tag_get_related_tags()} | |
3115 | * @deprecated since 3.1 | |
3116 | */ | |
3117 | define('TAG_RELATED_ALL', 0); | |
3118 | /** | |
3119 | * Used to specify that we only want back tags that were manually related. | |
3120 | * Only used in deprecated function {@link tag_get_related_tags()} | |
3121 | * @deprecated since 3.1 | |
3122 | */ | |
3123 | define('TAG_RELATED_MANUAL', 1); | |
3124 | /** | |
3125 | * Used to specify that we only want back tags where the relationship was automatically correlated. | |
3126 | * Only used in deprecated function {@link tag_get_related_tags()} | |
3127 | * @deprecated since 3.1 | |
3128 | */ | |
3129 | define('TAG_RELATED_CORRELATED', 2); | |
3130 | ||
3131 | /** | |
3132 | * Set the tags assigned to a record. This overwrites the current tags. | |
3133 | * | |
3134 | * This function is meant to be fed the string coming up from the user interface, which contains all tags assigned to a record. | |
3135 | * | |
3136 | * Due to API change $component and $contextid are now required. Instead of | |
3137 | * calling this function you can use {@link core_tag_tag::set_item_tags()} or | |
3138 | * {@link core_tag_tag::set_related_tags()} | |
3139 | * | |
3140 | * @package core_tag | |
3141 | * @deprecated since 3.1 | |
3142 | * @param string $itemtype the type of record to tag ('post' for blogs, 'user' for users, 'tag' for tags, etc.) | |
3143 | * @param int $itemid the id of the record to tag | |
3144 | * @param array $tags the array of tags to set on the record. If given an empty array, all tags will be removed. | |
3145 | * @param string|null $component the component that was tagged | |
3146 | * @param int|null $contextid the context id of where this tag was assigned | |
3147 | * @return bool|null | |
3148 | */ | |
3149 | function tag_set($itemtype, $itemid, $tags, $component = null, $contextid = null) { | |
3150 | debugging('Function tag_set() is deprecated. Use ' . | |
3151 | ' core_tag_tag::set_item_tags() instead', DEBUG_DEVELOPER); | |
3152 | ||
3153 | if ($itemtype === 'tag') { | |
3154 | return core_tag_tag::get($itemid, '*', MUST_EXIST)->set_related_tags($tags); | |
3155 | } else { | |
3156 | $context = $contextid ? context::instance_by_id($contextid) : context_system::instance(); | |
3157 | return core_tag_tag::set_item_tags($component, $itemtype, $itemid, $context, $tags); | |
3158 | } | |
3159 | } | |
3160 | ||
3161 | /** | |
3162 | * Adds a tag to a record, without overwriting the current tags. | |
3163 | * | |
3164 | * This function remains here for backward compatiblity. It is recommended to use | |
3165 | * {@link core_tag_tag::add_item_tag()} or {@link core_tag_tag::add_related_tags()} instead | |
3166 | * | |
3167 | * @package core_tag | |
3168 | * @deprecated since 3.1 | |
3169 | * @param string $itemtype the type of record to tag ('post' for blogs, 'user' for users, etc.) | |
3170 | * @param int $itemid the id of the record to tag | |
3171 | * @param string $tag the tag to add | |
3172 | * @param string|null $component the component that was tagged | |
3173 | * @param int|null $contextid the context id of where this tag was assigned | |
3174 | * @return bool|null | |
3175 | */ | |
3176 | function tag_set_add($itemtype, $itemid, $tag, $component = null, $contextid = null) { | |
3177 | debugging('Function tag_set_add() is deprecated. Use ' . | |
3178 | ' core_tag_tag::add_item_tag() instead', DEBUG_DEVELOPER); | |
3179 | ||
3180 | if ($itemtype === 'tag') { | |
3181 | return core_tag_tag::get($itemid, '*', MUST_EXIST)->add_related_tags(array($tag)); | |
3182 | } else { | |
3183 | $context = $contextid ? context::instance_by_id($contextid) : context_system::instance(); | |
3184 | return core_tag_tag::add_item_tag($component, $itemtype, $itemid, $context, $tag); | |
3185 | } | |
3186 | } | |
3187 | ||
3188 | /** | |
3189 | * Removes a tag from a record, without overwriting other current tags. | |
3190 | * | |
3191 | * This function remains here for backward compatiblity. It is recommended to use | |
3192 | * {@link core_tag_tag::remove_item_tag()} instead | |
3193 | * | |
3194 | * @package core_tag | |
3195 | * @deprecated since 3.1 | |
3196 | * @param string $itemtype the type of record to tag ('post' for blogs, 'user' for users, etc.) | |
3197 | * @param int $itemid the id of the record to tag | |
3198 | * @param string $tag the tag to delete | |
3199 | * @param string|null $component the component that was tagged | |
3200 | * @param int|null $contextid the context id of where this tag was assigned | |
3201 | * @return bool|null | |
3202 | */ | |
3203 | function tag_set_delete($itemtype, $itemid, $tag, $component = null, $contextid = null) { | |
3204 | debugging('Function tag_set_delete() is deprecated. Use ' . | |
3205 | ' core_tag_tag::remove_item_tag() instead', DEBUG_DEVELOPER); | |
3206 | return core_tag_tag::remove_item_tag($component, $itemtype, $itemid, $tag); | |
3207 | } | |
3208 | ||
3209 | /** | |
3210 | * Simple function to just return a single tag object when you know the name or something | |
3211 | * | |
3212 | * See also {@link core_tag_tag::get()} and {@link core_tag_tag::get_by_name()} | |
3213 | * | |
3214 | * @package core_tag | |
3215 | * @deprecated since 3.1 | |
3216 | * @param string $field which field do we use to identify the tag: id, name or rawname | |
3217 | * @param string $value the required value of the aforementioned field | |
3218 | * @param string $returnfields which fields do we want returned. This is a comma seperated string containing any combination of | |
3219 | * 'id', 'name', 'rawname' or '*' to include all fields. | |
3220 | * @return mixed tag object | |
3221 | */ | |
3222 | function tag_get($field, $value, $returnfields='id, name, rawname, tagcollid') { | |
3223 | global $DB; | |
3224 | debugging('Function tag_get() is deprecated. Use ' . | |
3225 | ' core_tag_tag::get() or core_tag_tag::get_by_name()', | |
3226 | DEBUG_DEVELOPER); | |
3227 | if ($field === 'id') { | |
3228 | $tag = core_tag_tag::get((int)$value, $returnfields); | |
3229 | } else if ($field === 'name') { | |
3230 | $tag = core_tag_tag::get_by_name(0, $value, $returnfields); | |
3231 | } else { | |
3232 | $params = array($field => $value); | |
3233 | return $DB->get_record('tag', $params, $returnfields); | |
3234 | } | |
3235 | if ($tag) { | |
3236 | return $tag->to_object(); | |
3237 | } | |
3238 | return null; | |
3239 | } | |
3240 | ||
3241 | /** | |
3242 | * Returns tags related to a tag | |
3243 | * | |
3244 | * Related tags of a tag come from two sources: | |
3245 | * - manually added related tags, which are tag_instance entries for that tag | |
3246 | * - correlated tags, which are calculated | |
3247 | * | |
3248 | * @package core_tag | |
3249 | * @deprecated since 3.1 | |
3250 | * @param string $tagid is a single **normalized** tag name or the id of a tag | |
3251 | * @param int $type the function will return either manually (TAG_RELATED_MANUAL) related tags or correlated | |
3252 | * (TAG_RELATED_CORRELATED) tags. Default is TAG_RELATED_ALL, which returns everything. | |
3253 | * @param int $limitnum (optional) return a subset comprising this many records, the default is 10 | |
3254 | * @return array an array of tag objects | |
3255 | */ | |
3256 | function tag_get_related_tags($tagid, $type=TAG_RELATED_ALL, $limitnum=10) { | |
3257 | debugging('Method tag_get_related_tags() is deprecated, ' | |
3258 | . 'use core_tag_tag::get_correlated_tags(), core_tag_tag::get_related_tags() or ' | |
3259 | . 'core_tag_tag::get_manual_related_tags()', DEBUG_DEVELOPER); | |
3260 | $result = array(); | |
3261 | if ($tag = core_tag_tag::get($tagid)) { | |
3262 | if ($type == TAG_RELATED_CORRELATED) { | |
3263 | $tags = $tag->get_correlated_tags(); | |
3264 | } else if ($type == TAG_RELATED_MANUAL) { | |
3265 | $tags = $tag->get_manual_related_tags(); | |
3266 | } else { | |
3267 | $tags = $tag->get_related_tags(); | |
3268 | } | |
3269 | $tags = array_slice($tags, 0, $limitnum); | |
3270 | foreach ($tags as $id => $tag) { | |
3271 | $result[$id] = $tag->to_object(); | |
3272 | } | |
3273 | } | |
3274 | return $result; | |
3275 | } | |
3276 | ||
3277 | /** | |
3278 | * Delete one or more tag, and all their instances if there are any left. | |
3279 | * | |
3280 | * @package core_tag | |
3281 | * @deprecated since 3.1 | |
3282 | * @param mixed $tagids one tagid (int), or one array of tagids to delete | |
3283 | * @return bool true on success, false otherwise | |
3284 | */ | |
3285 | function tag_delete($tagids) { | |
3286 | debugging('Method tag_delete() is deprecated, use core_tag_tag::delete_tags()', | |
3287 | DEBUG_DEVELOPER); | |
3288 | return core_tag_tag::delete_tags($tagids); | |
3289 | } | |
3290 | ||
3291 | /** | |
3292 | * Deletes all the tag instances given a component and an optional contextid. | |
3293 | * | |
3294 | * @deprecated since 3.1 | |
3295 | * @param string $component | |
3296 | * @param int $contextid if null, then we delete all tag instances for the $component | |
3297 | */ | |
3298 | function tag_delete_instances($component, $contextid = null) { | |
3299 | debugging('Method tag_delete() is deprecated, use core_tag_tag::delete_instances()', | |
3300 | DEBUG_DEVELOPER); | |
3301 | core_tag_tag::delete_instances($component, null, $contextid); | |
3302 | } | |
3303 | ||
3304 | /** | |
3305 | * Clean up the tag tables, making sure all tagged object still exists. | |
3306 | * | |
3307 | * This should normally not be necessary, but in case related tags are not deleted when the tagged record is removed, this should be | |
3308 | * done once in a while, perhaps on an occasional cron run. On a site with lots of tags, this could become an expensive function to | |
3309 | * call: don't run at peak time. | |
3310 | * | |
3311 | * @package core_tag | |
3312 | * @deprecated since 3.1 | |
3313 | */ | |
3314 | function tag_cleanup() { | |
3315 | debugging('Method tag_cleanup() is deprecated, use \core\task\tag_cron_task::cleanup()', | |
3316 | DEBUG_DEVELOPER); | |
3317 | ||
3318 | $task = new \core\task\tag_cron_task(); | |
3319 | return $task->cleanup(); | |
3320 | } | |
3321 | ||
3322 | /** | |
3323 | * This function will delete numerous tag instances efficiently. | |
3324 | * This removes tag instances only. It doesn't check to see if it is the last use of a tag. | |
3325 | * | |
3326 | * @deprecated since 3.1 | |
3327 | * @param array $instances An array of tag instance objects with the addition of the tagname and tagrawname | |
3328 | * (used for recording a delete event). | |
3329 | */ | |
3330 | function tag_bulk_delete_instances($instances) { | |
3331 | debugging('Method tag_bulk_delete_instances() is deprecated, ' | |
3332 | . 'use \core\task\tag_cron_task::bulk_delete_instances()', | |
3333 | DEBUG_DEVELOPER); | |
3334 | ||
3335 | $task = new \core\task\tag_cron_task(); | |
3336 | return $task->bulk_delete_instances($instances); | |
3337 | } | |
3338 | ||
3339 | /** | |
3340 | * Calculates and stores the correlated tags of all tags. The correlations are stored in the 'tag_correlation' table. | |
3341 | * | |
3342 | * Two tags are correlated if they appear together a lot. Ex.: Users tagged with "computers" will probably also be tagged with "algorithms". | |
3343 | * | |
3344 | * The rationale for the 'tag_correlation' table is performance. It works as a cache for a potentially heavy load query done at the | |
3345 | * 'tag_instance' table. So, the 'tag_correlation' table stores redundant information derived from the 'tag_instance' table. | |
3346 | * | |
3347 | * @package core_tag | |
3348 | * @deprecated since 3.1 | |
3349 | * @param int $mincorrelation Only tags with more than $mincorrelation correlations will be identified. | |
3350 | */ | |
3351 | function tag_compute_correlations($mincorrelation = 2) { | |
3352 | debugging('Method tag_compute_correlations() is deprecated, ' | |
3353 | . 'use \core\task\tag_cron_task::compute_correlations()', | |
3354 | DEBUG_DEVELOPER); | |
3355 | ||
3356 | $task = new \core\task\tag_cron_task(); | |
3357 | return $task->compute_correlations($mincorrelation); | |
3358 | } | |
3359 | ||
3360 | /** | |
3361 | * This function processes a tag correlation and makes changes in the database as required. | |
3362 | * | |
3363 | * The tag correlation object needs have both a tagid property and a correlatedtags property that is an array. | |
3364 | * | |
3365 | * @package core_tag | |
3366 | * @deprecated since 3.1 | |
3367 | * @param stdClass $tagcorrelation | |
3368 | * @return int/bool The id of the tag correlation that was just processed or false. | |
3369 | */ | |
3370 | function tag_process_computed_correlation(stdClass $tagcorrelation) { | |
3371 | debugging('Method tag_process_computed_correlation() is deprecated, ' | |
3372 | . 'use \core\task\tag_cron_task::process_computed_correlation()', | |
3373 | DEBUG_DEVELOPER); | |
3374 | ||
3375 | $task = new \core\task\tag_cron_task(); | |
3376 | return $task->process_computed_correlation($tagcorrelation); | |
3377 | } | |
3378 | ||
3379 | /** | |
3380 | * Tasks that should be performed at cron time | |
3381 | * | |
3382 | * @package core_tag | |
3383 | * @deprecated since 3.1 | |
3384 | */ | |
3385 | function tag_cron() { | |
3386 | debugging('Method tag_cron() is deprecated, use \core\task\tag_cron_task::execute()', | |
3387 | DEBUG_DEVELOPER); | |
3388 | ||
3389 | $task = new \core\task\tag_cron_task(); | |
3390 | $task->execute(); | |
3391 | } | |
3392 | ||
3393 | /** | |
3394 | * Search for tags with names that match some text | |
3395 | * | |
3396 | * @package core_tag | |
3397 | * @deprecated since 3.1 | |
3398 | * @param string $text escaped string that the tag names will be matched against | |
3399 | * @param bool $ordered If true, tags are ordered by their popularity. If false, no ordering. | |
3400 | * @param int/string $limitfrom (optional, required if $limitnum is set) return a subset of records, starting at this point. | |
3401 | * @param int/string $limitnum (optional, required if $limitfrom is set) return a subset comprising this many records. | |
3402 | * @param int $tagcollid | |
3403 | * @return array/boolean an array of objects, or false if no records were found or an error occured. | |
3404 | */ | |
3405 | function tag_find_tags($text, $ordered=true, $limitfrom='', $limitnum='', $tagcollid = null) { | |
3406 | debugging('Method tag_find_tags() is deprecated without replacement', DEBUG_DEVELOPER); | |
3407 | global $DB; | |
3408 | ||
3409 | $text = core_text::strtolower(clean_param($text, PARAM_TAG)); | |
3410 | ||
3411 | list($sql, $params) = $DB->get_in_or_equal($tagcollid ? array($tagcollid) : | |
3412 | array_keys(core_tag_collection::get_collections(true))); | |
3413 | array_unshift($params, "%{$text}%"); | |
3414 | ||
3415 | if ($ordered) { | |
3416 | $query = "SELECT tg.id, tg.name, tg.rawname, tg.tagcollid, COUNT(ti.id) AS count | |
3417 | FROM {tag} tg LEFT JOIN {tag_instance} ti ON tg.id = ti.tagid | |
3418 | WHERE tg.name LIKE ? AND tg.tagcollid $sql | |
3419 | GROUP BY tg.id, tg.name, tg.rawname | |
3420 | ORDER BY count DESC"; | |
3421 | } else { | |
3422 | $query = "SELECT tg.id, tg.name, tg.rawname, tg.tagcollid | |
3423 | FROM {tag} tg | |
3424 | WHERE tg.name LIKE ? AND tg.tagcollid $sql"; | |
3425 | } | |
3426 | return $DB->get_records_sql($query, $params, $limitfrom , $limitnum); | |
3427 | } | |
3428 | ||
3429 | /** | |
3430 | * Get the name of a tag | |
3431 | * | |
3432 | * @package core_tag | |
3433 | * @deprecated since 3.1 | |
3434 | * @param mixed $tagids the id of the tag, or an array of ids | |
3435 | * @return mixed string name of one tag, or id-indexed array of strings | |
3436 | */ | |
3437 | function tag_get_name($tagids) { | |
3438 | debugging('Method tag_get_name() is deprecated without replacement', DEBUG_DEVELOPER); | |
3439 | global $DB; | |
3440 | ||
3441 | if (!is_array($tagids)) { | |
3442 | if ($tag = $DB->get_record('tag', array('id'=>$tagids))) { | |
3443 | return $tag->name; | |
3444 | } | |
3445 | return false; | |
3446 | } | |
3447 | ||
3448 | $tag_names = array(); | |
3449 | foreach($DB->get_records_list('tag', 'id', $tagids) as $tag) { | |
3450 | $tag_names[$tag->id] = $tag->name; | |
3451 | } | |
3452 | ||
3453 | return $tag_names; | |
3454 | } | |
3455 | ||
3456 | /** | |
3457 | * Returns the correlated tags of a tag, retrieved from the tag_correlation table. Make sure cron runs, otherwise the table will be | |