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