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