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