MDL-49688 navigation: First review fixes and version bump.
[moodle.git] / lib / deprecatedlib.php
CommitLineData
c861fe2f 1<?php
2
a5cb8d69 3// This file is part of Moodle - http://moodle.org/
4//
c861fe2f 5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
a5cb8d69 14//
c861fe2f 15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
c4d0753b 17
18/**
19 * deprecatedlib.php - Old functions retained only for backward compatibility
20 *
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
23 *
78bfb562 24 * @package core
c861fe2f 25 * @subpackage deprecated
78bfb562
PS
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
c861fe2f 28 * @deprecated
c4d0753b 29 */
30
78bfb562
PS
31defined('MOODLE_INTERNAL') || die();
32
d6e7a63d
PS
33/**
34 * Convert region timezone to php supported timezone
35 *
36 * @deprecated since Moodle 2.9
37 * @param string $tz value from ical file
38 * @return string $tz php supported timezone
39 */
40function calendar_normalize_tz($tz) {
41 debugging('calendar_normalize_tz() is deprecated, use core_date::normalise_timezone() instead', DEBUG_DEVELOPER);
42 return core_date::normalise_timezone($tz);
43}
44
45/**
46 * Returns a float which represents the user's timezone difference from GMT in hours
47 * Checks various settings and picks the most dominant of those which have a value
48 * @deprecated since Moodle 2.9
49 * @param float|int|string $tz timezone user timezone
50 * @return float
51 */
52function get_user_timezone_offset($tz = 99) {
53 debugging('get_user_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER);
54 $tz = core_date::get_user_timezone($tz);
55 $date = new DateTime('now', new DateTimeZone($tz));
56 return ($date->getOffset() - dst_offset_on(time(), $tz)) / (3600.0);
57}
58
59/**
60 * Returns an int which represents the systems's timezone difference from GMT in seconds
61 * @deprecated since Moodle 2.9
62 * @param float|int|string $tz timezone for which offset is required.
63 * {@link http://docs.moodle.org/dev/Time_API#Timezone}
64 * @return int|bool if found, false is timezone 99 or error
65 */
66function get_timezone_offset($tz) {
67 debugging('get_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER);
68 $date = new DateTime('now', new DateTimeZone(core_date::normalise_timezone($tz)));
69 return $date->getOffset() - dst_offset_on(time(), $tz);
70}
71
72/**
73 * Returns a list of timezones in the current language.
74 * @deprecated since Moodle 2.9
75 * @return array
76 */
77function get_list_of_timezones() {
78 debugging('update_timezone_records() is deprecated, use core_date::get_list_of_timezones() instead', DEBUG_DEVELOPER);
79 return core_date::get_list_of_timezones();
80}
81
82/**
83 * Previous internal API, it was not supposed to be used anywhere.
84 * @deprecated since Moodle 2.9
85 * @param array $timezones
86 */
87function update_timezone_records($timezones) {
88 debugging('update_timezone_records() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER);
89}
90
91/**
92 * Previous internal API, it was not supposed to be used anywhere.
93 * @deprecated since Moodle 2.9
94 * @param int $fromyear
95 * @param int $toyear
96 * @param mixed $strtimezone
97 * @return bool
98 */
99function calculate_user_dst_table($fromyear = null, $toyear = null, $strtimezone = null) {
100 debugging('calculate_user_dst_table() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER);
101 return false;
102}
103
104/**
105 * Previous internal API, it was not supposed to be used anywhere.
106 * @deprecated since Moodle 2.9
107 * @param int|string $year
108 * @param mixed $timezone
109 * @return null
110 */
111function dst_changes_for_year($year, $timezone) {
112 debugging('dst_changes_for_year() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER);
113 return null;
114}
115
116/**
117 * Previous internal API, it was not supposed to be used anywhere.
118 * @deprecated since Moodle 2.9
119 * @param string $timezonename
120 * @return array
121 */
122function get_timezone_record($timezonename) {
123 debugging('get_timezone_record() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER);
124 return array();
125}
126
7eaca5a8 127/**
b33da4bf 128 * Add an entry to the legacy log table.
7eaca5a8
129 *
130 * @deprecated since 2.7 use new events instead
131 *
132 * @param int $courseid The course id
133 * @param string $module The module name e.g. forum, journal, resource, course, user etc
134 * @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
135 * @param string $url The file and parameters used to see the results of the action
136 * @param string $info Additional description information
137 * @param int $cm The course_module->id if there is one
138 * @param int|stdClass $user If log regards $user other than $USER
139 * @return void
140 */
141function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0) {
b33da4bf 142 debugging('add_to_log() has been deprecated, please rewrite your code to the new events API', DEBUG_DEVELOPER);
7eaca5a8
143
144 // This is a nasty hack that allows us to put all the legacy stuff into legacy storage,
145 // this way we may move all the legacy settings there too.
146 $manager = get_log_manager();
147 if (method_exists($manager, 'legacy_add_to_log')) {
148 $manager->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
149 }
150}
151
114e3209
152/**
153 * Adds a file upload to the log table so that clam can resolve the filename to the user later if necessary
154 *
155 * @deprecated since 2.7 - use new file picker instead
156 *
114e3209
157 */
158function clam_log_upload($newfilepath, $course=null, $nourl=false) {
6dd7175a 159 throw new coding_exception('clam_log_upload() can not be used any more, please use file picker instead');
114e3209
160}
161
162/**
163 * This function logs to error_log and to the log table that an infected file has been found and what's happened to it.
164 *
165 * @deprecated since 2.7 - use new file picker instead
166 *
114e3209
167 */
168function clam_log_infected($oldfilepath='', $newfilepath='', $userid=0) {
6dd7175a 169 throw new coding_exception('clam_log_infected() can not be used any more, please use file picker instead');
114e3209
170}
171
172/**
173 * Some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path.
174 *
175 * @deprecated since 2.7 - use new file picker instead
176 *
114e3209
177 */
178function clam_change_log($oldpath, $newpath, $update=true) {
6dd7175a 179 throw new coding_exception('clam_change_log() can not be used any more, please use file picker instead');
114e3209
180}
181
182/**
183 * Replaces the given file with a string.
184 *
185 * @deprecated since 2.7 - infected files are now deleted in file picker
186 *
114e3209
187 */
188function clam_replace_infected_file($file) {
6dd7175a 189 throw new coding_exception('clam_replace_infected_file() can not be used any more, please use file picker instead');
114e3209
190}
191
7293a1aa
DP
192/**
193 * Deals with an infected file - either moves it to a quarantinedir
194 * (specified in CFG->quarantinedir) or deletes it.
195 *
196 * If moving it fails, it deletes it.
197 *
198 * @deprecated since 2.7
199 */
200function clam_handle_infected_file($file, $userid=0, $basiconly=false) {
201 throw new coding_exception('clam_handle_infected_file() can not be used any more, please use file picker instead');
202}
203
204/**
205 * If $CFG->runclamonupload is set, we scan a given file. (called from {@link preprocess_files()})
206 *
207 * @deprecated since 2.7
208 */
209function clam_scan_moodle_file(&$file, $course) {
210 throw new coding_exception('clam_scan_moodle_file() can not be used any more, please use file picker instead');
211}
212
213
6780a1d3
214/**
215 * Checks whether the password compatibility library will work with the current
216 * version of PHP. This cannot be done using PHP version numbers since the fix
217 * has been backported to earlier versions in some distributions.
218 *
219 * See https://github.com/ircmaxell/password_compat/issues/10 for more details.
220 *
221 * @deprecated since 2.7 PHP 5.4.x should be always compatible.
222 *
223 * @return bool always returns false
224 */
225function password_compat_not_supported() {
226 debugging('Do not use password_compat_not_supported() - bcrypt is now always available', DEBUG_DEVELOPER);
227 return false;
228}
229
d79d5ac2
PS
230/**
231 * Factory method that was returning moodle_session object.
232 *
233 * @deprecated since 2.6
234 * @return \core\session\manager
235 */
236function session_get_instance() {
237 // Note: the new session manager includes all methods from the original session class.
238 static $deprecatedinstance = null;
239
240 debugging('session_get_instance() is deprecated, use \core\session\manager instead', DEBUG_DEVELOPER);
241
242 if (!$deprecatedinstance) {
243 $deprecatedinstance = new \core\session\manager();
244 }
245
246 return $deprecatedinstance;
247}
248
249/**
250 * Returns true if legacy session used.
251 *
252 * @deprecated since 2.6
253 * @return bool
254 */
255function session_is_legacy() {
256 debugging('session_is_legacy() is deprecated, do not use any more', DEBUG_DEVELOPER);
257 return false;
258}
259
260/**
261 * Terminates all sessions, auth hooks are not executed.
262 * Useful in upgrade scripts.
263 *
264 * @deprecated since 2.6
265 */
266function session_kill_all() {
267 debugging('session_kill_all() is deprecated, use \core\session\manager::kill_all_sessions() instead', DEBUG_DEVELOPER);
268 \core\session\manager::kill_all_sessions();
269}
270
271/**
272 * Mark session as accessed, prevents timeouts.
273 *
274 * @deprecated since 2.6
275 * @param string $sid
276 */
277function session_touch($sid) {
278 debugging('session_touch() is deprecated, use \core\session\manager::touch_session() instead', DEBUG_DEVELOPER);
279 \core\session\manager::touch_session($sid);
280}
281
282/**
283 * Terminates one sessions, auth hooks are not executed.
284 *
285 * @deprecated since 2.6
286 * @param string $sid session id
287 */
288function session_kill($sid) {
289 debugging('session_kill() is deprecated, use \core\session\manager::kill_session() instead', DEBUG_DEVELOPER);
290 \core\session\manager::kill_session($sid);
291}
292
293/**
294 * Terminates all sessions of one user, auth hooks are not executed.
295 * NOTE: This can not work for file based sessions!
296 *
297 * @deprecated since 2.6
298 * @param int $userid user id
299 */
300function session_kill_user($userid) {
301 debugging('session_kill_user() is deprecated, use \core\session\manager::kill_user_sessions() instead', DEBUG_DEVELOPER);
302 \core\session\manager::kill_user_sessions($userid);
303}
304
d79d5ac2
PS
305/**
306 * Setup $USER object - called during login, loginas, etc.
307 *
308 * Call sync_user_enrolments() manually after log-in, or log-in-as.
309 *
310 * @deprecated since 2.6
311 * @param stdClass $user full user record object
312 * @return void
313 */
314function session_set_user($user) {
315 debugging('session_set_user() is deprecated, use \core\session\manager::set_user() instead', DEBUG_DEVELOPER);
316 \core\session\manager::set_user($user);
317}
318
319/**
320 * Is current $USER logged-in-as somebody else?
321 * @deprecated since 2.6
322 * @return bool
323 */
324function session_is_loggedinas() {
325 debugging('session_is_loggedinas() is deprecated, use \core\session\manager::is_loggedinas() instead', DEBUG_DEVELOPER);
326 return \core\session\manager::is_loggedinas();
327}
328
329/**
330 * Returns the $USER object ignoring current login-as session
331 * @deprecated since 2.6
332 * @return stdClass user object
333 */
334function session_get_realuser() {
335 debugging('session_get_realuser() is deprecated, use \core\session\manager::get_realuser() instead', DEBUG_DEVELOPER);
336 return \core\session\manager::get_realuser();
337}
338
339/**
340 * Login as another user - no security checks here.
341 * @deprecated since 2.6
342 * @param int $userid
343 * @param stdClass $context
344 * @return void
345 */
346function session_loginas($userid, $context) {
347 debugging('session_loginas() is deprecated, use \core\session\manager::loginas() instead', DEBUG_DEVELOPER);
348 \core\session\manager::loginas($userid, $context);
349}
350
6b32d6bc
PS
351/**
352 * Minify JavaScript files.
353 *
354 * @deprecated since 2.6
355 *
356 * @param array $files
357 * @return string
358 */
359function js_minify($files) {
360 debugging('js_minify() is deprecated, use core_minify::js_files() or core_minify::js() instead.');
361 return core_minify::js_files($files);
362}
363
364/**
365 * Minify CSS files.
366 *
367 * @deprecated since 2.6
368 *
369 * @param array $files
370 * @return string
371 */
372function css_minify_css($files) {
373 debugging('css_minify_css() is deprecated, use core_minify::css_files() or core_minify::css() instead.');
374 return core_minify::css_files($files);
375}
376
f0f0e1fe
PS
377/**
378 * Function to call all event handlers when triggering an event
379 *
380 * @deprecated since 2.6
381 *
382 * @param string $eventname name of the event
383 * @param mixed $eventdata event data object
384 * @return int number of failed events
385 */
386function events_trigger($eventname, $eventdata) {
9634712a 387 debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
f0f0e1fe
PS
388 return events_trigger_legacy($eventname, $eventdata);
389}
390
9e19a0f0
PS
391/**
392 * List all core subsystems and their location
393 *
394 * This is a whitelist of components that are part of the core and their
395 * language strings are defined in /lang/en/<<subsystem>>.php. If a given
396 * plugin is not listed here and it does not have proper plugintype prefix,
397 * then it is considered as course activity module.
398 *
399 * The location is optionally dirroot relative path. NULL means there is no special
400 * directory for this subsystem. If the location is set, the subsystem's
401 * renderer.php is expected to be there.
402 *
403 * @deprecated since 2.6, use core_component::get_core_subsystems()
404 *
405 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
406 * @return array of (string)name => (string|null)location
407 */
408function get_core_subsystems($fullpaths = false) {
409 global $CFG;
410
411 // NOTE: do not add any other debugging here, keep forever.
412
413 $subsystems = core_component::get_core_subsystems();
414
415 if ($fullpaths) {
416 return $subsystems;
417 }
418
419 debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
420
421 $dlength = strlen($CFG->dirroot);
422
423 foreach ($subsystems as $k => $v) {
424 if ($v === null) {
425 continue;
426 }
427 $subsystems[$k] = substr($v, $dlength+1);
428 }
429
430 return $subsystems;
431}
432
433/**
434 * Lists all plugin types.
435 *
436 * @deprecated since 2.6, use core_component::get_plugin_types()
437 *
438 * @param bool $fullpaths false means relative paths from dirroot
439 * @return array Array of strings - name=>location
440 */
441function get_plugin_types($fullpaths = true) {
442 global $CFG;
443
444 // NOTE: do not add any other debugging here, keep forever.
445
446 $types = core_component::get_plugin_types();
447
448 if ($fullpaths) {
449 return $types;
450 }
451
452 debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
453
454 $dlength = strlen($CFG->dirroot);
455
456 foreach ($types as $k => $v) {
457 if ($k === 'theme') {
458 $types[$k] = 'theme';
459 continue;
460 }
461 $types[$k] = substr($v, $dlength+1);
462 }
463
464 return $types;
465}
466
467/**
468 * Use when listing real plugins of one type.
469 *
470 * @deprecated since 2.6, use core_component::get_plugin_list()
471 *
472 * @param string $plugintype type of plugin
473 * @return array name=>fulllocation pairs of plugins of given type
474 */
475function get_plugin_list($plugintype) {
476
477 // NOTE: do not add any other debugging here, keep forever.
478
479 if ($plugintype === '') {
480 $plugintype = 'mod';
481 }
482
483 return core_component::get_plugin_list($plugintype);
484}
485
486/**
487 * Get a list of all the plugins of a given type that define a certain class
488 * in a certain file. The plugin component names and class names are returned.
489 *
490 * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
491 *
492 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
493 * @param string $class the part of the name of the class after the
494 * frankenstyle prefix. e.g 'thing' if you are looking for classes with
495 * names like report_courselist_thing. If you are looking for classes with
496 * the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
497 * @param string $file the name of file within the plugin that defines the class.
498 * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
499 * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
500 */
501function get_plugin_list_with_class($plugintype, $class, $file) {
502
503 // NOTE: do not add any other debugging here, keep forever.
504
505 return core_component::get_plugin_list_with_class($plugintype, $class, $file);
506}
507
508/**
509 * Returns the exact absolute path to plugin directory.
510 *
511 * @deprecated since 2.6, use core_component::get_plugin_directory()
512 *
513 * @param string $plugintype type of plugin
514 * @param string $name name of the plugin
515 * @return string full path to plugin directory; NULL if not found
516 */
517function get_plugin_directory($plugintype, $name) {
518
519 // NOTE: do not add any other debugging here, keep forever.
520
521 if ($plugintype === '') {
522 $plugintype = 'mod';
523 }
524
525 return core_component::get_plugin_directory($plugintype, $name);
526}
527
528/**
529 * Normalize the component name using the "frankenstyle" names.
530 *
531 * @deprecated since 2.6, use core_component::normalize_component()
532 *
533 * @param string $component
534 * @return array as (string)$type => (string)$plugin
535 */
536function normalize_component($component) {
537
538 // NOTE: do not add any other debugging here, keep forever.
539
540 return core_component::normalize_component($component);
541}
542
543/**
544 * Return exact absolute path to a plugin directory.
545 *
546 * @deprecated since 2.6, use core_component::normalize_component()
547 *
548 * @param string $component name such as 'moodle', 'mod_forum'
549 * @return string full path to component directory; NULL if not found
550 */
551function get_component_directory($component) {
552
553 // NOTE: do not add any other debugging here, keep forever.
554
555 return core_component::get_component_directory($component);
556}
557
558
559// === Deprecated before 2.6.0 ===
560
689096bc
PS
561/**
562 * Hack to find out the GD version by parsing phpinfo output
563 *
564 * @return int GD version (1, 2, or 0)
565 */
566function check_gd_version() {
567 // TODO: delete function in Moodle 2.7
568 debugging('check_gd_version() is deprecated, GD extension is always available now');
569
570 $gdversion = 0;
571
572 if (function_exists('gd_info')){
573 $gd_info = gd_info();
574 if (substr_count($gd_info['GD Version'], '2.')) {
575 $gdversion = 2;
576 } else if (substr_count($gd_info['GD Version'], '1.')) {
577 $gdversion = 1;
578 }
579
580 } else {
581 ob_start();
582 phpinfo(INFO_MODULES);
583 $phpinfo = ob_get_contents();
584 ob_end_clean();
585
586 $phpinfo = explode("\n", $phpinfo);
587
588
589 foreach ($phpinfo as $text) {
590 $parts = explode('</td>', $text);
591 foreach ($parts as $key => $val) {
592 $parts[$key] = trim(strip_tags($val));
593 }
594 if ($parts[0] == 'GD Version') {
595 if (substr_count($parts[1], '2.0')) {
596 $parts[1] = '2.0';
597 }
598 $gdversion = intval($parts[1]);
599 }
600 }
601 }
602
603 return $gdversion; // 1, 2 or 0
604}
605
b28247fe
PS
606/**
607 * Not used any more, the account lockout handling is now
608 * part of authenticate_user_login().
609 * @deprecated
610 */
611function update_login_count() {
c4844bf4
PS
612 // TODO: delete function in Moodle 2.6
613 debugging('update_login_count() is deprecated, all calls need to be removed');
b28247fe
PS
614}
615
616/**
617 * Not used any more, replaced by proper account lockout.
618 * @deprecated
619 */
620function reset_login_count() {
c4844bf4
PS
621 // TODO: delete function in Moodle 2.6
622 debugging('reset_login_count() is deprecated, all calls need to be removed');
b28247fe
PS
623}
624
c6d75bff
PS
625/**
626 * Insert or update log display entry. Entry may already exist.
627 * $module, $action must be unique
628 * @deprecated
629 *
630 * @param string $module
631 * @param string $action
632 * @param string $mtable
633 * @param string $field
634 * @return void
635 *
636 */
637function update_log_display_entry($module, $action, $mtable, $field) {
638 global $DB;
639
640 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
641}
642
35716b86 643/**
05226d76 644 * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
35716b86 645 * this was abused mostly for embedding of attachments
35716b86
PS
646 */
647function filter_text($text, $courseid = NULL) {
e4d9185e 648 throw new coding_exception('filter_text() can not be used anymore, use format_text(), format_string() etc instead.');
35716b86
PS
649}
650
17c70aa0 651/**
17c70aa0
PS
652 * @deprecated use $PAGE->https_required() instead
653 */
654function httpsrequired() {
e4d9185e 655 throw new coding_exception('httpsrequired() can not be used any more use $PAGE->https_required() instead.');
17c70aa0
PS
656}
657
50a8bd6c
PS
658/**
659 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
660 *
661 * @deprecated use moodle_url factory methods instead
662 *
663 * @param string $path Physical path to a file
664 * @param array $options associative array of GET variables to append to the URL
665 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
666 * @return string URL to file
667 */
668function get_file_url($path, $options=null, $type='coursefile') {
17c70aa0 669 global $CFG;
50a8bd6c
PS
670
671 $path = str_replace('//', '/', $path);
672 $path = trim($path, '/'); // no leading and trailing slashes
673
674 // type of file
675 switch ($type) {
676 case 'questionfile':
677 $url = $CFG->wwwroot."/question/exportfile.php";
678 break;
679 case 'rssfile':
680 $url = $CFG->wwwroot."/rss/file.php";
681 break;
682 case 'httpscoursefile':
683 $url = $CFG->httpswwwroot."/file.php";
684 break;
685 case 'coursefile':
686 default:
687 $url = $CFG->wwwroot."/file.php";
688 }
689
690 if ($CFG->slasharguments) {
691 $parts = explode('/', $path);
692 foreach ($parts as $key => $part) {
693 /// anchor dash character should not be encoded
694 $subparts = explode('#', $part);
695 $subparts = array_map('rawurlencode', $subparts);
696 $parts[$key] = implode('#', $subparts);
697 }
698 $path = implode('/', $parts);
699 $ffurl = $url.'/'.$path;
700 $separator = '?';
701 } else {
702 $path = rawurlencode('/'.$path);
703 $ffurl = $url.'?file='.$path;
704 $separator = '&amp;';
705 }
706
707 if ($options) {
708 foreach ($options as $name=>$value) {
709 $ffurl = $ffurl.$separator.$name.'='.$value;
710 $separator = '&amp;';
711 }
712 }
713
714 return $ffurl;
715}
716
613bbd7c 717/**
05226d76 718 * @deprecated use get_enrolled_users($context) instead.
613bbd7c 719 */
4f0c2d00 720function get_course_participants($courseid) {
e4d9185e 721 throw new coding_exception('get_course_participants() can not be used any more, use get_enrolled_users() instead.');
613bbd7c 722}
723
613bbd7c 724/**
05226d76 725 * @deprecated use is_enrolled($context, $userid) instead.
613bbd7c 726 */
4f0c2d00 727function is_course_participant($userid, $courseid) {
e4d9185e 728 throw new coding_exception('is_course_participant() can not be used any more, use is_enrolled() instead.');
613bbd7c 729}
730
731/**
732 * Searches logs to find all enrolments since a certain date
733 *
734 * used to print recent activity
735 *
613bbd7c 736 * @param int $courseid The course in question.
c861fe2f 737 * @param int $timestart The date to check forward of
613bbd7c 738 * @return object|false {@link $USER} records or false if error.
613bbd7c 739 */
740function get_recent_enrolments($courseid, $timestart) {
10df888a 741 global $DB;
364fffda 742
02ca2cad 743 debugging('get_recent_enrolments() is deprecated as it returned inaccurate results.', DEBUG_DEVELOPER);
613bbd7c 744
02ca2cad 745 $context = context_course::instance($courseid);
210751f6 746 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
10df888a 747 FROM {user} u, {role_assignments} ra, {log} l
748 WHERE l.time > ?
749 AND l.course = ?
750 AND l.module = 'course'
751 AND l.action = 'enrol'
9f43d70d 752 AND ".$DB->sql_cast_char2int('l.info')." = u.id
10df888a 753 AND u.id = ra.userid
754 AND ra.contextid ".get_related_contexts_string($context)."
210751f6
PS
755 GROUP BY u.id, u.firstname, u.lastname
756 ORDER BY MAX(l.time) ASC";
10df888a 757 $params = array($timestart, $courseid);
758 return $DB->get_records_sql($sql, $params);
613bbd7c 759}
760
ed5dd29f 761/**
05226d76 762 * @deprecated use clean_param($string, PARAM_FILE) instead.
ed5dd29f 763 */
764function detect_munged_arguments($string, $allowdots=1) {
e4d9185e 765 throw new coding_exception('detect_munged_arguments() can not be used any more, please use clean_param(,PARAM_FILE) instead.');
ed5dd29f 766}
767
9152fc99 768
0c6d2dd4 769/**
770 * Unzip one zip file to a destination dir
771 * Both parameters must be FULL paths
772 * If destination isn't specified, it will be the
773 * SAME directory where the zip file resides.
c861fe2f 774 *
775 * @global object
776 * @param string $zipfile The zip file to unzip
777 * @param string $destination The location to unzip to
778 * @param bool $showstatus_ignored Unused
0c6d2dd4 779 */
780function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
781 global $CFG;
782
783 //Extract everything from zipfile
784 $path_parts = pathinfo(cleardoubleslashes($zipfile));
785 $zippath = $path_parts["dirname"]; //The path of the zip file
786 $zipfilename = $path_parts["basename"]; //The name of the zip file
787 $extension = $path_parts["extension"]; //The extension of the file
788
789 //If no file, error
790 if (empty($zipfilename)) {
791 return false;
792 }
793
794 //If no extension, error
795 if (empty($extension)) {
796 return false;
797 }
798
799 //Clear $zipfile
800 $zipfile = cleardoubleslashes($zipfile);
801
802 //Check zipfile exists
803 if (!file_exists($zipfile)) {
804 return false;
805 }
806
807 //If no destination, passed let's go with the same directory
808 if (empty($destination)) {
809 $destination = $zippath;
810 }
811
812 //Clear $destination
813 $destpath = rtrim(cleardoubleslashes($destination), "/");
814
815 //Check destination path exists
816 if (!is_dir($destpath)) {
817 return false;
818 }
819
0b0bfa93 820 $packer = get_file_packer('application/zip');
821
822 $result = $packer->extract_to_pathname($zipfile, $destpath);
0c6d2dd4 823
824 if ($result === false) {
825 return false;
826 }
827
828 foreach ($result as $status) {
829 if ($status !== true) {
830 return false;
831 }
832 }
833
834 return true;
835}
836
ed94cb66 837/**
838 * Zip an array of files/dirs to a destination zip file
839 * Both parameters must be FULL paths to the files/dirs
c861fe2f 840 *
841 * @global object
842 * @param array $originalfiles Files to zip
843 * @param string $destination The destination path
844 * @return bool Outcome
ed94cb66 845 */
846function zip_files ($originalfiles, $destination) {
847 global $CFG;
848
849 //Extract everything from destination
850 $path_parts = pathinfo(cleardoubleslashes($destination));
851 $destpath = $path_parts["dirname"]; //The path of the zip file
852 $destfilename = $path_parts["basename"]; //The name of the zip file
853 $extension = $path_parts["extension"]; //The extension of the file
854
855 //If no file, error
856 if (empty($destfilename)) {
857 return false;
858 }
859
860 //If no extension, add it
861 if (empty($extension)) {
862 $extension = 'zip';
863 $destfilename = $destfilename.'.'.$extension;
864 }
865
866 //Check destination path exists
867 if (!is_dir($destpath)) {
868 return false;
869 }
870
871 //Check destination path is writable. TODO!!
872
873 //Clean destination filename
874 $destfilename = clean_filename($destfilename);
875
876 //Now check and prepare every file
877 $files = array();
878 $origpath = NULL;
879
880 foreach ($originalfiles as $file) { //Iterate over each file
881 //Check for every file
882 $tempfile = cleardoubleslashes($file); // no doubleslashes!
883 //Calculate the base path for all files if it isn't set
884 if ($origpath === NULL) {
885 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
886 }
887 //See if the file is readable
888 if (!is_readable($tempfile)) { //Is readable
889 continue;
890 }
891 //See if the file/dir is in the same directory than the rest
892 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
893 continue;
894 }
895 //Add the file to the array
896 $files[] = $tempfile;
897 }
898
899 $zipfiles = array();
900 $start = strlen($origpath)+1;
901 foreach($files as $file) {
902 $zipfiles[substr($file, $start)] = $file;
903 }
904
0b0bfa93 905 $packer = get_file_packer('application/zip');
ed94cb66 906
3ed22f1a 907 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
ed94cb66 908}
909
5bf243d1 910/**
05226d76 911 * @deprecated use groups_get_all_groups() instead.
5bf243d1 912 */
913function mygroupid($courseid) {
e4d9185e 914 throw new coding_exception('mygroupid() can not be used any more, please use groups_get_all_groups() instead.');
5bf243d1 915}
916
5bf243d1 917
5bf243d1 918/**
919 * Returns the current group mode for a given course or activity module
364fffda 920 *
5bf243d1 921 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
c861fe2f 922 *
923 * @param object $course Course Object
924 * @param object $cm Course Manager Object
925 * @return mixed $course->groupmode
5bf243d1 926 */
927function groupmode($course, $cm=null) {
928
929 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
930 return $cm->groupmode;
931 }
932 return $course->groupmode;
933}
934
c584346c 935/**
936 * Sets the current group in the session variable
937 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
938 * Sets currentgroup[$courseid] in the session variable appropriately.
939 * Does not do any permission checking.
c861fe2f 940 *
941 * @global object
c584346c 942 * @param int $courseid The course being examined - relates to id field in
943 * 'course' table.
944 * @param int $groupid The group being examined.
945 * @return int Current group id which was set by this function
946 */
947function set_current_group($courseid, $groupid) {
948 global $SESSION;
949 return $SESSION->currentgroup[$courseid] = $groupid;
950}
951
5bf243d1 952
5bf243d1 953/**
364fffda 954 * Gets the current group - either from the session variable or from the database.
5bf243d1 955 *
c861fe2f 956 * @global object
364fffda 957 * @param int $courseid The course being examined - relates to id field in
5bf243d1 958 * 'course' table.
364fffda 959 * @param bool $full If true, the return value is a full record object.
5bf243d1 960 * If false, just the id of the record.
c861fe2f 961 * @return int|bool
5bf243d1 962 */
963function get_current_group($courseid, $full = false) {
964 global $SESSION;
965
966 if (isset($SESSION->currentgroup[$courseid])) {
967 if ($full) {
968 return groups_get_group($SESSION->currentgroup[$courseid]);
969 } else {
970 return $SESSION->currentgroup[$courseid];
971 }
972 }
973
974 $mygroupid = mygroupid($courseid);
975 if (is_array($mygroupid)) {
976 $mygroupid = array_shift($mygroupid);
977 set_current_group($courseid, $mygroupid);
978 if ($full) {
979 return groups_get_group($mygroupid);
980 } else {
981 return $mygroupid;
982 }
983 }
984
985 if ($full) {
986 return false;
987 } else {
988 return 0;
989 }
990}
991
061e6b28 992/**
993 * Filter a user list and return only the users that can see the course module based on
994 * groups/permissions etc. It is assumed that the users are pre-filtered to those who are enrolled in the course.
995 *
996 * @category group
997 * @param stdClass|cm_info $cm The course module
998 * @param array $users An array of users, indexed by userid
999 * @return array A filtered list of users that can see the module, indexed by userid.
1000 * @deprecated Since Moodle 2.8
1001 */
1002function groups_filter_users_by_course_module_visible($cm, $users) {
1003 debugging('groups_filter_users_by_course_module_visible() is deprecated. ' .
1004 'Replace with a call to \core_availability\info_module::filter_user_list(), ' .
1005 'which does basically the same thing but includes other restrictions such ' .
1006 'as profile restrictions.', DEBUG_DEVELOPER);
1007 if (empty($users)) {
1008 return $users;
1009 }
1010 // Since this function allows stdclass, let's play it safe and ensure we
1011 // do have a cm_info.
1012 if (!($cm instanceof cm_info)) {
1013 $modinfo = get_fast_modinfo($cm->course);
1014 $cm = $modinfo->get_cm($cm->id);
1015 }
1016 $info = new \core_availability\info_module($cm);
1017 return $info->filter_user_list($users);
1018}
1019
1020/**
1021 * Determine if a course module is currently visible to a user
1022 *
1023 * Deprecated (it was never very useful as it only took into account the
1024 * groupmembersonly option and no other way of hiding activities). Always
1025 * returns true.
1026 *
1027 * @category group
1028 * @param stdClass|cm_info $cm The course module
1029 * @param int $userid The user to check against the group.
1030 * @return bool True
1031 * @deprecated Since Moodle 2.8
1032 */
1033function groups_course_module_visible($cm, $userid=null) {
1034 debugging('groups_course_module_visible() is deprecated and always returns ' .
1035 'true; use $cm->uservisible to decide whether the current user can ' .
1036 'access an activity.', DEBUG_DEVELOPER);
1037 return true;
1038}
5bf243d1 1039
8ec50604 1040/**
a8ab8de9
PS
1041 * Inndicates fatal error. This function was originally printing the
1042 * error message directly, since 2.0 it is throwing exception instead.
3400bf6c 1043 * The error printing is handled in default exception handler.
a8ab8de9 1044 *
8ec50604 1045 * Old method, don't call directly in new code - use print_error instead.
1046 *
8ec50604 1047 * @param string $message The message to display to the user about the error.
1048 * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
a8ab8de9 1049 * @return void, always throws moodle_exception
8ec50604 1050 */
245ac557 1051function error($message, $link='') {
78946b9b 1052 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
251387d0 1053}
8ec50604 1054
8ec50604 1055
b7009474 1056/**
1057 * @deprecated use $PAGE->theme->name instead.
b7009474 1058 */
1059function current_theme() {
e4d9185e 1060 throw new coding_exception('current_theme() can not be used any more, please use $PAGE->theme->name instead');
b7009474 1061}
1062
8954245a 1063/**
1064 * Prints some red text using echo
1065 *
1066 * @deprecated
1067 * @param string $error The text to be displayed in red
1068 */
1069function formerr($error) {
3bd6b994 1070 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
8954245a 1071 global $OUTPUT;
1072 echo $OUTPUT->error_text($error);
1073}
1074
34a2777c 1075/**
34a2777c 1076 * @deprecated use $OUTPUT->skip_link_target() in instead.
34a2777c 1077 */
1078function skip_main_destination() {
e4d9185e 1079 throw new coding_exception('skip_main_destination() can not be used any more, please use $OUTPUT->skip_link_target() instead.');
34a2777c 1080}
1081
34a2777c 1082/**
05226d76 1083 * @deprecated use $OUTPUT->container() instead.
34a2777c 1084 */
1085function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
e4d9185e 1086 throw new coding_exception('print_container() can not be used any more. Please use $OUTPUT->container() instead.');
34a2777c 1087}
1088
1089/**
05226d76 1090 * @deprecated use $OUTPUT->container_start() instead.
34a2777c 1091 */
1092function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
e4d9185e 1093 throw new coding_exception('print_container_start() can not be used any more. Please use $OUTPUT->container_start() instead.');
34a2777c 1094}
1095
1096/**
05226d76 1097 * @deprecated use $OUTPUT->container_end() instead.
34a2777c 1098 */
1099function print_container_end($return=false) {
e4d9185e 1100 throw new coding_exception('print_container_end() can not be used any more. Please use $OUTPUT->container_end() instead.');
34a2777c 1101}
1102
1103/**
1104 * Print a bold message in an optional color.
1105 *
1106 * @deprecated use $OUTPUT->notification instead.
1107 * @param string $message The message to print out
1108 * @param string $style Optional style to display message text in
1109 * @param string $align Alignment option
1110 * @param bool $return whether to return an output string or echo now
a5cb8d69 1111 * @return string|bool Depending on $result
34a2777c 1112 */
1113function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
1114 global $OUTPUT;
1115
1116 if ($classes == 'green') {
1117 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1118 $classes = 'notifysuccess'; // Backward compatible with old color system
1119 }
1120
1121 $output = $OUTPUT->notification($message, $classes);
1122 if ($return) {
1123 return $output;
1124 } else {
1125 echo $output;
1126 }
1127}
1128
1129/**
05226d76 1130 * @deprecated use $OUTPUT->continue_button() instead.
34a2777c 1131 */
1132function print_continue($link, $return = false) {
e4d9185e 1133 throw new coding_exception('print_continue() can not be used any more. Please use $OUTPUT->continue_button() instead.');
34a2777c 1134}
1135
34a2777c 1136/**
05226d76 1137 * @deprecated use $PAGE methods instead.
34a2777c 1138 */
1139function print_header($title='', $heading='', $navigation='', $focus='',
e120c61d 1140 $meta='', $cache=true, $button='&nbsp;', $menu=null,
34a2777c 1141 $usexml=false, $bodytags='', $return=false) {
34a2777c 1142
e4d9185e 1143 throw new coding_exception('print_header() can not be used any more. Please use $PAGE methods instead.');
34a2777c 1144}
1145
47a1aa45 1146/**
05226d76 1147 * @deprecated use $PAGE methods instead.
47a1aa45 1148 */
1149function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1150 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
1151
e4d9185e 1152 throw new coding_exception('print_header_simple() can not be used any more. Please use $PAGE methods instead.');
47a1aa45 1153}
1154
a5cb8d69 1155/**
05226d76 1156 * @deprecated use $OUTPUT->block() instead.
a5cb8d69 1157 */
1158function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
e4d9185e 1159 throw new coding_exception('print_side_block() can not be used any more, please use $OUTPUT->block() instead.');
a5cb8d69 1160}
1161
f8065dd2 1162/**
1163 * Prints a basic textarea field.
1164 *
1165 * @deprecated since Moodle 2.0
1166 *
1167 * When using this function, you should
1168 *
1169 * @global object
3d27180e 1170 * @param bool $unused No longer used.
f8065dd2 1171 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1172 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1173 * @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.
1174 * @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.
1175 * @param string $name Name to use for the textarea element.
1176 * @param string $value Initial content to display in the textarea.
1177 * @param int $obsolete deprecated
1178 * @param bool $return If false, will output string. If true, will return string value.
1179 * @param string $id CSS ID to add to the textarea element.
1180 * @return string|void depending on the value of $return
1181 */
3d27180e 1182function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
f8065dd2 1183 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1184 /// However, you can set them to zero to override the mincols and minrows values below.
1185
3d8a479b
MD
1186 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1187 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
f8065dd2 1188
1189 global $CFG;
1190
1191 $mincols = 65;
1192 $minrows = 10;
1193 $str = '';
1194
1195 if ($id === '') {
1196 $id = 'edit-'.$name;
1197 }
1198
3d27180e
DW
1199 if ($height && ($rows < $minrows)) {
1200 $rows = $minrows;
f8065dd2 1201 }
3d27180e
DW
1202 if ($width && ($cols < $mincols)) {
1203 $cols = $mincols;
f8065dd2 1204 }
1205
3d27180e
DW
1206 editors_head_setup();
1207 $editor = editors_get_preferred_editor(FORMAT_HTML);
1208 $editor->use_editor($id, array('legacy'=>true));
1209
0ac97084 1210 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
3d27180e 1211 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
f8065dd2 1212 $str .= '</textarea>'."\n";
1213
1214 if ($return) {
1215 return $str;
1216 }
1217 echo $str;
1218}
1219
4bcc5118
PS
1220/**
1221 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
1222 * Should be used only with htmleditor or textarea.
1223 *
1224 * @global object
1225 * @global object
1226 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
1227 * helpbutton.
1228 * @return string Link to help button
1229 */
1230function editorhelpbutton(){
1231 return '';
1232
1233 /// TODO: MDL-21215
f8065dd2 1234}
1235
4bcc5118
PS
1236/**
1237 * Print a help button.
1238 *
1239 * Prints a special help button for html editors (htmlarea in this case)
1240 *
1241 * @todo Write code into this function! detect current editor and print correct info
1242 * @global object
1243 * @return string Only returns an empty string at the moment
1244 */
1245function editorshortcutshelpbutton() {
1246 /// TODO: MDL-21215
1247
1248 global $CFG;
1249 //TODO: detect current editor and print correct info
4bcc5118
PS
1250 return '';
1251}
1252
1253
f8065dd2 1254/**
1255 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1256 * provide this function with the language strings for sortasc and sortdesc.
1257 *
05226d76 1258 * @deprecated use $OUTPUT->arrow() instead.
e4d9185e 1259 * @todo final deprecation of this function once MDL-45448 is resolved
f8065dd2 1260 *
f8065dd2 1261 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1262 *
1263 * @global object
1264 * @param string $direction 'up' or 'down'
1265 * @param string $strsort The language string used for the alt attribute of this image
1266 * @param bool $return Whether to print directly or return the html string
1267 * @return string|void depending on $return
1268 *
1269 */
1270function print_arrow($direction='up', $strsort=null, $return=false) {
f8065dd2 1271 global $OUTPUT;
1272
05226d76
DP
1273 debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER);
1274
f8065dd2 1275 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1276 return null;
1277 }
1278
1279 $return = null;
1280
1281 switch ($direction) {
1282 case 'up':
1283 $sortdir = 'asc';
1284 break;
1285 case 'down':
1286 $sortdir = 'desc';
1287 break;
1288 case 'move':
1289 $sortdir = 'asc';
1290 break;
1291 default:
1292 $sortdir = null;
1293 break;
1294 }
1295
1296 // Prepare language string
1297 $strsort = '';
1298 if (empty($strsort) && !empty($sortdir)) {
1299 $strsort = get_string('sort' . $sortdir, 'grades');
1300 }
1301
b5d0cafc 1302 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
f8065dd2 1303
1304 if ($return) {
1305 return $return;
1306 } else {
1307 echo $return;
1308 }
1309}
1310
8100c169 1311/**
1312 * Given an array of values, output the HTML for a select element with those options.
1313 *
1314 * @deprecated since Moodle 2.0
1315 *
1316 * Normally, you only need to use the first few parameters.
1317 *
1318 * @param array $options The options to offer. An array of the form
1319 * $options[{value}] = {text displayed for that option};
1320 * @param string $name the name of this form control, as in &lt;select name="..." ...
1321 * @param string $selected the option to select initially, default none.
1322 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
1323 * Set this to '' if you don't want a 'nothing is selected' option.
1324 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
1325 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
1326 * @param boolean $return if false (the default) the the output is printed directly, If true, the
1327 * generated HTML is returned as a string.
1328 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
1329 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
1330 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
1331 * then a suitable one is constructed.
1332 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
1333 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
1334 * $listbox is an integer, that number is used for size instead.
1335 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
1336 * when $listbox display is enabled
1337 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
1338 * then a suitable one is constructed.
1339 * @return string|void If $return=true returns string, else echo's and returns void
1340 */
1341function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
1342 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
1343 $id='', $listbox=false, $multiple=false, $class='') {
053203a8 1344
8100c169 1345 global $OUTPUT;
4461cc60 1346 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
053203a8 1347
1348 if ($script) {
1349 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
1350 }
4461cc60
PS
1351 $attributes = array();
1352 $attributes['disabled'] = $disabled ? 'disabled' : null;
1353 $attributes['tabindex'] = $tabindex ? $tabindex : null;
1354 $attributes['multiple'] = $multiple ? $multiple : null;
1355 $attributes['class'] = $class ? $class : null;
1356 $attributes['id'] = $id ? $id : null;
053203a8 1357
4461cc60 1358 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
053203a8 1359
1360 if ($return) {
1361 return $output;
1362 } else {
1363 echo $output;
8100c169 1364 }
053203a8 1365}
1366
c68e4098 1367/**
05226d76 1368 * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
c68e4098 1369 */
1370function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
e4d9185e
DP
1371 throw new coding_exception('print_scale_menu_helpbutton() can not be used any more. '.
1372 'Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.');
c68e4098 1373}
1374
49c8c8d2 1375/**
05226d76 1376 * @deprecated use html_writer::checkbox() instead.
49c8c8d2 1377 */
916276fc 1378function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
e4d9185e 1379 throw new coding_exception('print_checkbox() can not be used any more. Please use html_writer::checkbox() instead.');
49c8c8d2 1380}
6a5c71b9 1381
c351150f 1382/**
1383 * Prints the 'update this xxx' button that appears on module pages.
1384 *
1385 * @deprecated since Moodle 2.0
1386 *
1387 * @param string $cmid the course_module id.
1388 * @param string $ignored not used any more. (Used to be courseid.)
1389 * @param string $string the module name - get_string('modulename', 'xxx')
1390 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
1391 */
1392function update_module_button($cmid, $ignored, $string) {
d1f06fb5 1393 global $CFG, $OUTPUT;
c351150f 1394
bc2e0484 1395 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
c351150f 1396
d1f06fb5 1397 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
1398
b0c6dc1c 1399 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
d1f06fb5 1400 $string = get_string('updatethis', '', $string);
1401
5c2ed7e2
PS
1402 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
1403 return $OUTPUT->single_button($url, $string);
d1f06fb5 1404 } else {
1405 return '';
1406 }
c351150f 1407}
1408
7d2a0492 1409/**
05226d76 1410 * @deprecated use $OUTPUT->navbar() instead
7d2a0492 1411 */
1412function print_navigation ($navigation, $separator=0, $return=false) {
e4d9185e 1413 throw new coding_exception('print_navigation() can not be used any more, please update use $OUTPUT->navbar() instead.');
7d2a0492 1414}
1415
1416/**
05226d76 1417 * @deprecated Please use $PAGE->navabar methods instead.
7d2a0492 1418 */
1419function build_navigation($extranavlinks, $cm = null) {
e4d9185e 1420 throw new coding_exception('build_navigation() can not be used any more, please use $PAGE->navbar methods instead.');
7d2a0492 1421}
1422
1423/**
05226d76 1424 * @deprecated not relevant with global navigation in Moodle 2.x+
7d2a0492 1425 */
1426function navmenu($course, $cm=NULL, $targetwindow='self') {
e4d9185e 1427 throw new coding_exception('navmenu() can not be used any more, it is no longer relevant with global navigation.');
f43cdceb 1428}
76d9df3f
SH
1429
1430/// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
1431
1432
1433/**
05226d76 1434 * @deprecated please use calendar_event::create() instead.
76d9df3f
SH
1435 */
1436 function add_event($event) {
e4d9185e 1437 throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.');
76d9df3f
SH
1438}
1439
1440/**
1441 * Call this function to update an event in the calendar table
1442 * the event will be identified by the id field of the $event object.
1443 *
1444 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1445 * @return bool Success
05226d76 1446 * @deprecated please calendar_event->update() instead.
76d9df3f
SH
1447 */
1448function update_event($event) {
1449 global $CFG;
1450 require_once($CFG->dirroot.'/calendar/lib.php');
05226d76
DP
1451
1452 debugging('update_event() is deprecated, please use calendar_event->update() instead.', DEBUG_DEVELOPER);
76d9df3f
SH
1453 $event = (object)$event;
1454 $calendarevent = calendar_event::load($event->id);
1455 return $calendarevent->update($event);
1456}
1457
1458/**
05226d76 1459 * @deprecated please use calendar_event->delete() instead.
76d9df3f
SH
1460 */
1461function delete_event($id) {
e4d9185e
DP
1462 throw new coding_exception('delete_event() can not be used any more, please use '.
1463 'calendar_event->delete() instead.');
76d9df3f
SH
1464}
1465
1466/**
05226d76 1467 * @deprecated please use calendar_event->toggle_visibility(false) instead.
76d9df3f
SH
1468 */
1469function hide_event($event) {
e4d9185e
DP
1470 throw new coding_exception('hide_event() can not be used any more, please use '.
1471 'calendar_event->toggle_visibility(false) instead.');
76d9df3f
SH
1472}
1473
1474/**
05226d76 1475 * @deprecated please use calendar_event->toggle_visibility(true) instead.
76d9df3f
SH
1476 */
1477function show_event($event) {
e4d9185e
DP
1478 throw new coding_exception('show_event() can not be used any more, please use '.
1479 'calendar_event->toggle_visibility(true) instead.');
0189bf77 1480}
6f3451e5 1481
3fed29a7
PS
1482/**
1483 * Original singleton helper function, please use static methods instead,
6b61c2c4 1484 * ex: core_text::convert().
3fed29a7 1485 *
6b61c2c4
FM
1486 * @deprecated since Moodle 2.2 use core_text::xxxx() instead.
1487 * @see core_text
3fed29a7
PS
1488 */
1489function textlib_get_instance() {
6b61c2c4
FM
1490 throw new coding_exception('textlib_get_instance() can not be used any more, please use '.
1491 'core_text::functioname() instead.');
3fed29a7
PS
1492}
1493
ee7084e9
MG
1494/**
1495 * Gets the generic section name for a courses section
1496 *
1497 * The global function is deprecated. Each course format can define their own generic section name
1498 *
1499 * @deprecated since 2.4
1500 * @see get_section_name()
1501 * @see format_base::get_section_name()
1502 *
1503 * @param string $format Course format ID e.g. 'weeks' $course->format
1504 * @param stdClass $section Section object from database
1505 * @return Display name that the course format prefers, e.g. "Week 2"
1506 */
1507function get_generic_section_name($format, stdClass $section) {
1508 debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER);
1509 return get_string('sectionname', "format_$format") . ' ' . $section->section;
1510}
99e9f9a6
MG
1511
1512/**
1513 * Returns an array of sections for the requested course id
1514 *
1515 * It is usually not recommended to display the list of sections used
1516 * in course because the course format may have it's own way to do it.
1517 *
1518 * If you need to just display the name of the section please call:
1519 * get_section_name($course, $section)
1520 * {@link get_section_name()}
1521 * from 2.4 $section may also be just the field course_sections.section
1522 *
1523 * If you need the list of all sections it is more efficient to get this data by calling
b46be6ad 1524 * $modinfo = get_fast_modinfo($courseorid);
99e9f9a6
MG
1525 * $sections = $modinfo->get_section_info_all()
1526 * {@link get_fast_modinfo()}
1527 * {@link course_modinfo::get_section_info_all()}
1528 *
1529 * Information about one section (instance of section_info):
b46be6ad 1530 * get_fast_modinfo($courseorid)->get_sections_info($section)
99e9f9a6
MG
1531 * {@link course_modinfo::get_section_info()}
1532 *
1533 * @deprecated since 2.4
1534 *
1535 * @param int $courseid
1536 * @return array Array of section_info objects
1537 */
1538function get_all_sections($courseid) {
1539 global $DB;
1540 debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER);
b46be6ad 1541 return get_fast_modinfo($courseid)->get_section_info_all();
99e9f9a6 1542}
722e6ba9
MG
1543
1544/**
1545 * Given a full mod object with section and course already defined, adds this module to that section.
1546 *
1547 * This function is deprecated, please use {@link course_add_cm_to_section()}
1548 * Note that course_add_cm_to_section() also updates field course_modules.section and
1549 * calls rebuild_course_cache()
1550 *
1551 * @deprecated since 2.4
1552 *
1553 * @param object $mod
1554 * @param int $beforemod An existing ID which we will insert the new module before
1555 * @return int The course_sections ID where the mod is inserted
1556 */
44aa854e 1557function add_mod_to_section($mod, $beforemod = null) {
722e6ba9
MG
1558 debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER);
1559 global $DB;
b46be6ad 1560 return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod);
722e6ba9 1561}
d57aa283
MG
1562
1563/**
1564 * Returns a number of useful structures for course displays
1565 *
1566 * Function get_all_mods() is deprecated in 2.4
1567 * Instead of:
1568 * <code>
b46be6ad 1569 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
d57aa283
MG
1570 * </code>
1571 * please use:
1572 * <code>
b46be6ad 1573 * $mods = get_fast_modinfo($courseorid)->get_cms();
d57aa283
MG
1574 * $modnames = get_module_types_names();
1575 * $modnamesplural = get_module_types_names(true);
b46be6ad 1576 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
d57aa283
MG
1577 * </code>
1578 *
1579 * @deprecated since 2.4
1580 *
1581 * @param int $courseid id of the course to get info about
1582 * @param array $mods (return) list of course modules
1583 * @param array $modnames (return) list of names of all module types installed and available
1584 * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form
1585 * @param array $modnamesused (return) list of names of all module types used in the course
1586 */
1587function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
1588 debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER);
1589
1590 global $COURSE;
1591 $modnames = get_module_types_names();
1592 $modnamesplural= get_module_types_names(true);
b46be6ad 1593 $modinfo = get_fast_modinfo($courseid);
d57aa283
MG
1594 $mods = $modinfo->get_cms();
1595 $modnamesused = $modinfo->get_used_module_names();
1596}
4ede27b2
MG
1597
1598/**
1599 * Returns course section - creates new if does not exist yet
1600 *
1601 * This function is deprecated. To create a course section call:
b46be6ad 1602 * course_create_sections_if_missing($courseorid, $sections);
4ede27b2 1603 * to get the section call:
b46be6ad 1604 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
4ede27b2
MG
1605 *
1606 * @see course_create_sections_if_missing()
1607 * @see get_fast_modinfo()
1608 * @deprecated since 2.4
1609 *
1610 * @param int $section relative section number (field course_sections.section)
1611 * @param int $courseid
1612 * @return stdClass record from table {course_sections}
1613 */
1614function get_course_section($section, $courseid) {
1615 global $DB;
1616 debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER);
1617
1618 if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
1619 return $cw;
1620 }
1621 $cw = new stdClass();
1622 $cw->course = $courseid;
1623 $cw->section = $section;
1624 $cw->summary = "";
1625 $cw->summaryformat = FORMAT_HTML;
1626 $cw->sequence = "";
1627 $id = $DB->insert_record("course_sections", $cw);
1628 rebuild_course_cache($courseid, true);
1629 return $DB->get_record("course_sections", array("id"=>$id));
1630}
1b2581f4
MG
1631
1632/**
1633 * Return the start and end date of the week in Weekly course format
1634 *
1635 * It is not recommended to use this function outside of format_weeks plugin
1636 *
1637 * @deprecated since 2.4
1638 * @see format_weeks::get_section_dates()
1639 *
1640 * @param stdClass $section The course_section entry from the DB
1641 * @param stdClass $course The course entry from DB
1642 * @return stdClass property start for startdate, property end for enddate
1643 */
1644function format_weeks_get_section_dates($section, $course) {
1645 debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
1646 ' use it outside of format_weeks plugin', DEBUG_DEVELOPER);
1647 if (isset($course->format) && $course->format === 'weeks') {
1648 return course_get_format($course)->get_section_dates($section);
1649 }
1650 return null;
1651}
9a36be73
MG
1652
1653/**
1654 * Obtains shared data that is used in print_section when displaying a
1655 * course-module entry.
1656 *
1657 * Deprecated. Instead of:
1658 * list($content, $name) = get_print_section_cm_text($cm, $course);
1659 * use:
1660 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
1661 * $name = $cm->get_formatted_name();
1662 *
1663 * @deprecated since 2.5
1664 * @see cm_info::get_formatted_content()
1665 * @see cm_info::get_formatted_name()
1666 *
1667 * This data is also used in other areas of the code.
1668 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
1669 * @param object $course (argument not used)
1670 * @return array An array with the following values in this order:
1671 * $content (optional extra content for after link),
1672 * $instancename (text of link)
1673 */
1674function get_print_section_cm_text(cm_info $cm, $course) {
1675 debugging('Function get_print_section_cm_text() is deprecated. Please use '.
1676 'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
1677 DEBUG_DEVELOPER);
1678 return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
1679 $cm->get_formatted_name());
1680}
1681
1682/**
1683 * Prints the menus to add activities and resources.
1684 *
1685 * Deprecated. Please use:
1686 * $courserenderer = $PAGE->get_renderer('core', 'course');
1687 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
1688 * array('inblock' => $vertical));
1689 * echo $output; // if $return argument in print_section_add_menus() set to false
1690 *
1691 * @deprecated since 2.5
1692 * @see core_course_renderer::course_section_add_cm_control()
1693 *
1694 * @param stdClass $course course object, must be the same as set on the page
1695 * @param int $section relative section number (field course_sections.section)
1696 * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
1697 * @param bool $vertical Vertical orientation
1698 * @param bool $return Return the menus or send them to output
1699 * @param int $sectionreturn The section to link back to
1700 * @return void|string depending on $return
1701 */
1702function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
1703 global $PAGE;
1704 debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
1705 'function course_section_add_cm_control()', DEBUG_DEVELOPER);
1706 $output = '';
1707 $courserenderer = $PAGE->get_renderer('core', 'course');
1708 $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
1709 array('inblock' => $vertical));
1710 if ($return) {
1711 return $output;
1712 } else {
1713 echo $output;
1714 return !empty($output);
1715 }
1716}
1717
1718/**
1719 * Produces the editing buttons for a module
1720 *
1721 * Deprecated. Please use:
1722 * $courserenderer = $PAGE->get_renderer('core', 'course');
1723 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
1724 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
1725 *
1726 * @deprecated since 2.5
1727 * @see course_get_cm_edit_actions()
1728 * @see core_course_renderer->course_section_cm_edit_actions()
1729 *
1730 * @param stdClass $mod The module to produce editing buttons for
1731 * @param bool $absolute_ignored (argument ignored) - all links are absolute
1732 * @param bool $moveselect (argument ignored)
1733 * @param int $indent The current indenting
1734 * @param int $section The section to link back to
1735 * @return string XHTML for the editing buttons
1736 */
1737function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
1738 global $PAGE;
1739 debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
1740 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
1741 if (!($mod instanceof cm_info)) {
1742 $modinfo = get_fast_modinfo($mod->course);
1743 $mod = $modinfo->get_cm($mod->id);
1744 }
1745 $actions = course_get_cm_edit_actions($mod, $indent, $section);
1746
1747 $courserenderer = $PAGE->get_renderer('core', 'course');
1748 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
1749 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
1750 // the course page HTML will allow this to be removed.
1751 return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
1752}
1753
1754/**
1755 * Prints a section full of activity modules
1756 *
1757 * Deprecated. Please use:
1758 * $courserenderer = $PAGE->get_renderer('core', 'course');
1759 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
1760 * array('hidecompletion' => $hidecompletion));
1761 *
1762 * @deprecated since 2.5
1763 * @see core_course_renderer::course_section_cm_list()
1764 *
1765 * @param stdClass $course The course
1766 * @param stdClass|section_info $section The section object containing properties id and section
1767 * @param array $mods (argument not used)
1768 * @param array $modnamesused (argument not used)
1769 * @param bool $absolute (argument not used)
1770 * @param string $width (argument not used)
1771 * @param bool $hidecompletion Hide completion status
1772 * @param int $sectionreturn The section to return to
1773 * @return void
1774 */
1775function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
1776 global $PAGE;
1777 debugging('Function print_section() is deprecated. Please use course renderer function '.
1778 'course_section_cm_list() instead.', DEBUG_DEVELOPER);
1779 $displayoptions = array('hidecompletion' => $hidecompletion);
1780 $courserenderer = $PAGE->get_renderer('core', 'course');
1781 echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
1782}
00ba185d 1783
ff233851
MG
1784/**
1785 * Displays the list of courses with user notes
1786 *
1787 * This function is not used in core. It was replaced by block course_overview
1788 *
1789 * @deprecated since 2.5
1790 *
1791 * @param array $courses
1792 * @param array $remote_courses
1793 */
1794function print_overview($courses, array $remote_courses=array()) {
1795 global $CFG, $USER, $DB, $OUTPUT;
1796 debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER);
1797
1798 $htmlarray = array();
1799 if ($modules = $DB->get_records('modules')) {
1800 foreach ($modules as $mod) {
1801 if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
1802 include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
1803 $fname = $mod->name.'_print_overview';
1804 if (function_exists($fname)) {
1805 $fname($courses,$htmlarray);
1806 }
1807 }
1808 }
1809 }
1810 foreach ($courses as $course) {
1811 $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
1812 echo $OUTPUT->box_start('coursebox');
1813 $attributes = array('title' => s($fullname));
1814 if (empty($course->visible)) {
1815 $attributes['class'] = 'dimmed';
1816 }
1817 echo $OUTPUT->heading(html_writer::link(
1818 new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3);
1819 if (array_key_exists($course->id,$htmlarray)) {
1820 foreach ($htmlarray[$course->id] as $modname => $html) {
1821 echo $html;
1822 }
1823 }
1824 echo $OUTPUT->box_end();
1825 }
1826
1827 if (!empty($remote_courses)) {
1828 echo $OUTPUT->heading(get_string('remotecourses', 'mnet'));
1829 }
1830 foreach ($remote_courses as $course) {
1831 echo $OUTPUT->box_start('coursebox');
1832 $attributes = array('title' => s($course->fullname));
1833 echo $OUTPUT->heading(html_writer::link(
1834 new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)),
1835 format_string($course->shortname),
1836 $attributes) . ' (' . format_string($course->hostname) . ')', 3);
1837 echo $OUTPUT->box_end();
1838 }
1839}
a3f66bde
MG
1840
1841/**
1842 * This function trawls through the logs looking for
1843 * anything new since the user's last login
1844 *
1845 * This function was only used to print the content of block recent_activity
1846 * All functionality is moved into class {@link block_recent_activity}
1847 * and renderer {@link block_recent_activity_renderer}
1848 *
1849 * @deprecated since 2.5
1850 * @param stdClass $course
1851 */
1852function print_recent_activity($course) {
1853 // $course is an object
1854 global $CFG, $USER, $SESSION, $DB, $OUTPUT;
1855 debugging('Function print_recent_activity() is deprecated. It is not recommended to'.
1856 ' use it outside of block_recent_activity', DEBUG_DEVELOPER);
1857
1858 $context = context_course::instance($course->id);
1859
1860 $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
1861
1862 $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds
1863
1864 if (!isguestuser()) {
1865 if (!empty($USER->lastcourseaccess[$course->id])) {
1866 if ($USER->lastcourseaccess[$course->id] > $timestart) {
1867 $timestart = $USER->lastcourseaccess[$course->id];
1868 }
1869 }
1870 }
1871
1872 echo '<div class="activitydate">';
1873 echo get_string('activitysince', '', userdate($timestart));
1874 echo '</div>';
1875 echo '<div class="activityhead">';
1876
1877 echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>';
1878
1879 echo "</div>\n";
1880
1881 $content = false;
1882
1883/// Firstly, have there been any new enrolments?
1884
1885 $users = get_recent_enrolments($course->id, $timestart);
1886
1887 //Accessibility: new users now appear in an <OL> list.
1888 if ($users) {
1889 echo '<div class="newusers">';
1890 echo $OUTPUT->heading(get_string("newusers").':', 3);
1891 $content = true;
1892 echo "<ol class=\"list\">\n";
1893 foreach ($users as $user) {
1894 $fullname = fullname($user, $viewfullnames);
1895 echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
1896 }
1897 echo "</ol>\n</div>\n";
1898 }
1899
1900/// Next, have there been any modifications to the course structure?
1901
1902 $modinfo = get_fast_modinfo($course);
1903
1904 $changelist = array();
1905
1906 $logs = $DB->get_records_select('log', "time > ? AND course = ? AND
1907 module = 'course' AND
1908 (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
1909 array($timestart, $course->id), "id ASC");
1910
1911 if ($logs) {
1912 $actions = array('add mod', 'update mod', 'delete mod');
1913 $newgones = array(); // added and later deleted items
1914 foreach ($logs as $key => $log) {
1915 if (!in_array($log->action, $actions)) {
1916 continue;
1917 }
1918 $info = explode(' ', $log->info);
1919
1920 // note: in most cases I replaced hardcoding of label with use of
1921 // $cm->has_view() but it was not possible to do this here because
1922 // we don't necessarily have the $cm for it
1923 if ($info[0] == 'label') { // Labels are ignored in recent activity
1924 continue;
1925 }
1926
1927 if (count($info) != 2) {
1928 debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER);
1929 continue;
1930 }
1931
1932 $modname = $info[0];
1933 $instanceid = $info[1];
1934
1935 if ($log->action == 'delete mod') {
1936 // unfortunately we do not know if the mod was visible
1937 if (!array_key_exists($log->info, $newgones)) {
1938 $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
1939 $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
1940 }
1941 } else {
1942 if (!isset($modinfo->instances[$modname][$instanceid])) {
1943 if ($log->action == 'add mod') {
1944 // do not display added and later deleted activities
1945 $newgones[$log->info] = true;
1946 }
1947 continue;
1948 }
1949 $cm = $modinfo->instances[$modname][$instanceid];
1950 if (!$cm->uservisible) {
1951 continue;
1952 }
1953
1954 if ($log->action == 'add mod') {
1955 $stradded = get_string('added', 'moodle', get_string('modulename', $modname));
1956 $changelist[$log->info] = array('operation' => 'add', 'text' => "$stradded:<br /><a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true)."</a>");
1957
1958 } else if ($log->action == 'update mod' and empty($changelist[$log->info])) {
1959 $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
1960 $changelist[$log->info] = array('operation' => 'update', 'text' => "$strupdated:<br /><a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true)."</a>");
1961 }
1962 }
1963 }
1964 }
1965
1966 if (!empty($changelist)) {
1967 echo $OUTPUT->heading(get_string("courseupdates").':', 3);
1968 $content = true;
1969 foreach ($changelist as $changeinfo => $change) {
1970 echo '<p class="activity">'.$change['text'].'</p>';
1971 }
1972 }
1973
1974/// Now display new things from each module
1975
1976 $usedmodules = array();
1977 foreach($modinfo->cms as $cm) {
1978 if (isset($usedmodules[$cm->modname])) {
1979 continue;
1980 }
1981 if (!$cm->uservisible) {
1982 continue;
1983 }
1984 $usedmodules[$cm->modname] = $cm->modname;
1985 }
1986
1987 foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
1988 if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) {
1989 include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
1990 $print_recent_activity = $modname.'_print_recent_activity';
1991 if (function_exists($print_recent_activity)) {
1992 // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
1993 $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
1994 }
1995 } else {
1996 debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
1997 }
1998 }
1999
2000 if (! $content) {
2001 echo '<p class="message">'.get_string('nothingnew').'</p>';
2002 }
2003}
a347aee3
MN
2004
2005/**
2006 * Delete a course module and any associated data at the course level (events)
2007 * Until 1.5 this function simply marked a deleted flag ... now it
2008 * deletes it completely.
2009 *
2010 * @deprecated since 2.5
2011 *
2012 * @param int $id the course module id
2013 * @return boolean true on success, false on failure
2014 */
2015function delete_course_module($id) {
2016 debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER);
2017
2018 global $CFG, $DB;
2019
2020 require_once($CFG->libdir.'/gradelib.php');
2021 require_once($CFG->dirroot.'/blog/lib.php');
2022
2023 if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
2024 return true;
2025 }
2026 $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module));
2027 //delete events from calendar
2028 if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
2029 foreach($events as $event) {
2030 delete_event($event->id);
2031 }
2032 }
2033 //delete grade items, outcome items and grades attached to modules
2034 if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
2035 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) {
2036 foreach ($grade_items as $grade_item) {
2037 $grade_item->delete('moddelete');
2038 }
2039 }
2040 // Delete completion and availability data; it is better to do this even if the
2041 // features are not turned on, in case they were turned on previously (these will be
2042 // very quick on an empty table)
2043 $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id));
a347aee3
MN
2044 $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id,
2045 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
2046
2047 delete_context(CONTEXT_MODULE, $cm->id);
2048 return $DB->delete_records('course_modules', array('id'=>$cm->id));
2049}
2c49fb4c
MG
2050
2051/**
2052 * Prints the turn editing on/off button on course/index.php or course/category.php.
2053 *
2054 * @deprecated since 2.5
2055 *
2056 * @param integer $categoryid The id of the category we are showing, or 0 for system context.
2057 * @return string HTML of the editing button, or empty string, if this user is not allowed
2058 * to see it.
2059 */
2060function update_category_button($categoryid = 0) {
2061 global $CFG, $PAGE, $OUTPUT;
2062 debugging('Function update_category_button() is deprecated. Pages to view '.
2063 'and edit courses are now separate and no longer depend on editing mode.',
2064 DEBUG_DEVELOPER);
2065
2066 // Check permissions.
2067 if (!can_edit_in_category($categoryid)) {
2068 return '';
2069 }
2070
2071 // Work out the appropriate action.
2072 if ($PAGE->user_is_editing()) {
2073 $label = get_string('turneditingoff');
2074 $edit = 'off';
2075 } else {
2076 $label = get_string('turneditingon');
2077 $edit = 'on';
2078 }
2079
2080 // Generate the button HTML.
2081 $options = array('categoryedit' => $edit, 'sesskey' => sesskey());
2082 if ($categoryid) {
2083 $options['id'] = $categoryid;
2084 $page = 'category.php';
2085 } else {
2086 $page = 'index.php';
2087 }
2088 return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
2089}
4e0b6025
MG
2090
2091/**
2092 * This function recursively travels the categories, building up a nice list
2093 * for display. It also makes an array that list all the parents for each
2094 * category.
2095 *
2096 * For example, if you have a tree of categories like:
2097 * Miscellaneous (id = 1)
2098 * Subcategory (id = 2)
2099 * Sub-subcategory (id = 4)
2100 * Other category (id = 3)
2101 * Then after calling this function you will have
2102 * $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory',
2103 * 4 => 'Miscellaneous / Subcategory / Sub-subcategory',
2104 * 3 => 'Other category');
2105 * $parents = array(2 => array(1), 4 => array(1, 2));
2106 *
2107 * If you specify $requiredcapability, then only categories where the current
2108 * user has that capability will be added to $list, although all categories
2109 * will still be added to $parents, and if you only have $requiredcapability
2110 * in a child category, not the parent, then the child catgegory will still be
2111 * included.
2112 *
2113 * If you specify the option $excluded, then that category, and all its children,
2114 * are omitted from the tree. This is useful when you are doing something like
2115 * moving categories, where you do not want to allow people to move a category
2116 * to be the child of itself.
2117 *
2118 * This function is deprecated! For list of categories use
2119 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
2120 * For parents of one particular category use
2121 * coursecat::get($id)->get_parents()
2122 *
2123 * @deprecated since 2.5
2124 *
2125 * @param array $list For output, accumulates an array categoryid => full category path name
2126 * @param array $parents For output, accumulates an array categoryid => list of parent category ids.
2127 * @param string/array $requiredcapability if given, only categories where the current
2128 * user has this capability will be added to $list. Can also be an array of capabilities,
2129 * in which case they are all required.
2130 * @param integer $excludeid Omit this category and its children from the lists built.
2131 * @param object $category Not used
2132 * @param string $path Not used
2133 */
2134function make_categories_list(&$list, &$parents, $requiredcapability = '',
2135 $excludeid = 0, $category = NULL, $path = "") {
2136 global $CFG, $DB;
2137 require_once($CFG->libdir.'/coursecatlib.php');
2138
2139 debugging('Global function make_categories_list() is deprecated. Please use '.
2140 'coursecat::make_categories_list() and coursecat::get_parents()',
2141 DEBUG_DEVELOPER);
2142
2143 // For categories list use just this one function:
2144 if (empty($list)) {
2145 $list = array();
2146 }
2147 $list += coursecat::make_categories_list($requiredcapability, $excludeid);
2148
2149 // Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed.
2150 // Usually user needs only parents for one particular category, in which case should be used:
2151 // coursecat::get($categoryid)->get_parents()
2152 if (empty($parents)) {
2153 $parents = array();
2154 }
2155 $all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder');
2156 foreach ($all as $record) {
2157 if ($record->parent) {
2158 $parents[$record->id] = array_merge($parents[$record->parent], array($record->parent));
2159 } else {
2160 $parents[$record->id] = array();
2161 }
2162 }
2163}
deb65ced
MG
2164
2165/**
2166 * Delete category, but move contents to another category.
2167 *
2168 * This function is deprecated. Please use
2169 * coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2170 *
2171 * @see coursecat::delete_move()
2172 * @deprecated since 2.5
2173 *
2174 * @param object $category
2175 * @param int $newparentid category id
2176 * @return bool status
2177 */
2178function category_delete_move($category, $newparentid, $showfeedback=true) {
2179 global $CFG;
2180 require_once($CFG->libdir.'/coursecatlib.php');
2181
2182 debugging('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.');
2183
2184 return coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2185}
2186
2187/**
2188 * Recursively delete category including all subcategories and courses.
2189 *
2190 * This function is deprecated. Please use
2191 * coursecat::get($category->id)->delete_full($showfeedback);
2192 *
2193 * @see coursecat::delete_full()
2194 * @deprecated since 2.5
2195 *
2196 * @param stdClass $category
2197 * @param boolean $showfeedback display some notices
2198 * @return array return deleted courses
2199 */
2200function category_delete_full($category, $showfeedback=true) {
2201 global $CFG, $DB;
2202 require_once($CFG->libdir.'/coursecatlib.php');
2203
2204 debugging('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.');
2205
2206 return coursecat::get($category->id)->delete_full($showfeedback);
2207}
6e1d1ee0
MG
2208
2209/**
2210 * Efficiently moves a category - NOTE that this can have
2211 * a huge impact access-control-wise...
2212 *
2213 * This function is deprecated. Please use
2214 * $coursecat = coursecat::get($category->id);
2215 * if ($coursecat->can_change_parent($newparentcat->id)) {
2216 * $coursecat->change_parent($newparentcat->id);
2217 * }
2218 *
2219 * Alternatively you can use
2220 * $coursecat->update(array('parent' => $newparentcat->id));
2221 *
2222 * Function update() also updates field course_categories.timemodified
2223 *
2224 * @see coursecat::change_parent()
2225 * @see coursecat::update()
2226 * @deprecated since 2.5
2227 *
2228 * @param stdClass|coursecat $category
2229 * @param stdClass|coursecat $newparentcat
2230 */
2231function move_category($category, $newparentcat) {
2232 global $CFG;
2233 require_once($CFG->libdir.'/coursecatlib.php');
2234
2235 debugging('Function move_category() is deprecated. Please use coursecat::change_parent() instead.');
2236
2237 return coursecat::get($category->id)->change_parent($newparentcat->id);
2238}
2239
2240/**
2241 * Hide course category and child course and subcategories
2242 *
2243 * This function is deprecated. Please use
2244 * coursecat::get($category->id)->hide();
2245 *
2246 * @see coursecat::hide()
2247 * @deprecated since 2.5
2248 *
2249 * @param stdClass $category
2250 * @return void
2251 */
2252function course_category_hide($category) {
2253 global $CFG;
2254 require_once($CFG->libdir.'/coursecatlib.php');
2255
2256 debugging('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.');
2257
2258 coursecat::get($category->id)->hide();
2259}
2260
2261/**
2262 * Show course category and child course and subcategories
2263 *
2264 * This function is deprecated. Please use
2265 * coursecat::get($category->id)->show();
2266 *
2267 * @see coursecat::show()
2268 * @deprecated since 2.5
2269 *
2270 * @param stdClass $category
2271 * @return void
2272 */
2273function course_category_show($category) {
2274 global $CFG;
2275 require_once($CFG->libdir.'/coursecatlib.php');
2276
2277 debugging('Function course_category_show() is deprecated. Please use coursecat::show() instead.');
2278
2279 coursecat::get($category->id)->show();
2280}
2d8a275b
MG
2281
2282/**
2283 * Return specified category, default if given does not exist
2284 *
2285 * This function is deprecated.
2286 * To get the category with the specified it please use:
2287 * coursecat::get($catid, IGNORE_MISSING);
2288 * or
2289 * coursecat::get($catid, MUST_EXIST);
2290 *
2291 * To get the first available category please use
2292 * coursecat::get_default();
2293 *
2294 * class coursecat will also make sure that at least one category exists in DB
2295 *
2296 * @deprecated since 2.5
2297 * @see coursecat::get()
2298 * @see coursecat::get_default()
2299 *
2300 * @param int $catid course category id
2301 * @return object caregory
2302 */
2303function get_course_category($catid=0) {
2304 global $DB;
2305
2306 debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details');
2307
2308 $category = false;
2309
2310 if (!empty($catid)) {
2311 $category = $DB->get_record('course_categories', array('id'=>$catid));
2312 }
2313
2314 if (!$category) {
2315 // the first category is considered default for now
2316 if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) {
2317 $category = reset($category);
2318
2319 } else {
2320 $cat = new stdClass();
2321 $cat->name = get_string('miscellaneous');
2322 $cat->depth = 1;
2323 $cat->sortorder = MAX_COURSES_IN_CATEGORY;
2324 $cat->timemodified = time();
2325 $catid = $DB->insert_record('course_categories', $cat);
2326 // make sure category context exists
2327 context_coursecat::instance($catid);
2328 mark_context_dirty('/'.SYSCONTEXTID);
2329 fix_course_sortorder(); // Required to build course_categories.depth and .path.
2330 $category = $DB->get_record('course_categories', array('id'=>$catid));
2331 }
2332 }
2333
2334 return $category;
2335}
9bad61db
MG
2336
2337/**
2338 * Create a new course category and marks the context as dirty
2339 *
2340 * This function does not set the sortorder for the new category and
2341 * {@link fix_course_sortorder()} should be called after creating a new course
2342 * category
2343 *
2344 * Please note that this function does not verify access control.
2345 *
2346 * This function is deprecated. It is replaced with the method create() in class coursecat.
2347 * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action
2348 *
2349 * @deprecated since 2.5
2350 *
2351 * @param object $category All of the data required for an entry in the course_categories table
2352 * @return object new course category
2353 */
2354function create_course_category($category) {
2355 global $DB;
2356
2357 debugging('Function create_course_category() is deprecated. Please use coursecat::create(), see phpdocs for more details', DEBUG_DEVELOPER);
2358
2359 $category->timemodified = time();
2360 $category->id = $DB->insert_record('course_categories', $category);
2361 $category = $DB->get_record('course_categories', array('id' => $category->id));
2362
2363 // We should mark the context as dirty
2364 $category->context = context_coursecat::instance($category->id);
2365 $category->context->mark_dirty();
2366
2367 return $category;
2368}
bc81b006
MG
2369
2370/**
2371 * Returns an array of category ids of all the subcategories for a given
2372 * category.
2373 *
2374 * This function is deprecated.
2375 *
2376 * To get visible children categories of the given category use:
2377 * coursecat::get($categoryid)->get_children();
2378 * This function will return the array or coursecat objects, on each of them
2379 * you can call get_children() again
2380 *
2381 * @see coursecat::get()
2382 * @see coursecat::get_children()
2383 *
2384 * @deprecated since 2.5
2385 *
2386 * @global object
2387 * @param int $catid - The id of the category whose subcategories we want to find.
2388 * @return array of category ids.
2389 */
2390function get_all_subcategories($catid) {
2391 global $DB;
2392
2393 debugging('Function get_all_subcategories() is deprecated. Please use appropriate methods() of coursecat class. See phpdocs for more details',
2394 DEBUG_DEVELOPER);
2395
2396 $subcats = array();
2397
2398 if ($categories = $DB->get_records('course_categories', array('parent' => $catid))) {
2399 foreach ($categories as $cat) {
2400 array_push($subcats, $cat->id);
2401 $subcats = array_merge($subcats, get_all_subcategories($cat->id));
2402 }
2403 }
2404 return $subcats;
2405}
8db5dcb7
MG
2406
2407/**
2408 * Gets the child categories of a given courses category
2409 *
2410 * This function is deprecated. Please use functions in class coursecat:
2411 * - coursecat::get($parentid)->has_children()
2412 * tells if the category has children (visible or not to the current user)
2413 *
2414 * - coursecat::get($parentid)->get_children()
2415 * returns an array of coursecat objects, each of them represents a children category visible
2416 * to the current user (i.e. visible=1 or user has capability to view hidden categories)
2417 *
2418 * - coursecat::get($parentid)->get_children_count()
2419 * returns number of children categories visible to the current user
2420 *
2421 * - coursecat::count_all()
2422 * returns total count of all categories in the system (both visible and not)
2423 *
2424 * - coursecat::get_default()
2425 * returns the first category (usually to be used if count_all() == 1)
2426 *
2427 * @deprecated since 2.5
2428 *
2429 * @param int $parentid the id of a course category.
2430 * @return array all the child course categories.
2431 */
2432function get_child_categories($parentid) {
2433 global $DB;
2434 debugging('Function get_child_categories() is deprecated. Use coursecat::get_children() or see phpdocs for more details.',
2435 DEBUG_DEVELOPER);
2436
2437 $rv = array();
2438 $sql = context_helper::get_preload_record_columns_sql('ctx');
2439 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
2440 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
2441 array(CONTEXT_COURSECAT, $parentid));
2442 foreach ($records as $category) {
2443 context_helper::preload_from_record($category);
2444 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
2445 continue;
2446 }
2447 $rv[] = $category;
2448 }
2449 return $rv;
2450}
e1d54562
MG
2451
2452/**
2453 * Returns a sorted list of categories.
2454 *
2455 * When asking for $parent='none' it will return all the categories, regardless
2456 * of depth. Wheen asking for a specific parent, the default is to return
2457 * a "shallow" resultset. Pass false to $shallow and it will return all
2458 * the child categories as well.
2459 *
2460 * @deprecated since 2.5
2461 *
2462 * This function is deprecated. Use appropriate functions from class coursecat.
2463 * Examples:
2464 *
2465 * coursecat::get($categoryid)->get_children()
2466 * - returns all children of the specified category as instances of class
0198b4a5
MG
2467 * coursecat, which means on each of them method get_children() can be called again.
2468 * Only categories visible to the current user are returned.
e1d54562 2469 *
0198b4a5
MG
2470 * coursecat::get(0)->get_children()
2471 * - returns all top-level categories visible to the current user.
e1d54562
MG
2472 *
2473 * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()}
2474 *
0198b4a5
MG
2475 * coursecat::make_categories_list()
2476 * - returns an array of all categories id/names in the system.
2477 * Also only returns categories visible to current user and can additionally be
2478 * filetered by capability, see phpdocs to {@link coursecat::make_categories_list()}
2479 *
2480 * make_categories_options()
2481 * - Returns full course categories tree to be used in html_writer::select()
2482 *
e1d54562
MG
2483 * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()},
2484 * {@link coursecat::get_default()}
2485 *
2486 * The code of this deprecated function is left as it is because coursecat::get_children()
0198b4a5
MG
2487 * returns categories as instances of coursecat and not stdClass. Also there is no
2488 * substitute for retrieving the category with all it's subcategories. Plugin developers
2489 * may re-use the code/queries from this function in their plugins if really necessary.
e1d54562
MG
2490 *
2491 * @param string $parent The parent category if any
2492 * @param string $sort the sortorder
2493 * @param bool $shallow - set to false to get the children too
2494 * @return array of categories
2495 */
2496function get_categories($parent='none', $sort=NULL, $shallow=true) {
2497 global $DB;
2498
0198b4a5 2499 debugging('Function get_categories() is deprecated. Please use coursecat::get_children() or see phpdocs for other alternatives',
e1d54562
MG
2500 DEBUG_DEVELOPER);
2501
2502 if ($sort === NULL) {
2503 $sort = 'ORDER BY cc.sortorder ASC';
2504 } elseif ($sort ==='') {
2505 // leave it as empty
2506 } else {
2507 $sort = "ORDER BY $sort";
2508 }
2509
2510 list($ccselect, $ccjoin) = context_instance_preload_sql('cc.id', CONTEXT_COURSECAT, 'ctx');
2511
2512 if ($parent === 'none') {
2513 $sql = "SELECT cc.* $ccselect
2514 FROM {course_categories} cc
2515 $ccjoin
2516 $sort";
2517 $params = array();
2518
2519 } elseif ($shallow) {
2520 $sql = "SELECT cc.* $ccselect
2521 FROM {course_categories} cc
2522 $ccjoin
2523 WHERE cc.parent=?
2524 $sort";
2525 $params = array($parent);
2526
2527 } else {
2528 $sql = "SELECT cc.* $ccselect
2529 FROM {course_categories} cc
2530 $ccjoin
2531 JOIN {course_categories} ccp
2532 ON ((cc.parent = ccp.id) OR (cc.path LIKE ".$DB->sql_concat('ccp.path',"'/%'")."))
2533 WHERE ccp.id=?
2534 $sort";
2535 $params = array($parent);
2536 }
2537 $categories = array();
2538
2539 $rs = $DB->get_recordset_sql($sql, $params);
2540 foreach($rs as $cat) {
db314f34 2541 context_helper::preload_from_record($cat);
e1d54562
MG
2542 $catcontext = context_coursecat::instance($cat->id);
2543 if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) {
2544 $categories[$cat->id] = $cat;
2545 }
2546 }
2547 $rs->close();
2548 return $categories;
2549}
a8d683ca
MG
2550
2551/**
2552* Displays a course search form
2553*
2554* This function is deprecated, please use course renderer:
2555* $renderer = $PAGE->get_renderer('core', 'course');
2556* echo $renderer->course_search_form($value, $format);
2557*
2558* @deprecated since 2.5
2559*
2560* @param string $value default value to populate the search field
2561* @param bool $return if true returns the value, if false - outputs
2562* @param string $format display format - 'plain' (default), 'short' or 'navbar'
2563* @return null|string
2564*/
2565function print_course_search($value="", $return=false, $format="plain") {
2566 global $PAGE;
2567 debugging('Function print_course_search() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2568 $renderer = $PAGE->get_renderer('core', 'course');
2569 if ($return) {
2570 return $renderer->course_search_form($value, $format);
2571 } else {
2572 echo $renderer->course_search_form($value, $format);
2573 }
2574}
09ae7ee0
MG
2575
2576/**
2577 * Prints custom user information on the home page
2578 *
2579 * This function is deprecated, please use:
2580 * $renderer = $PAGE->get_renderer('core', 'course');
2581 * echo $renderer->frontpage_my_courses()
2582 *
2583 * @deprecated since 2.5
2584 */
2585function print_my_moodle() {
2586 global $PAGE;
2587 debugging('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()', DEBUG_DEVELOPER);
2588
2589 $renderer = $PAGE->get_renderer('core', 'course');
2590 echo $renderer->frontpage_my_courses();
2591}
2592
2593/**
2594 * Prints information about one remote course
2595 *
2596 * This function is deprecated, it is replaced with protected function
2597 * {@link core_course_renderer::frontpage_remote_course()}
2598 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
2599 *
2600 * @deprecated since 2.5
2601 */
2602function print_remote_course($course, $width="100%") {
2603 global $CFG, $USER;
2604 debugging('Function print_remote_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2605
2606 $linkcss = '';
2607
2608 $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}";
2609
2610 echo '<div class="coursebox remotecoursebox clearfix">';
2611 echo '<div class="info">';
2612 echo '<div class="name"><a title="'.get_string('entercourse').'"'.
2613 $linkcss.' href="'.$url.'">'
2614 . format_string($course->fullname) .'</a><br />'
2615 . format_string($course->hostname) . ' : '
2616 . format_string($course->cat_name) . ' : '
2617 . format_string($course->shortname). '</div>';
2618 echo '</div><div class="summary">';
2619 $options = new stdClass();
2620 $options->noclean = true;
2621 $options->para = false;
2622 $options->overflowdiv = true;
2623 echo format_text($course->summary, $course->summaryformat, $options);
2624 echo '</div>';
2625 echo '</div>';
2626}
2627
2628/**
2629 * Prints information about one remote host
2630 *
2631 * This function is deprecated, it is replaced with protected function
2632 * {@link core_course_renderer::frontpage_remote_host()}
2633 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
2634 *
2635 * @deprecated since 2.5
2636 */
2637function print_remote_host($host, $width="100%") {
2638 global $OUTPUT;
2639 debugging('Function print_remote_host() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2640
2641 $linkcss = '';
2642
2643 echo '<div class="coursebox clearfix">';
2644 echo '<div class="info">';
2645 echo '<div class="name">';
2646 echo '<img src="'.$OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="'.get_string('course').'" />';
2647 echo '<a title="'.s($host['name']).'" href="'.s($host['url']).'">'
2648 . s($host['name']).'</a> - ';
2649 echo $host['count'] . ' ' . get_string('courses');
2650 echo '</div>';
2651 echo '</div>';
2652 echo '</div>';
2653}
2654
2655/**
2656 * Recursive function to print out all the categories in a nice format
2657 * with or without courses included
2658 *
2659 * @deprecated since 2.5
2660 *
2661 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
2662 */
2663function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) {
2664 global $PAGE;
2665 debugging('Function print_whole_category_list() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2666
2667 $renderer = $PAGE->get_renderer('core', 'course');
2668 if ($showcourses && $category) {
2669 echo $renderer->course_category($category);
2670 } else if ($showcourses) {
2671 echo $renderer->frontpage_combo_list();
2672 } else {
2673 echo $renderer->frontpage_categories_list();
2674 }
2675}
2676
2677/**
2678 * Prints the category information.
2679 *
2680 * @deprecated since 2.5
2681 *
2682 * This function was only used by {@link print_whole_category_list()} but now
2683 * all course category rendering is moved to core_course_renderer.
2684 *
2685 * @param stdClass $category
2686 * @param int $depth The depth of the category.
2687 * @param bool $showcourses If set to true course information will also be printed.
2688 * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet.
2689 */
2690function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) {
2691 global $PAGE;
2692 debugging('Function print_category_info() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2693
2694 $renderer = $PAGE->get_renderer('core', 'course');
2695 echo $renderer->course_category($category);
2696}
2697
2698/**
2699 * This function generates a structured array of courses and categories.
2700 *
2701 * @deprecated since 2.5
2702 *
2703 * This function is not used any more in moodle core and course renderer does not have render function for it.
2704 * Combo list on the front page is displayed as:
2705 * $renderer = $PAGE->get_renderer('core', 'course');
2706 * echo $renderer->frontpage_combo_list()
2707 *
2708 * The new class {@link coursecat} stores the information about course category tree
2709 * To get children categories use:
2710 * coursecat::get($id)->get_children()
2711 * To get list of courses use:
2712 * coursecat::get($id)->get_courses()
2713 *
2714 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
2715 *
2716 * @param int $id
2717 * @param int $depth
2718 */
2719function get_course_category_tree($id = 0, $depth = 0) {
2720 global $DB, $CFG;
2721 if (!$depth) {
2722 debugging('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class, see function phpdocs for more info', DEBUG_DEVELOPER);
2723 }
2724
2725 $categories = array();
2726 $categoryids = array();
2727 $sql = context_helper::get_preload_record_columns_sql('ctx');
2728 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
2729 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
2730 array(CONTEXT_COURSECAT, $id));
2731 foreach ($records as $category) {
2732 context_helper::preload_from_record($category);
2733 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
2734 continue;
2735 }
2736 $categories[] = $category;
2737 $categoryids[$category->id] = $category;
2738 if (empty($CFG->maxcategorydepth) || $depth <= $CFG->maxcategorydepth) {
2739 list($category->categories, $subcategories) = get_course_category_tree($category->id, $depth+1);
2740 foreach ($subcategories as $subid=>$subcat) {
2741 $categoryids[$subid] = $subcat;
2742 }
2743 $category->courses = array();
2744 }
2745 }
2746
2747 if ($depth > 0) {
2748 // This is a recursive call so return the required array
2749 return array($categories, $categoryids);
2750 }
2751
2752 if (empty($categoryids)) {
2753 // No categories available (probably all hidden).
2754 return array();
2755 }
2756
2757 // The depth is 0 this function has just been called so we can finish it off
2758
2759 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
2760 list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids));
2761 $sql = "SELECT
2762 c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category
2763 $ccselect
2764 FROM {course} c
2765 $ccjoin
2766 WHERE c.category $catsql ORDER BY c.sortorder ASC";
2767 if ($courses = $DB->get_records_sql($sql, $catparams)) {
2768 // loop throught them
2769 foreach ($courses as $course) {
2770 if ($course->id == SITEID) {
2771 continue;
2772 }
db314f34 2773 context_helper::preload_from_record($course);
09ae7ee0
MG
2774 if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
2775 $categoryids[$course->category]->courses[$course->id] = $course;
2776 }
2777 }
2778 }
2779 return $categories;
2780}
2781
2782/**
2783 * Print courses in category. If category is 0 then all courses are printed.
2784 *
2785 * @deprecated since 2.5
2786 *
2787 * To print a generic list of courses use:
2788 * $renderer = $PAGE->get_renderer('core', 'course');
2789 * echo $renderer->courses_list($courses);
2790 *
2791 * To print list of all courses:
2792 * $renderer = $PAGE->get_renderer('core', 'course');
2793 * echo $renderer->frontpage_available_courses();
2794 *
2795 * To print list of courses inside category:
2796 * $renderer = $PAGE->get_renderer('core', 'course');
2797 * echo $renderer->course_category($category); // this will also print subcategories
2798 *
2799 * @param int|stdClass $category category object or id.
2800 * @return bool true if courses found and printed, else false.
2801 */
2802function print_courses($category) {
2803 global $CFG, $OUTPUT, $PAGE;
2804 require_once($CFG->libdir. '/coursecatlib.php');
2805 debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2806
2807 if (!is_object($category) && $category==0) {
2808 $courses = coursecat::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true));
2809 } else {
2810 $courses = coursecat::get($category->id)->get_courses(array('summary' => true, 'coursecontacts' => true));
2811 }
2812
2813 if ($courses) {
2814 $renderer = $PAGE->get_renderer('core', 'course');
2815 echo $renderer->courses_list($courses);
2816 } else {
2817 echo $OUTPUT->heading(get_string("nocoursesyet"));
2818 $context = context_system::instance();
2819 if (has_capability('moodle/course:create', $context)) {
2820 $options = array();
2821 if (!empty($category->id)) {
2822 $options['category'] = $category->id;
2823 } else {
2824 $options['category'] = $CFG->defaultrequestcategory;
2825 }
2826 echo html_writer::start_tag('div', array('class'=>'addcoursebutton'));
2827 echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
2828 echo html_writer::end_tag('div');
2829 return false;
2830 }
2831 }
2832 return true;
2833}
2834
2835/**
2836 * Print a description of a course, suitable for browsing in a list.
2837 *
2838 * @deprecated since 2.5
2839 *
2840 * Please use course renderer to display a course information box.
2841 * $renderer = $PAGE->get_renderer('core', 'course');
2842 * echo $renderer->courses_list($courses); // will print list of courses
2843 * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox
2844 *
2845 * @param object $course the course object.
2846 * @param string $highlightterms Ignored in this deprecated function!
2847 */
2848function print_course($course, $highlightterms = '') {
2849 global $PAGE;
2850
2851 debugging('Function print_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2852 $renderer = $PAGE->get_renderer('core', 'course');
2853 // Please note, correct would be to use $renderer->coursecat_coursebox() but this function is protected.
2854 // To print list of courses use $renderer->courses_list();
2855 echo $renderer->course_info_box($course);
2856}
2857
2858/**
2859 * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category.
2860 *
2861 * @deprecated since 2.5
2862 *
2863 * This function is not used any more in moodle core and course renderer does not have render function for it.
2864 * Combo list on the front page is displayed as:
2865 * $renderer = $PAGE->get_renderer('core', 'course');
2866 * echo $renderer->frontpage_combo_list()
2867 *
2868 * The new class {@link coursecat} stores the information about course category tree
2869 * To get children categories use:
2870 * coursecat::get($id)->get_children()
2871 * To get list of courses use:
2872 * coursecat::get($id)->get_courses()
2873 *
2874 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
2875 *
2876 * @param int $categoryid
2877 * @return array
2878 */
2879function get_category_courses_array($categoryid = 0) {
2880 debugging('Function get_category_courses_array() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
2881 $tree = get_course_category_tree($categoryid);
2882 $flattened = array();
2883 foreach ($tree as $category) {
2884 get_category_courses_array_recursively($flattened, $category);
2885 }
2886 return $flattened;
2887}
2888
2889/**
2890 * Recursive function to help flatten the course category tree.
2891 *
2892 * @deprecated since 2.5
2893 *
2894 * Was intended to be called from {@link get_category_courses_array()}
2895 *
2896 * @param array &$flattened An array passed by reference in which to store courses for each category.
2897 * @param stdClass $category The category to get courses for.
2898 */
2899function get_category_courses_array_recursively(array &$flattened, $category) {
2900 debugging('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
2901 $flattened[$category->id] = $category->courses;
2902 foreach ($category->categories as $childcategory) {
2903 get_category_courses_array_recursively($flattened, $childcategory);
2904 }
2905}
2906
7ac18cf9
AA
2907/**
2908 * Returns a URL based on the context of the current page.
2909 * This URL points to blog/index.php and includes filter parameters appropriate for the current page.
2910 *
2911 * @param stdclass $context
2912 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
2913 * @todo Remove this in 2.7
2914 * @return string
2915 */
2916function blog_get_context_url($context=null) {
2917 global $CFG;
2918
2919 debugging('Function blog_get_context_url() is deprecated, getting params from context is not reliable for blogs.', DEBUG_DEVELOPER);
2920 $viewblogentriesurl = new moodle_url('/blog/index.php');
2921
2922 if (empty($context)) {
2923 global $PAGE;
2924 $context = $PAGE->context;
2925 }
2926
2927 // Change contextlevel to SYSTEM if viewing the site course
2928 if ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) {
2929 $context = context_system::instance();
2930 }
2931
2932 $filterparam = '';
2933 $strlevel = '';
2934
2935 switch ($context->contextlevel) {
2936 case CONTEXT_SYSTEM:
2937 case CONTEXT_BLOCK:
2938 case CONTEXT_COURSECAT:
2939 break;
2940 case CONTEXT_COURSE:
2941 $filterparam = 'courseid';
2942 $strlevel = get_string('course');
2943 break;
2944 case CONTEXT_MODULE:
2945 $filterparam = 'modid';
329846f1 2946 $strlevel = $context->get_context_name();
7ac18cf9
AA
2947 break;
2948 case CONTEXT_USER:
2949 $filterparam = 'userid';
2950 $strlevel = get_string('user');
2951 break;
2952 }
2953
2954 if (!empty($filterparam)) {
2955 $viewblogentriesurl->param($filterparam, $context->instanceid);
2956 }
2957
2958 return $viewblogentriesurl;
2959}
2960
09ae7ee0
MG
2961/**
2962 * Retrieve course records with the course managers and other related records
2963 * that we need for print_course(). This allows print_courses() to do its job
2964 * in a constant number of DB queries, regardless of the number of courses,
2965 * role assignments, etc.
2966 *
2967 * The returned array is indexed on c.id, and each course will have
2968 * - $course->managers - array containing RA objects that include a $user obj
2969 * with the minimal fields needed for fullname()
2970 *
2971 * @deprecated since 2.5
2972 *
2973 * To get list of all courses with course contacts ('managers') use
2974 * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true));
2975 *
2976 * To get list of courses inside particular category use
2977 * coursecat::get($id)->get_courses(array('coursecontacts' => true));
2978 *
2979 * Additionally you can specify sort order, offset and maximum number of courses,
2980 * see {@link coursecat::get_courses()}
2981 *
2982 * Please note that code of this function is not changed to use coursecat class because
2983 * coursecat::get_courses() returns result in slightly different format. Also note that
2984 * get_courses_wmanagers() DOES NOT check that users are enrolled in the course and
2985 * coursecat::get_courses() does.
2986 *
2987 * @global object
2988 * @global object
2989 * @global object
2990 * @uses CONTEXT_COURSE
2991 * @uses CONTEXT_SYSTEM
2992 * @uses CONTEXT_COURSECAT
2993 * @uses SITEID
2994 * @param int|string $categoryid Either the categoryid for the courses or 'all'
2995 * @param string $sort A SQL sort field and direction
2996 * @param array $fields An array of additional fields to fetch
2997 * @return array
2998 */
2999function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) {
3000 /*
3001 * The plan is to
3002 *
3003 * - Grab the courses JOINed w/context
3004 *
3005 * - Grab the interesting course-manager RAs
3006 * JOINed with a base user obj and add them to each course
3007 *
3008 * So as to do all the work in 2 DB queries. The RA+user JOIN
3009 * ends up being pretty expensive if it happens over _all_
3010 * courses on a large site. (Are we surprised!?)
3011 *
3012 * So this should _never_ get called with 'all' on a large site.
3013 *
3014 */
3015 global $USER, $CFG, $DB;
3016 debugging('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()', DEBUG_DEVELOPER);
3017
3018 $params = array();
3019 $allcats = false; // bool flag
3020 if ($categoryid === 'all') {
3021 $categoryclause = '';
3022 $allcats = true;
3023 } elseif (is_numeric($categoryid)) {
3024 $categoryclause = "c.category = :catid";
3025 $params['catid'] = $categoryid;
3026 } else {
3027 debugging("Could not recognise categoryid = $categoryid");
3028 $categoryclause = '';
3029 }
3030
3031 $basefields = array('id', 'category', 'sortorder',
3032 'shortname', 'fullname', 'idnumber',
3033 'startdate', 'visible',
3034 'newsitems', 'groupmode', 'groupmodeforce');
3035
3036 if (!is_null($fields) && is_string($fields)) {
3037 if (empty($fields)) {
3038 $fields = $basefields;
3039 } else {
3040 // turn the fields from a string to an array that
3041 // get_user_courses_bycap() will like...
3042 $fields = explode(',',$fields);
3043 $fields = array_map('trim', $fields);
3044 $fields = array_unique(array_merge($basefields, $fields));
3045 }
3046 } elseif (is_array($fields)) {
3047 $fields = array_merge($basefields,$fields);
3048 }
3049 $coursefields = 'c.' .join(',c.', $fields);
3050
3051 if (empty($sort)) {
3052 $sortstatement = "";
3053 } else {
3054 $sortstatement = "ORDER BY $sort";
3055 }
3056
3057 $where = 'WHERE c.id != ' . SITEID;
3058 if ($categoryclause !== ''){
3059 $where = "$where AND $categoryclause";
3060 }
3061
3062 // pull out all courses matching the cat
3063 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3064 $sql = "SELECT $coursefields $ccselect
3065 FROM {course} c
3066 $ccjoin
3067 $where
3068 $sortstatement";
3069
3070 $catpaths = array();
3071 $catpath = NULL;
3072 if ($courses = $DB->get_records_sql($sql, $params)) {
3073 // loop on courses materialising
3074 // the context, and prepping data to fetch the
3075 // managers efficiently later...
3076 foreach ($courses as $k => $course) {
db314f34 3077 context_helper::preload_from_record($course);
09ae7ee0
MG
3078 $coursecontext = context_course::instance($course->id);
3079 $courses[$k] = $course;
3080 $courses[$k]->managers = array();
3081 if ($allcats === false) {
3082 // single cat, so take just the first one...
3083 if ($catpath === NULL) {
3084 $catpath = preg_replace(':/\d+$:', '', $coursecontext->path);
3085 }
3086 } else {
3087 // chop off the contextid of the course itself
3088 // like dirname() does...
3089 $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path);
3090 }
3091 }
3092 } else {
3093 return array(); // no courses!
3094 }
3095
3096 $CFG->coursecontact = trim($CFG->coursecontact);
3097 if (empty($CFG->coursecontact)) {
3098 return $courses;
3099 }
3100
3101 $managerroles = explode(',', $CFG->coursecontact);
3102 $catctxids = '';
3103 if (count($managerroles)) {
3104 if ($allcats === true) {
3105 $catpaths = array_unique($catpaths);
3106 $ctxids = array();
3107 foreach ($catpaths as $cpath) {
3108 $ctxids = array_merge($ctxids, explode('/',substr($cpath,1)));
3109 }
3110 $ctxids = array_unique($ctxids);
3111 $catctxids = implode( ',' , $ctxids);
3112 unset($catpaths);
3113 unset($cpath);
3114 } else {
3115 // take the ctx path from the first course
3116 // as all categories will be the same...
3117 $catpath = substr($catpath,1);
3118 $catpath = preg_replace(':/\d+$:','',$catpath);
3119 $catctxids = str_replace('/',',',$catpath);
3120 }
3121 if ($categoryclause !== '') {
3122 $categoryclause = "AND $categoryclause";
3123 }
3124 /*
3125 * Note: Here we use a LEFT OUTER JOIN that can
3126 * "optionally" match to avoid passing a ton of context
3127 * ids in an IN() clause. Perhaps a subselect is faster.
3128 *
3129 * In any case, this SQL is not-so-nice over large sets of
3130 * courses with no $categoryclause.
3131 *
3132 */
3133 $sql = "SELECT ctx.path, ctx.instanceid, ctx.contextlevel,
3134 r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname,
3135 rn.name AS rolecoursealias, u.id AS userid, u.firstname, u.lastname
3136 FROM {role_assignments} ra
3137 JOIN {context} ctx ON ra.contextid = ctx.id
3138 JOIN {user} u ON ra.userid = u.id
3139 JOIN {role} r ON ra.roleid = r.id
3140 LEFT JOIN {role_names} rn ON (rn.contextid = ctx.id AND rn.roleid = r.id)
3141 LEFT OUTER JOIN {course} c
3142 ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.")
3143 WHERE ( c.id IS NOT NULL";
3144 // under certain conditions, $catctxids is NULL
3145 if($catctxids == NULL){
3146 $sql .= ") ";
3147 }else{
3148 $sql .= " OR ra.contextid IN ($catctxids) )";
3149 }
3150
3151 $sql .= "AND ra.roleid IN ({$CFG->coursecontact})
3152 $categoryclause
3153 ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC";
3154 $rs = $DB->get_recordset_sql($sql, $params);
3155
3156 // This loop is fairly stupid as it stands - might get better
3157 // results doing an initial pass clustering RAs by path.
3158 foreach($rs as $ra) {
3159 $user = new stdClass;
3160 $user->id = $ra->userid; unset($ra->userid);
3161 $user->firstname = $ra->firstname; unset($ra->firstname);
3162 $user->lastname = $ra->lastname; unset($ra->lastname);
3163 $ra->user = $user;
3164 if ($ra->contextlevel == CONTEXT_SYSTEM) {
3165 foreach ($courses as $k => $course) {
3166 $courses[$k]->managers[] = $ra;
3167 }
3168 } else if ($ra->contextlevel == CONTEXT_COURSECAT) {
3169 if ($allcats === false) {
3170 // It always applies
3171 foreach ($courses as $k => $course) {
3172 $courses[$k]->managers[] = $ra;
3173 }
3174 } else {
3175 foreach ($courses as $k => $course) {
3176 $coursecontext = context_course::instance($course->id);
3177 // Note that strpos() returns 0 as "matched at pos 0"
3178 if (strpos($coursecontext->path, $ra->path.'/') === 0) {
3179 // Only add it to subpaths
3180 $courses[$k]->managers[] = $ra;
3181 }
3182 }
3183 }
3184 } else { // course-level
3185 if (!array_key_exists($ra->instanceid, $courses)) {
3186 //this course is not in a list, probably a frontpage course
3187 continue;
3188 }
3189 $courses[$ra->instanceid]->managers[] = $ra;
3190 }
3191 }
3192 $rs->close();
3193 }
3194
3195 return $courses;
3196}
c269b9d1
MG
3197
3198/**
3199 * Converts a nested array tree into HTML ul:li [recursive]
3200 *
3201 * @deprecated since 2.5
3202 *
3203 * @param array $tree A tree array to convert
3204 * @param int $row Used in identifying the iteration level and in ul classes
3205 * @return string HTML structure
3206 */
3207function convert_tree_to_html($tree, $row=0) {
3208 debugging('Function convert_tree_to_html() is deprecated since Moodle 2.5. Consider using class tabtree and core_renderer::render_tabtree()', DEBUG_DEVELOPER);
3209
3210 $str = "\n".'<ul class="tabrow'.$row.'">'."\n";
3211
3212 $first = true;
3213 $count = count($tree);
3214
3215 foreach ($tree as $tab) {
3216 $count--; // countdown to zero
3217
3218 $liclass = '';
3219
3220 if ($first && ($count == 0)) { // Just one in the row
3221 $liclass = 'first last';
3222 $first = false;
3223 } else if ($first) {
3224 $liclass = 'first';
3225 $first = false;
3226 } else if ($count == 0) {
3227 $liclass = 'last';
3228 }
3229
3230 if ((empty($tab->subtree)) && (!empty($tab->selected))) {
3231 $liclass .= (empty($liclass)) ? 'onerow' : ' onerow';
3232 }
3233
3234 if ($tab->inactive || $tab->active || $tab->selected) {
3235 if ($tab->selected) {
3236 $liclass .= (empty($liclass)) ? 'here selected' : ' here selected';
3237 } else if ($tab->active) {
3238 $liclass .= (empty($liclass)) ? 'here active' : ' here active';
3239 }
3240 }
3241
3242 $str .= (!empty($liclass)) ? '<li class="'.$liclass.'">' : '<li>';
3243
3244 if ($tab->inactive || $tab->active || ($tab->selected && !$tab->linkedwhenselected)) {
3245 // The a tag is used for styling
3246 $str .= '<a class="nolink"><span>'.$tab->text.'</span></a>';
3247 } else {
3248 $str .= '<a href="'.$tab->link.'" title="'.$tab->title.'"><span>'.$tab->text.'</span></a>';
3249 }
3250
3251 if (!empty($tab->subtree)) {
3252 $str .= convert_tree_to_html($tab->subtree, $row+1);
3253 } else if ($tab->selected) {
3254 $str .= '<div class="tabrow'.($row+1).' empty">&nbsp;</div>'."\n";
3255 }
3256
3257 $str .= ' </li>'."\n";
3258 }
3259 $str .= '</ul>'."\n";
3260
3261 return $str;
3262}
3263
3264/**
3265 * Convert nested tabrows to a nested array
3266 *
3267 * @deprecated since 2.5
3268 *
3269 * @param array $tabrows A [nested] array of tab row objects
3270 * @param string $selected The tabrow to select (by id)
3271 * @param array $inactive An array of tabrow id's to make inactive
3272 * @param array $activated An array of tabrow id's to make active
3273 * @return array The nested array
3274 */
3275function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
3276
3277 debugging('Function convert_tabrows_to_tree() is deprecated since Moodle 2.5. Consider using class tabtree', DEBUG_DEVELOPER);
c269b9d1 3278
3d7414b3 3279 // Work backwards through the rows (bottom to top) collecting the tree as we go.
c269b9d1
MG
3280 $tabrows = array_reverse($tabrows);
3281
3282 $subtree = array();
3283
3284 foreach ($tabrows as $row) {
3285 $tree = array();
3286
3287 foreach ($row as $tab) {
3288 $tab->inactive = in_array((string)$tab->id, $inactive);
3289 $tab->active = in_array((string)$tab->id, $activated);
3290 $tab->selected = (string)$tab->id == $selected;
3291
3292 if ($tab->active || $tab->selected) {
3293 if ($subtree) {
3294 $tab->subtree = $subtree;
3295 }
3296 }
3297 $tree[] = $tab;
3298 }
3299 $subtree = $tree;
3300 }
3301
3302 return $subtree;
3303}
9052fc44 3304
8ef3a222
DP
3305/**
3306 * Can handle rotated text. Whether it is safe to use the trickery in textrotate.js.
3307 *
3308 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
3309 * @return bool True for yes, false for no
3310 */
3311function can_use_rotated_text() {
3312 debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.', DEBUG_DEVELOPER);
3313 return true;
3314}
61a0299a
AA
3315
3316/**
3317 * Get the context instance as an object. This function will create the
3318 * context instance if it does not exist yet.
3319 *
3320 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
3321 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
3322 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
3323 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
3324 * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
3325 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
3326 * MUST_EXIST means throw exception if no record or multiple records found
3327 * @return context The context object.
3328 */
3329function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
3330
1b80060f 3331 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
61a0299a
AA
3332
3333 $instances = (array)$instance;
3334 $contexts = array();
3335
3336 $classname = context_helper::get_class_for_level($contextlevel);
3337
3338 // we do not load multiple contexts any more, PAGE should be responsible for any preloading
3339 foreach ($instances as $inst) {
3340 $contexts[$inst] = $classname::instance($inst, $strictness);
3341 }
3342
3343 if (is_array($instance)) {
3344 return $contexts;
3345 } else {
3346 return $contexts[$instance];
3347 }
3348}
7b2ca655 3349
ce2b2150
RT
3350/**
3351 * Get a context instance as an object, from a given context id.
3352 *
3353 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
ce2b2150 3354 * @see context::instance_by_id($id)
ce2b2150
RT
3355 */
3356function get_context_instance_by_id($id, $strictness = IGNORE_MISSING) {
f9b7be4f 3357 throw new coding_exception('get_context_instance_by_id() is now removed, please use context::instance_by_id($id) instead.');
ce2b2150 3358}
85b2e46f 3359
492ba9de
AA
3360/**
3361 * Returns system context or null if can not be created yet.
3362 *
3363 * @see context_system::instance()
01546175 3364 * @deprecated since 2.2
492ba9de
AA
3365 * @param bool $cache use caching
3366 * @return context system context (null if context table not created yet)
3367 */
3368function get_system_context($cache = true) {
3369 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
3370 return context_system::instance(0, IGNORE_MISSING, $cache);
3371}
8e8891b7
FM
3372
3373/**
3374 * Recursive function which, given a context, find all parent context ids,
3375 * and return the array in reverse order, i.e. parent first, then grand
3376 * parent, etc.
3377 *
3378 * @see context::get_parent_context_ids()
3379 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
3380 * @param context $context
3381 * @param bool $includeself optional, defaults to false
3382 * @return array
3383 */
3384function get_parent_contexts(context $context, $includeself = false) {
3385 debugging('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER);
3386 return $context->get_parent_context_ids($includeself);
3387}
766fd0d9
AD
3388
3389/**
7f5b51c4
RT
3390 * Return the id of the parent of this context, or false if there is no parent (only happens if this
3391 * is the site context.)
3392 *
3393 * @deprecated since Moodle 2.2
3394 * @see context::get_parent_context()
3395 * @param context $context
3396 * @return integer the id of the parent context.
766fd0d9 3397 */
7f5b51c4
RT
3398function get_parent_contextid(context $context) {
3399 debugging('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER);
3400
3401 if ($parent = $context->get_parent_context()) {
3402 return $parent->id;
3403 } else {
3404 return false;
3405 }
766fd0d9 3406}
f9aa8016
FM
3407
3408/**
3409 * Recursive function which, given a context, find all its children contexts.
3410 *
3411 * For course category contexts it will return immediate children only categories and courses.
3412 * It will NOT recurse into courses or child categories.
3413 * If you want to do that, call it on the returned courses/categories.
3414 *
3415 * When called for a course context, it will return the modules and blocks
3416 * displayed in the course page.
3417 *
3418 * If called on a user/course/module context it _will_ populate the cache with the appropriate
3419 * contexts ;-)
3420 *
3421 * @see context::get_child_contexts()
3422 * @deprecated since 2.2
3423 * @param context $context
3424 * @return array Array of child records
3425 */
3426function get_child_contexts(context $context) {
3427 debugging('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER);
3428 return $context->get_child_contexts();
3429}
9fdbf620
FM
3430
3431/**
3432 * Precreates all contexts including all parents.
3433 *
3434 * @see context_helper::create_instances()
3435 * @deprecated since 2.2
3436 * @param int $contextlevel empty means all
3437 * @param bool $buildpaths update paths and depths
3438 * @return void
3439 */
3440function create_contexts($contextlevel = null, $buildpaths = true) {
3441 debugging('create_contexts() is deprecated, please use context_helper::create_instances() instead.', DEBUG_DEVELOPER);
3442 context_helper::create_instances($contextlevel, $buildpaths);
3443}
84378a57
FM
3444
3445/**
3446 * Remove stale context records.
3447 *
3448 * @see context_helper::cleanup_instances()
3449 * @deprecated since 2.2
3450 * @return bool
3451 */
3452function cleanup_contexts() {
3453 debugging('cleanup_contexts() is deprecated, please use context_helper::cleanup_instances() instead.', DEBUG_DEVELOPER);
3454 context_helper::cleanup_instances();
3455 return true;
3456}
79f6b384
FM
3457
3458/**
3459 * Populate context.path and context.depth where missing.
3460 *
3461 * @see context_helper::build_all_paths()
3462 * @deprecated since 2.2
3463 * @param bool $force force a complete rebuild of the path and depth fields, defaults to false
3464 * @return void
3465 */
3466function build_context_path($force = false) {
3467 debugging('build_context_path() is deprecated, please use context_helper::build_all_paths() instead.', DEBUG_DEVELOPER);
3468 context_helper::build_all_paths($force);
3469}
cc4de415
FM
3470
3471/**
3472 * Rebuild all related context depth and path caches.
3473 *
3474 * @see context::reset_paths()
3475 * @deprecated since 2.2
3476 * @param array $fixcontexts array of contexts, strongtyped
3477 * @return void
3478 */
3479function rebuild_contexts(array $fixcontexts) {
3480 debugging('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.', DEBUG_DEVELOPER);
3481 foreach ($fixcontexts as $fixcontext) {
3482 $fixcontext->reset_paths(false);
3483 }
3484 context_helper::build_all_paths(false);
3485}
8f7d3d12
RT
3486
3487/**
3488 * Preloads all contexts relating to a course: course, modules. Block contexts
3489 * are no longer loaded here. The contexts for all the blocks on the current
3490 * page are now efficiently loaded by {@link block_manager::load_blocks()}.
3491 *
3492 * @deprecated since Moodle 2.2
3493 * @see context_helper::preload_course()
3494 * @param int $courseid Course ID
3495 * @return void
3496 */
3497function preload_course_contexts($courseid) {
3498 debugging('preload_course_contexts() is deprecated, please use context_helper::preload_course() instead.', DEBUG_DEVELOPER);
3499 context_helper::preload_course($courseid);
3500}
2c5b0eb7
RT
3501
3502/**
3503 * Update the path field of the context and all dep. subcontexts that follow
3504 *
3505 * Update the path field of the context and
3506 * all the dependent subcontexts that follow
3507 * the move.
3508 *
3509 * The most important thing here is to be as
3510 * DB efficient as possible. This op can have a
3511 * massive impact in the DB.
3512 *
3513 * @deprecated since Moodle 2.2
3514 * @see context::update_moved()
3515 * @param context $context context obj
3516 * @param context $newparent new parent obj
3517 * @return void
3518 */
3519function context_moved(context $context, context $newparent) {
3520 debugging('context_moved() is deprecated, please use context::update_moved() instead.', DEBUG_DEVELOPER);
3521 $context->update_moved($newparent);
c5dcd25d
AA
3522}
3523
a439b2f9
FM
3524/**
3525 * Extracts the relevant capabilities given a contextid.
3526 * All case based, example an instance of forum context.
3527 * Will fetch all forum related capabilities, while course contexts
3528 * Will fetch all capabilities
3529 *
3530 * capabilities
3531 * `name` varchar(150) NOT NULL,
3532 * `captype` varchar(50) NOT NULL,
3533 * `contextlevel` int(10) NOT NULL,
3534 * `component` varchar(100) NOT NULL,
3535 *
3536 * @see context::get_capabilities()
3537 * @deprecated since 2.2
3538 * @param context $context
3539 * @return array
3540 */
3541function fetch_context_capabilities(context $context) {
3542 debugging('fetch_context_capabilities() is deprecated, please use $context->get_capabilities() instead.', DEBUG_DEVELOPER);
3543 return $context->get_capabilities();
3544}
3545
c5dcd25d
AA
3546/**
3547 * Preloads context information from db record and strips the cached info.
3548 * The db request has to contain both the $join and $select from context_instance_preload_sql()
3549 *
3550 * @deprecated since 2.2
3551 * @see context_helper::preload_from_record()
3552 * @param stdClass $rec
3553 * @return void (modifies $rec)
3554 */
3555function context_instance_preload(stdClass $rec) {
3556 debugging('context_instance_preload() is deprecated, please use context_helper::preload_from_record() instead.', DEBUG_DEVELOPER);
3557 context_helper::preload_from_record($rec);
3558}
b4482dfe
AG
3559
3560/**
3561 * Returns context level name
3562 *
3563 * @deprecated since 2.2
3564 * @see context_helper::get_level_name()
3565 * @param integer $contextlevel $context->context level. One of the CONTEXT_... constants.
3566 * @return string the name for this type of context.
3567 */
3568function get_contextlevel_name($contextlevel) {
3569 debugging('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER);
3570 return context_helper::get_level_name($contextlevel);
3571}
329846f1
AG
3572
3573/**
3574 * Prints human readable context identifier.
3575 *
3576 * @deprecated since 2.2
3577 * @see context::get_context_name()
3578 * @param context $context the context.
3579 * @param boolean $withprefix whether to prefix the name of the context with the
3580 * type of context, e.g. User, Course, Forum, etc.
3581 * @param boolean $short whether to user the short name of the thing. Only applies
3582 * to course contexts
3583 * @return string the human readable context name.
3584 */
3585function print_context_name(context $context, $withprefix = true, $short = false) {
3586 debugging('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER);
3587 return $context->get_context_name($withprefix, $short);
3588}
1de02d62
AG
3589
3590/**
3591 * Mark a context as dirty (with timestamp) so as to force reloading of the context.
3592 *
3593 * @deprecated since 2.2, use $context->mark_dirty() instead
3594 * @see context::mark_dirty()
3595 * @param string $path context path
3596 */
3597function mark_context_dirty($path) {
3598 global $CFG, $USER, $ACCESSLIB_PRIVATE;
3599 debugging('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER);
3600
3601 if (during_initial_install()) {
3602 return;
3603 }
3604
3605 // only if it is a non-empty string
3606 if (is_string($path) && $path !== '') {
3607 set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+$CFG->sessiontimeout);
3608 if (isset($ACCESSLIB_PRIVATE->dirtycontexts)) {
3609 $ACCESSLIB_PRIVATE->dirtycontexts[$path] = 1;
3610 } else {
3611 if (CLI_SCRIPT) {
3612 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
3613 } else {
3614 if (isset($USER->access['time'])) {
3615 $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $USER->access['time']-2);
3616 } else {
3617 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
3618 }
3619 // flags not loaded yet, it will be done later in $context->reload_if_dirty()
3620 }
3621 }
3622 }
3623}
c592eea2
RT
3624
3625/**
3626 * Remove a context record and any dependent entries,
3627 * removes context from static context cache too
3628 *
3629 * @deprecated since Moodle 2.2
3630 * @see context_helper::delete_instance() or context::delete_content()
3631 * @param int $contextlevel
3632 * @param int $instanceid
3633 * @param bool $deleterecord false means keep record for now
3634 * @return bool returns true or throws an exception
3635 */
3636function delete_context($contextlevel, $instanceid, $deleterecord = true) {
3637 if ($deleterecord) {
3638 debugging('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER);
3639 context_helper::delete_instance($contextlevel, $instanceid);
3640 } else {
3641 debugging('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER);
3642 $classname = context_helper::get_class_for_level($contextlevel);
3643 if ($context = $classname::instance($instanceid, IGNORE_MISSING)) {
3644 $context->delete_content();
3645 }
3646 }
3647
3648 return true;
3649}
6c89d4e1
MN
3650
3651/**
3652 * Get a URL for a context, if there is a natural one. For example, for
3653 * CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the
3654 * user profile page.
3655 *
3656 * @deprecated since 2.2
3657 * @see context::get_url()
3658 * @param context $context the context
3659 * @return moodle_url
3660 */
3661function get_context_url(context $context) {
3662 debugging('get_context_url() is deprecated, please use $context->get_url() instead.', DEBUG_DEVELOPER);
3663 return $context->get_url();
3664}
3665
dd33f4af
MN
3666/**
3667 * Is this context part of any course? if yes return course context,
3668 * if not return null or throw exception.
3669 *
3670 * @deprecated since 2.2
3671 * @see context::get_course_context()
3672 * @param context $context
aa386d29 3673 * @return context_course context of the enclosing course, null if not found or exception
dd33f4af
MN
3674 */
3675function get_course_context(context $context) {
3676 debugging('get_course_context() is deprecated, please use $context->get_course_context(true) instead.', DEBUG_DEVELOPER);
3677 return $context->get_course_context(true);
3678}
6acc54b3
AA
3679
3680/**
3681 * Get an array of courses where cap requested is available
3682 * and user is enrolled, this can be relatively slow.
3683 *
3684 * @deprecated since 2.2
3685 * @see enrol_get_users_courses()
3686 * @param int $userid A user id. By default (null) checks the permissions of the current user.
3687 * @param string $cap - name of the capability
3688 * @param array $accessdata_ignored
3689 * @param bool $doanything_ignored
3690 * @param string $sort - sorting fields - prefix each fieldname with "c."
3691 * @param array $fields - additional fields you are interested in...
3692 * @param int $limit_ignored
3693 * @return array $courses - ordered array of course objects - see notes above
3694 */
3695function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) {
3696
3697 debugging('get_user_courses_bycap() is deprecated, please use enrol_get_users_courses() instead.', DEBUG_DEVELOPER);
3698 $courses = enrol_get_users_courses($userid, true, $fields, $sort);
3699 foreach ($courses as $id=>$course) {
3700 $context = context_course::instance($id);
3701 if (!has_capability($cap, $context, $userid)) {
3702 unset($courses[$id]);
3703 }
3704 }
3705
3706 return $courses;
3707}
ae38dcb1
RT
3708
3709/**
3710 * This is really slow!!! do not use above course context level
3711 *
3712 * @deprecated since Moodle 2.2
3713 * @param int $roleid
3714 * @param context $context
3715 * @return array
3716 */
3717function get_role_context_caps($roleid, context $context) {
3718 global $DB;
3719 debugging('get_role_context_caps() is deprecated, it is really slow. Don\'t use it.', DEBUG_DEVELOPER);
3720
3721 // This is really slow!!!! - do not use above course context level.
3722 $result = array();
3723 $result[$context->id] = array();
3724
3725 // First emulate the parent context capabilities merging into context.
3726 $searchcontexts = array_reverse($context->get_parent_context_ids(true));
3727 foreach ($searchcontexts as $cid) {
3728 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
3729 foreach ($capabilities as $cap) {
3730 if (!array_key_exists($cap->capability, $result[$context->id])) {
3731 $result[$context->id][$cap->capability] = 0;
3732 }
3733 $result[$context->id][$cap->capability] += $cap->permission;
3734 }
3735 }
3736 }
3737
3738 // Now go through the contexts below given context.
3739 $searchcontexts = array_keys($context->get_child_contexts());
3740 foreach ($searchcontexts as $cid) {
3741 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
3742 foreach ($capabilities as $cap) {
3743 if (!array_key_exists($cap->contextid, $result)) {
3744 $result[$cap->contextid] = array();
3745 }
3746 $result[$cap->contextid][$cap->capability] = $cap->permission;
3747 }
3748 }
3749 }
3750
3751 return $result;
3752}
b123a543
FM
3753
3754/**
3755 * Returns current course id or false if outside of course based on context parameter.
3756 *
3757 * @see context::get_course_context()
3758 * @deprecated since 2.2
3759 * @param context $context
3760 * @return int|bool related course id or false
3761 */
3762function get_courseid_from_context(context $context) {
3763 debugging('get_courseid_from_context() is deprecated, please use $context->get_course_context(false) instead.', DEBUG_DEVELOPER);
3764 if ($coursecontext = $context->get_course_context(false)) {
3765 return $coursecontext->instanceid;
3766 } else {
3767 return false;
3768 }
6a30b48d 3769}
2e4c0c91
FM
3770
3771/**
3772 * Preloads context information together with instances.
3773 * Use context_instance_preload() to strip the context info from the record and cache the context instance.
3774 *
3775 * If you are using this methid, you should have something like this:
3776 *
3777 * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3778 *
3779 * To prevent the use of this deprecated function, replace the line above with something similar to this:
3780 *
3781 * $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
3782 * ^
3783 * $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
3784 * ^ ^ ^ ^
3785 * $params = array('contextlevel' => CONTEXT_COURSE);
3786 * ^
3787 * @see context_helper:;get_preload_record_columns_sql()
3788 * @deprecated since 2.2
3789 * @param string $joinon for example 'u.id'
3790 * @param string $contextlevel context level of instance in $joinon
3791 * @param string $tablealias context table alias
3792 * @return array with two values - select and join part
3793 */
3794function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
3795 debugging('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.', DEBUG_DEVELOPER);
3796 $select = ", " . context_helper::get_preload_record_columns_sql($tablealias);
3797 $join = "LEFT JOIN {context} $tablealias ON ($tablealias.instanceid = $joinon AND $tablealias.contextlevel = $contextlevel)";
3798 return array($select, $join);
b123a543 3799}
b6452844
MN
3800
3801/**
3802 * Gets a string for sql calls, searching for stuff in this context or above.
3803 *
3804 * @deprecated since 2.2
3805 * @see context::get_parent_context_ids()
3806 * @param context $context
3807 * @return string
3808 */
3809function get_related_contexts_string(context $context) {
3810 debugging('get_related_contexts_string() is deprecated, please use $context->get_parent_context_ids(true) instead.', DEBUG_DEVELOPER);
3811 if ($parents = $context->get_parent_context_ids()) {
3812 return (' IN ('.$context->id.','.implode(',', $parents).')');
3813 } else {
3814 return (' ='.$context->id);
3815 }
3816}
0142523d 3817
d0cac8b5
FM
3818/**
3819 * Get a list of all the plugins of a given type that contain a particular file.
3820 *
3821 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
3822 * @param string $file the name of file that must be present in the plugin.
3823 * (e.g. 'view.php', 'db/install.xml').
3824 * @param bool $include if true (default false), the file will be include_once-ed if found.
3825 * @return array with plugin name as keys (e.g. 'forum', 'courselist') and the path
3826 * to the file relative to dirroot as value (e.g. "$CFG->dirroot/mod/forum/view.php").
3827 * @deprecated since 2.6
3828 * @see core_component::get_plugin_list_with_file()
3829 */
3830function get_plugin_list_with_file($plugintype, $file, $include = false) {
3831 debugging('get_plugin_list_with_file() is deprecated, please use core_component::get_plugin_list_with_file() instead.',
3832 DEBUG_DEVELOPER);
3833 return core_component::get_plugin_list_with_file($plugintype, $file, $include);
3834}
c3d2fbf9
SH
3835
3836/**
3837 * Checks to see if is the browser operating system matches the specified brand.
3838 *
3839 * Known brand: 'Windows','Linux','Macintosh','SGI','SunOS','HP-UX'
3840 *