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