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