MDL-52619 lib: Update of ADODB to 5.20.3
[moodle.git] / lib / deprecatedlib.php
blobb787c16f1cdd70aa509ea163faf78796ed8e4c8a
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
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/>.
18 /**
19 * deprecatedlib.php - Old functions retained only for backward compatibility
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
24 * @package core
25 * @subpackage deprecated
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * @deprecated
31 defined('MOODLE_INTERNAL') || die();
33 /* === Functions that needs to be kept longer in deprecated lib than normal time period === */
35 /**
36 * Add an entry to the legacy log table.
38 * @deprecated since 2.7 use new events instead
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
49 function 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);
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);
60 /**
61 * Function to call all event handlers when triggering an event
63 * @deprecated since 2.6
65 * @param string $eventname name of the event
66 * @param mixed $eventdata event data object
67 * @return int number of failed events
69 function events_trigger($eventname, $eventdata) {
70 debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
71 return events_trigger_legacy($eventname, $eventdata);
74 /**
75 * List all core subsystems and their location
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.
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.
86 * @deprecated since 2.6, use core_component::get_core_subsystems()
88 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
89 * @return array of (string)name => (string|null)location
91 function get_core_subsystems($fullpaths = false) {
92 global $CFG;
94 // NOTE: do not add any other debugging here, keep forever.
96 $subsystems = core_component::get_core_subsystems();
98 if ($fullpaths) {
99 return $subsystems;
102 debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
104 $dlength = strlen($CFG->dirroot);
106 foreach ($subsystems as $k => $v) {
107 if ($v === null) {
108 continue;
110 $subsystems[$k] = substr($v, $dlength+1);
113 return $subsystems;
117 * Lists all plugin types.
119 * @deprecated since 2.6, use core_component::get_plugin_types()
121 * @param bool $fullpaths false means relative paths from dirroot
122 * @return array Array of strings - name=>location
124 function get_plugin_types($fullpaths = true) {
125 global $CFG;
127 // NOTE: do not add any other debugging here, keep forever.
129 $types = core_component::get_plugin_types();
131 if ($fullpaths) {
132 return $types;
135 debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
137 $dlength = strlen($CFG->dirroot);
139 foreach ($types as $k => $v) {
140 if ($k === 'theme') {
141 $types[$k] = 'theme';
142 continue;
144 $types[$k] = substr($v, $dlength+1);
147 return $types;
151 * Use when listing real plugins of one type.
153 * @deprecated since 2.6, use core_component::get_plugin_list()
155 * @param string $plugintype type of plugin
156 * @return array name=>fulllocation pairs of plugins of given type
158 function get_plugin_list($plugintype) {
160 // NOTE: do not add any other debugging here, keep forever.
162 if ($plugintype === '') {
163 $plugintype = 'mod';
166 return core_component::get_plugin_list($plugintype);
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.
173 * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
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').
184 function get_plugin_list_with_class($plugintype, $class, $file) {
186 // NOTE: do not add any other debugging here, keep forever.
188 return core_component::get_plugin_list_with_class($plugintype, $class, $file);
192 * Returns the exact absolute path to plugin directory.
194 * @deprecated since 2.6, use core_component::get_plugin_directory()
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
200 function get_plugin_directory($plugintype, $name) {
202 // NOTE: do not add any other debugging here, keep forever.
204 if ($plugintype === '') {
205 $plugintype = 'mod';
208 return core_component::get_plugin_directory($plugintype, $name);
212 * Normalize the component name using the "frankenstyle" names.
214 * @deprecated since 2.6, use core_component::normalize_component()
216 * @param string $component
217 * @return array as (string)$type => (string)$plugin
219 function normalize_component($component) {
221 // NOTE: do not add any other debugging here, keep forever.
223 return core_component::normalize_component($component);
227 * Return exact absolute path to a plugin directory.
229 * @deprecated since 2.6, use core_component::normalize_component()
231 * @param string $component name such as 'moodle', 'mod_forum'
232 * @return string full path to component directory; NULL if not found
234 function get_component_directory($component) {
236 // NOTE: do not add any other debugging here, keep forever.
238 return core_component::get_component_directory($component);
242 * Get the context instance as an object. This function will create the
243 * context instance if it does not exist yet.
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.
254 function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
256 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
258 $instances = (array)$instance;
259 $contexts = array();
261 $classname = context_helper::get_class_for_level($contextlevel);
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);
268 if (is_array($instance)) {
269 return $contexts;
270 } else {
271 return $contexts[$instance];
274 /* === End of long term deprecated api list === */
277 * Adds a file upload to the log table so that clam can resolve the filename to the user later if necessary
279 * @deprecated since 2.7 - use new file picker instead
282 function clam_log_upload($newfilepath, $course=null, $nourl=false) {
283 throw new coding_exception('clam_log_upload() can not be used any more, please use file picker instead');
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.
289 * @deprecated since 2.7 - use new file picker instead
292 function clam_log_infected($oldfilepath='', $newfilepath='', $userid=0) {
293 throw new coding_exception('clam_log_infected() can not be used any more, please use file picker instead');
297 * Some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path.
299 * @deprecated since 2.7 - use new file picker instead
302 function clam_change_log($oldpath, $newpath, $update=true) {
303 throw new coding_exception('clam_change_log() can not be used any more, please use file picker instead');
307 * Replaces the given file with a string.
309 * @deprecated since 2.7 - infected files are now deleted in file picker
312 function clam_replace_infected_file($file) {
313 throw new coding_exception('clam_replace_infected_file() can not be used any more, please use file picker instead');
317 * Deals with an infected file - either moves it to a quarantinedir
318 * (specified in CFG->quarantinedir) or deletes it.
320 * If moving it fails, it deletes it.
322 * @deprecated since 2.7
324 function 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');
329 * If $CFG->runclamonupload is set, we scan a given file. (called from {@link preprocess_files()})
331 * @deprecated since 2.7
333 function 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');
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.
343 * See https://github.com/ircmaxell/password_compat/issues/10 for more details.
345 * @deprecated since 2.7 PHP 5.4.x should be always compatible.
348 function password_compat_not_supported() {
349 throw new coding_exception('Do not use password_compat_not_supported() - bcrypt is now always available');
353 * Factory method that was returning moodle_session object.
355 * @deprecated since 2.6
357 function session_get_instance() {
358 throw new coding_exception('session_get_instance() is removed, use \core\session\manager instead');
362 * Returns true if legacy session used.
364 * @deprecated since 2.6
366 function session_is_legacy() {
367 throw new coding_exception('session_is_legacy() is removed, do not use any more');
371 * Terminates all sessions, auth hooks are not executed.
373 * @deprecated since 2.6
375 function session_kill_all() {
376 throw new coding_exception('session_kill_all() is removed, use \core\session\manager::kill_all_sessions() instead');
380 * Mark session as accessed, prevents timeouts.
382 * @deprecated since 2.6
384 function session_touch($sid) {
385 throw new coding_exception('session_touch() is removed, use \core\session\manager::touch_session() instead');
389 * Terminates one sessions, auth hooks are not executed.
391 * @deprecated since 2.6
393 function session_kill($sid) {
394 throw new coding_exception('session_kill() is removed, use \core\session\manager::kill_session() instead');
398 * Terminates all sessions of one user, auth hooks are not executed.
400 * @deprecated since 2.6
402 function session_kill_user($userid) {
403 throw new coding_exception('session_kill_user() is removed, use \core\session\manager::kill_user_sessions() instead');
407 * Setup $USER object - called during login, loginas, etc.
409 * Call sync_user_enrolments() manually after log-in, or log-in-as.
411 * @deprecated since 2.6
413 function session_set_user($user) {
414 throw new coding_exception('session_set_user() is removed, use \core\session\manager::set_user() instead');
418 * Is current $USER logged-in-as somebody else?
419 * @deprecated since 2.6
421 function session_is_loggedinas() {
422 throw new coding_exception('session_is_loggedinas() is removed, use \core\session\manager::is_loggedinas() instead');
426 * Returns the $USER object ignoring current login-as session
427 * @deprecated since 2.6
429 function session_get_realuser() {
430 throw new coding_exception('session_get_realuser() is removed, use \core\session\manager::get_realuser() instead');
434 * Login as another user - no security checks here.
435 * @deprecated since 2.6
437 function session_loginas($userid, $context) {
438 throw new coding_exception('session_loginas() is removed, use \core\session\manager::loginas() instead');
442 * Minify JavaScript files.
444 * @deprecated since 2.6
446 function js_minify($files) {
447 throw new coding_exception('js_minify() is removed, use core_minify::js_files() or core_minify::js() instead.');
451 * Minify CSS files.
453 * @deprecated since 2.6
455 function css_minify_css($files) {
456 throw new coding_exception('css_minify_css() is removed, use core_minify::css_files() or core_minify::css() instead.');
459 // === Deprecated before 2.6.0 ===
462 * Hack to find out the GD version by parsing phpinfo output
464 function check_gd_version() {
465 throw new coding_exception('check_gd_version() is removed, GD extension is always available now');
469 * Not used any more, the account lockout handling is now
470 * part of authenticate_user_login().
471 * @deprecated
473 function update_login_count() {
474 throw new coding_exception('update_login_count() is removed, all calls need to be removed');
478 * Not used any more, replaced by proper account lockout.
479 * @deprecated
481 function reset_login_count() {
482 throw new coding_exception('reset_login_count() is removed, all calls need to be removed');
486 * @deprecated
488 function update_log_display_entry($module, $action, $mtable, $field) {
490 throw new coding_exception('The update_log_display_entry() is removed, please use db/log.php description file instead.');
494 * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
495 * this was abused mostly for embedding of attachments
497 function filter_text($text, $courseid = NULL) {
498 throw new coding_exception('filter_text() can not be used anymore, use format_text(), format_string() etc instead.');
502 * @deprecated use $PAGE->https_required() instead
504 function httpsrequired() {
505 throw new coding_exception('httpsrequired() can not be used any more use $PAGE->https_required() instead.');
509 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
511 * @deprecated since 3.1 - replacement legacy file API methods can be found on the moodle_url class, for example:
512 * The moodle_url::make_legacyfile_url() method can be used to generate a legacy course file url. To generate
513 * course module file.php url the moodle_url::make_file_url() should be used.
515 * @param string $path Physical path to a file
516 * @param array $options associative array of GET variables to append to the URL
517 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
518 * @return string URL to file
520 function get_file_url($path, $options=null, $type='coursefile') {
521 debugging('Function get_file_url() is deprecated, please use moodle_url factory methods instead.', DEBUG_DEVELOPER);
522 global $CFG;
524 $path = str_replace('//', '/', $path);
525 $path = trim($path, '/'); // no leading and trailing slashes
527 // type of file
528 switch ($type) {
529 case 'questionfile':
530 $url = $CFG->wwwroot."/question/exportfile.php";
531 break;
532 case 'rssfile':
533 $url = $CFG->wwwroot."/rss/file.php";
534 break;
535 case 'httpscoursefile':
536 $url = $CFG->httpswwwroot."/file.php";
537 break;
538 case 'coursefile':
539 default:
540 $url = $CFG->wwwroot."/file.php";
543 if ($CFG->slasharguments) {
544 $parts = explode('/', $path);
545 foreach ($parts as $key => $part) {
546 /// anchor dash character should not be encoded
547 $subparts = explode('#', $part);
548 $subparts = array_map('rawurlencode', $subparts);
549 $parts[$key] = implode('#', $subparts);
551 $path = implode('/', $parts);
552 $ffurl = $url.'/'.$path;
553 $separator = '?';
554 } else {
555 $path = rawurlencode('/'.$path);
556 $ffurl = $url.'?file='.$path;
557 $separator = '&amp;';
560 if ($options) {
561 foreach ($options as $name=>$value) {
562 $ffurl = $ffurl.$separator.$name.'='.$value;
563 $separator = '&amp;';
567 return $ffurl;
571 * @deprecated use get_enrolled_users($context) instead.
573 function get_course_participants($courseid) {
574 throw new coding_exception('get_course_participants() can not be used any more, use get_enrolled_users() instead.');
578 * @deprecated use is_enrolled($context, $userid) instead.
580 function is_course_participant($userid, $courseid) {
581 throw new coding_exception('is_course_participant() can not be used any more, use is_enrolled() instead.');
585 * @deprecated
587 function get_recent_enrolments($courseid, $timestart) {
588 throw new coding_exception('get_recent_enrolments() is removed as it returned inaccurate results.');
592 * @deprecated use clean_param($string, PARAM_FILE) instead.
594 function detect_munged_arguments($string, $allowdots=1) {
595 throw new coding_exception('detect_munged_arguments() can not be used any more, please use clean_param(,PARAM_FILE) instead.');
600 * Unzip one zip file to a destination dir
601 * Both parameters must be FULL paths
602 * If destination isn't specified, it will be the
603 * SAME directory where the zip file resides.
605 * @global object
606 * @param string $zipfile The zip file to unzip
607 * @param string $destination The location to unzip to
608 * @param bool $showstatus_ignored Unused
610 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
611 global $CFG;
613 //Extract everything from zipfile
614 $path_parts = pathinfo(cleardoubleslashes($zipfile));
615 $zippath = $path_parts["dirname"]; //The path of the zip file
616 $zipfilename = $path_parts["basename"]; //The name of the zip file
617 $extension = $path_parts["extension"]; //The extension of the file
619 //If no file, error
620 if (empty($zipfilename)) {
621 return false;
624 //If no extension, error
625 if (empty($extension)) {
626 return false;
629 //Clear $zipfile
630 $zipfile = cleardoubleslashes($zipfile);
632 //Check zipfile exists
633 if (!file_exists($zipfile)) {
634 return false;
637 //If no destination, passed let's go with the same directory
638 if (empty($destination)) {
639 $destination = $zippath;
642 //Clear $destination
643 $destpath = rtrim(cleardoubleslashes($destination), "/");
645 //Check destination path exists
646 if (!is_dir($destpath)) {
647 return false;
650 $packer = get_file_packer('application/zip');
652 $result = $packer->extract_to_pathname($zipfile, $destpath);
654 if ($result === false) {
655 return false;
658 foreach ($result as $status) {
659 if ($status !== true) {
660 return false;
664 return true;
668 * Zip an array of files/dirs to a destination zip file
669 * Both parameters must be FULL paths to the files/dirs
671 * @global object
672 * @param array $originalfiles Files to zip
673 * @param string $destination The destination path
674 * @return bool Outcome
676 function zip_files ($originalfiles, $destination) {
677 global $CFG;
679 //Extract everything from destination
680 $path_parts = pathinfo(cleardoubleslashes($destination));
681 $destpath = $path_parts["dirname"]; //The path of the zip file
682 $destfilename = $path_parts["basename"]; //The name of the zip file
683 $extension = $path_parts["extension"]; //The extension of the file
685 //If no file, error
686 if (empty($destfilename)) {
687 return false;
690 //If no extension, add it
691 if (empty($extension)) {
692 $extension = 'zip';
693 $destfilename = $destfilename.'.'.$extension;
696 //Check destination path exists
697 if (!is_dir($destpath)) {
698 return false;
701 //Check destination path is writable. TODO!!
703 //Clean destination filename
704 $destfilename = clean_filename($destfilename);
706 //Now check and prepare every file
707 $files = array();
708 $origpath = NULL;
710 foreach ($originalfiles as $file) { //Iterate over each file
711 //Check for every file
712 $tempfile = cleardoubleslashes($file); // no doubleslashes!
713 //Calculate the base path for all files if it isn't set
714 if ($origpath === NULL) {
715 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
717 //See if the file is readable
718 if (!is_readable($tempfile)) { //Is readable
719 continue;
721 //See if the file/dir is in the same directory than the rest
722 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
723 continue;
725 //Add the file to the array
726 $files[] = $tempfile;
729 $zipfiles = array();
730 $start = strlen($origpath)+1;
731 foreach($files as $file) {
732 $zipfiles[substr($file, $start)] = $file;
735 $packer = get_file_packer('application/zip');
737 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
741 * @deprecated use groups_get_all_groups() instead.
743 function mygroupid($courseid) {
744 throw new coding_exception('mygroupid() can not be used any more, please use groups_get_all_groups() instead.');
749 * Returns the current group mode for a given course or activity module
751 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
753 * @deprecated since Moodle 2.0 MDL-14617 - please do not use this function any more.
754 * @todo MDL-50273 This will be deleted in Moodle 3.2.
756 * @param object $course Course Object
757 * @param object $cm Course Manager Object
758 * @return mixed $course->groupmode
760 function groupmode($course, $cm=null) {
762 debugging('groupmode() is deprecated, please use groups_get_* instead', DEBUG_DEVELOPER);
763 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
764 return $cm->groupmode;
766 return $course->groupmode;
770 * Sets the current group in the session variable
771 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
772 * Sets currentgroup[$courseid] in the session variable appropriately.
773 * Does not do any permission checking.
775 * @deprecated Since year 2006 - please do not use this function any more.
776 * @todo MDL-50273 This will be deleted in Moodle 3.2.
778 * @global object
779 * @global object
780 * @param int $courseid The course being examined - relates to id field in
781 * 'course' table.
782 * @param int $groupid The group being examined.
783 * @return int Current group id which was set by this function
785 function set_current_group($courseid, $groupid) {
786 global $SESSION;
788 debugging('set_current_group() is deprecated, please use $SESSION->currentgroup[$courseid] instead', DEBUG_DEVELOPER);
789 return $SESSION->currentgroup[$courseid] = $groupid;
793 * Gets the current group - either from the session variable or from the database.
795 * @deprecated Since year 2006 - please do not use this function any more.
796 * @todo MDL-50273 This will be deleted in Moodle 3.2.
798 * @global object
799 * @param int $courseid The course being examined - relates to id field in
800 * 'course' table.
801 * @param bool $full If true, the return value is a full record object.
802 * If false, just the id of the record.
803 * @return int|bool
805 function get_current_group($courseid, $full = false) {
806 global $SESSION;
808 debugging('get_current_group() is deprecated, please use groups_get_* instead', DEBUG_DEVELOPER);
809 if (isset($SESSION->currentgroup[$courseid])) {
810 if ($full) {
811 return groups_get_group($SESSION->currentgroup[$courseid]);
812 } else {
813 return $SESSION->currentgroup[$courseid];
817 $mygroupid = mygroupid($courseid);
818 if (is_array($mygroupid)) {
819 $mygroupid = array_shift($mygroupid);
820 set_current_group($courseid, $mygroupid);
821 if ($full) {
822 return groups_get_group($mygroupid);
823 } else {
824 return $mygroupid;
828 if ($full) {
829 return false;
830 } else {
831 return 0;
836 * @deprecated Since Moodle 2.8
838 function groups_filter_users_by_course_module_visible($cm, $users) {
839 throw new coding_exception('groups_filter_users_by_course_module_visible() is removed. ' .
840 'Replace with a call to \core_availability\info_module::filter_user_list(), ' .
841 'which does basically the same thing but includes other restrictions such ' .
842 'as profile restrictions.');
846 * @deprecated Since Moodle 2.8
848 function groups_course_module_visible($cm, $userid=null) {
849 throw new coding_exception('groups_course_module_visible() is removed, use $cm->uservisible to decide whether the current
850 user can ' . 'access an activity.', DEBUG_DEVELOPER);
854 * @deprecated since 2.0
856 function error($message, $link='') {
857 throw new coding_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a removed, please call
858 print_error() instead of error()');
863 * @deprecated use $PAGE->theme->name instead.
865 function current_theme() {
866 throw new coding_exception('current_theme() can not be used any more, please use $PAGE->theme->name instead');
870 * @deprecated
872 function formerr($error) {
873 throw new coding_exception('formerr() is removed. Please change your code to use $OUTPUT->error_text($string).');
877 * @deprecated use $OUTPUT->skip_link_target() in instead.
879 function skip_main_destination() {
880 throw new coding_exception('skip_main_destination() can not be used any more, please use $OUTPUT->skip_link_target() instead.');
884 * @deprecated use $OUTPUT->container() instead.
886 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
887 throw new coding_exception('print_container() can not be used any more. Please use $OUTPUT->container() instead.');
891 * @deprecated use $OUTPUT->container_start() instead.
893 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
894 throw new coding_exception('print_container_start() can not be used any more. Please use $OUTPUT->container_start() instead.');
898 * @deprecated use $OUTPUT->container_end() instead.
900 function print_container_end($return=false) {
901 throw new coding_exception('print_container_end() can not be used any more. Please use $OUTPUT->container_end() instead.');
905 * Print a bold message in an optional color.
907 * @deprecated since Moodle 2.0 MDL-19077 - use $OUTPUT->notification instead.
908 * @todo MDL-50469 This will be deleted in Moodle 3.3.
909 * @param string $message The message to print out
910 * @param string $classes Optional style to display message text in
911 * @param string $align Alignment option
912 * @param bool $return whether to return an output string or echo now
913 * @return string|bool Depending on $result
915 function notify($message, $classes = 'error', $align = 'center', $return = false) {
916 global $OUTPUT;
918 debugging('notify() is deprecated, please use $OUTPUT->notification() instead', DEBUG_DEVELOPER);
920 if ($classes == 'green') {
921 debugging('Use of deprecated class name "green" in notify. Please change to "success".', DEBUG_DEVELOPER);
922 $classes = 'success'; // Backward compatible with old color system.
925 $output = $OUTPUT->notification($message, $classes);
926 if ($return) {
927 return $output;
928 } else {
929 echo $output;
934 * @deprecated use $OUTPUT->continue_button() instead.
936 function print_continue($link, $return = false) {
937 throw new coding_exception('print_continue() can not be used any more. Please use $OUTPUT->continue_button() instead.');
941 * @deprecated use $PAGE methods instead.
943 function print_header($title='', $heading='', $navigation='', $focus='',
944 $meta='', $cache=true, $button='&nbsp;', $menu=null,
945 $usexml=false, $bodytags='', $return=false) {
947 throw new coding_exception('print_header() can not be used any more. Please use $PAGE methods instead.');
951 * @deprecated use $PAGE methods instead.
953 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
954 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
956 throw new coding_exception('print_header_simple() can not be used any more. Please use $PAGE methods instead.');
960 * @deprecated use $OUTPUT->block() instead.
962 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
963 throw new coding_exception('print_side_block() can not be used any more, please use $OUTPUT->block() instead.');
967 * Prints a basic textarea field.
969 * @deprecated since Moodle 2.0
971 * When using this function, you should
973 * @global object
974 * @param bool $unused No longer used.
975 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
976 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
977 * @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.
978 * @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.
979 * @param string $name Name to use for the textarea element.
980 * @param string $value Initial content to display in the textarea.
981 * @param int $obsolete deprecated
982 * @param bool $return If false, will output string. If true, will return string value.
983 * @param string $id CSS ID to add to the textarea element.
984 * @return string|void depending on the value of $return
986 function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
987 /// $width and height are legacy fields and no longer used as pixels like they used to be.
988 /// However, you can set them to zero to override the mincols and minrows values below.
990 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
991 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
993 global $CFG;
995 $mincols = 65;
996 $minrows = 10;
997 $str = '';
999 if ($id === '') {
1000 $id = 'edit-'.$name;
1003 if ($height && ($rows < $minrows)) {
1004 $rows = $minrows;
1006 if ($width && ($cols < $mincols)) {
1007 $cols = $mincols;
1010 editors_head_setup();
1011 $editor = editors_get_preferred_editor(FORMAT_HTML);
1012 $editor->set_text($value);
1013 $editor->use_editor($id, array('legacy'=>true));
1015 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
1016 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
1017 $str .= '</textarea>'."\n";
1019 if ($return) {
1020 return $str;
1022 echo $str;
1026 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1027 * provide this function with the language strings for sortasc and sortdesc.
1029 * @deprecated use $OUTPUT->arrow() instead.
1030 * @todo final deprecation of this function once MDL-45448 is resolved
1032 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1034 * @global object
1035 * @param string $direction 'up' or 'down'
1036 * @param string $strsort The language string used for the alt attribute of this image
1037 * @param bool $return Whether to print directly or return the html string
1038 * @return string|void depending on $return
1041 function print_arrow($direction='up', $strsort=null, $return=false) {
1042 global $OUTPUT;
1044 debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER);
1046 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1047 return null;
1050 $return = null;
1052 switch ($direction) {
1053 case 'up':
1054 $sortdir = 'asc';
1055 break;
1056 case 'down':
1057 $sortdir = 'desc';
1058 break;
1059 case 'move':
1060 $sortdir = 'asc';
1061 break;
1062 default:
1063 $sortdir = null;
1064 break;
1067 // Prepare language string
1068 $strsort = '';
1069 if (empty($strsort) && !empty($sortdir)) {
1070 $strsort = get_string('sort' . $sortdir, 'grades');
1073 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
1075 if ($return) {
1076 return $return;
1077 } else {
1078 echo $return;
1083 * @deprecated since Moodle 2.0
1085 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
1086 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
1087 $id='', $listbox=false, $multiple=false, $class='') {
1088 throw new coding_exception('choose_from_menu() is removed. Please change your code to use html_writer::select().');
1093 * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
1095 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
1096 throw new coding_exception('print_scale_menu_helpbutton() can not be used any more. '.
1097 'Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.');
1101 * @deprecated use html_writer::checkbox() instead.
1103 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
1104 throw new coding_exception('print_checkbox() can not be used any more. Please use html_writer::checkbox() instead.');
1108 * Prints the 'update this xxx' button that appears on module pages.
1110 * @deprecated since Moodle 2.0
1112 * @param string $cmid the course_module id.
1113 * @param string $ignored not used any more. (Used to be courseid.)
1114 * @param string $string the module name - get_string('modulename', 'xxx')
1115 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
1117 function update_module_button($cmid, $ignored, $string) {
1118 global $CFG, $OUTPUT;
1120 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
1122 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
1124 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
1125 $string = get_string('updatethis', '', $string);
1127 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
1128 return $OUTPUT->single_button($url, $string);
1129 } else {
1130 return '';
1135 * @deprecated use $OUTPUT->navbar() instead
1137 function print_navigation ($navigation, $separator=0, $return=false) {
1138 throw new coding_exception('print_navigation() can not be used any more, please update use $OUTPUT->navbar() instead.');
1142 * @deprecated Please use $PAGE->navabar methods instead.
1144 function build_navigation($extranavlinks, $cm = null) {
1145 throw new coding_exception('build_navigation() can not be used any more, please use $PAGE->navbar methods instead.');
1149 * @deprecated not relevant with global navigation in Moodle 2.x+
1151 function navmenu($course, $cm=NULL, $targetwindow='self') {
1152 throw new coding_exception('navmenu() can not be used any more, it is no longer relevant with global navigation.');
1155 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
1159 * @deprecated please use calendar_event::create() instead.
1161 function add_event($event) {
1162 throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.');
1166 * @deprecated please calendar_event->update() instead.
1168 function update_event($event) {
1169 throw new coding_exception('update_event() is removed, please use calendar_event->update() instead.');
1173 * @deprecated please use calendar_event->delete() instead.
1175 function delete_event($id) {
1176 throw new coding_exception('delete_event() can not be used any more, please use '.
1177 'calendar_event->delete() instead.');
1181 * @deprecated please use calendar_event->toggle_visibility(false) instead.
1183 function hide_event($event) {
1184 throw new coding_exception('hide_event() can not be used any more, please use '.
1185 'calendar_event->toggle_visibility(false) instead.');
1189 * @deprecated please use calendar_event->toggle_visibility(true) instead.
1191 function show_event($event) {
1192 throw new coding_exception('show_event() can not be used any more, please use '.
1193 'calendar_event->toggle_visibility(true) instead.');
1197 * @deprecated since Moodle 2.2 use core_text::xxxx() instead.
1198 * @see core_text
1200 function textlib_get_instance() {
1201 throw new coding_exception('textlib_get_instance() can not be used any more, please use '.
1202 'core_text::functioname() instead.');
1206 * @deprecated since 2.4
1207 * @see get_section_name()
1208 * @see format_base::get_section_name()
1211 function get_generic_section_name($format, stdClass $section) {
1212 throw new coding_exception('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base');
1216 * Returns an array of sections for the requested course id
1218 * It is usually not recommended to display the list of sections used
1219 * in course because the course format may have it's own way to do it.
1221 * If you need to just display the name of the section please call:
1222 * get_section_name($course, $section)
1223 * {@link get_section_name()}
1224 * from 2.4 $section may also be just the field course_sections.section
1226 * If you need the list of all sections it is more efficient to get this data by calling
1227 * $modinfo = get_fast_modinfo($courseorid);
1228 * $sections = $modinfo->get_section_info_all()
1229 * {@link get_fast_modinfo()}
1230 * {@link course_modinfo::get_section_info_all()}
1232 * Information about one section (instance of section_info):
1233 * get_fast_modinfo($courseorid)->get_sections_info($section)
1234 * {@link course_modinfo::get_section_info()}
1236 * @deprecated since 2.4
1238 function get_all_sections($courseid) {
1240 throw new coding_exception('get_all_sections() is removed. See phpdocs for this function');
1244 * This function is deprecated, please use {@link course_add_cm_to_section()}
1245 * Note that course_add_cm_to_section() also updates field course_modules.section and
1246 * calls rebuild_course_cache()
1248 * @deprecated since 2.4
1250 function add_mod_to_section($mod, $beforemod = null) {
1251 throw new coding_exception('Function add_mod_to_section() is removed, please use course_add_cm_to_section()');
1255 * Returns a number of useful structures for course displays
1257 * Function get_all_mods() is deprecated in 2.4
1258 * Instead of:
1259 * <code>
1260 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
1261 * </code>
1262 * please use:
1263 * <code>
1264 * $mods = get_fast_modinfo($courseorid)->get_cms();
1265 * $modnames = get_module_types_names();
1266 * $modnamesplural = get_module_types_names(true);
1267 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
1268 * </code>
1270 * @deprecated since 2.4
1272 function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
1273 throw new coding_exception('Function get_all_mods() is removed. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details');
1277 * Returns course section - creates new if does not exist yet
1279 * This function is deprecated. To create a course section call:
1280 * course_create_sections_if_missing($courseorid, $sections);
1281 * to get the section call:
1282 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
1284 * @see course_create_sections_if_missing()
1285 * @see get_fast_modinfo()
1286 * @deprecated since 2.4
1288 function get_course_section($section, $courseid) {
1289 throw new coding_exception('Function get_course_section() is removed. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.');
1293 * @deprecated since 2.4
1294 * @see format_weeks::get_section_dates()
1296 function format_weeks_get_section_dates($section, $course) {
1297 throw new coding_exception('Function format_weeks_get_section_dates() is removed. It is not recommended to'.
1298 ' use it outside of format_weeks plugin');
1302 * Deprecated. Instead of:
1303 * list($content, $name) = get_print_section_cm_text($cm, $course);
1304 * use:
1305 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
1306 * $name = $cm->get_formatted_name();
1308 * @deprecated since 2.5
1309 * @see cm_info::get_formatted_content()
1310 * @see cm_info::get_formatted_name()
1312 function get_print_section_cm_text(cm_info $cm, $course) {
1313 throw new coding_exception('Function get_print_section_cm_text() is removed. Please use '.
1314 'cm_info::get_formatted_content() and cm_info::get_formatted_name()');
1318 * Deprecated. Please use:
1319 * $courserenderer = $PAGE->get_renderer('core', 'course');
1320 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
1321 * array('inblock' => $vertical));
1322 * echo $output;
1324 * @deprecated since 2.5
1325 * @see core_course_renderer::course_section_add_cm_control()
1327 function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
1328 throw new coding_exception('Function print_section_add_menus() is removed. Please use course renderer '.
1329 'function course_section_add_cm_control()');
1333 * Deprecated. Please use:
1334 * $courserenderer = $PAGE->get_renderer('core', 'course');
1335 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
1336 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
1338 * @deprecated since 2.5
1339 * @see course_get_cm_edit_actions()
1340 * @see core_course_renderer->course_section_cm_edit_actions()
1342 function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
1343 throw new coding_exception('Function make_editing_buttons() is removed, please see PHPdocs in '.
1344 'lib/deprecatedlib.php on how to replace it');
1348 * Deprecated. Please use:
1349 * $courserenderer = $PAGE->get_renderer('core', 'course');
1350 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
1351 * array('hidecompletion' => $hidecompletion));
1353 * @deprecated since 2.5
1354 * @see core_course_renderer::course_section_cm_list()
1356 function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
1357 throw new coding_exception('Function print_section() is removed. Please use course renderer function '.
1358 'course_section_cm_list() instead.');
1362 * @deprecated since 2.5
1364 function print_overview($courses, array $remote_courses=array()) {
1365 throw new coding_exception('Function print_overview() is removed. Use block course_overview to display this information');
1369 * @deprecated since 2.5
1371 function print_recent_activity($course) {
1372 throw new coding_exception('Function print_recent_activity() is removed. It is not recommended to'.
1373 ' use it outside of block_recent_activity');
1377 * @deprecated since 2.5
1379 function delete_course_module($id) {
1380 throw new coding_exception('Function delete_course_module() is removed. Please use course_delete_module() instead.');
1384 * @deprecated since 2.5
1386 function update_category_button($categoryid = 0) {
1387 throw new coding_exception('Function update_category_button() is removed. Pages to view '.
1388 'and edit courses are now separate and no longer depend on editing mode.');
1392 * This function is deprecated! For list of categories use
1393 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
1394 * For parents of one particular category use
1395 * coursecat::get($id)->get_parents()
1397 * @deprecated since 2.5
1399 function make_categories_list(&$list, &$parents, $requiredcapability = '',
1400 $excludeid = 0, $category = NULL, $path = "") {
1401 throw new coding_exception('Global function make_categories_list() is removed. Please use '.
1402 'coursecat::make_categories_list() and coursecat::get_parents()');
1406 * @deprecated since 2.5
1408 function category_delete_move($category, $newparentid, $showfeedback=true) {
1409 throw new coding_exception('Function category_delete_move() is removed. Please use coursecat::delete_move() instead.');
1413 * @deprecated since 2.5
1415 function category_delete_full($category, $showfeedback=true) {
1416 throw new coding_exception('Function category_delete_full() is removed. Please use coursecat::delete_full() instead.');
1420 * This function is deprecated. Please use
1421 * $coursecat = coursecat::get($category->id);
1422 * if ($coursecat->can_change_parent($newparentcat->id)) {
1423 * $coursecat->change_parent($newparentcat->id);
1426 * Alternatively you can use
1427 * $coursecat->update(array('parent' => $newparentcat->id));
1429 * @see coursecat::change_parent()
1430 * @see coursecat::update()
1431 * @deprecated since 2.5
1433 function move_category($category, $newparentcat) {
1434 throw new coding_exception('Function move_category() is removed. Please use coursecat::change_parent() instead.');
1438 * This function is deprecated. Please use
1439 * coursecat::get($category->id)->hide();
1441 * @see coursecat::hide()
1442 * @deprecated since 2.5
1444 function course_category_hide($category) {
1445 throw new coding_exception('Function course_category_hide() is removed. Please use coursecat::hide() instead.');
1449 * This function is deprecated. Please use
1450 * coursecat::get($category->id)->show();
1452 * @see coursecat::show()
1453 * @deprecated since 2.5
1455 function course_category_show($category) {
1456 throw new coding_exception('Function course_category_show() is removed. Please use coursecat::show() instead.');
1460 * This function is deprecated.
1461 * To get the category with the specified it please use:
1462 * coursecat::get($catid, IGNORE_MISSING);
1463 * or
1464 * coursecat::get($catid, MUST_EXIST);
1466 * To get the first available category please use
1467 * coursecat::get_default();
1469 * @deprecated since 2.5
1471 function get_course_category($catid=0) {
1472 throw new coding_exception('Function get_course_category() is removed. Please use coursecat::get(), see phpdocs for more details');
1476 * This function is deprecated. It is replaced with the method create() in class coursecat.
1477 * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action
1479 * @deprecated since 2.5
1481 function create_course_category($category) {
1482 throw new coding_exception('Function create_course_category() is removed. Please use coursecat::create(), see phpdocs for more details');
1486 * This function is deprecated.
1488 * To get visible children categories of the given category use:
1489 * coursecat::get($categoryid)->get_children();
1490 * This function will return the array or coursecat objects, on each of them
1491 * you can call get_children() again
1493 * @see coursecat::get()
1494 * @see coursecat::get_children()
1496 * @deprecated since 2.5
1498 function get_all_subcategories($catid) {
1499 throw new coding_exception('Function get_all_subcategories() is removed. Please use appropriate methods() of coursecat
1500 class. See phpdocs for more details');
1504 * This function is deprecated. Please use functions in class coursecat:
1505 * - coursecat::get($parentid)->has_children()
1506 * tells if the category has children (visible or not to the current user)
1508 * - coursecat::get($parentid)->get_children()
1509 * returns an array of coursecat objects, each of them represents a children category visible
1510 * to the current user (i.e. visible=1 or user has capability to view hidden categories)
1512 * - coursecat::get($parentid)->get_children_count()
1513 * returns number of children categories visible to the current user
1515 * - coursecat::count_all()
1516 * returns total count of all categories in the system (both visible and not)
1518 * - coursecat::get_default()
1519 * returns the first category (usually to be used if count_all() == 1)
1521 * @deprecated since 2.5
1523 function get_child_categories($parentid) {
1524 throw new coding_exception('Function get_child_categories() is removed. Use coursecat::get_children() or see phpdocs for
1525 more details.');
1530 * @deprecated since 2.5
1532 * This function is deprecated. Use appropriate functions from class coursecat.
1533 * Examples:
1535 * coursecat::get($categoryid)->get_children()
1536 * - returns all children of the specified category as instances of class
1537 * coursecat, which means on each of them method get_children() can be called again.
1538 * Only categories visible to the current user are returned.
1540 * coursecat::get(0)->get_children()
1541 * - returns all top-level categories visible to the current user.
1543 * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()}
1545 * coursecat::make_categories_list()
1546 * - returns an array of all categories id/names in the system.
1547 * Also only returns categories visible to current user and can additionally be
1548 * filetered by capability, see phpdocs to {@link coursecat::make_categories_list()}
1550 * make_categories_options()
1551 * - Returns full course categories tree to be used in html_writer::select()
1553 * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()},
1554 * {@link coursecat::get_default()}
1556 function get_categories($parent='none', $sort=NULL, $shallow=true) {
1557 throw new coding_exception('Function get_categories() is removed. Please use coursecat::get_children() or see phpdocs for other alternatives');
1561 * This function is deprecated, please use course renderer:
1562 * $renderer = $PAGE->get_renderer('core', 'course');
1563 * echo $renderer->course_search_form($value, $format);
1565 * @deprecated since 2.5
1567 function print_course_search($value="", $return=false, $format="plain") {
1568 throw new coding_exception('Function print_course_search() is removed, please use course renderer');
1572 * This function is deprecated, please use:
1573 * $renderer = $PAGE->get_renderer('core', 'course');
1574 * echo $renderer->frontpage_my_courses()
1576 * @deprecated since 2.5
1578 function print_my_moodle() {
1579 throw new coding_exception('Function print_my_moodle() is removed, please use course renderer function frontpage_my_courses()');
1583 * This function is deprecated, it is replaced with protected function
1584 * {@link core_course_renderer::frontpage_remote_course()}
1585 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
1587 * @deprecated since 2.5
1589 function print_remote_course($course, $width="100%") {
1590 throw new coding_exception('Function print_remote_course() is removed, please use course renderer');
1594 * This function is deprecated, it is replaced with protected function
1595 * {@link core_course_renderer::frontpage_remote_host()}
1596 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
1598 * @deprecated since 2.5
1600 function print_remote_host($host, $width="100%") {
1601 throw new coding_exception('Function print_remote_host() is removed, please use course renderer');
1605 * @deprecated since 2.5
1607 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
1609 function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) {
1610 throw new coding_exception('Function print_whole_category_list() is removed, please use course renderer');
1614 * @deprecated since 2.5
1616 function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) {
1617 throw new coding_exception('Function print_category_info() is removed, please use course renderer');
1621 * @deprecated since 2.5
1623 * This function is not used any more in moodle core and course renderer does not have render function for it.
1624 * Combo list on the front page is displayed as:
1625 * $renderer = $PAGE->get_renderer('core', 'course');
1626 * echo $renderer->frontpage_combo_list()
1628 * The new class {@link coursecat} stores the information about course category tree
1629 * To get children categories use:
1630 * coursecat::get($id)->get_children()
1631 * To get list of courses use:
1632 * coursecat::get($id)->get_courses()
1634 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
1636 function get_course_category_tree($id = 0, $depth = 0) {
1637 throw new coding_exception('Function get_course_category_tree() is removed, please use course renderer or coursecat class,
1638 see function phpdocs for more info');
1642 * @deprecated since 2.5
1644 * To print a generic list of courses use:
1645 * $renderer = $PAGE->get_renderer('core', 'course');
1646 * echo $renderer->courses_list($courses);
1648 * To print list of all courses:
1649 * $renderer = $PAGE->get_renderer('core', 'course');
1650 * echo $renderer->frontpage_available_courses();
1652 * To print list of courses inside category:
1653 * $renderer = $PAGE->get_renderer('core', 'course');
1654 * echo $renderer->course_category($category); // this will also print subcategories
1656 function print_courses($category) {
1657 throw new coding_exception('Function print_courses() is removed, please use course renderer');
1661 * @deprecated since 2.5
1663 * Please use course renderer to display a course information box.
1664 * $renderer = $PAGE->get_renderer('core', 'course');
1665 * echo $renderer->courses_list($courses); // will print list of courses
1666 * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox
1668 function print_course($course, $highlightterms = '') {
1669 throw new coding_exception('Function print_course() is removed, please use course renderer');
1673 * @deprecated since 2.5
1675 * This function is not used any more in moodle core and course renderer does not have render function for it.
1676 * Combo list on the front page is displayed as:
1677 * $renderer = $PAGE->get_renderer('core', 'course');
1678 * echo $renderer->frontpage_combo_list()
1680 * The new class {@link coursecat} stores the information about course category tree
1681 * To get children categories use:
1682 * coursecat::get($id)->get_children()
1683 * To get list of courses use:
1684 * coursecat::get($id)->get_courses()
1686 function get_category_courses_array($categoryid = 0) {
1687 throw new coding_exception('Function get_category_courses_array() is removed, please use methods of coursecat class');
1691 * @deprecated since 2.5
1693 function get_category_courses_array_recursively(array &$flattened, $category) {
1694 throw new coding_exception('Function get_category_courses_array_recursively() is removed, please use methods of coursecat class', DEBUG_DEVELOPER);
1698 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
1700 function blog_get_context_url($context=null) {
1701 throw new coding_exception('Function blog_get_context_url() is removed, getting params from context is not reliable for blogs.');
1705 * @deprecated since 2.5
1707 * To get list of all courses with course contacts ('managers') use
1708 * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true));
1710 * To get list of courses inside particular category use
1711 * coursecat::get($id)->get_courses(array('coursecontacts' => true));
1713 * Additionally you can specify sort order, offset and maximum number of courses,
1714 * see {@link coursecat::get_courses()}
1716 function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) {
1717 throw new coding_exception('Function get_courses_wmanagers() is removed, please use coursecat::get_courses()');
1721 * @deprecated since 2.5
1723 function convert_tree_to_html($tree, $row=0) {
1724 throw new coding_exception('Function convert_tree_to_html() is removed. Consider using class tabtree and core_renderer::render_tabtree()');
1728 * @deprecated since 2.5
1730 function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
1731 throw new coding_exception('Function convert_tabrows_to_tree() is removed. Consider using class tabtree');
1735 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
1737 function can_use_rotated_text() {
1738 debugging('can_use_rotated_text() is removed. JS feature detection is used automatically.');
1742 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
1743 * @see context::instance_by_id($id)
1745 function get_context_instance_by_id($id, $strictness = IGNORE_MISSING) {
1746 throw new coding_exception('get_context_instance_by_id() is now removed, please use context::instance_by_id($id) instead.');
1750 * Returns system context or null if can not be created yet.
1752 * @see context_system::instance()
1753 * @deprecated since 2.2
1754 * @param bool $cache use caching
1755 * @return context system context (null if context table not created yet)
1757 function get_system_context($cache = true) {
1758 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
1759 return context_system::instance(0, IGNORE_MISSING, $cache);
1763 * @see context::get_parent_context_ids()
1764 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
1766 function get_parent_contexts(context $context, $includeself = false) {
1767 throw new coding_exception('get_parent_contexts() is removed, please use $context->get_parent_context_ids() instead.');
1771 * @deprecated since Moodle 2.2
1772 * @see context::get_parent_context()
1774 function get_parent_contextid(context $context) {
1775 throw new coding_exception('get_parent_contextid() is removed, please use $context->get_parent_context() instead.');
1779 * @see context::get_child_contexts()
1780 * @deprecated since 2.2
1782 function get_child_contexts(context $context) {
1783 throw new coding_exception('get_child_contexts() is removed, please use $context->get_child_contexts() instead.');
1787 * @see context_helper::create_instances()
1788 * @deprecated since 2.2
1790 function create_contexts($contextlevel = null, $buildpaths = true) {
1791 throw new coding_exception('create_contexts() is removed, please use context_helper::create_instances() instead.');
1795 * @see context_helper::cleanup_instances()
1796 * @deprecated since 2.2
1798 function cleanup_contexts() {
1799 throw new coding_exception('cleanup_contexts() is removed, please use context_helper::cleanup_instances() instead.');
1803 * Populate context.path and context.depth where missing.
1805 * @deprecated since 2.2
1807 function build_context_path($force = false) {
1808 throw new coding_exception('build_context_path() is removed, please use context_helper::build_all_paths() instead.');
1812 * @deprecated since 2.2
1814 function rebuild_contexts(array $fixcontexts) {
1815 throw new coding_exception('rebuild_contexts() is removed, please use $context->reset_paths(true) instead.');
1819 * @deprecated since Moodle 2.2
1820 * @see context_helper::preload_course()
1822 function preload_course_contexts($courseid) {
1823 throw new coding_exception('preload_course_contexts() is removed, please use context_helper::preload_course() instead.');
1827 * @deprecated since Moodle 2.2
1828 * @see context::update_moved()
1830 function context_moved(context $context, context $newparent) {
1831 throw new coding_exception('context_moved() is removed, please use context::update_moved() instead.');
1835 * @see context::get_capabilities()
1836 * @deprecated since 2.2
1838 function fetch_context_capabilities(context $context) {
1839 throw new coding_exception('fetch_context_capabilities() is removed, please use $context->get_capabilities() instead.');
1843 * @deprecated since 2.2
1844 * @see context_helper::preload_from_record()
1846 function context_instance_preload(stdClass $rec) {
1847 throw new coding_exception('context_instance_preload() is removed, please use context_helper::preload_from_record() instead.');
1851 * Returns context level name
1853 * @deprecated since 2.2
1854 * @see context_helper::get_level_name()
1856 function get_contextlevel_name($contextlevel) {
1857 throw new coding_exception('get_contextlevel_name() is removed, please use context_helper::get_level_name() instead.');
1861 * @deprecated since 2.2
1862 * @see context::get_context_name()
1864 function print_context_name(context $context, $withprefix = true, $short = false) {
1865 throw new coding_exception('print_context_name() is removed, please use $context->get_context_name() instead.');
1869 * @deprecated since 2.2, use $context->mark_dirty() instead
1870 * @see context::mark_dirty()
1872 function mark_context_dirty($path) {
1873 throw new coding_exception('mark_context_dirty() is removed, please use $context->mark_dirty() instead.');
1877 * @deprecated since Moodle 2.2
1878 * @see context_helper::delete_instance() or context::delete_content()
1880 function delete_context($contextlevel, $instanceid, $deleterecord = true) {
1881 if ($deleterecord) {
1882 throw new coding_exception('delete_context() is removed, please use context_helper::delete_instance() instead.');
1883 } else {
1884 throw new coding_exception('delete_context() is removed, please use $context->delete_content() instead.');
1889 * @deprecated since 2.2
1890 * @see context::get_url()
1892 function get_context_url(context $context) {
1893 throw new coding_exception('get_context_url() is removed, please use $context->get_url() instead.');
1897 * @deprecated since 2.2
1898 * @see context::get_course_context()
1900 function get_course_context(context $context) {
1901 throw new coding_exception('get_course_context() is removed, please use $context->get_course_context(true) instead.');
1905 * @deprecated since 2.2
1906 * @see enrol_get_users_courses()
1908 function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) {
1910 throw new coding_exception('get_user_courses_bycap() is removed, please use enrol_get_users_courses() instead.');
1914 * @deprecated since Moodle 2.2
1916 function get_role_context_caps($roleid, context $context) {
1917 throw new coding_exception('get_role_context_caps() is removed, it is really slow. Don\'t use it.');
1921 * @see context::get_course_context()
1922 * @deprecated since 2.2
1924 function get_courseid_from_context(context $context) {
1925 throw new coding_exception('get_courseid_from_context() is removed, please use $context->get_course_context(false) instead.');
1929 * If you are using this methid, you should have something like this:
1931 * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
1933 * To prevent the use of this deprecated function, replace the line above with something similar to this:
1935 * $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
1937 * $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
1938 * ^ ^ ^ ^
1939 * $params = array('contextlevel' => CONTEXT_COURSE);
1941 * @see context_helper:;get_preload_record_columns_sql()
1942 * @deprecated since 2.2
1944 function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
1945 throw new coding_exception('context_instance_preload_sql() is removed, please use context_helper::get_preload_record_columns_sql() instead.');
1949 * @deprecated since 2.2
1950 * @see context::get_parent_context_ids()
1952 function get_related_contexts_string(context $context) {
1953 throw new coding_exception('get_related_contexts_string() is removed, please use $context->get_parent_context_ids(true) instead.');
1957 * @deprecated since 2.6
1958 * @see core_component::get_plugin_list_with_file()
1960 function get_plugin_list_with_file($plugintype, $file, $include = false) {
1961 throw new coding_exception('get_plugin_list_with_file() is removed, please use core_component::get_plugin_list_with_file() instead.');
1965 * @deprecated since 2.6
1967 function check_browser_operating_system($brand) {
1968 throw new coding_exception('check_browser_operating_system is removed, please update your code to use core_useragent instead.');
1972 * @deprecated since 2.6
1974 function check_browser_version($brand, $version = null) {
1975 throw new coding_exception('check_browser_version is removed, please update your code to use core_useragent instead.');
1979 * @deprecated since 2.6
1981 function get_device_type() {
1982 throw new coding_exception('get_device_type is removed, please update your code to use core_useragent instead.');
1986 * @deprecated since 2.6
1988 function get_device_type_list($incusertypes = true) {
1989 throw new coding_exception('get_device_type_list is removed, please update your code to use core_useragent instead.');
1993 * @deprecated since 2.6
1995 function get_selected_theme_for_device_type($devicetype = null) {
1996 throw new coding_exception('get_selected_theme_for_device_type is removed, please update your code to use core_useragent instead.');
2000 * @deprecated since 2.6
2002 function get_device_cfg_var_name($devicetype = null) {
2003 throw new coding_exception('get_device_cfg_var_name is removed, please update your code to use core_useragent instead.');
2007 * @deprecated since 2.6
2009 function set_user_device_type($newdevice) {
2010 throw new coding_exception('set_user_device_type is removed, please update your code to use core_useragent instead.');
2014 * @deprecated since 2.6
2016 function get_user_device_type() {
2017 throw new coding_exception('get_user_device_type is removed, please update your code to use core_useragent instead.');
2021 * @deprecated since 2.6
2023 function get_browser_version_classes() {
2024 throw new coding_exception('get_browser_version_classes is removed, please update your code to use core_useragent instead.');
2028 * @deprecated since Moodle 2.6
2029 * @see core_user::get_support_user()
2031 function generate_email_supportuser() {
2032 throw new coding_exception('generate_email_supportuser is removed, please use core_user::get_support_user');
2036 * @deprecated since Moodle 2.6
2038 function badges_get_issued_badge_info($hash) {
2039 throw new coding_exception('Function badges_get_issued_badge_info() is removed. Please use core_badges_assertion class and methods to generate badge assertion.');
2043 * @deprecated since 2.6
2045 function can_use_html_editor() {
2046 throw new coding_exception('can_use_html_editor is removed, please update your code to assume it returns true.');
2051 * @deprecated since Moodle 2.7, use {@link user_count_login_failures()} instead.
2053 function count_login_failures($mode, $username, $lastlogin) {
2054 throw new coding_exception('count_login_failures() can not be used any more, please use user_count_login_failures().');
2058 * @deprecated since 2.7 MDL-33099/MDL-44088 - please do not use this function any more.
2060 function ajaxenabled(array $browsers = null) {
2061 throw new coding_exception('ajaxenabled() can not be used anymore. Update your code to work with JS at all times.');
2065 * @deprecated Since Moodle 2.7 MDL-44070
2067 function coursemodule_visible_for_user($cm, $userid=0) {
2068 throw new coding_exception('coursemodule_visible_for_user() can not be used any more,
2069 please use \core_availability\info_module::is_user_visible()');
2073 * @deprecated since Moodle 2.8 MDL-36014, MDL-35618 this functionality is removed
2075 function enrol_cohort_get_cohorts(course_enrolment_manager $manager) {
2076 throw new coding_exception('Function enrol_cohort_get_cohorts() is removed, use enrol_cohort_search_cohorts() or '.
2077 'cohort_get_available_cohorts() instead');
2081 * This function is deprecated, use {@link cohort_can_view_cohort()} instead since it also
2082 * takes into account current context
2084 * @deprecated since Moodle 2.8 MDL-36014 please use cohort_can_view_cohort()
2086 function enrol_cohort_can_view_cohort($cohortid) {
2087 throw new coding_exception('Function enrol_cohort_can_view_cohort() is removed, use cohort_can_view_cohort() instead');
2091 * It is advisable to use {@link cohort_get_available_cohorts()} instead.
2093 * @deprecated since Moodle 2.8 MDL-36014 use cohort_get_available_cohorts() instead
2095 function cohort_get_visible_list($course, $onlyenrolled=true) {
2096 throw new coding_exception('Function cohort_get_visible_list() is removed. Please use function cohort_get_available_cohorts() ".
2097 "that correctly checks capabilities.');
2101 * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
2103 function enrol_cohort_enrol_all_users(course_enrolment_manager $manager, $cohortid, $roleid) {
2104 throw new coding_exception('enrol_cohort_enrol_all_users() is removed. This functionality is moved to enrol_manual.');
2108 * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
2110 function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset = 0, $limit = 25, $search = '') {
2111 throw new coding_exception('enrol_cohort_search_cohorts() is removed. This functionality is moved to enrol_manual.');
2114 /* === Apis deprecated in since Moodle 2.9 === */
2117 * Is $USER one of the supplied users?
2119 * $user2 will be null if viewing a user's recent conversations
2121 * @deprecated since Moodle 2.9 MDL-49371 - please do not use this function any more.
2123 function message_current_user_is_involved($user1, $user2) {
2124 throw new coding_exception('message_current_user_is_involved() can not be used any more.');
2128 * Print badges on user profile page.
2130 * @deprecated since Moodle 2.9 MDL-45898 - please do not use this function any more.
2131 * @param int $userid User ID.
2132 * @param int $courseid Course if we need to filter badges (optional).
2134 function profile_display_badges($userid, $courseid = 0) {
2135 global $CFG, $PAGE, $USER, $SITE;
2136 require_once($CFG->dirroot . '/badges/renderer.php');
2138 debugging('profile_display_badges() is deprecated.', DEBUG_DEVELOPER);
2140 // Determine context.
2141 if (isloggedin()) {
2142 $context = context_user::instance($USER->id);
2143 } else {
2144 $context = context_system::instance();
2147 if ($USER->id == $userid || has_capability('moodle/badges:viewotherbadges', $context)) {
2148 $records = badges_get_user_badges($userid, $courseid, null, null, null, true);
2149 $renderer = new core_badges_renderer($PAGE, '');
2151 // Print local badges.
2152 if ($records) {
2153 $left = get_string('localbadgesp', 'badges', format_string($SITE->fullname));
2154 $right = $renderer->print_badges_list($records, $userid, true);
2155 echo html_writer::tag('dt', $left);
2156 echo html_writer::tag('dd', $right);
2159 // Print external badges.
2160 if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack)) {
2161 $backpack = get_backpack_settings($userid);
2162 if (isset($backpack->totalbadges) && $backpack->totalbadges !== 0) {
2163 $left = get_string('externalbadgesp', 'badges');
2164 $right = $renderer->print_badges_list($backpack->badges, $userid, true, true);
2165 echo html_writer::tag('dt', $left);
2166 echo html_writer::tag('dd', $right);
2173 * Adds user preferences elements to user edit form.
2175 * @deprecated since Moodle 2.9 MDL-45774 - Please do not use this function any more.
2177 function useredit_shared_definition_preferences($user, &$mform, $editoroptions = null, $filemanageroptions = null) {
2178 throw new coding_exception('useredit_shared_definition_preferences() can not be used any more.');
2183 * Convert region timezone to php supported timezone
2185 * @deprecated since Moodle 2.9
2187 function calendar_normalize_tz($tz) {
2188 throw new coding_exception('calendar_normalize_tz() can not be used any more, please use core_date::normalise_timezone() instead.');
2192 * Returns a float which represents the user's timezone difference from GMT in hours
2193 * Checks various settings and picks the most dominant of those which have a value
2194 * @deprecated since Moodle 2.9
2195 * @param float|int|string $tz timezone user timezone
2196 * @return float
2198 function get_user_timezone_offset($tz = 99) {
2199 debugging('get_user_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER);
2200 $tz = core_date::get_user_timezone($tz);
2201 $date = new DateTime('now', new DateTimeZone($tz));
2202 return ($date->getOffset() - dst_offset_on(time(), $tz)) / (3600.0);
2206 * Returns an int which represents the systems's timezone difference from GMT in seconds
2207 * @deprecated since Moodle 2.9
2208 * @param float|int|string $tz timezone for which offset is required.
2209 * {@link http://docs.moodle.org/dev/Time_API#Timezone}
2210 * @return int|bool if found, false is timezone 99 or error
2212 function get_timezone_offset($tz) {
2213 debugging('get_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER);
2214 $date = new DateTime('now', new DateTimeZone(core_date::normalise_timezone($tz)));
2215 return $date->getOffset() - dst_offset_on(time(), $tz);
2219 * Returns a list of timezones in the current language.
2220 * @deprecated since Moodle 2.9
2221 * @return array
2223 function get_list_of_timezones() {
2224 debugging('get_list_of_timezones() is deprecated, use core_date::get_list_of_timezones() instead', DEBUG_DEVELOPER);
2225 return core_date::get_list_of_timezones();
2229 * Previous internal API, it was not supposed to be used anywhere.
2230 * @deprecated since Moodle 2.9
2231 * @param array $timezones
2233 function update_timezone_records($timezones) {
2234 debugging('update_timezone_records() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER);
2238 * Previous internal API, it was not supposed to be used anywhere.
2239 * @deprecated since Moodle 2.9
2240 * @param int $fromyear
2241 * @param int $toyear
2242 * @param mixed $strtimezone
2243 * @return bool
2245 function calculate_user_dst_table($fromyear = null, $toyear = null, $strtimezone = null) {
2246 debugging('calculate_user_dst_table() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER);
2247 return false;
2251 * Previous internal API, it was not supposed to be used anywhere.
2252 * @deprecated since Moodle 2.9
2253 * @param int|string $year
2254 * @param mixed $timezone
2255 * @return null
2257 function dst_changes_for_year($year, $timezone) {
2258 debugging('dst_changes_for_year() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER);
2259 return null;
2263 * Previous internal API, it was not supposed to be used anywhere.
2264 * @deprecated since Moodle 2.9
2265 * @param string $timezonename
2266 * @return array
2268 function get_timezone_record($timezonename) {
2269 debugging('get_timezone_record() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER);
2270 return array();
2273 /* === Apis deprecated since Moodle 3.0 === */
2275 * Returns the URL of the HTTP_REFERER, less the querystring portion if required.
2277 * @deprecated since Moodle 3.0 MDL-49360 - please do not use this function any more.
2278 * @todo Remove this function in Moodle 3.2
2279 * @param boolean $stripquery if true, also removes the query part of the url.
2280 * @return string The resulting referer or empty string.
2282 function get_referer($stripquery = true) {
2283 debugging('get_referer() is deprecated. Please use get_local_referer() instead.', DEBUG_DEVELOPER);
2284 if (isset($_SERVER['HTTP_REFERER'])) {
2285 if ($stripquery) {
2286 return strip_querystring($_SERVER['HTTP_REFERER']);
2287 } else {
2288 return $_SERVER['HTTP_REFERER'];
2290 } else {
2291 return '';
2296 * Checks if current user is a web crawler.
2298 * This list can not be made complete, this is not a security
2299 * restriction, we make the list only to help these sites
2300 * especially when automatic guest login is disabled.
2302 * If admin needs security they should enable forcelogin
2303 * and disable guest access!!
2305 * @return bool
2306 * @deprecated since Moodle 3.0 use \core_useragent::is_web_crawler instead.
2308 function is_web_crawler() {
2309 debugging('is_web_crawler() has been deprecated, please use core_useragent::is_web_crawler() instead.', DEBUG_DEVELOPER);
2310 return core_useragent::is_web_crawler();
2314 * Update user's course completion statuses
2316 * First update all criteria completions, then aggregate all criteria completions
2317 * and update overall course completions.
2319 * @deprecated since Moodle 3.0 MDL-50287 - please do not use this function any more.
2320 * @todo Remove this function in Moodle 3.2 MDL-51226.
2322 function completion_cron() {
2323 global $CFG;
2324 require_once($CFG->dirroot.'/completion/cron.php');
2326 debugging('completion_cron() is deprecated. Functionality has been moved to scheduled tasks.', DEBUG_DEVELOPER);
2327 completion_cron_mark_started();
2329 completion_cron_criteria();
2331 completion_cron_completions();
2335 * Returns an ordered array of tags associated with visible courses
2336 * (boosted replacement of get_all_tags() allowing association with user and tagtype).
2338 * @deprecated since 3.0
2339 * @package core_tag
2340 * @category tag
2341 * @param int $courseid A course id. Passing 0 will return all distinct tags for all visible courses
2342 * @param int $userid (optional) the user id, a default of 0 will return all users tags for the course
2343 * @param string $tagtype (optional) The type of tag, empty string returns all types. Currently (Moodle 2.2) there are two
2344 * types of tags which are used within Moodle, they are 'official' and 'default'.
2345 * @param int $numtags (optional) number of tags to display, default of 80 is set in the block, 0 returns all
2346 * @param string $unused (optional) was selected sorting, moved to tag_print_cloud()
2347 * @return array
2349 function coursetag_get_tags($courseid, $userid=0, $tagtype='', $numtags=0, $unused = '') {
2350 debugging('Function coursetag_get_tags() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
2352 global $CFG, $DB;
2354 // get visible course ids
2355 $courselist = array();
2356 if ($courseid === 0) {
2357 if ($courses = $DB->get_records_select('course', 'visible=1 AND category>0', null, '', 'id')) {
2358 foreach ($courses as $key => $value) {
2359 $courselist[] = $key;
2364 // get tags from the db ordered by highest count first
2365 $params = array();
2366 $sql = "SELECT id as tkey, name, id, isstandard, rawname, f.timemodified, flag, count
2367 FROM {tag} t,
2368 (SELECT tagid, MAX(timemodified) as timemodified, COUNT(id) as count
2369 FROM {tag_instance}
2370 WHERE itemtype = 'course' ";
2372 if ($courseid > 0) {
2373 $sql .= " AND itemid = :courseid ";
2374 $params['courseid'] = $courseid;
2375 } else {
2376 if (!empty($courselist)) {
2377 list($usql, $uparams) = $DB->get_in_or_equal($courselist, SQL_PARAMS_NAMED);
2378 $sql .= "AND itemid $usql ";
2379 $params = $params + $uparams;
2383 if ($userid > 0) {
2384 $sql .= " AND tiuserid = :userid ";
2385 $params['userid'] = $userid;
2388 $sql .= " GROUP BY tagid) f
2389 WHERE t.id = f.tagid ";
2390 if ($tagtype != '') {
2391 $sql .= "AND isstandard = :isstandard ";
2392 $params['isstandard'] = ($tagtype === 'official') ? 1 : 0;
2394 $sql .= "ORDER BY count DESC, name ASC";
2396 // limit the number of tags for output
2397 if ($numtags == 0) {
2398 $tags = $DB->get_records_sql($sql, $params);
2399 } else {
2400 $tags = $DB->get_records_sql($sql, $params, 0, $numtags);
2403 // prepare the return
2404 $return = array();
2405 if ($tags) {
2406 // avoid print_tag_cloud()'s ksort upsetting ordering by setting the key here
2407 foreach ($tags as $value) {
2408 $return[] = $value;
2412 return $return;
2417 * Returns an ordered array of tags
2418 * (replaces popular_tags_count() allowing sorting).
2420 * @deprecated since 3.0
2421 * @package core_tag
2422 * @category tag
2423 * @param string $unused (optional) was selected sorting - moved to tag_print_cloud()
2424 * @param int $numtags (optional) number of tags to display, default of 20 is set in the block, 0 returns all
2425 * @return array
2427 function coursetag_get_all_tags($unused='', $numtags=0) {
2428 debugging('Function coursetag_get_all_tag() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
2430 global $CFG, $DB;
2432 // note that this selects all tags except for courses that are not visible
2433 $sql = "SELECT id, name, isstandard, rawname, f.timemodified, flag, count
2434 FROM {tag} t,
2435 (SELECT tagid, MAX(timemodified) as timemodified, COUNT(id) as count
2436 FROM {tag_instance} WHERE tagid NOT IN
2437 (SELECT tagid FROM {tag_instance} ti, {course} c
2438 WHERE c.visible = 0
2439 AND ti.itemtype = 'course'
2440 AND ti.itemid = c.id)
2441 GROUP BY tagid) f
2442 WHERE t.id = f.tagid
2443 ORDER BY count DESC, name ASC";
2444 if ($numtags == 0) {
2445 $tags = $DB->get_records_sql($sql);
2446 } else {
2447 $tags = $DB->get_records_sql($sql, null, 0, $numtags);
2450 $return = array();
2451 if ($tags) {
2452 foreach ($tags as $value) {
2453 $return[] = $value;
2457 return $return;
2461 * Returns javascript for use in tags block and supporting pages
2463 * @deprecated since 3.0
2464 * @package core_tag
2465 * @category tag
2466 * @return null
2468 function coursetag_get_jscript() {
2469 debugging('Function coursetag_get_jscript() is deprecated and obsolete.', DEBUG_DEVELOPER);
2470 return '';
2474 * Returns javascript to create the links in the tag block footer.
2476 * @deprecated since 3.0
2477 * @package core_tag
2478 * @category tag
2479 * @param string $elementid the element to attach the footer to
2480 * @param array $coursetagslinks links arrays each consisting of 'title', 'onclick' and 'text' elements
2481 * @return string always returns a blank string
2483 function coursetag_get_jscript_links($elementid, $coursetagslinks) {
2484 debugging('Function coursetag_get_jscript_links() is deprecated and obsolete.', DEBUG_DEVELOPER);
2485 return '';
2489 * Returns all tags created by a user for a course
2491 * @deprecated since 3.0
2492 * @package core_tag
2493 * @category tag
2494 * @param int $courseid tags are returned for the course that has this courseid
2495 * @param int $userid return tags which were created by this user
2497 function coursetag_get_records($courseid, $userid) {
2498 debugging('Function coursetag_get_records() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
2500 global $CFG, $DB;
2502 $sql = "SELECT t.id, name, rawname
2503 FROM {tag} t, {tag_instance} ti
2504 WHERE t.id = ti.tagid
2505 AND ti.tiuserid = :userid
2506 AND ti.itemid = :courseid
2507 ORDER BY name ASC";
2509 return $DB->get_records_sql($sql, array('userid'=>$userid, 'courseid'=>$courseid));
2513 * Stores a tag for a course for a user
2515 * @deprecated since 3.0
2516 * @package core_tag
2517 * @category tag
2518 * @param array $tags simple array of keywords to be stored
2519 * @param int $courseid the id of the course we wish to store a tag for
2520 * @param int $userid the id of the user we wish to store a tag for
2521 * @param string $tagtype official or default only
2522 * @param string $myurl (optional) for logging creation of course tags
2524 function coursetag_store_keywords($tags, $courseid, $userid=0, $tagtype='official', $myurl='') {
2525 debugging('Function coursetag_store_keywords() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
2527 global $CFG;
2529 if (is_array($tags) and !empty($tags)) {
2530 if ($tagtype === 'official') {
2531 $tagcoll = core_tag_area::get_collection('core', 'course');
2532 // 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.
2533 core_tag_tag::create_if_missing($tagcoll, $tags, true);
2535 foreach ($tags as $tag) {
2536 $tag = trim($tag);
2537 if (strlen($tag) > 0) {
2538 core_tag_tag::add_item_tag('core', 'course', $courseid, context_course::instance($courseid), $tag, $userid);
2546 * Deletes a personal tag for a user for a course.
2548 * @deprecated since 3.0
2549 * @package core_tag
2550 * @category tag
2551 * @param int $tagid the tag we wish to delete
2552 * @param int $userid the user that the tag is associated with
2553 * @param int $courseid the course that the tag is associated with
2555 function coursetag_delete_keyword($tagid, $userid, $courseid) {
2556 debugging('Function coursetag_delete_keyword() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
2558 $tag = core_tag_tag::get($tagid);
2559 core_tag_tag::remove_item_tag('core', 'course', $courseid, $tag->rawname, $userid);
2563 * Get courses tagged with a tag
2565 * @deprecated since 3.0
2566 * @package core_tag
2567 * @category tag
2568 * @param int $tagid
2569 * @return array of course objects
2571 function coursetag_get_tagged_courses($tagid) {
2572 debugging('Function coursetag_get_tagged_courses() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
2574 global $DB;
2576 $courses = array();
2578 $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
2580 $sql = "SELECT c.*, $ctxselect
2581 FROM {course} c
2582 JOIN {tag_instance} t ON t.itemid = c.id
2583 JOIN {context} ctx ON ctx.instanceid = c.id
2584 WHERE t.tagid = :tagid AND
2585 t.itemtype = 'course' AND
2586 ctx.contextlevel = :contextlevel
2587 ORDER BY c.sortorder ASC";
2588 $params = array('tagid' => $tagid, 'contextlevel' => CONTEXT_COURSE);
2589 $rs = $DB->get_recordset_sql($sql, $params);
2590 foreach ($rs as $course) {
2591 context_helper::preload_from_record($course);
2592 if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
2593 $courses[$course->id] = $course;
2596 return $courses;
2600 * Course tagging function used only during the deletion of a course (called by lib/moodlelib.php) to clean up associated tags
2602 * @package core_tag
2603 * @deprecated since 3.0
2604 * @param int $courseid the course we wish to delete tag instances from
2605 * @param bool $showfeedback if we should output a notification of the delete to the end user
2607 function coursetag_delete_course_tags($courseid, $showfeedback=false) {
2608 debugging('Function coursetag_delete_course_tags() is deprecated. Use core_tag_tag::remove_all_item_tags().', DEBUG_DEVELOPER);
2610 global $OUTPUT;
2611 core_tag_tag::remove_all_item_tags('core', 'course', $courseid);
2613 if ($showfeedback) {
2614 echo $OUTPUT->notification(get_string('deletedcoursetags', 'tag'), 'notifysuccess');
2619 * Set the type of a tag. At this time (version 2.2) the possible values are 'default' or 'official'. Official tags will be
2620 * displayed separately "at tagging time" (while selecting the tags to apply to a record).
2622 * @package core_tag
2623 * @deprecated since 3.1
2624 * @param string $tagid tagid to modify
2625 * @param string $type either 'default' or 'official'
2626 * @return bool true on success, false otherwise
2628 function tag_type_set($tagid, $type) {
2629 debugging('Function tag_type_set() is deprecated and can be replaced with use core_tag_tag::get($tagid)->update().', DEBUG_DEVELOPER);
2630 if ($tag = core_tag_tag::get($tagid, '*')) {
2631 return $tag->update(array('isstandard' => ($type === 'official') ? 1 : 0));
2633 return false;
2637 * Set the description of a tag
2639 * @package core_tag
2640 * @deprecated since 3.1
2641 * @param int $tagid the id of the tag
2642 * @param string $description the tag's description string to be set
2643 * @param int $descriptionformat the moodle text format of the description
2644 * {@link http://docs.moodle.org/dev/Text_formats_2.0#Database_structure}
2645 * @return bool true on success, false otherwise
2647 function tag_description_set($tagid, $description, $descriptionformat) {
2648 debugging('Function tag_type_set() is deprecated and can be replaced with core_tag_tag::get($tagid)->update().', DEBUG_DEVELOPER);
2649 if ($tag = core_tag_tag::get($tagid, '*')) {
2650 return $tag->update(array('description' => $description, 'descriptionformat' => $descriptionformat));
2652 return false;
2656 * Get the array of db record of tags associated to a record (instances).
2658 * @package core_tag
2659 * @deprecated since 3.1
2660 * @param string $record_type the record type for which we want to get the tags
2661 * @param int $record_id the record id for which we want to get the tags
2662 * @param string $type the tag type (either 'default' or 'official'). By default, all tags are returned.
2663 * @param int $userid (optional) only required for course tagging
2664 * @return array the array of tags
2666 function tag_get_tags($record_type, $record_id, $type=null, $userid=0) {
2667 debugging('Method tag_get_tags() is deprecated and replaced with core_tag_tag::get_item_tags(). ' .
2668 'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER);
2669 $standardonly = ($type === 'official' ? core_tag_tag::STANDARD_ONLY :
2670 (!empty($type) ? core_tag_tag::NOT_STANDARD_ONLY : core_tag_tag::BOTH_STANDARD_AND_NOT));
2671 $tags = core_tag_tag::get_item_tags(null, $record_type, $record_id, $standardonly, $userid);
2672 $rv = array();
2673 foreach ($tags as $id => $t) {
2674 $rv[$id] = $t->to_object();
2676 return $rv;
2680 * Get the array of tags display names, indexed by id.
2682 * @package core_tag
2683 * @deprecated since 3.1
2684 * @param string $record_type the record type for which we want to get the tags
2685 * @param int $record_id the record id for which we want to get the tags
2686 * @param string $type the tag type (either 'default' or 'official'). By default, all tags are returned.
2687 * @return array the array of tags (with the value returned by core_tag_tag::make_display_name), indexed by id
2689 function tag_get_tags_array($record_type, $record_id, $type=null) {
2690 debugging('Method tag_get_tags_array() is deprecated and replaced with core_tag_tag::get_item_tags_array(). ' .
2691 'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER);
2692 $standardonly = ($type === 'official' ? core_tag_tag::STANDARD_ONLY :
2693 (!empty($type) ? core_tag_tag::NOT_STANDARD_ONLY : core_tag_tag::BOTH_STANDARD_AND_NOT));
2694 return core_tag_tag::get_item_tags_array('', $record_type, $record_id, $standardonly);
2698 * Get a comma-separated string of tags associated to a record.
2700 * Use {@link tag_get_tags()} to get the same information in an array.
2702 * @package core_tag
2703 * @deprecated since 3.1
2704 * @param string $record_type the record type for which we want to get the tags
2705 * @param int $record_id the record id for which we want to get the tags
2706 * @param int $html either TAG_RETURN_HTML or TAG_RETURN_TEXT, depending on the type of output desired
2707 * @param string $type either 'official' or 'default', if null, all tags are returned
2708 * @return string the comma-separated list of tags.
2710 function tag_get_tags_csv($record_type, $record_id, $html=null, $type=null) {
2711 global $CFG, $OUTPUT;
2712 debugging('Method tag_get_tags_csv() is deprecated. Instead you should use either ' .
2713 'core_tag_tag::get_item_tags_array() or $OUTPUT->tag_list(core_tag_tag::get_item_tags()). ' .
2714 'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER);
2715 $standardonly = ($type === 'official' ? core_tag_tag::STANDARD_ONLY :
2716 (!empty($type) ? core_tag_tag::NOT_STANDARD_ONLY : core_tag_tag::BOTH_STANDARD_AND_NOT));
2717 if ($html != TAG_RETURN_TEXT) {
2718 return $OUTPUT->tag_list(core_tag_tag::get_item_tags('', $record_type, $record_id, $standardonly), '');
2719 } else {
2720 return join(', ', core_tag_tag::get_item_tags_array('', $record_type, $record_id, $standardonly, 0, false));
2725 * Get an array of tag ids associated to a record.
2727 * @package core_tag
2728 * @deprecated since 3.1
2729 * @param string $record_type the record type for which we want to get the tags
2730 * @param int $record_id the record id for which we want to get the tags
2731 * @return array tag ids, indexed and sorted by 'ordering'
2733 function tag_get_tags_ids($record_type, $record_id) {
2734 debugging('Method tag_get_tags_ids() is deprecated. Please consider using core_tag_tag::get_item_tags() or similar methods.', DEBUG_DEVELOPER);
2735 $tag_ids = array();
2736 $tagobjects = core_tag_tag::get_item_tags(null, $record_type, $record_id);
2737 foreach ($tagobjects as $tagobject) {
2738 $tag = $tagobject->to_object();
2739 if ( array_key_exists($tag->ordering, $tag_ids) ) {
2740 $tag->ordering++;
2742 $tag_ids[$tag->ordering] = $tag->id;
2744 ksort($tag_ids);
2745 return $tag_ids;
2749 * Returns the database ID of a set of tags.
2751 * @deprecated since 3.1
2752 * @param mixed $tags one tag, or array of tags, to look for.
2753 * @param bool $return_value specify the type of the returned value. Either TAG_RETURN_OBJECT, or TAG_RETURN_ARRAY (default).
2754 * If TAG_RETURN_ARRAY is specified, an array will be returned even if only one tag was passed in $tags.
2755 * @return mixed tag-indexed array of ids (or objects, if second parameter is TAG_RETURN_OBJECT), or only an int, if only one tag
2756 * is given *and* the second parameter is null. No value for a key means the tag wasn't found.
2758 function tag_get_id($tags, $return_value = null) {
2759 global $CFG, $DB;
2760 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(). ' .
2761 'You need to specify tag collection when retrieving tag by name', DEBUG_DEVELOPER);
2763 if (!is_array($tags)) {
2764 if(is_null($return_value) || $return_value == TAG_RETURN_OBJECT) {
2765 if ($tagobject = core_tag_tag::get_by_name(core_tag_collection::get_default(), $tags)) {
2766 return $tagobject->id;
2767 } else {
2768 return 0;
2771 $tags = array($tags);
2774 $records = core_tag_tag::get_by_name_bulk(core_tag_collection::get_default(), $tags,
2775 $return_value == TAG_RETURN_OBJECT ? '*' : 'id, name');
2776 foreach ($records as $name => $record) {
2777 if ($return_value != TAG_RETURN_OBJECT) {
2778 $records[$name] = $record->id ? $record->id : null;
2779 } else {
2780 $records[$name] = $record->to_object();
2783 return $records;
2787 * Change the "value" of a tag, and update the associated 'name'.
2789 * @package core_tag
2790 * @deprecated since 3.1
2791 * @param int $tagid the id of the tag to modify
2792 * @param string $newrawname the new rawname
2793 * @return bool true on success, false otherwise
2795 function tag_rename($tagid, $newrawname) {
2796 debugging('Function tag_rename() is deprecated and may be replaced with core_tag_tag::get($tagid)->update().', DEBUG_DEVELOPER);
2797 if ($tag = core_tag_tag::get($tagid, '*')) {
2798 return $tag->update(array('rawname' => $newrawname));
2800 return false;
2804 * Delete one instance of a tag. If the last instance was deleted, it will also delete the tag, unless its type is 'official'.
2806 * @package core_tag
2807 * @deprecated since 3.1
2808 * @param string $record_type the type of the record for which to remove the instance
2809 * @param int $record_id the id of the record for which to remove the instance
2810 * @param int $tagid the tagid that needs to be removed
2811 * @param int $userid (optional) the userid
2812 * @return bool true on success, false otherwise
2814 function tag_delete_instance($record_type, $record_id, $tagid, $userid = null) {
2815 debugging('Function tag_delete_instance() is deprecated and replaced with core_tag_tag::remove_item_tag() instead. ' .
2816 'Component is required for retrieving instances', DEBUG_DEVELOPER);
2817 $tag = core_tag_tag::get($tagid);
2818 core_tag_tag::remove_item_tag('', $record_type, $record_id, $tag->rawname, $userid);
2822 * Find all records tagged with a tag of a given type ('post', 'user', etc.)
2824 * @package core_tag
2825 * @category tag
2826 * @param string $tag tag to look for
2827 * @param string $type type to restrict search to. If null, every matching record will be returned
2828 * @param int $limitfrom (optional, required if $limitnum is set) return a subset of records, starting at this point.
2829 * @param int $limitnum (optional, required if $limitfrom is set) return a subset comprising this many records.
2830 * @return array of matching objects, indexed by record id, from the table containing the type requested
2832 function tag_find_records($tag, $type, $limitfrom='', $limitnum='') {
2833 debugging('Function tag_find_records() is deprecated and replaced with core_tag_tag::get_by_name()->get_tagged_items(). '.
2834 'You need to specify tag collection when retrieving tag by name', DEBUG_DEVELOPER);
2836 if (!$tag || !$type) {
2837 return array();
2840 $tagobject = core_tag_tag::get_by_name(core_tag_area::get_collection('', $type), $tag);
2841 return $tagobject->get_tagged_items('', $type, $limitfrom, $limitnum);
2845 * Adds one or more tag in the database. This function should not be called directly : you should
2846 * use tag_set.
2848 * @package core_tag
2849 * @deprecated since 3.1
2850 * @param mixed $tags one tag, or an array of tags, to be created
2851 * @param string $type type of tag to be created ("default" is the default value and "official" is the only other supported
2852 * value at this time). An official tag is kept even if there are no records tagged with it.
2853 * @return array $tags ids indexed by their lowercase normalized names. Any boolean false in the array indicates an error while
2854 * adding the tag.
2856 function tag_add($tags, $type="default") {
2857 debugging('Function tag_add() is deprecated. You can use core_tag_tag::create_if_missing(), however it should not be necessary ' .
2858 'since tags are created automatically when assigned to items', DEBUG_DEVELOPER);
2859 if (!is_array($tags)) {
2860 $tags = array($tags);
2862 $objects = core_tag_tag::create_if_missing(core_tag_collection::get_default(), $tags,
2863 $type === 'official');
2865 // New function returns the tags in different format, for BC we keep the format that this function used to have.
2866 $rv = array();
2867 foreach ($objects as $name => $tagobject) {
2868 if (isset($tagobject->id)) {
2869 $rv[$tagobject->name] = $tagobject->id;
2870 } else {
2871 $rv[$name] = false;
2874 return $rv;
2878 * Assigns a tag to a record; if the record already exists, the time and ordering will be updated.
2880 * @package core_tag
2881 * @deprecated since 3.1
2882 * @param string $record_type the type of the record that will be tagged
2883 * @param int $record_id the id of the record that will be tagged
2884 * @param string $tagid the tag id to set on the record.
2885 * @param int $ordering the order of the instance for this record
2886 * @param int $userid (optional) only required for course tagging
2887 * @param string|null $component the component that was tagged
2888 * @param int|null $contextid the context id of where this tag was assigned
2889 * @return bool true on success, false otherwise
2891 function tag_assign($record_type, $record_id, $tagid, $ordering, $userid = 0, $component = null, $contextid = null) {
2892 global $DB;
2893 $message = 'Function tag_assign() is deprecated. Use core_tag_tag::set_item_tags() or core_tag_tag::add_item_tag() instead. ' .
2894 'Tag instance ordering should not be set manually';
2895 if ($component === null || $contextid === null) {
2896 $message .= '. You should specify the component and contextid of the item being tagged in your call to tag_assign.';
2898 debugging($message, DEBUG_DEVELOPER);
2900 if ($contextid) {
2901 $context = context::instance_by_id($contextid);
2902 } else {
2903 $context = context_system::instance();
2906 // Get the tag.
2907 $tag = $DB->get_record('tag', array('id' => $tagid), 'name, rawname', MUST_EXIST);
2909 $taginstanceid = core_tag_tag::add_item_tag($component, $record_type, $record_id, $context, $tag->rawname, $userid);
2911 // Alter the "ordering" of tag_instance. This should never be done manually and only remains here for the backward compatibility.
2912 $taginstance = new stdClass();
2913 $taginstance->id = $taginstanceid;
2914 $taginstance->ordering = $ordering;
2915 $taginstance->timemodified = time();
2917 $DB->update_record('tag_instance', $taginstance);
2919 return true;
2923 * Count how many records are tagged with a specific tag.
2925 * @package core_tag
2926 * @deprecated since 3.1
2927 * @param string $record_type record to look for ('post', 'user', etc.)
2928 * @param int $tagid is a single tag id
2929 * @return int number of mathing tags.
2931 function tag_record_count($record_type, $tagid) {
2932 debugging('Method tag_record_count() is deprecated and replaced with core_tag_tag::get($tagid)->count_tagged_items(). '.
2933 'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER);
2934 return core_tag_tag::get($tagid)->count_tagged_items('', $record_type);
2938 * Determine if a record is tagged with a specific tag
2940 * @package core_tag
2941 * @deprecated since 3.1
2942 * @param string $record_type the record type to look for
2943 * @param int $record_id the record id to look for
2944 * @param string $tag a tag name
2945 * @return bool/int true if it is tagged, 0 (false) otherwise
2947 function tag_record_tagged_with($record_type, $record_id, $tag) {
2948 debugging('Method tag_record_tagged_with() is deprecated and replaced with core_tag_tag::get($tagid)->is_item_tagged_with(). '.
2949 'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER);
2950 return core_tag_tag::is_item_tagged_with('', $record_type, $record_id, $tag);
2954 * Flag a tag as inappropriate.
2956 * @deprecated since 3.1
2957 * @param int|array $tagids a single tagid, or an array of tagids
2959 function tag_set_flag($tagids) {
2960 debugging('Function tag_set_flag() is deprecated and replaced with core_tag_tag::get($tagid)->flag().', DEBUG_DEVELOPER);
2961 $tagids = (array) $tagids;
2962 foreach ($tagids as $tagid) {
2963 if ($tag = core_tag_tag::get($tagid, '*')) {
2964 $tag->flag();
2970 * Remove the inappropriate flag on a tag.
2972 * @deprecated since 3.1
2973 * @param int|array $tagids a single tagid, or an array of tagids
2975 function tag_unset_flag($tagids) {
2976 debugging('Function tag_unset_flag() is deprecated and replaced with core_tag_tag::get($tagid)->reset_flag().', DEBUG_DEVELOPER);
2977 $tagids = (array) $tagids;
2978 foreach ($tagids as $tagid) {
2979 if ($tag = core_tag_tag::get($tagid, '*')) {
2980 $tag->reset_flag();
2986 * Prints or returns a HTML tag cloud with varying classes styles depending on the popularity and type of each tag.
2988 * @deprecated since 3.1
2990 * @param array $tagset Array of tags to display
2991 * @param int $nr_of_tags Limit for the number of tags to return/display, used if $tagset is null
2992 * @param bool $return if true the function will return the generated tag cloud instead of displaying it.
2993 * @param string $sort (optional) selected sorting, default is alpha sort (name) also timemodified or popularity
2994 * @return string|null a HTML string or null if this function does the output
2996 function tag_print_cloud($tagset=null, $nr_of_tags=150, $return=false, $sort='') {
2997 global $OUTPUT;
2999 debugging('Function tag_print_cloud() is deprecated and replaced with function core_tag_collection::get_tag_cloud(), '
3000 . 'templateable core_tag\output\tagcloud and template core_tag/tagcloud.', DEBUG_DEVELOPER);
3002 // Set up sort global - used to pass sort type into core_tag_collection::cloud_sort through usort() avoiding multiple sort functions.
3003 if ($sort == 'popularity') {
3004 $sort = 'count';
3005 } else if ($sort == 'date') {
3006 $sort = 'timemodified';
3007 } else {
3008 $sort = 'name';
3011 if (is_null($tagset)) {
3012 // No tag set received, so fetch tags from database.
3013 // Always add query by tagcollid even when it's not known to make use of the table index.
3014 $tagcloud = core_tag_collection::get_tag_cloud(0, false, $nr_of_tags, $sort);
3015 } else {
3016 $tagsincloud = $tagset;
3018 $etags = array();
3019 foreach ($tagsincloud as $tag) {
3020 $etags[] = $tag;
3023 core_tag_collection::$cloudsortfield = $sort;
3024 usort($tagsincloud, "core_tag_collection::cloud_sort");
3026 $tagcloud = new \core_tag\output\tagcloud($tagsincloud);
3029 $output = $OUTPUT->render_from_template('core_tag/tagcloud', $tagcloud->export_for_template($OUTPUT));
3030 if ($return) {
3031 return $output;
3032 } else {
3033 echo $output;
3038 * Function that returns tags that start with some text, for use by the autocomplete feature
3040 * @package core_tag
3041 * @deprecated since 3.0
3042 * @access private
3043 * @param string $text string that the tag names will be matched against
3044 * @return mixed an array of objects, or false if no records were found or an error occured.
3046 function tag_autocomplete($text) {
3047 debugging('Function tag_autocomplete() is deprecated without replacement. ' .
3048 'New form element "tags" does proper autocomplete.', DEBUG_DEVELOPER);
3049 global $DB;
3050 return $DB->get_records_sql("SELECT tg.id, tg.name, tg.rawname
3051 FROM {tag} tg
3052 WHERE tg.name LIKE ?", array(core_text::strtolower($text)."%"));
3056 * Prints a box with the description of a tag and its related tags
3058 * @package core_tag
3059 * @deprecated since 3.1
3060 * @param stdClass $tag_object
3061 * @param bool $return if true the function will return the generated tag cloud instead of displaying it.
3062 * @return string/null a HTML box showing a description of the tag object and it's relationsips or null if output is done directly
3063 * in the function.
3065 function tag_print_description_box($tag_object, $return=false) {
3066 global $USER, $CFG, $OUTPUT;
3067 require_once($CFG->libdir.'/filelib.php');
3069 debugging('Function tag_print_description_box() is deprecated without replacement. ' .
3070 'See core_tag_renderer for similar code.', DEBUG_DEVELOPER);
3072 $relatedtags = array();
3073 if ($tag = core_tag_tag::get($tag_object->id)) {
3074 $relatedtags = $tag->get_related_tags();
3077 $content = !empty($tag_object->description);
3078 $output = '';
3080 if ($content) {
3081 $output .= $OUTPUT->box_start('generalbox tag-description');
3084 if (!empty($tag_object->description)) {
3085 $options = new stdClass();
3086 $options->para = false;
3087 $options->overflowdiv = true;
3088 $tag_object->description = file_rewrite_pluginfile_urls($tag_object->description, 'pluginfile.php', context_system::instance()->id, 'tag', 'description', $tag_object->id);
3089 $output .= format_text($tag_object->description, $tag_object->descriptionformat, $options);
3092 if ($content) {
3093 $output .= $OUTPUT->box_end();
3096 if ($relatedtags) {
3097 $output .= $OUTPUT->tag_list($relatedtags, get_string('relatedtags', 'tag'), 'tag-relatedtags');
3100 if ($return) {
3101 return $output;
3102 } else {
3103 echo $output;
3108 * Prints a box that contains the management links of a tag
3110 * @deprecated since 3.1
3111 * @param core_tag_tag|stdClass $tag_object
3112 * @param bool $return if true the function will return the generated tag cloud instead of displaying it.
3113 * @return string|null a HTML string or null if this function does the output
3115 function tag_print_management_box($tag_object, $return=false) {
3116 global $USER, $CFG, $OUTPUT;
3118 debugging('Function tag_print_description_box() is deprecated without replacement. ' .
3119 'See core_tag_renderer for similar code.', DEBUG_DEVELOPER);
3121 $tagname = core_tag_tag::make_display_name($tag_object);
3122 $output = '';
3124 if (!isguestuser()) {
3125 $output .= $OUTPUT->box_start('box','tag-management-box');
3126 $systemcontext = context_system::instance();
3127 $links = array();
3129 // Add a link for users to add/remove this from their interests
3130 if (core_tag_tag::is_enabled('core', 'user') && core_tag_area::get_collection('core', 'user') == $tag_object->tagcollid) {
3131 if (core_tag_tag::is_item_tagged_with('core', 'user', $USER->id, $tag_object->name)) {
3132 $links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=removeinterest&amp;sesskey='. sesskey() .
3133 '&amp;tag='. rawurlencode($tag_object->name) .'">'.
3134 get_string('removetagfrommyinterests', 'tag', $tagname) .'</a>';
3135 } else {
3136 $links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=addinterest&amp;sesskey='. sesskey() .
3137 '&amp;tag='. rawurlencode($tag_object->name) .'">'.
3138 get_string('addtagtomyinterests', 'tag', $tagname) .'</a>';
3142 // Flag as inappropriate link. Only people with moodle/tag:flag capability.
3143 if (has_capability('moodle/tag:flag', $systemcontext)) {
3144 $links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=flaginappropriate&amp;sesskey='.
3145 sesskey() . '&amp;id='. $tag_object->id . '">'. get_string('flagasinappropriate',
3146 'tag', rawurlencode($tagname)) .'</a>';
3149 // Edit tag: Only people with moodle/tag:edit capability who either have it as an interest or can manage tags
3150 if (has_capability('moodle/tag:edit', $systemcontext) ||
3151 has_capability('moodle/tag:manage', $systemcontext)) {
3152 $links[] = '<a href="' . $CFG->wwwroot . '/tag/edit.php?id=' . $tag_object->id . '">' .
3153 get_string('edittag', 'tag') . '</a>';
3156 $output .= implode(' | ', $links);
3157 $output .= $OUTPUT->box_end();
3160 if ($return) {
3161 return $output;
3162 } else {
3163 echo $output;
3168 * Prints the tag search box
3170 * @deprecated since 3.1
3171 * @param bool $return if true return html string
3172 * @return string|null a HTML string or null if this function does the output
3174 function tag_print_search_box($return=false) {
3175 global $CFG, $OUTPUT;
3177 debugging('Function tag_print_search_box() is deprecated without replacement. ' .
3178 'See core_tag_renderer for similar code.', DEBUG_DEVELOPER);
3180 $query = optional_param('query', '', PARAM_RAW);
3182 $output = $OUTPUT->box_start('','tag-search-box');
3183 $output .= '<form action="'.$CFG->wwwroot.'/tag/search.php" style="display:inline">';
3184 $output .= '<div>';
3185 $output .= '<label class="accesshide" for="searchform_search">'.get_string('searchtags', 'tag').'</label>';
3186 $output .= '<input id="searchform_search" name="query" type="text" size="40" value="'.s($query).'" />';
3187 $output .= '<button id="searchform_button" type="submit">'. get_string('search', 'tag') .'</button><br />';
3188 $output .= '</div>';
3189 $output .= '</form>';
3190 $output .= $OUTPUT->box_end();
3192 if ($return) {
3193 return $output;
3195 else {
3196 echo $output;
3201 * Prints the tag search results
3203 * @deprecated since 3.1
3204 * @param string $query text that tag names will be matched against
3205 * @param int $page current page
3206 * @param int $perpage nr of users displayed per page
3207 * @param bool $return if true return html string
3208 * @return string|null a HTML string or null if this function does the output
3210 function tag_print_search_results($query, $page, $perpage, $return=false) {
3211 global $CFG, $USER, $OUTPUT;
3213 debugging('Function tag_print_search_results() is deprecated without replacement. ' .
3214 'In /tag/search.php the search results are printed using the core_tag/tagcloud template.', DEBUG_DEVELOPER);
3216 $query = clean_param($query, PARAM_TAG);
3218 $count = count(tag_find_tags($query, false));
3219 $tags = array();
3221 if ( $found_tags = tag_find_tags($query, true, $page * $perpage, $perpage) ) {
3222 $tags = array_values($found_tags);
3225 $baseurl = $CFG->wwwroot.'/tag/search.php?query='. rawurlencode($query);
3226 $output = '';
3228 // link "Add $query to my interests"
3229 $addtaglink = '';
3230 if (core_tag_tag::is_enabled('core', 'user') && !core_tag_tag::is_item_tagged_with('core', 'user', $USER->id, $query)) {
3231 $addtaglink = html_writer::link(new moodle_url('/tag/user.php', array('action' => 'addinterest', 'sesskey' => sesskey(),
3232 'tag' => $query)), get_string('addtagtomyinterests', 'tag', s($query)));
3235 if ( !empty($tags) ) { // there are results to display!!
3236 $output .= $OUTPUT->heading(get_string('searchresultsfor', 'tag', htmlspecialchars($query)) ." : {$count}", 3, 'main');
3238 //print a link "Add $query to my interests"
3239 if (!empty($addtaglink)) {
3240 $output .= $OUTPUT->box($addtaglink, 'box', 'tag-management-box');
3243 $nr_of_lis_per_ul = 6;
3244 $nr_of_uls = ceil( sizeof($tags) / $nr_of_lis_per_ul );
3246 $output .= '<ul id="tag-search-results">';
3247 for($i = 0; $i < $nr_of_uls; $i++) {
3248 foreach (array_slice($tags, $i * $nr_of_lis_per_ul, $nr_of_lis_per_ul) as $tag) {
3249 $output .= '<li>';
3250 $tag_link = html_writer::link(core_tag_tag::make_url($tag->tagcollid, $tag->rawname),
3251 core_tag_tag::make_display_name($tag));
3252 $output .= $tag_link;
3253 $output .= '</li>';
3256 $output .= '</ul>';
3257 $output .= '<div>&nbsp;</div>'; // <-- small layout hack in order to look good in Firefox
3259 $output .= $OUTPUT->paging_bar($count, $page, $perpage, $baseurl);
3261 else { //no results were found!!
3262 $output .= $OUTPUT->heading(get_string('noresultsfor', 'tag', htmlspecialchars($query)), 3, 'main');
3264 //print a link "Add $query to my interests"
3265 if (!empty($addtaglink)) {
3266 $output .= $OUTPUT->box($addtaglink, 'box', 'tag-management-box');
3270 if ($return) {
3271 return $output;
3273 else {
3274 echo $output;
3279 * Prints a table of the users tagged with the tag passed as argument
3281 * @deprecated since 3.1
3282 * @param stdClass $tagobject the tag we wish to return data for
3283 * @param int $limitfrom (optional, required if $limitnum is set) prints users starting at this point.
3284 * @param int $limitnum (optional, required if $limitfrom is set) prints this many users.
3285 * @param bool $return if true return html string
3286 * @return string|null a HTML string or null if this function does the output
3288 function tag_print_tagged_users_table($tagobject, $limitfrom='', $limitnum='', $return=false) {
3290 debugging('Function tag_print_tagged_users_table() is deprecated without replacement. ' .
3291 'See core_user_renderer for similar code.', DEBUG_DEVELOPER);
3293 //List of users with this tag
3294 $tagobject = core_tag_tag::get($tagobject->id);
3295 $userlist = $tagobject->get_tagged_items('core', 'user', $limitfrom, $limitnum);
3297 $output = tag_print_user_list($userlist, true);
3299 if ($return) {
3300 return $output;
3302 else {
3303 echo $output;
3308 * Prints an individual user box
3310 * @deprecated since 3.1
3311 * @param user_object $user (contains the following fields: id, firstname, lastname and picture)
3312 * @param bool $return if true return html string
3313 * @return string|null a HTML string or null if this function does the output
3315 function tag_print_user_box($user, $return=false) {
3316 global $CFG, $OUTPUT;
3318 debugging('Function tag_print_user_box() is deprecated without replacement. ' .
3319 'See core_user_renderer for similar code.', DEBUG_DEVELOPER);
3321 $usercontext = context_user::instance($user->id);
3322 $profilelink = '';
3324 if ($usercontext and (has_capability('moodle/user:viewdetails', $usercontext) || has_coursecontact_role($user->id))) {
3325 $profilelink = $CFG->wwwroot .'/user/view.php?id='. $user->id;
3328 $output = $OUTPUT->box_start('user-box', 'user'. $user->id);
3329 $fullname = fullname($user);
3330 $alt = '';
3332 if (!empty($profilelink)) {
3333 $output .= '<a href="'. $profilelink .'">';
3334 $alt = $fullname;
3337 $output .= $OUTPUT->user_picture($user, array('size'=>100));
3338 $output .= '<br />';
3340 if (!empty($profilelink)) {
3341 $output .= '</a>';
3344 //truncate name if it's too big
3345 if (core_text::strlen($fullname) > 26) {
3346 $fullname = core_text::substr($fullname, 0, 26) .'...';
3349 $output .= '<strong>'. $fullname .'</strong>';
3350 $output .= $OUTPUT->box_end();
3352 if ($return) {
3353 return $output;
3355 else {
3356 echo $output;
3361 * Prints a list of users
3363 * @deprecated since 3.1
3364 * @param array $userlist an array of user objects
3365 * @param bool $return if true return html string, otherwise output the result
3366 * @return string|null a HTML string or null if this function does the output
3368 function tag_print_user_list($userlist, $return=false) {
3370 debugging('Function tag_print_user_list() is deprecated without replacement. ' .
3371 'See core_user_renderer for similar code.', DEBUG_DEVELOPER);
3373 $output = '<div><ul class="inline-list">';
3375 foreach ($userlist as $user){
3376 $output .= '<li>'. tag_print_user_box($user, true) ."</li>\n";
3378 $output .= "</ul></div>\n";
3380 if ($return) {
3381 return $output;
3383 else {
3384 echo $output;
3389 * Function that returns the name that should be displayed for a specific tag
3391 * @package core_tag
3392 * @category tag
3393 * @deprecated since 3.1
3394 * @param stdClass|core_tag_tag $tagobject a line out of tag table, as returned by the adobd functions
3395 * @param int $html TAG_RETURN_HTML (default) will return htmlspecialchars encoded string, TAG_RETURN_TEXT will not encode.
3396 * @return string
3398 function tag_display_name($tagobject, $html=TAG_RETURN_HTML) {
3399 debugging('Function tag_display_name() is deprecated. Use core_tag_tag::make_display_name().', DEBUG_DEVELOPER);
3400 if (!isset($tagobject->name)) {
3401 return '';
3403 return core_tag_tag::make_display_name($tagobject, $html != TAG_RETURN_TEXT);
3407 * Function that normalizes a list of tag names.
3409 * @package core_tag
3410 * @deprecated since 3.1
3411 * @param array/string $rawtags array of tags, or a single tag.
3412 * @param int $case case to use for returned value (default: lower case). Either TAG_CASE_LOWER (default) or TAG_CASE_ORIGINAL
3413 * @return array lowercased normalized tags, indexed by the normalized tag, in the same order as the original array.
3414 * (Eg: 'Banana' => 'banana').
3416 function tag_normalize($rawtags, $case = TAG_CASE_LOWER) {
3417 debugging('Function tag_normalize() is deprecated. Use core_tag_tag::normalize().', DEBUG_DEVELOPER);
3419 if ( !is_array($rawtags) ) {
3420 $rawtags = array($rawtags);
3423 return core_tag_tag::normalize($rawtags, $case == TAG_CASE_LOWER);
3427 * Get a comma-separated list of tags related to another tag.
3429 * @package core_tag
3430 * @deprecated since 3.1
3431 * @param array $related_tags the array returned by tag_get_related_tags
3432 * @param int $html either TAG_RETURN_HTML (default) or TAG_RETURN_TEXT : return html links, or just text.
3433 * @return string comma-separated list
3435 function tag_get_related_tags_csv($related_tags, $html=TAG_RETURN_HTML) {
3436 global $OUTPUT;
3437 debugging('Method tag_get_related_tags_csv() is deprecated. Consider '
3438 . 'looping through array or using $OUTPUT->tag_list(core_tag_tag::get_item_tags())',
3439 DEBUG_DEVELOPER);
3440 if ($html != TAG_RETURN_TEXT) {
3441 return $OUTPUT->tag_list($related_tags, '');
3444 $tagsnames = array();
3445 foreach ($related_tags as $tag) {
3446 $tagsnames[] = core_tag_tag::make_display_name($tag, false);
3448 return implode(', ', $tagsnames);
3452 * Used to require that the return value from a function is an array.
3453 * Only used in the deprecated function {@link tag_get_id()}
3454 * @deprecated since 3.1
3456 define('TAG_RETURN_ARRAY', 0);
3458 * Used to require that the return value from a function is an object.
3459 * Only used in the deprecated function {@link tag_get_id()}
3460 * @deprecated since 3.1
3462 define('TAG_RETURN_OBJECT', 1);
3464 * Use to specify that HTML free text is expected to be returned from a function.
3465 * Only used in deprecated functions {@link tag_get_tags_csv()}, {@link tag_display_name()},
3466 * {@link tag_get_related_tags_csv()}
3467 * @deprecated since 3.1
3469 define('TAG_RETURN_TEXT', 2);
3471 * Use to specify that encoded HTML is expected to be returned from a function.
3472 * Only used in deprecated functions {@link tag_get_tags_csv()}, {@link tag_display_name()},
3473 * {@link tag_get_related_tags_csv()}
3474 * @deprecated since 3.1
3476 define('TAG_RETURN_HTML', 3);
3479 * Used to specify that we wish a lowercased string to be returned
3480 * Only used in deprecated function {@link tag_normalize()}
3481 * @deprecated since 3.1
3483 define('TAG_CASE_LOWER', 0);
3485 * Used to specify that we do not wish the case of the returned string to change
3486 * Only used in deprecated function {@link tag_normalize()}
3487 * @deprecated since 3.1
3489 define('TAG_CASE_ORIGINAL', 1);
3492 * Used to specify that we want all related tags returned, no matter how they are related.
3493 * Only used in deprecated function {@link tag_get_related_tags()}
3494 * @deprecated since 3.1
3496 define('TAG_RELATED_ALL', 0);
3498 * Used to specify that we only want back tags that were manually related.
3499 * Only used in deprecated function {@link tag_get_related_tags()}
3500 * @deprecated since 3.1
3502 define('TAG_RELATED_MANUAL', 1);
3504 * Used to specify that we only want back tags where the relationship was automatically correlated.
3505 * Only used in deprecated function {@link tag_get_related_tags()}
3506 * @deprecated since 3.1
3508 define('TAG_RELATED_CORRELATED', 2);
3511 * Set the tags assigned to a record. This overwrites the current tags.
3513 * This function is meant to be fed the string coming up from the user interface, which contains all tags assigned to a record.
3515 * Due to API change $component and $contextid are now required. Instead of
3516 * calling this function you can use {@link core_tag_tag::set_item_tags()} or
3517 * {@link core_tag_tag::set_related_tags()}
3519 * @package core_tag
3520 * @deprecated since 3.1
3521 * @param string $itemtype the type of record to tag ('post' for blogs, 'user' for users, 'tag' for tags, etc.)
3522 * @param int $itemid the id of the record to tag
3523 * @param array $tags the array of tags to set on the record. If given an empty array, all tags will be removed.
3524 * @param string|null $component the component that was tagged
3525 * @param int|null $contextid the context id of where this tag was assigned
3526 * @return bool|null
3528 function tag_set($itemtype, $itemid, $tags, $component = null, $contextid = null) {
3529 debugging('Function tag_set() is deprecated. Use ' .
3530 ' core_tag_tag::set_item_tags() instead', DEBUG_DEVELOPER);
3532 if ($itemtype === 'tag') {
3533 return core_tag_tag::get($itemid, '*', MUST_EXIST)->set_related_tags($tags);
3534 } else {
3535 $context = $contextid ? context::instance_by_id($contextid) : context_system::instance();
3536 return core_tag_tag::set_item_tags($component, $itemtype, $itemid, $context, $tags);
3541 * Adds a tag to a record, without overwriting the current tags.
3543 * This function remains here for backward compatiblity. It is recommended to use
3544 * {@link core_tag_tag::add_item_tag()} or {@link core_tag_tag::add_related_tags()} instead
3546 * @package core_tag
3547 * @deprecated since 3.1
3548 * @param string $itemtype the type of record to tag ('post' for blogs, 'user' for users, etc.)
3549 * @param int $itemid the id of the record to tag
3550 * @param string $tag the tag to add
3551 * @param string|null $component the component that was tagged
3552 * @param int|null $contextid the context id of where this tag was assigned
3553 * @return bool|null
3555 function tag_set_add($itemtype, $itemid, $tag, $component = null, $contextid = null) {
3556 debugging('Function tag_set_add() is deprecated. Use ' .
3557 ' core_tag_tag::add_item_tag() instead', DEBUG_DEVELOPER);
3559 if ($itemtype === 'tag') {
3560 return core_tag_tag::get($itemid, '*', MUST_EXIST)->add_related_tags(array($tag));
3561 } else {
3562 $context = $contextid ? context::instance_by_id($contextid) : context_system::instance();
3563 return core_tag_tag::add_item_tag($component, $itemtype, $itemid, $context, $tag);
3568 * Removes a tag from a record, without overwriting other current tags.
3570 * This function remains here for backward compatiblity. It is recommended to use
3571 * {@link core_tag_tag::remove_item_tag()} instead
3573 * @package core_tag
3574 * @deprecated since 3.1
3575 * @param string $itemtype the type of record to tag ('post' for blogs, 'user' for users, etc.)
3576 * @param int $itemid the id of the record to tag
3577 * @param string $tag the tag to delete
3578 * @param string|null $component the component that was tagged
3579 * @param int|null $contextid the context id of where this tag was assigned
3580 * @return bool|null
3582 function tag_set_delete($itemtype, $itemid, $tag, $component = null, $contextid = null) {
3583 debugging('Function tag_set_delete() is deprecated. Use ' .
3584 ' core_tag_tag::remove_item_tag() instead', DEBUG_DEVELOPER);
3585 return core_tag_tag::remove_item_tag($component, $itemtype, $itemid, $tag);
3589 * Simple function to just return a single tag object when you know the name or something
3591 * See also {@link core_tag_tag::get()} and {@link core_tag_tag::get_by_name()}
3593 * @package core_tag
3594 * @deprecated since 3.1
3595 * @param string $field which field do we use to identify the tag: id, name or rawname
3596 * @param string $value the required value of the aforementioned field
3597 * @param string $returnfields which fields do we want returned. This is a comma seperated string containing any combination of
3598 * 'id', 'name', 'rawname' or '*' to include all fields.
3599 * @return mixed tag object
3601 function tag_get($field, $value, $returnfields='id, name, rawname, tagcollid') {
3602 global $DB;
3603 debugging('Function tag_get() is deprecated. Use ' .
3604 ' core_tag_tag::get() or core_tag_tag::get_by_name()',
3605 DEBUG_DEVELOPER);
3606 if ($field === 'id') {
3607 $tag = core_tag_tag::get((int)$value, $returnfields);
3608 } else if ($field === 'name') {
3609 $tag = core_tag_tag::get_by_name(0, $value, $returnfields);
3610 } else {
3611 $params = array($field => $value);
3612 return $DB->get_record('tag', $params, $returnfields);
3614 if ($tag) {
3615 return $tag->to_object();
3617 return null;
3621 * Returns tags related to a tag
3623 * Related tags of a tag come from two sources:
3624 * - manually added related tags, which are tag_instance entries for that tag
3625 * - correlated tags, which are calculated
3627 * @package core_tag
3628 * @deprecated since 3.1
3629 * @param string $tagid is a single **normalized** tag name or the id of a tag
3630 * @param int $type the function will return either manually (TAG_RELATED_MANUAL) related tags or correlated
3631 * (TAG_RELATED_CORRELATED) tags. Default is TAG_RELATED_ALL, which returns everything.
3632 * @param int $limitnum (optional) return a subset comprising this many records, the default is 10
3633 * @return array an array of tag objects
3635 function tag_get_related_tags($tagid, $type=TAG_RELATED_ALL, $limitnum=10) {
3636 debugging('Method tag_get_related_tags() is deprecated, '
3637 . 'use core_tag_tag::get_correlated_tags(), core_tag_tag::get_related_tags() or '
3638 . 'core_tag_tag::get_manual_related_tags()', DEBUG_DEVELOPER);
3639 $result = array();
3640 if ($tag = core_tag_tag::get($tagid)) {
3641 if ($type == TAG_RELATED_CORRELATED) {
3642 $tags = $tag->get_correlated_tags();
3643 } else if ($type == TAG_RELATED_MANUAL) {
3644 $tags = $tag->get_manual_related_tags();
3645 } else {
3646 $tags = $tag->get_related_tags();
3648 $tags = array_slice($tags, 0, $limitnum);
3649 foreach ($tags as $id => $tag) {
3650 $result[$id] = $tag->to_object();
3653 return $result;
3657 * Delete one or more tag, and all their instances if there are any left.
3659 * @package core_tag
3660 * @deprecated since 3.1
3661 * @param mixed $tagids one tagid (int), or one array of tagids to delete
3662 * @return bool true on success, false otherwise
3664 function tag_delete($tagids) {
3665 debugging('Method tag_delete() is deprecated, use core_tag_tag::delete_tags()',
3666 DEBUG_DEVELOPER);
3667 return core_tag_tag::delete_tags($tagids);
3671 * Deletes all the tag instances given a component and an optional contextid.
3673 * @deprecated since 3.1
3674 * @param string $component
3675 * @param int $contextid if null, then we delete all tag instances for the $component
3677 function tag_delete_instances($component, $contextid = null) {
3678 debugging('Method tag_delete() is deprecated, use core_tag_tag::delete_instances()',
3679 DEBUG_DEVELOPER);
3680 core_tag_tag::delete_instances($component, null, $contextid);
3684 * Clean up the tag tables, making sure all tagged object still exists.
3686 * This should normally not be necessary, but in case related tags are not deleted when the tagged record is removed, this should be
3687 * done once in a while, perhaps on an occasional cron run. On a site with lots of tags, this could become an expensive function to
3688 * call: don't run at peak time.
3690 * @package core_tag
3691 * @deprecated since 3.1
3693 function tag_cleanup() {
3694 debugging('Method tag_cleanup() is deprecated, use \core\task\tag_cron_task::cleanup()',
3695 DEBUG_DEVELOPER);
3697 $task = new \core\task\tag_cron_task();
3698 return $task->cleanup();
3702 * This function will delete numerous tag instances efficiently.
3703 * This removes tag instances only. It doesn't check to see if it is the last use of a tag.
3705 * @deprecated since 3.1
3706 * @param array $instances An array of tag instance objects with the addition of the tagname and tagrawname
3707 * (used for recording a delete event).
3709 function tag_bulk_delete_instances($instances) {
3710 debugging('Method tag_bulk_delete_instances() is deprecated, '
3711 . 'use \core\task\tag_cron_task::bulk_delete_instances()',
3712 DEBUG_DEVELOPER);
3714 $task = new \core\task\tag_cron_task();
3715 return $task->bulk_delete_instances($instances);
3719 * Calculates and stores the correlated tags of all tags. The correlations are stored in the 'tag_correlation' table.
3721 * Two tags are correlated if they appear together a lot. Ex.: Users tagged with "computers" will probably also be tagged with "algorithms".
3723 * The rationale for the 'tag_correlation' table is performance. It works as a cache for a potentially heavy load query done at the
3724 * 'tag_instance' table. So, the 'tag_correlation' table stores redundant information derived from the 'tag_instance' table.
3726 * @package core_tag
3727 * @deprecated since 3.1
3728 * @param int $mincorrelation Only tags with more than $mincorrelation correlations will be identified.
3730 function tag_compute_correlations($mincorrelation = 2) {
3731 debugging('Method tag_compute_correlations() is deprecated, '
3732 . 'use \core\task\tag_cron_task::compute_correlations()',
3733 DEBUG_DEVELOPER);
3735 $task = new \core\task\tag_cron_task();
3736 return $task->compute_correlations($mincorrelation);
3740 * This function processes a tag correlation and makes changes in the database as required.
3742 * The tag correlation object needs have both a tagid property and a correlatedtags property that is an array.
3744 * @package core_tag
3745 * @deprecated since 3.1
3746 * @param stdClass $tagcorrelation
3747 * @return int/bool The id of the tag correlation that was just processed or false.
3749 function tag_process_computed_correlation(stdClass $tagcorrelation) {
3750 debugging('Method tag_process_computed_correlation() is deprecated, '
3751 . 'use \core\task\tag_cron_task::process_computed_correlation()',
3752 DEBUG_DEVELOPER);
3754 $task = new \core\task\tag_cron_task();
3755 return $task->process_computed_correlation($tagcorrelation);
3759 * Tasks that should be performed at cron time
3761 * @package core_tag
3762 * @deprecated since 3.1
3764 function tag_cron() {
3765 debugging('Method tag_cron() is deprecated, use \core\task\tag_cron_task::execute()',
3766 DEBUG_DEVELOPER);
3768 $task = new \core\task\tag_cron_task();
3769 $task->execute();
3773 * Search for tags with names that match some text
3775 * @package core_tag
3776 * @deprecated since 3.1
3777 * @param string $text escaped string that the tag names will be matched against
3778 * @param bool $ordered If true, tags are ordered by their popularity. If false, no ordering.
3779 * @param int/string $limitfrom (optional, required if $limitnum is set) return a subset of records, starting at this point.
3780 * @param int/string $limitnum (optional, required if $limitfrom is set) return a subset comprising this many records.
3781 * @param int $tagcollid
3782 * @return array/boolean an array of objects, or false if no records were found or an error occured.
3784 function tag_find_tags($text, $ordered=true, $limitfrom='', $limitnum='', $tagcollid = null) {
3785 debugging('Method tag_find_tags() is deprecated without replacement', DEBUG_DEVELOPER);
3786 global $DB;
3788 $text = core_text::strtolower(clean_param($text, PARAM_TAG));
3790 list($sql, $params) = $DB->get_in_or_equal($tagcollid ? array($tagcollid) :
3791 array_keys(core_tag_collection::get_collections(true)));
3792 array_unshift($params, "%{$text}%");
3794 if ($ordered) {
3795 $query = "SELECT tg.id, tg.name, tg.rawname, tg.tagcollid, COUNT(ti.id) AS count
3796 FROM {tag} tg LEFT JOIN {tag_instance} ti ON tg.id = ti.tagid
3797 WHERE tg.name LIKE ? AND tg.tagcollid $sql
3798 GROUP BY tg.id, tg.name, tg.rawname
3799 ORDER BY count DESC";
3800 } else {
3801 $query = "SELECT tg.id, tg.name, tg.rawname, tg.tagcollid
3802 FROM {tag} tg
3803 WHERE tg.name LIKE ? AND tg.tagcollid $sql";
3805 return $DB->get_records_sql($query, $params, $limitfrom , $limitnum);
3809 * Get the name of a tag
3811 * @package core_tag
3812 * @deprecated since 3.1
3813 * @param mixed $tagids the id of the tag, or an array of ids
3814 * @return mixed string name of one tag, or id-indexed array of strings
3816 function tag_get_name($tagids) {
3817 debugging('Method tag_get_name() is deprecated without replacement', DEBUG_DEVELOPER);
3818 global $DB;
3820 if (!is_array($tagids)) {
3821 if ($tag = $DB->get_record('tag', array('id'=>$tagids))) {
3822 return $tag->name;
3824 return false;
3827 $tag_names = array();
3828 foreach($DB->get_records_list('tag', 'id', $tagids) as $tag) {
3829 $tag_names[$tag->id] = $tag->name;
3832 return $tag_names;
3836 * Returns the correlated tags of a tag, retrieved from the tag_correlation table. Make sure cron runs, otherwise the table will be
3837 * empty and this function won't return anything.
3839 * Correlated tags are calculated in cron based on existing tag instances.
3841 * @package core_tag
3842 * @deprecated since 3.1
3843 * @param int $tagid is a single tag id
3844 * @param int $notused this argument is no longer used
3845 * @return array an array of tag objects or an empty if no correlated tags are found
3847 function tag_get_correlated($tagid, $notused = null) {
3848 debugging('Method tag_get_correlated() is deprecated, '
3849 . 'use core_tag_tag::get_correlated_tags()', DEBUG_DEVELOPER);
3850 $result = array();
3851 if ($tag = core_tag_tag::get($tagid)) {
3852 $tags = $tag->get_correlated_tags(true);
3853 // Convert to objects for backward-compatibility.
3854 foreach ($tags as $id => $tag) {
3855 $result[$id] = $tag->to_object();
3858 return $result;
3862 * This function is used by print_tag_cloud, to usort() the tags in the cloud. See php.net/usort for the parameters documentation.
3863 * This was originally in blocks/blog_tags/block_blog_tags.php, named blog_tags_sort().
3865 * @package core_tag
3866 * @deprecated since 3.1
3867 * @param string $a Tag name to compare against $b
3868 * @param string $b Tag name to compare against $a
3869 * @return int The result of the comparison/validation 1, 0 or -1
3871 function tag_cloud_sort($a, $b) {
3872 debugging('Method tag_cloud_sort() is deprecated, similar method can be found in core_tag_collection::cloud_sort()', DEBUG_DEVELOPER);
3873 global $CFG;
3875 if (empty($CFG->tagsort)) {
3876 $tagsort = 'name'; // by default, sort by name
3877 } else {
3878 $tagsort = $CFG->tagsort;
3881 if (is_numeric($a->$tagsort)) {
3882 return ($a->$tagsort == $b->$tagsort) ? 0 : ($a->$tagsort > $b->$tagsort) ? 1 : -1;
3883 } elseif (is_string($a->$tagsort)) {
3884 return strcmp($a->$tagsort, $b->$tagsort);
3885 } else {
3886 return 0;
3891 * Loads the events definitions for the component (from file). If no
3892 * events are defined for the component, we simply return an empty array.
3894 * @access protected To be used from eventslib only
3895 * @deprecated since Moodle 3.1
3896 * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
3897 * @return array Array of capabilities or empty array if not exists
3899 function events_load_def($component) {
3900 global $CFG;
3901 if ($component === 'unittest') {
3902 $defpath = $CFG->dirroot.'/lib/tests/fixtures/events.php';
3903 } else {
3904 $defpath = core_component::get_component_directory($component).'/db/events.php';
3907 $handlers = array();
3909 if (file_exists($defpath)) {
3910 require($defpath);
3913 // make sure the definitions are valid and complete; tell devs what is wrong
3914 foreach ($handlers as $eventname => $handler) {
3915 if ($eventname === 'reset') {
3916 debugging("'reset' can not be used as event name.");
3917 unset($handlers['reset']);
3918 continue;
3920 if (!is_array($handler)) {
3921 debugging("Handler of '$eventname' must be specified as array'");
3922 unset($handlers[$eventname]);
3923 continue;
3925 if (!isset($handler['handlerfile'])) {
3926 debugging("Handler of '$eventname' must include 'handlerfile' key'");
3927 unset($handlers[$eventname]);
3928 continue;
3930 if (!isset($handler['handlerfunction'])) {
3931 debugging("Handler of '$eventname' must include 'handlerfunction' key'");
3932 unset($handlers[$eventname]);
3933 continue;
3935 if (!isset($handler['schedule'])) {
3936 $handler['schedule'] = 'instant';
3938 if ($handler['schedule'] !== 'instant' and $handler['schedule'] !== 'cron') {
3939 debugging("Handler of '$eventname' must include valid 'schedule' type (instant or cron)'");
3940 unset($handlers[$eventname]);
3941 continue;
3943 if (!isset($handler['internal'])) {
3944 $handler['internal'] = 1;
3946 $handlers[$eventname] = $handler;
3949 return $handlers;
3953 * Puts a handler on queue
3955 * @access protected To be used from eventslib only
3956 * @deprecated since Moodle 3.1
3957 * @param stdClass $handler event handler object from db
3958 * @param stdClass $event event data object
3959 * @param string $errormessage The error message indicating the problem
3960 * @return int id number of new queue handler
3962 function events_queue_handler($handler, $event, $errormessage) {
3963 global $DB;
3965 if ($qhandler = $DB->get_record('events_queue_handlers', array('queuedeventid'=>$event->id, 'handlerid'=>$handler->id))) {
3966 debugging("Please check code: Event id $event->id is already queued in handler id $qhandler->id");
3967 return $qhandler->id;
3970 // make a new queue handler
3971 $qhandler = new stdClass();
3972 $qhandler->queuedeventid = $event->id;
3973 $qhandler->handlerid = $handler->id;
3974 $qhandler->errormessage = $errormessage;
3975 $qhandler->timemodified = time();
3976 if ($handler->schedule === 'instant' and $handler->status == 1) {
3977 $qhandler->status = 1; //already one failed attempt to dispatch this event
3978 } else {
3979 $qhandler->status = 0;
3982 return $DB->insert_record('events_queue_handlers', $qhandler);
3986 * trigger a single event with a specified handler
3988 * @access protected To be used from eventslib only
3989 * @deprecated since Moodle 3.1
3990 * @param stdClass $handler This shoudl be a row from the events_handlers table.
3991 * @param stdClass $eventdata An object containing information about the event
3992 * @param string $errormessage error message indicating problem
3993 * @return bool|null True means event processed, false means retry event later; may throw exception, NULL means internal error
3995 function events_dispatch($handler, $eventdata, &$errormessage) {
3996 global $CFG;
3998 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.', DEBUG_DEVELOPER);
4000 $function = unserialize($handler->handlerfunction);
4002 if (is_callable($function)) {
4003 // oki, no need for includes
4005 } else if (file_exists($CFG->dirroot.$handler->handlerfile)) {
4006 include_once($CFG->dirroot.$handler->handlerfile);
4008 } else {
4009 $errormessage = "Handler file of component $handler->component: $handler->handlerfile can not be found!";
4010 return null;
4013 // checks for handler validity
4014 if (is_callable($function)) {
4015 $result = call_user_func($function, $eventdata);
4016 if ($result === false) {
4017 $errormessage = "Handler function of component $handler->component: $handler->handlerfunction requested resending of event!";
4018 return false;
4020 return true;
4022 } else {
4023 $errormessage = "Handler function of component $handler->component: $handler->handlerfunction not callable function or class method!";
4024 return null;
4029 * given a queued handler, call the respective event handler to process the event
4031 * @access protected To be used from eventslib only
4032 * @deprecated since Moodle 3.1
4033 * @param stdClass $qhandler events_queued_handler row from db
4034 * @return boolean true means event processed, false means retry later, NULL means fatal failure
4036 function events_process_queued_handler($qhandler) {
4037 global $DB;
4039 // get handler
4040 if (!$handler = $DB->get_record('events_handlers', array('id'=>$qhandler->handlerid))) {
4041 debugging("Error processing queue handler $qhandler->id, missing handler id: $qhandler->handlerid");
4042 //irrecoverable error, remove broken queue handler
4043 events_dequeue($qhandler);
4044 return NULL;
4047 // get event object
4048 if (!$event = $DB->get_record('events_queue', array('id'=>$qhandler->queuedeventid))) {
4049 // can't proceed with no event object - might happen when two crons running at the same time
4050 debugging("Error processing queue handler $qhandler->id, missing event id: $qhandler->queuedeventid");
4051 //irrecoverable error, remove broken queue handler
4052 events_dequeue($qhandler);
4053 return NULL;
4056 // call the function specified by the handler
4057 try {
4058 $errormessage = 'Unknown error';
4059 if (events_dispatch($handler, unserialize(base64_decode($event->eventdata)), $errormessage)) {
4060 //everything ok
4061 events_dequeue($qhandler);
4062 return true;
4064 } catch (Exception $e) {
4065 // the problem here is that we do not want one broken handler to stop all others,
4066 // cron handlers are very tricky because the needed data might have been deleted before the cron execution
4067 $errormessage = "Handler function of component $handler->component: $handler->handlerfunction threw exception :" .
4068 $e->getMessage() . "\n" . format_backtrace($e->getTrace(), true);
4069 if (!empty($e->debuginfo)) {
4070 $errormessage .= $e->debuginfo;
4074 //dispatching failed
4075 $qh = new stdClass();
4076 $qh->id = $qhandler->id;
4077 $qh->errormessage = $errormessage;
4078 $qh->timemodified = time();
4079 $qh->status = $qhandler->status + 1;
4080 $DB->update_record('events_queue_handlers', $qh);
4082 debugging($errormessage);
4084 return false;
4088 * Updates all of the event definitions within the database.
4090 * Unfortunately this isn't as simple as removing them all and then readding
4091 * the updated event definitions. Chances are queued items are referencing the
4092 * existing definitions.
4094 * Note that the absence of the db/events.php event definition file
4095 * will cause any queued events for the component to be removed from
4096 * the database.
4098 * @category event
4099 * @deprecated since Moodle 3.1
4100 * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
4101 * @return boolean always returns true
4103 function events_update_definition($component='moodle') {
4104 global $DB;
4106 // load event definition from events.php
4107 $filehandlers = events_load_def($component);
4109 if ($filehandlers) {
4110 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.', DEBUG_DEVELOPER);
4113 // load event definitions from db tables
4114 // if we detect an event being already stored, we discard from this array later
4115 // the remaining needs to be removed
4116 $cachedhandlers = events_get_cached($component);
4118 foreach ($filehandlers as $eventname => $filehandler) {
4119 if (!empty($cachedhandlers[$eventname])) {
4120 if ($cachedhandlers[$eventname]['handlerfile'] === $filehandler['handlerfile'] &&
4121 $cachedhandlers[$eventname]['handlerfunction'] === serialize($filehandler['handlerfunction']) &&
4122 $cachedhandlers[$eventname]['schedule'] === $filehandler['schedule'] &&
4123 $cachedhandlers[$eventname]['internal'] == $filehandler['internal']) {
4124 // exact same event handler already present in db, ignore this entry
4126 unset($cachedhandlers[$eventname]);
4127 continue;
4129 } else {
4130 // same event name matches, this event has been updated, update the datebase
4131 $handler = new stdClass();
4132 $handler->id = $cachedhandlers[$eventname]['id'];
4133 $handler->handlerfile = $filehandler['handlerfile'];
4134 $handler->handlerfunction = serialize($filehandler['handlerfunction']); // static class methods stored as array
4135 $handler->schedule = $filehandler['schedule'];
4136 $handler->internal = $filehandler['internal'];
4138 $DB->update_record('events_handlers', $handler);
4140 unset($cachedhandlers[$eventname]);
4141 continue;
4144 } else {
4145 // if we are here, this event handler is not present in db (new)
4146 // add it
4147 $handler = new stdClass();
4148 $handler->eventname = $eventname;
4149 $handler->component = $component;
4150 $handler->handlerfile = $filehandler['handlerfile'];
4151 $handler->handlerfunction = serialize($filehandler['handlerfunction']); // static class methods stored as array
4152 $handler->schedule = $filehandler['schedule'];
4153 $handler->status = 0;
4154 $handler->internal = $filehandler['internal'];
4156 $DB->insert_record('events_handlers', $handler);
4160 // clean up the left overs, the entries in cached events array at this points are deprecated event handlers
4161 // and should be removed, delete from db
4162 events_cleanup($component, $cachedhandlers);
4164 events_get_handlers('reset');
4166 return true;
4170 * Events cron will try to empty the events queue by processing all the queued events handlers
4172 * @access public Part of the public API
4173 * @deprecated since Moodle 3.1
4174 * @category event
4175 * @param string $eventname empty means all
4176 * @return int number of dispatched events
4178 function events_cron($eventname='') {
4179 global $DB;
4181 $failed = array();
4182 $processed = 0;
4184 if ($eventname) {
4185 $sql = "SELECT qh.*
4186 FROM {events_queue_handlers} qh, {events_handlers} h
4187 WHERE qh.handlerid = h.id AND h.eventname=?
4188 ORDER BY qh.id";
4189 $params = array($eventname);
4190 } else {
4191 $sql = "SELECT *
4192 FROM {events_queue_handlers}
4193 ORDER BY id";
4194 $params = array();
4197 $rs = $DB->get_recordset_sql($sql, $params);
4198 if ($rs->valid()) {
4199 debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.', DEBUG_DEVELOPER);
4202 foreach ($rs as $qhandler) {
4203 if (isset($failed[$qhandler->handlerid])) {
4204 // do not try to dispatch any later events when one already asked for retry or ended with exception
4205 continue;
4207 $status = events_process_queued_handler($qhandler);
4208 if ($status === false) {
4209 // handler is asking for retry, do not send other events to this handler now
4210 $failed[$qhandler->handlerid] = $qhandler->handlerid;
4211 } else if ($status === NULL) {
4212 // means completely broken handler, event data was purged
4213 $failed[$qhandler->handlerid] = $qhandler->handlerid;
4214 } else {
4215 $processed++;
4218 $rs->close();
4220 // remove events that do not have any handlers waiting
4221 $sql = "SELECT eq.id
4222 FROM {events_queue} eq
4223 LEFT JOIN {events_queue_handlers} qh ON qh.queuedeventid = eq.id
4224 WHERE qh.id IS NULL";
4225 $rs = $DB->get_recordset_sql($sql);
4226 foreach ($rs as $event) {
4227 //debugging('Purging stale event '.$event->id);
4228 $DB->delete_records('events_queue', array('id'=>$event->id));
4230 $rs->close();
4232 return $processed;
4236 * Do not call directly, this is intended to be used from new event base only.
4238 * @private
4239 * @deprecated since Moodle 3.1
4240 * @param string $eventname name of the event
4241 * @param mixed $eventdata event data object
4242 * @return int number of failed events
4244 function events_trigger_legacy($eventname, $eventdata) {
4245 global $CFG, $USER, $DB;
4247 $failedcount = 0; // number of failed events.
4249 // pull out all registered event handlers
4250 if ($handlers = events_get_handlers($eventname)) {
4251 foreach ($handlers as $handler) {
4252 $errormessage = '';
4254 if ($handler->schedule === 'instant') {
4255 if ($handler->status) {
4256 //check if previous pending events processed
4257 if (!$DB->record_exists('events_queue_handlers', array('handlerid'=>$handler->id))) {
4258 // ok, queue is empty, lets reset the status back to 0 == ok
4259 $handler->status = 0;
4260 $DB->set_field('events_handlers', 'status', 0, array('id'=>$handler->id));
4261 // reset static handler cache
4262 events_get_handlers('reset');
4266 // dispatch the event only if instant schedule and status ok
4267 if ($handler->status or (!$handler->internal and $DB->is_transaction_started())) {
4268 // increment the error status counter
4269 $handler->status++;
4270 $DB->set_field('events_handlers', 'status', $handler->status, array('id'=>$handler->id));
4271 // reset static handler cache
4272 events_get_handlers('reset');
4274 } else {
4275 $errormessage = 'Unknown error';
4276 $result = events_dispatch($handler, $eventdata, $errormessage);
4277 if ($result === true) {
4278 // everything is fine - event dispatched
4279 continue;
4280 } else if ($result === false) {
4281 // retry later - set error count to 1 == send next instant into cron queue
4282 $DB->set_field('events_handlers', 'status', 1, array('id'=>$handler->id));
4283 // reset static handler cache
4284 events_get_handlers('reset');
4285 } else {
4286 // internal problem - ignore the event completely
4287 $failedcount ++;
4288 continue;
4292 // update the failed counter
4293 $failedcount ++;
4295 } else if ($handler->schedule === 'cron') {
4296 //ok - use queueing of events only
4298 } else {
4299 // unknown schedule - ignore event completely
4300 debugging("Unknown handler schedule type: $handler->schedule");
4301 $failedcount ++;
4302 continue;
4305 // if even type is not instant, or dispatch asked for retry, queue it
4306 $event = new stdClass();
4307 $event->userid = $USER->id;
4308 $event->eventdata = base64_encode(serialize($eventdata));
4309 $event->timecreated = time();
4310 if (debugging()) {
4311 $dump = '';
4312 $callers = debug_backtrace();
4313 foreach ($callers as $caller) {
4314 if (!isset($caller['line'])) {
4315 $caller['line'] = '?';
4317 if (!isset($caller['file'])) {
4318 $caller['file'] = '?';
4320 $dump .= 'line ' . $caller['line'] . ' of ' . substr($caller['file'], strlen($CFG->dirroot) + 1);
4321 if (isset($caller['function'])) {
4322 $dump .= ': call to ';
4323 if (isset($caller['class'])) {
4324 $dump .= $caller['class'] . $caller['type'];
4326 $dump .= $caller['function'] . '()';
4328 $dump .= "\n";
4330 $event->stackdump = $dump;
4331 } else {
4332 $event->stackdump = '';
4334 $event->id = $DB->insert_record('events_queue', $event);
4335 events_queue_handler($handler, $event, $errormessage);
4337 } else {
4338 // No handler found for this event name - this is ok!
4341 return $failedcount;
4345 * checks if an event is registered for this component
4347 * @access public Part of the public API
4348 * @deprecated since Moodle 3.1
4349 * @param string $eventname name of the event
4350 * @param string $component component name, can be mod/data or moodle
4351 * @return bool
4353 function events_is_registered($eventname, $component) {
4354 global $DB;
4356 debugging('events_is_registered() has been deprecated along with all Events 1 API in favour of Events 2 API,' .
4357 ' please use it instead.', DEBUG_DEVELOPER);
4359 return $DB->record_exists('events_handlers', array('component'=>$component, 'eventname'=>$eventname));
4363 * checks if an event is queued for processing - either cron handlers attached or failed instant handlers
4365 * @access public Part of the public API
4366 * @deprecated since Moodle 3.1
4367 * @param string $eventname name of the event
4368 * @return int number of queued events
4370 function events_pending_count($eventname) {
4371 global $DB;
4373 debugging('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2 API,' .
4374 ' please use it instead.', DEBUG_DEVELOPER);
4376 $sql = "SELECT COUNT('x')
4377 FROM {events_queue_handlers} qh
4378 JOIN {events_handlers} h ON h.id = qh.handlerid
4379 WHERE h.eventname = ?";
4381 return $DB->count_records_sql($sql, array($eventname));
4385 * Emails admins about a clam outcome
4387 * @deprecated since Moodle 3.0 - this is a part of clamav plugin now.
4388 * @param string $notice The body of the email to be sent.
4389 * @return void
4391 function clam_message_admins($notice) {
4392 debugging('clam_message_admins() is deprecated, please use message_admins() method of \antivirus_clamav\scanner class.', DEBUG_DEVELOPER);
4394 $antivirus = \core\antivirus\manager::get_antivirus('clamav');
4395 $antivirus->message_admins($notice);
4399 * Returns the string equivalent of a numeric clam error code
4401 * @deprecated since Moodle 3.0 - this is a part of clamav plugin now.
4402 * @param int $returncode The numeric error code in question.
4403 * @return string The definition of the error code
4405 function get_clam_error_code($returncode) {
4406 debugging('get_clam_error_code() is deprecated, please use get_clam_error_code() method of \antivirus_clamav\scanner class.', DEBUG_DEVELOPER);
4408 $antivirus = \core\antivirus\manager::get_antivirus('clamav');
4409 return $antivirus->get_clam_error_code($returncode);
4413 * Returns the rename action.
4415 * @deprecated since 3.1
4416 * @param cm_info $mod The module to produce editing buttons for
4417 * @param int $sr The section to link back to (used for creating the links)
4418 * @return The markup for the rename action, or an empty string if not available.
4420 function course_get_cm_rename_action(cm_info $mod, $sr = null) {
4421 global $COURSE, $OUTPUT;
4423 static $str;
4424 static $baseurl;
4426 debugging('Function course_get_cm_rename_action() is deprecated. Please use inplace_editable ' .
4427 'https://docs.moodle.org/dev/Inplace_editable', DEBUG_DEVELOPER);
4429 $modcontext = context_module::instance($mod->id);
4430 $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext);
4432 if (!isset($str)) {
4433 $str = get_strings(array('edittitle'));
4436 if (!isset($baseurl)) {
4437 $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
4440 if ($sr !== null) {
4441 $baseurl->param('sr', $sr);
4444 // AJAX edit title.
4445 if ($mod->has_view() && $hasmanageactivities && course_ajax_enabled($COURSE) &&
4446 (($mod->course == $COURSE->id) || ($mod->course == SITEID))) {
4447 // we will not display link if we are on some other-course page (where we should not see this module anyway)
4448 return html_writer::span(
4449 html_writer::link(
4450 new moodle_url($baseurl, array('update' => $mod->id)),
4451 $OUTPUT->pix_icon('t/editstring', '', 'moodle', array('class' => 'iconsmall visibleifjs', 'title' => '')),
4452 array(
4453 'class' => 'editing_title',
4454 'data-action' => 'edittitle',
4455 'title' => $str->edittitle,
4460 return '';