PageRenderTime 50ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/deprecatedlib.php

http://github.com/moodle/moodle
PHP | 3408 lines | 1577 code | 488 blank | 1343 comment | 94 complexity | 4cc5bb0b4f96e72bfc6058437921ddf1 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * deprecatedlib.php - Old functions retained only for backward compatibility
  18. *
  19. * Old functions retained only for backward compatibility. New code should not
  20. * use any of these functions.
  21. *
  22. * @package core
  23. * @subpackage deprecated
  24. * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
  25. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26. * @deprecated
  27. */
  28. defined('MOODLE_INTERNAL') || die();
  29. /* === Functions that needs to be kept longer in deprecated lib than normal time period === */
  30. /**
  31. * Add an entry to the legacy log table.
  32. *
  33. * @deprecated since 2.7 use new events instead
  34. *
  35. * @param int $courseid The course id
  36. * @param string $module The module name e.g. forum, journal, resource, course, user etc
  37. * @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
  38. * @param string $url The file and parameters used to see the results of the action
  39. * @param string $info Additional description information
  40. * @param int $cm The course_module->id if there is one
  41. * @param int|stdClass $user If log regards $user other than $USER
  42. * @return void
  43. */
  44. function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0) {
  45. debugging('add_to_log() has been deprecated, please rewrite your code to the new events API', DEBUG_DEVELOPER);
  46. // This is a nasty hack that allows us to put all the legacy stuff into legacy storage,
  47. // this way we may move all the legacy settings there too.
  48. $manager = get_log_manager();
  49. if (method_exists($manager, 'legacy_add_to_log')) {
  50. $manager->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
  51. }
  52. }
  53. /**
  54. * @deprecated since 2.6
  55. */
  56. function events_trigger() {
  57. throw new coding_exception('events_trigger() has been deprecated along with all Events 1 API in favour of Events 2 API.');
  58. }
  59. /**
  60. * List all core subsystems and their location
  61. *
  62. * This is a whitelist of components that are part of the core and their
  63. * language strings are defined in /lang/en/<<subsystem>>.php. If a given
  64. * plugin is not listed here and it does not have proper plugintype prefix,
  65. * then it is considered as course activity module.
  66. *
  67. * The location is optionally dirroot relative path. NULL means there is no special
  68. * directory for this subsystem. If the location is set, the subsystem's
  69. * renderer.php is expected to be there.
  70. *
  71. * @deprecated since 2.6, use core_component::get_core_subsystems()
  72. *
  73. * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
  74. * @return array of (string)name => (string|null)location
  75. */
  76. function get_core_subsystems($fullpaths = false) {
  77. global $CFG;
  78. // NOTE: do not add any other debugging here, keep forever.
  79. $subsystems = core_component::get_core_subsystems();
  80. if ($fullpaths) {
  81. return $subsystems;
  82. }
  83. debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
  84. $dlength = strlen($CFG->dirroot);
  85. foreach ($subsystems as $k => $v) {
  86. if ($v === null) {
  87. continue;
  88. }
  89. $subsystems[$k] = substr($v, $dlength+1);
  90. }
  91. return $subsystems;
  92. }
  93. /**
  94. * Lists all plugin types.
  95. *
  96. * @deprecated since 2.6, use core_component::get_plugin_types()
  97. *
  98. * @param bool $fullpaths false means relative paths from dirroot
  99. * @return array Array of strings - name=>location
  100. */
  101. function get_plugin_types($fullpaths = true) {
  102. global $CFG;
  103. // NOTE: do not add any other debugging here, keep forever.
  104. $types = core_component::get_plugin_types();
  105. if ($fullpaths) {
  106. return $types;
  107. }
  108. debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
  109. $dlength = strlen($CFG->dirroot);
  110. foreach ($types as $k => $v) {
  111. if ($k === 'theme') {
  112. $types[$k] = 'theme';
  113. continue;
  114. }
  115. $types[$k] = substr($v, $dlength+1);
  116. }
  117. return $types;
  118. }
  119. /**
  120. * Use when listing real plugins of one type.
  121. *
  122. * @deprecated since 2.6, use core_component::get_plugin_list()
  123. *
  124. * @param string $plugintype type of plugin
  125. * @return array name=>fulllocation pairs of plugins of given type
  126. */
  127. function get_plugin_list($plugintype) {
  128. // NOTE: do not add any other debugging here, keep forever.
  129. if ($plugintype === '') {
  130. $plugintype = 'mod';
  131. }
  132. return core_component::get_plugin_list($plugintype);
  133. }
  134. /**
  135. * Get a list of all the plugins of a given type that define a certain class
  136. * in a certain file. The plugin component names and class names are returned.
  137. *
  138. * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
  139. *
  140. * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
  141. * @param string $class the part of the name of the class after the
  142. * frankenstyle prefix. e.g 'thing' if you are looking for classes with
  143. * names like report_courselist_thing. If you are looking for classes with
  144. * the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
  145. * @param string $file the name of file within the plugin that defines the class.
  146. * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
  147. * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
  148. */
  149. function get_plugin_list_with_class($plugintype, $class, $file) {
  150. // NOTE: do not add any other debugging here, keep forever.
  151. return core_component::get_plugin_list_with_class($plugintype, $class, $file);
  152. }
  153. /**
  154. * Returns the exact absolute path to plugin directory.
  155. *
  156. * @deprecated since 2.6, use core_component::get_plugin_directory()
  157. *
  158. * @param string $plugintype type of plugin
  159. * @param string $name name of the plugin
  160. * @return string full path to plugin directory; NULL if not found
  161. */
  162. function get_plugin_directory($plugintype, $name) {
  163. // NOTE: do not add any other debugging here, keep forever.
  164. if ($plugintype === '') {
  165. $plugintype = 'mod';
  166. }
  167. return core_component::get_plugin_directory($plugintype, $name);
  168. }
  169. /**
  170. * Normalize the component name using the "frankenstyle" names.
  171. *
  172. * @deprecated since 2.6, use core_component::normalize_component()
  173. *
  174. * @param string $component
  175. * @return array two-items list of [(string)type, (string|null)name]
  176. */
  177. function normalize_component($component) {
  178. // NOTE: do not add any other debugging here, keep forever.
  179. return core_component::normalize_component($component);
  180. }
  181. /**
  182. * Return exact absolute path to a plugin directory.
  183. *
  184. * @deprecated since 2.6, use core_component::normalize_component()
  185. *
  186. * @param string $component name such as 'moodle', 'mod_forum'
  187. * @return string full path to component directory; NULL if not found
  188. */
  189. function get_component_directory($component) {
  190. // NOTE: do not add any other debugging here, keep forever.
  191. return core_component::get_component_directory($component);
  192. }
  193. /**
  194. * Get the context instance as an object. This function will create the
  195. * context instance if it does not exist yet.
  196. *
  197. * @deprecated since 2.2, use context_course::instance() or other relevant class instead
  198. * @todo This will be deleted in Moodle 2.8, refer MDL-34472
  199. * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
  200. * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
  201. * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
  202. * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
  203. * MUST_EXIST means throw exception if no record or multiple records found
  204. * @return context The context object.
  205. */
  206. function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
  207. debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
  208. $instances = (array)$instance;
  209. $contexts = array();
  210. $classname = context_helper::get_class_for_level($contextlevel);
  211. // we do not load multiple contexts any more, PAGE should be responsible for any preloading
  212. foreach ($instances as $inst) {
  213. $contexts[$inst] = $classname::instance($inst, $strictness);
  214. }
  215. if (is_array($instance)) {
  216. return $contexts;
  217. } else {
  218. return $contexts[$instance];
  219. }
  220. }
  221. /* === End of long term deprecated api list === */
  222. /**
  223. * @deprecated since 2.7 - use new file picker instead
  224. */
  225. function clam_log_upload() {
  226. throw new coding_exception('clam_log_upload() can not be used any more, please use file picker instead');
  227. }
  228. /**
  229. * @deprecated since 2.7 - use new file picker instead
  230. */
  231. function clam_log_infected() {
  232. throw new coding_exception('clam_log_infected() can not be used any more, please use file picker instead');
  233. }
  234. /**
  235. * @deprecated since 2.7 - use new file picker instead
  236. */
  237. function clam_change_log() {
  238. throw new coding_exception('clam_change_log() can not be used any more, please use file picker instead');
  239. }
  240. /**
  241. * @deprecated since 2.7 - infected files are now deleted in file picker
  242. */
  243. function clam_replace_infected_file() {
  244. throw new coding_exception('clam_replace_infected_file() can not be used any more, please use file picker instead');
  245. }
  246. /**
  247. * @deprecated since 2.7
  248. */
  249. function clam_handle_infected_file() {
  250. throw new coding_exception('clam_handle_infected_file() can not be used any more, please use file picker instead');
  251. }
  252. /**
  253. * @deprecated since 2.7
  254. */
  255. function clam_scan_moodle_file() {
  256. throw new coding_exception('clam_scan_moodle_file() can not be used any more, please use file picker instead');
  257. }
  258. /**
  259. * @deprecated since 2.7 PHP 5.4.x should be always compatible.
  260. */
  261. function password_compat_not_supported() {
  262. throw new coding_exception('Do not use password_compat_not_supported() - bcrypt is now always available');
  263. }
  264. /**
  265. * @deprecated since 2.6
  266. */
  267. function session_get_instance() {
  268. throw new coding_exception('session_get_instance() is removed, use \core\session\manager instead');
  269. }
  270. /**
  271. * @deprecated since 2.6
  272. */
  273. function session_is_legacy() {
  274. throw new coding_exception('session_is_legacy() is removed, do not use any more');
  275. }
  276. /**
  277. * @deprecated since 2.6
  278. */
  279. function session_kill_all() {
  280. throw new coding_exception('session_kill_all() is removed, use \core\session\manager::kill_all_sessions() instead');
  281. }
  282. /**
  283. * @deprecated since 2.6
  284. */
  285. function session_touch() {
  286. throw new coding_exception('session_touch() is removed, use \core\session\manager::touch_session() instead');
  287. }
  288. /**
  289. * @deprecated since 2.6
  290. */
  291. function session_kill() {
  292. throw new coding_exception('session_kill() is removed, use \core\session\manager::kill_session() instead');
  293. }
  294. /**
  295. * @deprecated since 2.6
  296. */
  297. function session_kill_user() {
  298. throw new coding_exception('session_kill_user() is removed, use \core\session\manager::kill_user_sessions() instead');
  299. }
  300. /**
  301. * @deprecated since 2.6
  302. */
  303. function session_set_user() {
  304. throw new coding_exception('session_set_user() is removed, use \core\session\manager::set_user() instead');
  305. }
  306. /**
  307. * @deprecated since 2.6
  308. */
  309. function session_is_loggedinas() {
  310. throw new coding_exception('session_is_loggedinas() is removed, use \core\session\manager::is_loggedinas() instead');
  311. }
  312. /**
  313. * @deprecated since 2.6
  314. */
  315. function session_get_realuser() {
  316. throw new coding_exception('session_get_realuser() is removed, use \core\session\manager::get_realuser() instead');
  317. }
  318. /**
  319. * @deprecated since 2.6
  320. */
  321. function session_loginas() {
  322. throw new coding_exception('session_loginas() is removed, use \core\session\manager::loginas() instead');
  323. }
  324. /**
  325. * @deprecated since 2.6
  326. */
  327. function js_minify() {
  328. throw new coding_exception('js_minify() is removed, use core_minify::js_files() or core_minify::js() instead.');
  329. }
  330. /**
  331. * @deprecated since 2.6
  332. */
  333. function css_minify_css() {
  334. throw new coding_exception('css_minify_css() is removed, use core_minify::css_files() or core_minify::css() instead.');
  335. }
  336. // === Deprecated before 2.6.0 ===
  337. /**
  338. * @deprecated
  339. */
  340. function check_gd_version() {
  341. throw new coding_exception('check_gd_version() is removed, GD extension is always available now');
  342. }
  343. /**
  344. * @deprecated
  345. */
  346. function update_login_count() {
  347. throw new coding_exception('update_login_count() is removed, all calls need to be removed');
  348. }
  349. /**
  350. * @deprecated
  351. */
  352. function reset_login_count() {
  353. throw new coding_exception('reset_login_count() is removed, all calls need to be removed');
  354. }
  355. /**
  356. * @deprecated
  357. */
  358. function update_log_display_entry() {
  359. throw new coding_exception('The update_log_display_entry() is removed, please use db/log.php description file instead.');
  360. }
  361. /**
  362. * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
  363. * this was abused mostly for embedding of attachments
  364. */
  365. function filter_text() {
  366. throw new coding_exception('filter_text() can not be used anymore, use format_text(), format_string() etc instead.');
  367. }
  368. /**
  369. * @deprecated Loginhttps is no longer supported
  370. */
  371. function httpsrequired() {
  372. throw new coding_exception('httpsrequired() can not be used any more. Loginhttps is no longer supported.');
  373. }
  374. /**
  375. * @deprecated since 3.1 - replacement legacy file API methods can be found on the moodle_url class, for example:
  376. * The moodle_url::make_legacyfile_url() method can be used to generate a legacy course file url. To generate
  377. * course module file.php url the moodle_url::make_file_url() should be used.
  378. */
  379. function get_file_url() {
  380. throw new coding_exception('get_file_url() can not be used anymore. Please use ' .
  381. 'moodle_url factory methods instead.');
  382. }
  383. /**
  384. * @deprecated use get_enrolled_users($context) instead.
  385. */
  386. function get_course_participants() {
  387. throw new coding_exception('get_course_participants() can not be used any more, use get_enrolled_users() instead.');
  388. }
  389. /**
  390. * @deprecated use is_enrolled($context, $userid) instead.
  391. */
  392. function is_course_participant() {
  393. throw new coding_exception('is_course_participant() can not be used any more, use is_enrolled() instead.');
  394. }
  395. /**
  396. * @deprecated
  397. */
  398. function get_recent_enrolments() {
  399. throw new coding_exception('get_recent_enrolments() is removed as it returned inaccurate results.');
  400. }
  401. /**
  402. * @deprecated use clean_param($string, PARAM_FILE) instead.
  403. */
  404. function detect_munged_arguments() {
  405. throw new coding_exception('detect_munged_arguments() can not be used any more, please use clean_param(,PARAM_FILE) instead.');
  406. }
  407. /**
  408. * Unzip one zip file to a destination dir
  409. * Both parameters must be FULL paths
  410. * If destination isn't specified, it will be the
  411. * SAME directory where the zip file resides.
  412. *
  413. * @global object
  414. * @param string $zipfile The zip file to unzip
  415. * @param string $destination The location to unzip to
  416. * @param bool $showstatus_ignored Unused
  417. * @deprecated since 2.0 MDL-15919
  418. */
  419. function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
  420. debugging(__FUNCTION__ . '() is deprecated. '
  421. . 'Please use the application/zip file_packer implementation instead.', DEBUG_DEVELOPER);
  422. // Extract everything from zipfile.
  423. $path_parts = pathinfo(cleardoubleslashes($zipfile));
  424. $zippath = $path_parts["dirname"]; //The path of the zip file
  425. $zipfilename = $path_parts["basename"]; //The name of the zip file
  426. $extension = $path_parts["extension"]; //The extension of the file
  427. //If no file, error
  428. if (empty($zipfilename)) {
  429. return false;
  430. }
  431. //If no extension, error
  432. if (empty($extension)) {
  433. return false;
  434. }
  435. //Clear $zipfile
  436. $zipfile = cleardoubleslashes($zipfile);
  437. //Check zipfile exists
  438. if (!file_exists($zipfile)) {
  439. return false;
  440. }
  441. //If no destination, passed let's go with the same directory
  442. if (empty($destination)) {
  443. $destination = $zippath;
  444. }
  445. //Clear $destination
  446. $destpath = rtrim(cleardoubleslashes($destination), "/");
  447. //Check destination path exists
  448. if (!is_dir($destpath)) {
  449. return false;
  450. }
  451. $packer = get_file_packer('application/zip');
  452. $result = $packer->extract_to_pathname($zipfile, $destpath);
  453. if ($result === false) {
  454. return false;
  455. }
  456. foreach ($result as $status) {
  457. if ($status !== true) {
  458. return false;
  459. }
  460. }
  461. return true;
  462. }
  463. /**
  464. * Zip an array of files/dirs to a destination zip file
  465. * Both parameters must be FULL paths to the files/dirs
  466. *
  467. * @global object
  468. * @param array $originalfiles Files to zip
  469. * @param string $destination The destination path
  470. * @return bool Outcome
  471. *
  472. * @deprecated since 2.0 MDL-15919
  473. */
  474. function zip_files($originalfiles, $destination) {
  475. debugging(__FUNCTION__ . '() is deprecated. '
  476. . 'Please use the application/zip file_packer implementation instead.', DEBUG_DEVELOPER);
  477. // Extract everything from destination.
  478. $path_parts = pathinfo(cleardoubleslashes($destination));
  479. $destpath = $path_parts["dirname"]; //The path of the zip file
  480. $destfilename = $path_parts["basename"]; //The name of the zip file
  481. $extension = $path_parts["extension"]; //The extension of the file
  482. //If no file, error
  483. if (empty($destfilename)) {
  484. return false;
  485. }
  486. //If no extension, add it
  487. if (empty($extension)) {
  488. $extension = 'zip';
  489. $destfilename = $destfilename.'.'.$extension;
  490. }
  491. //Check destination path exists
  492. if (!is_dir($destpath)) {
  493. return false;
  494. }
  495. //Check destination path is writable. TODO!!
  496. //Clean destination filename
  497. $destfilename = clean_filename($destfilename);
  498. //Now check and prepare every file
  499. $files = array();
  500. $origpath = NULL;
  501. foreach ($originalfiles as $file) { //Iterate over each file
  502. //Check for every file
  503. $tempfile = cleardoubleslashes($file); // no doubleslashes!
  504. //Calculate the base path for all files if it isn't set
  505. if ($origpath === NULL) {
  506. $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
  507. }
  508. //See if the file is readable
  509. if (!is_readable($tempfile)) { //Is readable
  510. continue;
  511. }
  512. //See if the file/dir is in the same directory than the rest
  513. if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
  514. continue;
  515. }
  516. //Add the file to the array
  517. $files[] = $tempfile;
  518. }
  519. $zipfiles = array();
  520. $start = strlen($origpath)+1;
  521. foreach($files as $file) {
  522. $zipfiles[substr($file, $start)] = $file;
  523. }
  524. $packer = get_file_packer('application/zip');
  525. return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
  526. }
  527. /**
  528. * @deprecated use groups_get_all_groups() instead.
  529. */
  530. function mygroupid() {
  531. throw new coding_exception('mygroupid() can not be used any more, please use groups_get_all_groups() instead.');
  532. }
  533. /**
  534. * @deprecated since Moodle 2.0 MDL-14617 - please do not use this function any more.
  535. */
  536. function groupmode() {
  537. throw new coding_exception('groupmode() can not be used any more, please use groups_get_* instead.');
  538. }
  539. /**
  540. * @deprecated Since year 2006 - please do not use this function any more.
  541. */
  542. function set_current_group() {
  543. throw new coding_exception('set_current_group() can not be used anymore, please use $SESSION->currentgroup[$courseid] instead');
  544. }
  545. /**
  546. * @deprecated Since year 2006 - please do not use this function any more.
  547. */
  548. function get_current_group() {
  549. throw new coding_exception('get_current_group() can not be used any more, please use groups_get_* instead');
  550. }
  551. /**
  552. * @deprecated Since Moodle 2.8
  553. */
  554. function groups_filter_users_by_course_module_visible() {
  555. throw new coding_exception('groups_filter_users_by_course_module_visible() is removed. ' .
  556. 'Replace with a call to \core_availability\info_module::filter_user_list(), ' .
  557. 'which does basically the same thing but includes other restrictions such ' .
  558. 'as profile restrictions.');
  559. }
  560. /**
  561. * @deprecated Since Moodle 2.8
  562. */
  563. function groups_course_module_visible() {
  564. throw new coding_exception('groups_course_module_visible() is removed, use $cm->uservisible to decide whether the current
  565. user can ' . 'access an activity.', DEBUG_DEVELOPER);
  566. }
  567. /**
  568. * @deprecated since 2.0
  569. */
  570. function error() {
  571. throw new coding_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a removed, please call
  572. print_error() instead of error()');
  573. }
  574. /**
  575. * @deprecated use $PAGE->theme->name instead.
  576. */
  577. function current_theme() {
  578. throw new coding_exception('current_theme() can not be used any more, please use $PAGE->theme->name instead');
  579. }
  580. /**
  581. * @deprecated
  582. */
  583. function formerr() {
  584. throw new coding_exception('formerr() is removed. Please change your code to use $OUTPUT->error_text($string).');
  585. }
  586. /**
  587. * @deprecated use $OUTPUT->skip_link_target() in instead.
  588. */
  589. function skip_main_destination() {
  590. throw new coding_exception('skip_main_destination() can not be used any more, please use $OUTPUT->skip_link_target() instead.');
  591. }
  592. /**
  593. * @deprecated use $OUTPUT->container() instead.
  594. */
  595. function print_container() {
  596. throw new coding_exception('print_container() can not be used any more. Please use $OUTPUT->container() instead.');
  597. }
  598. /**
  599. * @deprecated use $OUTPUT->container_start() instead.
  600. */
  601. function print_container_start() {
  602. throw new coding_exception('print_container_start() can not be used any more. Please use $OUTPUT->container_start() instead.');
  603. }
  604. /**
  605. * @deprecated use $OUTPUT->container_end() instead.
  606. */
  607. function print_container_end() {
  608. throw new coding_exception('print_container_end() can not be used any more. Please use $OUTPUT->container_end() instead.');
  609. }
  610. /**
  611. * @deprecated since Moodle 2.0 MDL-19077 - use $OUTPUT->notification instead.
  612. */
  613. function notify() {
  614. throw new coding_exception('notify() is removed, please use $OUTPUT->notification() instead');
  615. }
  616. /**
  617. * @deprecated use $OUTPUT->continue_button() instead.
  618. */
  619. function print_continue() {
  620. throw new coding_exception('print_continue() can not be used any more. Please use $OUTPUT->continue_button() instead.');
  621. }
  622. /**
  623. * @deprecated use $PAGE methods instead.
  624. */
  625. function print_header() {
  626. throw new coding_exception('print_header() can not be used any more. Please use $PAGE methods instead.');
  627. }
  628. /**
  629. * @deprecated use $PAGE methods instead.
  630. */
  631. function print_header_simple() {
  632. throw new coding_exception('print_header_simple() can not be used any more. Please use $PAGE methods instead.');
  633. }
  634. /**
  635. * @deprecated use $OUTPUT->block() instead.
  636. */
  637. function print_side_block() {
  638. throw new coding_exception('print_side_block() can not be used any more, please use $OUTPUT->block() instead.');
  639. }
  640. /**
  641. * Prints a basic textarea field.
  642. *
  643. * This was 'deprecated' in 2.0, but not properly (there was no alternative) so the
  644. * debugging message was commented out.
  645. *
  646. * @deprecated since Moodle 3.6
  647. *
  648. * When using this function, you should
  649. *
  650. * @global object
  651. * @param bool $unused No longer used.
  652. * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
  653. * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
  654. * @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.
  655. * @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.
  656. * @param string $name Name to use for the textarea element.
  657. * @param string $value Initial content to display in the textarea.
  658. * @param int $obsolete deprecated
  659. * @param bool $return If false, will output string. If true, will return string value.
  660. * @param string $id CSS ID to add to the textarea element.
  661. * @return string|void depending on the value of $return
  662. */
  663. function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
  664. /// $width and height are legacy fields and no longer used as pixels like they used to be.
  665. /// However, you can set them to zero to override the mincols and minrows values below.
  666. // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
  667. debugging('print_textarea() is deprecated. Please use $OUTPUT->print_textarea() instead.', DEBUG_DEVELOPER);
  668. global $OUTPUT;
  669. $mincols = 65;
  670. $minrows = 10;
  671. if ($id === '') {
  672. $id = 'edit-'.$name;
  673. }
  674. if ($height && ($rows < $minrows)) {
  675. $rows = $minrows;
  676. }
  677. if ($width && ($cols < $mincols)) {
  678. $cols = $mincols;
  679. }
  680. $textarea = $OUTPUT->print_textarea($name, $id, $value, $rows, $cols);
  681. if ($return) {
  682. return $textarea;
  683. }
  684. echo $textarea;
  685. }
  686. /**
  687. * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
  688. * provide this function with the language strings for sortasc and sortdesc.
  689. *
  690. * @deprecated use $OUTPUT->arrow() instead.
  691. * @todo final deprecation of this function once MDL-45448 is resolved
  692. *
  693. * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
  694. *
  695. * @global object
  696. * @param string $direction 'up' or 'down'
  697. * @param string $strsort The language string used for the alt attribute of this image
  698. * @param bool $return Whether to print directly or return the html string
  699. * @return string|void depending on $return
  700. *
  701. */
  702. function print_arrow($direction='up', $strsort=null, $return=false) {
  703. global $OUTPUT;
  704. debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER);
  705. if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
  706. return null;
  707. }
  708. $return = null;
  709. switch ($direction) {
  710. case 'up':
  711. $sortdir = 'asc';
  712. break;
  713. case 'down':
  714. $sortdir = 'desc';
  715. break;
  716. case 'move':
  717. $sortdir = 'asc';
  718. break;
  719. default:
  720. $sortdir = null;
  721. break;
  722. }
  723. // Prepare language string
  724. $strsort = '';
  725. if (empty($strsort) && !empty($sortdir)) {
  726. $strsort = get_string('sort' . $sortdir, 'grades');
  727. }
  728. $return = ' ' . $OUTPUT->pix_icon('t/' . $direction, $strsort) . ' ';
  729. if ($return) {
  730. return $return;
  731. } else {
  732. echo $return;
  733. }
  734. }
  735. /**
  736. * @deprecated since Moodle 2.0
  737. */
  738. function choose_from_menu() {
  739. throw new coding_exception('choose_from_menu() is removed. Please change your code to use html_writer::select().');
  740. }
  741. /**
  742. * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
  743. */
  744. function print_scale_menu_helpbutton() {
  745. throw new coding_exception('print_scale_menu_helpbutton() can not be used any more. '.
  746. 'Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.');
  747. }
  748. /**
  749. * @deprecated use html_writer::checkbox() instead.
  750. */
  751. function print_checkbox() {
  752. throw new coding_exception('print_checkbox() can not be used any more. Please use html_writer::checkbox() instead.');
  753. }
  754. /**
  755. * @deprecated since Moodle 3.2
  756. */
  757. function update_module_button() {
  758. throw new coding_exception('update_module_button() can not be used anymore. Activity modules should ' .
  759. 'not add the edit module button, the link is already available in the Administration block. Themes ' .
  760. 'can choose to display the link in the buttons row consistently for all module types.');
  761. }
  762. /**
  763. * @deprecated use $OUTPUT->navbar() instead
  764. */
  765. function print_navigation () {
  766. throw new coding_exception('print_navigation() can not be used any more, please update use $OUTPUT->navbar() instead.');
  767. }
  768. /**
  769. * @deprecated Please use $PAGE->navabar methods instead.
  770. */
  771. function build_navigation() {
  772. throw new coding_exception('build_navigation() can not be used any more, please use $PAGE->navbar methods instead.');
  773. }
  774. /**
  775. * @deprecated not relevant with global navigation in Moodle 2.x+
  776. */
  777. function navmenu() {
  778. throw new coding_exception('navmenu() can not be used any more, it is no longer relevant with global navigation.');
  779. }
  780. /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
  781. /**
  782. * @deprecated please use calendar_event::create() instead.
  783. */
  784. function add_event() {
  785. throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.');
  786. }
  787. /**
  788. * @deprecated please calendar_event->update() instead.
  789. */
  790. function update_event() {
  791. throw new coding_exception('update_event() is removed, please use calendar_event->update() instead.');
  792. }
  793. /**
  794. * @deprecated please use calendar_event->delete() instead.
  795. */
  796. function delete_event() {
  797. throw new coding_exception('delete_event() can not be used any more, please use '.
  798. 'calendar_event->delete() instead.');
  799. }
  800. /**
  801. * @deprecated please use calendar_event->toggle_visibility(false) instead.
  802. */
  803. function hide_event() {
  804. throw new coding_exception('hide_event() can not be used any more, please use '.
  805. 'calendar_event->toggle_visibility(false) instead.');
  806. }
  807. /**
  808. * @deprecated please use calendar_event->toggle_visibility(true) instead.
  809. */
  810. function show_event() {
  811. throw new coding_exception('show_event() can not be used any more, please use '.
  812. 'calendar_event->toggle_visibility(true) instead.');
  813. }
  814. /**
  815. * @deprecated since Moodle 2.2 use core_text::xxxx() instead.
  816. */
  817. function textlib_get_instance() {
  818. throw new coding_exception('textlib_get_instance() can not be used any more, please use '.
  819. 'core_text::functioname() instead.');
  820. }
  821. /**
  822. * @deprecated since 2.4
  823. */
  824. function get_generic_section_name() {
  825. throw new coding_exception('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base');
  826. }
  827. /**
  828. * @deprecated since 2.4
  829. */
  830. function get_all_sections() {
  831. throw new coding_exception('get_all_sections() is removed. See phpdocs for this function');
  832. }
  833. /**
  834. * @deprecated since 2.4
  835. */
  836. function add_mod_to_section() {
  837. throw new coding_exception('Function add_mod_to_section() is removed, please use course_add_cm_to_section()');
  838. }
  839. /**
  840. * @deprecated since 2.4
  841. */
  842. function get_all_mods() {
  843. throw new coding_exception('Function get_all_mods() is removed. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details');
  844. }
  845. /**
  846. * @deprecated since 2.4
  847. */
  848. function get_course_section() {
  849. throw new coding_exception('Function get_course_section() is removed. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.');
  850. }
  851. /**
  852. * @deprecated since 2.4
  853. */
  854. function format_weeks_get_section_dates() {
  855. throw new coding_exception('Function format_weeks_get_section_dates() is removed. It is not recommended to'.
  856. ' use it outside of format_weeks plugin');
  857. }
  858. /**
  859. * @deprecated since 2.5
  860. */
  861. function get_print_section_cm_text() {
  862. throw new coding_exception('Function get_print_section_cm_text() is removed. Please use '.
  863. 'cm_info::get_formatted_content() and cm_info::get_formatted_name()');
  864. }
  865. /**
  866. * @deprecated since 2.5
  867. */
  868. function print_section_add_menus() {
  869. throw new coding_exception('Function print_section_add_menus() is removed. Please use course renderer '.
  870. 'function course_section_add_cm_control()');
  871. }
  872. /**
  873. * @deprecated since 2.5. Please use:
  874. * $courserenderer = $PAGE->get_renderer('core', 'course');
  875. * $actions = course_get_cm_edit_actions($mod, $indent, $section);
  876. * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
  877. */
  878. function make_editing_buttons() {
  879. throw new coding_exception('Function make_editing_buttons() is removed, please see PHPdocs in '.
  880. 'lib/deprecatedlib.php on how to replace it');
  881. }
  882. /**
  883. * @deprecated since 2.5
  884. */
  885. function print_section() {
  886. throw new coding_exception('Function print_section() is removed. Please use course renderer function '.
  887. 'course_section_cm_list() instead.');
  888. }
  889. /**
  890. * @deprecated since 2.5
  891. */
  892. function print_overview() {
  893. throw new coding_exception('Function print_overview() is removed. Use block course_overview to display this information');
  894. }
  895. /**
  896. * @deprecated since 2.5
  897. */
  898. function print_recent_activity() {
  899. throw new coding_exception('Function print_recent_activity() is removed. It is not recommended to'.
  900. ' use it outside of block_recent_activity');
  901. }
  902. /**
  903. * @deprecated since 2.5
  904. */
  905. function delete_course_module() {
  906. throw new coding_exception('Function delete_course_module() is removed. Please use course_delete_module() instead.');
  907. }
  908. /**
  909. * @deprecated since 2.5
  910. */
  911. function update_category_button() {
  912. throw new coding_exception('Function update_category_button() is removed. Pages to view '.
  913. 'and edit courses are now separate and no longer depend on editing mode.');
  914. }
  915. /**
  916. * @deprecated since 2.5
  917. */
  918. function make_categories_list() {
  919. throw new coding_exception('Global function make_categories_list() is removed. Please use '.
  920. 'core_course_category::make_categories_list() and core_course_category::get_parents()');
  921. }
  922. /**
  923. * @deprecated since 2.5
  924. */
  925. function category_delete_move() {
  926. throw new coding_exception('Function category_delete_move() is removed. Please use ' .
  927. 'core_course_category::delete_move() instead.');
  928. }
  929. /**
  930. * @deprecated since 2.5
  931. */
  932. function category_delete_full() {
  933. throw new coding_exception('Function category_delete_full() is removed. Please use ' .
  934. 'core_course_category::delete_full() instead.');
  935. }
  936. /**
  937. * @deprecated since 2.5
  938. */
  939. function move_category() {
  940. throw new coding_exception('Function move_category() is removed. Please use core_course_category::change_parent() instead.');
  941. }
  942. /**
  943. * @deprecated since 2.5
  944. */
  945. function course_category_hide() {
  946. throw new coding_exception('Function course_category_hide() is removed. Please use core_course_category::hide() instead.');
  947. }
  948. /**
  949. * @deprecated since 2.5
  950. */
  951. function course_category_show() {
  952. throw new coding_exception('Function course_category_show() is removed. Please use core_course_category::show() instead.');
  953. }
  954. /**
  955. * @deprecated since 2.5. Please use core_course_category::get($catid, IGNORE_MISSING) or
  956. * core_course_category::get($catid, MUST_EXIST).
  957. */
  958. function get_course_category() {
  959. throw new coding_exception('Function get_course_category() is removed. Please use core_course_category::get(), ' .
  960. 'see phpdocs for more details');
  961. }
  962. /**
  963. * @deprecated since 2.5
  964. */
  965. function create_course_category() {
  966. throw new coding_exception('Function create_course_category() is removed. Please use core_course_category::create(), ' .
  967. 'see phpdocs for more details');
  968. }
  969. /**
  970. * @deprecated since 2.5. Please use core_course_category::get() and core_course_category::get_children()
  971. */
  972. function get_all_subcategories() {
  973. throw new coding_exception('Function get_all_subcategories() is removed. Please use appropriate methods() '.
  974. 'of core_course_category class. See phpdocs for more details');
  975. }
  976. /**
  977. * @deprecated since 2.5. Please use core_course_category::get($parentid)->get_children().
  978. */
  979. function get_child_categories() {
  980. throw new coding_exception('Function get_child_categories() is removed. Use core_course_category::get_children() or see ' .
  981. 'phpdocs for more details.');
  982. }
  983. /**
  984. * @deprecated since 2.5
  985. */
  986. function get_categories() {
  987. throw new coding_exception('Function get_categories() is removed. Please use ' .
  988. 'appropriate functions from class core_course_category');
  989. }
  990. /**
  991. * @deprecated since 2.5
  992. */
  993. function print_course_search() {
  994. throw new coding_exception('Function print_course_search() is removed, please use course renderer');
  995. }
  996. /**
  997. * @deprecated since 2.5
  998. */
  999. function print_my_moodle() {
  1000. throw new coding_exception('Function print_my_moodle() is removed, please use course renderer ' .
  1001. 'function frontpage_my_courses()');
  1002. }
  1003. /**
  1004. * @deprecated since 2.5
  1005. */
  1006. function print_remote_course() {
  1007. throw new coding_exception('Function print_remote_course() is removed, please use course renderer');
  1008. }
  1009. /**
  1010. * @deprecated since 2.5
  1011. */
  1012. function print_remote_host() {
  1013. throw new coding_exception('Function print_remote_host() is removed, please use course renderer');
  1014. }
  1015. /**
  1016. * @deprecated since 2.5
  1017. */
  1018. function print_whole_category_list() {
  1019. throw new coding_exception('Function print_whole_category_list() is removed, please use course renderer');
  1020. }
  1021. /**
  1022. * @deprecated since 2.5
  1023. */
  1024. function print_category_info() {
  1025. throw new coding_exception('Function print_category_info() is removed, please use course renderer');
  1026. }
  1027. /**
  1028. * @deprecated since 2.5
  1029. */
  1030. function get_course_category_tree() {
  1031. throw new coding_exception('Function get_course_category_tree() is removed, please use course ' .
  1032. 'renderer or core_course_category class, see function phpdocs for more info');
  1033. }
  1034. /**
  1035. * @deprecated since 2.5
  1036. */
  1037. function print_courses() {
  1038. throw new coding_exception('Function print_courses() is removed, please use course renderer');
  1039. }
  1040. /**
  1041. * @deprecated since 2.5
  1042. */
  1043. function print_course() {
  1044. throw new coding_exception('Function print_course() is removed, please use course renderer');
  1045. }
  1046. /**
  1047. * @deprecated since 2.5
  1048. */
  1049. function get_category_courses_array() {
  1050. throw new coding_exception('Function get_category_courses_array() is removed, please use methods of ' .
  1051. 'core_course_category class');
  1052. }
  1053. /**
  1054. * @deprecated since 2.5
  1055. */
  1056. function get_category_courses_array_recursively() {
  1057. throw new coding_exception('Function get_category_courses_array_recursively() is removed, please use ' .
  1058. 'methods of core_course_category class', DEBUG_DEVELOPER);
  1059. }
  1060. /**
  1061. * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
  1062. */
  1063. function blog_get_context_url() {
  1064. throw new coding_exception('Function blog_get_context_url() is removed, getting params from context is not reliable for blogs.');
  1065. }
  1066. /**
  1067. * @deprecated since 2.5
  1068. */
  1069. function get_courses_wmanagers() {
  1070. throw new coding_exception('Function get_courses_wmanagers() is removed, please use ' .
  1071. 'core_course_category::get_courses()');
  1072. }
  1073. /**
  1074. * @deprecated since 2.5
  1075. */
  1076. function convert_tree_to_html() {
  1077. throw new coding_exception('Function convert_tree_to_html() is removed. Consider using class tabtree and core_renderer::render_tabtree()');
  1078. }
  1079. /**
  1080. * @deprecated since 2.5
  1081. */
  1082. function convert_tabrows_to_tree() {
  1083. throw new coding_exception('Function convert_tabrows_to_tree() is removed. Consider using class tabtree');
  1084. }
  1085. /**
  1086. * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
  1087. */
  1088. function can_use_rotated_text() {
  1089. debugging('can_use_rotated_text() is removed. JS feature detection is used automatically.');
  1090. }
  1091. /**
  1092. * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
  1093. */
  1094. function get_context_instance_by_id() {
  1095. throw new coding_exception('get_context_instance_by_id() is now removed, please use context::instance_by_id($id) instead.');
  1096. }
  1097. /**
  1098. * Returns system context or null if can not be created yet.
  1099. *
  1100. * @see context_system::instance()
  1101. * @deprecated since 2.2
  1102. * @param bool $cache use caching
  1103. * @return context system context (null if context table not created yet)
  1104. */
  1105. function get_system_context($cache = true) {
  1106. debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
  1107. return context_system::instance(0, IGNORE_MISSING, $cache);
  1108. }
  1109. /**
  1110. * @deprecated since 2.2, use $context->get_parent_context_ids() instead
  1111. */
  1112. function get_parent_contexts() {
  1113. throw new coding_exception('get_parent_contexts() is removed, please use $context->get_parent_context_ids() instead.');
  1114. }
  1115. /**
  1116. * @deprecated since Moodle 2.2
  1117. */
  1118. function get_parent_contextid() {
  1119. throw new coding_exception('get_parent_contextid() is removed, please use $context->get_parent_context() instead.');
  1120. }
  1121. /**
  1122. * @deprecated since 2.2
  1123. */
  1124. function get_child_contexts() {
  1125. throw new coding_exception('get_child_contexts() is removed, please use $context->get_child_contexts() instead.');
  1126. }
  1127. /**
  1128. * @deprecated since 2.2
  1129. */
  1130. function create_contexts() {
  1131. throw new coding_exception('create_contexts() is removed, please use context_helper::create_instances() instead.');
  1132. }
  1133. /**
  1134. * @deprecated since 2.2
  1135. */
  1136. function cleanup_contexts() {
  1137. throw new coding_exception('cleanup_contexts() is removed, please use context_helper::cleanup_instances() instead.');
  1138. }
  1139. /**
  1140. * @deprecated since 2.2
  1141. */
  1142. function build_context_path() {
  1143. throw new coding_exception('build_context_path() is removed, please use context_helper::build_all_paths() instead.');
  1144. }
  1145. /**
  1146. * @deprecated since 2.2
  1147. */
  1148. function rebuild_contexts() {
  1149. throw new coding_exception('rebuild_contexts() is removed, please use $context->reset_paths(true) instead.');
  1150. }
  1151. /**
  1152. * @deprecated since Moodle 2.2
  1153. */
  1154. function preload_course_contexts() {
  1155. throw new coding_exception('preload_course_contexts() is removed, please use context_helper::preload_course() instead.');
  1156. }
  1157. /**
  1158. * @deprecated since Moodle 2.2
  1159. */
  1160. function context_moved() {
  1161. throw new coding_exception('context_moved() is removed, please use context::update_moved() instead.');
  1162. }
  1163. /**
  1164. * @deprecated since 2.2
  1165. */
  1166. function fetch_context_capabilities() {
  1167. throw new coding_exception('fetch_context_capabilities() is removed, please use $context->get_capabilities() instead.');
  1168. }
  1169. /**
  1170. * @deprecated since 2.2
  1171. */
  1172. function context_instance_preload() {
  1173. throw new coding_exception('context_instance_preload() is removed, please use context_helper::preload_from_record() instead.');
  1174. }
  1175. /**
  1176. * @deprecated since 2.2
  1177. */
  1178. function get_contextlevel_name() {
  1179. throw new coding_exception('get_contextlevel_name() is removed, please use context_helper::get_level_name() instead.');
  1180. }
  1181. /**
  1182. * @deprecated since 2.2
  1183. */
  1184. function print_context_name() {
  1185. throw new coding_exception('print_context_name() is removed, please use $context->get_context_name() instead.');
  1186. }
  1187. /**
  1188. * @deprecated since 2.2, use $context->mark_dirty() instead
  1189. */
  1190. function mark_context_dirty() {
  1191. throw new coding_exception('mark_context_dirty() is removed, please use $context->mark_dirty() instead.');
  1192. }
  1193. /**
  1194. * @deprecated since Moodle 2.2
  1195. */
  1196. function delete_context() {
  1197. throw new coding_exception('delete_context() is removed, please use context_helper::delete_instance() ' .
  1198. 'or $context->delete_content() instead.');
  1199. }
  1200. /**
  1201. * @deprecated since 2.2
  1202. */
  1203. function get_context_url() {
  1204. throw new coding_exception('get_context_url() is removed, please use $context->get_url() instead.');
  1205. }
  1206. /**
  1207. * @deprecated since 2.2
  1208. */
  1209. function get_course_context() {
  1210. throw new coding_exception('get_course_context() is removed, please use $context->get_course_context(true) instead.');
  1211. }
  1212. /**
  1213. * @deprecated since 2.2
  1214. */
  1215. function get_user_courses_bycap() {
  1216. throw new coding_exception('get_user_courses_bycap() is removed, please use enrol_get_users_courses() instead.');
  1217. }
  1218. /**
  1219. * @deprecated since Moodle 2.2
  1220. */
  1221. function get_role_context_caps() {
  1222. throw new coding_exception('get_role_context_caps() is removed, it is really slow. Don\'t use it.');
  1223. }
  1224. /**
  1225. * @deprecated since 2.2
  1226. */
  1227. function get_courseid_from_context() {
  1228. throw new coding_exception('get_courseid_from_context() is removed, please use $context->get_course_context(false) instead.');
  1229. }
  1230. /**
  1231. * @deprecated since 2.2
  1232. */
  1233. function context_instance_preload_sql() {
  1234. throw new coding_exception('context_instance_preload_sql() is removed, please use context_helper::get_preload_record_columns_sql() instead.');
  1235. }
  1236. /**
  1237. * @deprecated since 2.2
  1238. */
  1239. function get_related_contexts_string() {
  1240. throw new coding_exception('get_related_contexts_string() is removed, please use $context->get_parent_context_ids(true) instead.');
  1241. }
  1242. /**
  1243. * @deprecated since 2.6
  1244. */
  1245. function get_plugin_list_with_file() {
  1246. throw new coding_exception('get_plugin_list_with_file() is removed, please use core_component::get_plugin_list_with_file() instead.');
  1247. }
  1248. /**
  1249. * @deprecated since 2.6
  1250. */
  1251. function check_browser_operating_system() {
  1252. throw new coding_exception('check_browser_operating_system is removed, please update your code to use core_useragent instead.');
  1253. }
  1254. /**
  1255. * @deprecated since 2.6
  1256. */
  1257. function check_browser_version() {
  1258. throw new coding_exception('check_browser_version is removed, please update your code to use core_useragent instead.');
  1259. }
  1260. /**
  1261. * @deprecated since 2.6
  1262. */
  1263. function get_device_type() {
  1264. throw new coding_exception('get_device_type is removed, please update your code to use core_useragent instead.');
  1265. }
  1266. /**
  1267. * @deprecated since 2.6
  1268. */
  1269. function get_device_type_list() {
  1270. throw new coding_exception('get_device_type_list is removed, please update your code to use core_useragent instead.');
  1271. }
  1272. /**
  1273. * @deprecated since 2.6
  1274. */
  1275. function get_selected_theme_for_device_type() {
  1276. throw new coding_exception('get_selected_theme_for_device_type is removed, please update your code to use core_useragent instead.');
  1277. }
  1278. /**
  1279. * @deprecated since 2.6
  1280. */
  1281. function get_device_cfg_var_name() {
  1282. throw new coding_exception('get_device_cfg_var_name is removed, please update your code to use core_useragent instead.');
  1283. }
  1284. /**
  1285. * @deprecated since 2.6
  1286. */
  1287. function set_user_device_type() {
  1288. throw new coding_exception('set_user_device_type is removed, please update your code to use core_useragent instead.');
  1289. }
  1290. /**
  1291. * @deprecated since 2.6
  1292. */
  1293. function get_user_device_type() {
  1294. throw new coding_exception('get_user_device_type is removed, please update your code to use core_useragent instead.');
  1295. }
  1296. /**
  1297. * @deprecated since 2.6
  1298. */
  1299. function get_browser_version_classes() {
  1300. throw new coding_exception('get_browser_version_classes is removed, please update your code to use core_useragent instead.');
  1301. }
  1302. /**
  1303. * @deprecated since Moodle 2.6
  1304. */
  1305. function generate_email_supportuser() {
  1306. throw new coding_exception('generate_email_supportuser is removed, please use core_user::get_support_user');
  1307. }
  1308. /**
  1309. * @deprecated since Moodle 2.6
  1310. */
  1311. function badges_get_issued_badge_info() {
  1312. throw new coding_exception('Function badges_get_issued_badge_info() is removed. Please use core_badges_assertion class and methods to generate badge assertion.');
  1313. }
  1314. /**
  1315. * @deprecated since 2.6
  1316. */
  1317. function can_use_html_editor() {
  1318. throw new coding_exception('can_use_html_editor is removed, please update your code to assume it returns true.');
  1319. }
  1320. /**
  1321. * @deprecated since Moodle 2.7, use {@link user_count_login_failures()} instead.
  1322. */
  1323. function count_login_failures() {
  1324. throw new coding_exception('count_login_failures() can not be used any more, please use user_count_login_failures().');
  1325. }
  1326. /**
  1327. * @deprecated since 2.7 MDL-33099/MDL-44088 - please do not use this function any more.
  1328. */
  1329. function ajaxenabled() {
  1330. throw new coding_exception('ajaxenabled() can not be used anymore. Update your code to work with JS at all times.');
  1331. }
  1332. /**
  1333. * @deprecated Since Moodle 2.7 MDL-44070
  1334. */
  1335. function coursemodule_visible_for_user() {
  1336. throw new coding_exception('coursemodule_visible_for_user() can not be used any more,
  1337. please use \core_availability\info_module::is_user_visible()');
  1338. }
  1339. /**
  1340. * @deprecated since Moodle 2.8 MDL-36014, MDL-35618 this functionality is removed
  1341. */
  1342. function enrol_cohort_get_cohorts() {
  1343. throw new coding_exception('Function enrol_cohort_get_cohorts() is removed, use '.
  1344. 'cohort_get_available_cohorts() instead');
  1345. }
  1346. /**
  1347. * @deprecated since Moodle 2.8 MDL-36014 please use cohort_can_view_cohort()
  1348. */
  1349. function enrol_cohort_can_view_cohort() {
  1350. throw new coding_exception('Function enrol_cohort_can_view_cohort() is removed, use cohort_can_view_cohort() instead');
  1351. }
  1352. /**
  1353. * @deprecated since Moodle 2.8 MDL-36014 use cohort_get_available_cohorts() instead
  1354. */
  1355. function cohort_get_visible_list() {
  1356. throw new coding_exception('Function cohort_get_visible_list() is removed. Please use function cohort_get_available_cohorts() ".
  1357. "that correctly checks capabilities.');
  1358. }
  1359. /**
  1360. * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
  1361. */
  1362. function enrol_cohort_enrol_all_users() {
  1363. throw new coding_exception('enrol_cohort_enrol_all_users() is removed. This functionality is moved to enrol_manual.');
  1364. }
  1365. /**
  1366. * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
  1367. */
  1368. function enrol_cohort_search_cohorts() {
  1369. throw new coding_exception('enrol_cohort_search_cohorts() is removed. This functionality is moved to enrol_manual.');
  1370. }
  1371. /* === Apis deprecated in since Moodle 2.9 === */
  1372. /**
  1373. * @deprecated since Moodle 2.9 MDL-49371 - please do not use this function any more.
  1374. */
  1375. function message_current_user_is_involved() {
  1376. throw new coding_exception('message_current_user_is_involved() can not be used any more.');
  1377. }
  1378. /**
  1379. * @deprecated since Moodle 2.9 MDL-45898 - please do not use this function any more.
  1380. */
  1381. function profile_display_badges() {
  1382. throw new coding_exception('profile_display_badges() can not be used any more.');
  1383. }
  1384. /**
  1385. * @deprecated since Moodle 2.9 MDL-45774 - Please do not use this function any more.
  1386. */
  1387. function useredit_shared_definition_preferences() {
  1388. throw new coding_exception('useredit_shared_definition_preferences() can not be used any more.');
  1389. }
  1390. /**
  1391. * @deprecated since Moodle 2.9
  1392. */
  1393. function calendar_normalize_tz() {
  1394. throw new coding_exception('calendar_normalize_tz() can not be used any more, please use core_date::normalise_timezone() instead.');
  1395. }
  1396. /**
  1397. * @deprecated since Moodle 2.9
  1398. */
  1399. function get_user_timezone_offset() {
  1400. throw new coding_exception('get_user_timezone_offset() can not be used any more, please use standard PHP DateTimeZone class instead');
  1401. }
  1402. /**
  1403. * @deprecated since Moodle 2.9
  1404. */
  1405. function get_timezone_offset() {
  1406. throw new coding_exception('get_timezone_offset() can not be used any more, please use standard PHP DateTimeZone class instead');
  1407. }
  1408. /**
  1409. * @deprecated since Moodle 2.9
  1410. */
  1411. function get_list_of_timezones() {
  1412. throw new coding_exception('get_list_of_timezones() can not be used any more, please use core_date::get_list_of_timezones() instead');
  1413. }
  1414. /**
  1415. * @deprecated since Moodle 2.9
  1416. */
  1417. function update_timezone_records() {
  1418. throw new coding_exception('update_timezone_records() can not be used any more, please use standard PHP DateTime class instead');
  1419. }
  1420. /**
  1421. * @deprecated since Moodle 2.9
  1422. */
  1423. function calculate_user_dst_table() {
  1424. throw new coding_exception('calculate_user_dst_table() can not be used any more, please use standard PHP DateTime class instead');
  1425. }
  1426. /**
  1427. * @deprecated since Moodle 2.9
  1428. */
  1429. function dst_changes_for_year() {
  1430. throw new coding_exception('dst_changes_for_year() can not be used any more, please use standard DateTime class instead');
  1431. }
  1432. /**
  1433. * @deprecated since Moodle 2.9
  1434. */
  1435. function get_timezone_record() {
  1436. throw new coding_exception('get_timezone_record() can not be used any more, please use standard PHP DateTime class instead');
  1437. }
  1438. /* === Apis deprecated since Moodle 3.0 === */
  1439. /**
  1440. * @deprecated since Moodle 3.0 MDL-49360 - please do not use this function any more.
  1441. */
  1442. function get_referer() {
  1443. throw new coding_exception('get_referer() can not be used any more. Please use get_local_referer() instead.');
  1444. }
  1445. /**
  1446. * @deprecated since Moodle 3.0 use \core_useragent::is_web_crawler instead.
  1447. */
  1448. function is_web_crawler() {
  1449. throw new coding_exception('is_web_crawler() can not be used any more. Please use core_useragent::is_web_crawler() instead.');
  1450. }
  1451. /**
  1452. * @deprecated since Moodle 3.0 MDL-50287 - please do not use this function any more.
  1453. */
  1454. function completion_cron() {
  1455. throw new coding_exception('completion_cron() can not be used any more. Functionality has been moved to scheduled tasks.');
  1456. }
  1457. /**
  1458. * @deprecated since 3.0
  1459. */
  1460. function coursetag_get_tags() {
  1461. throw new coding_exception('Function coursetag_get_tags() can not be used any more. ' .
  1462. 'Userid is no longer used for tagging courses.');
  1463. }
  1464. /**
  1465. * @deprecated since 3.0
  1466. */
  1467. function coursetag_get_all_tags() {
  1468. throw new coding_exception('Function coursetag_get_all_tags() can not be used any more. Userid is no ' .
  1469. 'longer used for tagging courses.');
  1470. }
  1471. /**
  1472. * @deprecated since 3.0
  1473. */
  1474. function coursetag_get_jscript() {
  1475. throw new coding_exception('Function coursetag_get_jscript() can not be used any more and is obsolete.');
  1476. }
  1477. /**
  1478. * @deprecated since 3.0
  1479. */
  1480. function coursetag_get_jscript_links() {
  1481. throw new coding_exception('Function coursetag_get_jscript_links() can not be used any more and is obsolete.');
  1482. }
  1483. /**
  1484. * @deprecated since 3.0
  1485. */
  1486. function coursetag_get_records() {
  1487. throw new coding_exception('Function coursetag_get_records() can not be used any more. ' .
  1488. 'Userid is no longer used for tagging courses.');
  1489. }
  1490. /**
  1491. * @deprecated since 3.0
  1492. */
  1493. function coursetag_store_keywords() {
  1494. throw new coding_exception('Function coursetag_store_keywords() can not be used any more. ' .
  1495. 'Userid is no longer used for tagging courses.');
  1496. }
  1497. /**
  1498. * @deprecated since 3.0
  1499. */
  1500. function coursetag_delete_keyword() {
  1501. throw new coding_exception('Function coursetag_delete_keyword() can not be used any more. ' .
  1502. 'Userid is no longer used for tagging courses.');
  1503. }
  1504. /**
  1505. * @deprecated since 3.0
  1506. */
  1507. function coursetag_get_tagged_courses() {
  1508. throw new coding_exception('Function coursetag_get_tagged_courses() can not be used any more. ' .
  1509. 'Userid is no longer used for tagging courses.');
  1510. }
  1511. /**
  1512. * @deprecated since 3.0
  1513. */
  1514. function coursetag_delete_course_tags() {
  1515. throw new coding_exception('Function coursetag_delete_course_tags() is deprecated. ' .
  1516. 'Use core_tag_tag::remove_all_item_tags().');
  1517. }
  1518. /**
  1519. * @deprecated since 3.1. Use core_tag_tag::get($tagid)->update() instead
  1520. */
  1521. function tag_type_set() {
  1522. throw new coding_exception('tag_type_set() can not be used anymore. Please use ' .
  1523. 'core_tag_tag::get($tagid)->update().');
  1524. }
  1525. /**
  1526. * @deprecated since 3.1. Use core_tag_tag::get($tagid)->update() instead
  1527. */
  1528. function tag_description_set() {
  1529. throw new coding_exception('tag_description_set() can not be used anymore. Please use ' .
  1530. 'core_tag_tag::get($tagid)->update().');
  1531. }
  1532. /**
  1533. * @deprecated since 3.1. Use core_tag_tag::get_item_tags() instead
  1534. */
  1535. function tag_get_tags() {
  1536. throw new coding_exception('tag_get_tags() can not be used anymore. Please use ' .
  1537. 'core_tag_tag::get_item_tags().');
  1538. }
  1539. /**
  1540. * @deprecated since 3.1
  1541. */
  1542. function tag_get_tags_array() {
  1543. throw new coding_exception('tag_get_tags_array() can not be used anymore. Please use ' .
  1544. 'core_tag_tag::get_item_tags_array().');
  1545. }
  1546. /**
  1547. * @deprecated since 3.1. Use core_tag_tag::get_item_tags_array() or $OUTPUT->tag_list(core_tag_tag::get_item_tags())
  1548. */
  1549. function tag_get_tags_csv() {
  1550. throw new coding_exception('tag_get_tags_csv() can not be used anymore. Please use ' .
  1551. 'core_tag_tag::get_item_tags_array() or $OUTPUT->tag_list(core_tag_tag::get_item_tags()).');
  1552. }
  1553. /**
  1554. * @deprecated since 3.1. Use core_tag_tag::get_item_tags() instead
  1555. */
  1556. function tag_get_tags_ids() {
  1557. throw new coding_exception('tag_get_tags_ids() can not be used anymore. Please consider using ' .
  1558. 'core_tag_tag::get_item_tags() or similar methods.');
  1559. }
  1560. /**
  1561. * @deprecated since 3.1. Use core_tag_tag::get_by_name() or core_tag_tag::get_by_name_bulk()
  1562. */
  1563. function tag_get_id() {
  1564. throw new coding_exception('tag_get_id() can not be used anymore. Please use ' .
  1565. 'core_tag_tag::get_by_name() or core_tag_tag::get_by_name_bulk()');
  1566. }
  1567. /**
  1568. * @deprecated since 3.1. Use core_tag_tag::get($tagid)->update() instead
  1569. */
  1570. function tag_rename() {
  1571. throw new coding_exception('tag_rename() can not be used anymore. Please use ' .
  1572. 'core_tag_tag::get($tagid)->update()');
  1573. }
  1574. /**
  1575. * @deprecated since 3.1. Use core_tag_tag::remove_item_tag() instead
  1576. */
  1577. function tag_delete_instance() {
  1578. throw new coding_exception('tag_delete_instance() can not be used anymore. Please use ' .
  1579. 'core_tag_tag::remove_item_tag()');
  1580. }
  1581. /**
  1582. * @deprecated since 3.1. Use core_tag_tag::get_by_name()->get_tagged_items() instead
  1583. */
  1584. function tag_find_records() {
  1585. throw new coding_exception('tag_find_records() can not be used anymore. Please use ' .
  1586. 'core_tag_tag::get_by_name()->get_tagged_items()');
  1587. }
  1588. /**
  1589. * @deprecated since 3.1
  1590. */
  1591. function tag_add() {
  1592. throw new coding_exception('tag_add() can not be used anymore. You can use ' .
  1593. 'core_tag_tag::create_if_missing(), however it should not be necessary since tags are ' .
  1594. 'created automatically when assigned to items');
  1595. }
  1596. /**
  1597. * @deprecated since 3.1. Use core_tag_tag::set_item_tags() or core_tag_tag::add_item_tag() instead
  1598. */
  1599. function tag_assign() {
  1600. throw new coding_exception('tag_assign() can not be used anymore. Please use ' .
  1601. 'core_tag_tag::set_item_tags() or core_tag_tag::add_item_tag() instead. Tag instance ' .
  1602. 'ordering should not be set manually');
  1603. }
  1604. /**
  1605. * @deprecated since 3.1. Use core_tag_tag::get($tagid)->count_tagged_items() instead
  1606. */
  1607. function tag_record_count() {
  1608. throw new coding_exception('tag_record_count() can not be used anymore. Please use ' .
  1609. 'core_tag_tag::get($tagid)->count_tagged_items().');
  1610. }
  1611. /**
  1612. * @deprecated since 3.1. Use core_tag_tag::get($tagid)->is_item_tagged_with() instead
  1613. */
  1614. function tag_record_tagged_with() {
  1615. throw new coding_exception('tag_record_tagged_with() can not be used anymore. Please use ' .
  1616. 'core_tag_tag::get($tagid)->is_item_tagged_with().');
  1617. }
  1618. /**
  1619. * @deprecated since 3.1. Use core_tag_tag::get($tagid)->flag() instead
  1620. */
  1621. function tag_set_flag() {
  1622. throw new coding_exception('tag_set_flag() can not be used anymore. Please use ' .
  1623. 'core_tag_tag::get($tagid)->flag()');
  1624. }
  1625. /**
  1626. * @deprecated since 3.1. Use core_tag_tag::get($tagid)->reset_flag() instead
  1627. */
  1628. function tag_unset_flag() {
  1629. throw new coding_exception('tag_unset_flag() can not be used anymore. Please use ' .
  1630. 'core_tag_tag::get($tagid)->reset_flag()');
  1631. }
  1632. /**
  1633. * @deprecated since 3.1
  1634. */
  1635. function tag_print_cloud() {
  1636. throw new coding_exception('tag_print_cloud() can not be used anymore. Please use ' .
  1637. 'core_tag_collection::get_tag_cloud(), templateable core_tag\output\tagcloud and ' .
  1638. 'template core_tag/tagcloud.');
  1639. }
  1640. /**
  1641. * @deprecated since 3.0
  1642. */
  1643. function tag_autocomplete() {
  1644. throw new coding_exception('tag_autocomplete() can not be used anymore. New form ' .
  1645. 'element "tags" does proper autocomplete.');
  1646. }
  1647. /**
  1648. * @deprecated since 3.1
  1649. */
  1650. function tag_print_description_box() {
  1651. throw new coding_exception('tag_print_description_box() can not be used anymore. ' .
  1652. 'See core_tag_renderer for similar code');
  1653. }
  1654. /**
  1655. * @deprecated since 3.1
  1656. */
  1657. function tag_print_management_box() {
  1658. throw new coding_exception('tag_print_management_box() can not be used anymore. ' .
  1659. 'See core_tag_renderer for similar code');
  1660. }
  1661. /**
  1662. * @deprecated since 3.1
  1663. */
  1664. function tag_print_search_box() {
  1665. throw new coding_exception('tag_print_search_box() can not be used anymore. ' .
  1666. 'See core_tag_renderer for similar code');
  1667. }
  1668. /**
  1669. * @deprecated since 3.1
  1670. */
  1671. function tag_print_search_results() {
  1672. throw new coding_exception('tag_print_search_results() can not be used anymore. ' .
  1673. 'In /tag/search.php the search results are printed using the core_tag/tagcloud template.');
  1674. }
  1675. /**
  1676. * @deprecated since 3.1
  1677. */
  1678. function tag_print_tagged_users_table() {
  1679. throw new coding_exception('tag_print_tagged_users_table() can not be used anymore. ' .
  1680. 'See core_user_renderer for similar code');
  1681. }
  1682. /**
  1683. * @deprecated since 3.1
  1684. */
  1685. function tag_print_user_box() {
  1686. throw new coding_exception('tag_print_user_box() can not be used anymore. ' .
  1687. 'See core_user_renderer for similar code');
  1688. }
  1689. /**
  1690. * @deprecated since 3.1
  1691. */
  1692. function tag_print_user_list() {
  1693. throw new coding_exception('tag_print_user_list() can not be used anymore. ' .
  1694. 'See core_user_renderer for similar code');
  1695. }
  1696. /**
  1697. * @deprecated since 3.1
  1698. */
  1699. function tag_display_name() {
  1700. throw new coding_exception('tag_display_name() can not be used anymore. Please use ' .
  1701. 'core_tag_tag::make_display_name().');
  1702. }
  1703. /**
  1704. * @deprecated since 3.1
  1705. */
  1706. function tag_normalize() {
  1707. throw new coding_exception('tag_normalize() can not be used anymore. Please use ' .
  1708. 'core_tag_tag::normalize().');
  1709. }
  1710. /**
  1711. * @deprecated since 3.1
  1712. */
  1713. function tag_get_related_tags_csv() {
  1714. throw new coding_exception('tag_get_related_tags_csv() can not be used anymore. Please ' .
  1715. 'consider looping through array or using $OUTPUT->tag_list(core_tag_tag::get_item_tags()).');
  1716. }
  1717. /**
  1718. * @deprecated since 3.1
  1719. */
  1720. function tag_set() {
  1721. throw new coding_exception('tag_set() can not be used anymore. Please use ' .
  1722. 'core_tag_tag::set_item_tags().');
  1723. }
  1724. /**
  1725. * @deprecated since 3.1
  1726. */
  1727. function tag_set_add() {
  1728. throw new coding_exception('tag_set_add() can not be used anymore. Please use ' .
  1729. 'core_tag_tag::add_item_tag().');
  1730. }
  1731. /**
  1732. * @deprecated since 3.1
  1733. */
  1734. function tag_set_delete() {
  1735. throw new coding_exception('tag_set_delete() can not be used anymore. Please use ' .
  1736. 'core_tag_tag::remove_item_tag().');
  1737. }
  1738. /**
  1739. * @deprecated since 3.1
  1740. */
  1741. function tag_get() {
  1742. throw new coding_exception('tag_get() can not be used anymore. Please use ' .
  1743. 'core_tag_tag::get() or core_tag_tag::get_by_name().');
  1744. }
  1745. /**
  1746. * @deprecated since 3.1
  1747. */
  1748. function tag_get_related_tags() {
  1749. throw new coding_exception('tag_get_related_tags() can not be used anymore. Please use ' .
  1750. 'core_tag_tag::get_correlated_tags(), core_tag_tag::get_related_tags() or ' .
  1751. 'core_tag_tag::get_manual_related_tags().');
  1752. }
  1753. /**
  1754. * @deprecated since 3.1
  1755. */
  1756. function tag_delete() {
  1757. throw new coding_exception('tag_delete() can not be used anymore. Please use ' .
  1758. 'core_tag_tag::delete_tags().');
  1759. }
  1760. /**
  1761. * @deprecated since 3.1
  1762. */
  1763. function tag_delete_instances() {
  1764. throw new coding_exception('tag_delete_instances() can not be used anymore. Please use ' .
  1765. 'core_tag_tag::delete_instances().');
  1766. }
  1767. /**
  1768. * @deprecated since 3.1
  1769. */
  1770. function tag_cleanup() {
  1771. throw new coding_exception('tag_cleanup() can not be used anymore. Please use ' .
  1772. '\core\task\tag_cron_task::cleanup().');
  1773. }
  1774. /**
  1775. * @deprecated since 3.1
  1776. */
  1777. function tag_bulk_delete_instances() {
  1778. throw new coding_exception('tag_bulk_delete_instances() can not be used anymore. Please use ' .
  1779. '\core\task\tag_cron_task::bulk_delete_instances().');
  1780. }
  1781. /**
  1782. * @deprecated since 3.1
  1783. */
  1784. function tag_compute_correlations() {
  1785. throw new coding_exception('tag_compute_correlations() can not be used anymore. Please use ' .
  1786. 'use \core\task\tag_cron_task::compute_correlations().');
  1787. }
  1788. /**
  1789. * @deprecated since 3.1
  1790. */
  1791. function tag_process_computed_correlation() {
  1792. throw new coding_exception('tag_process_computed_correlation() can not be used anymore. Please use ' .
  1793. 'use \core\task\tag_cron_task::process_computed_correlation().');
  1794. }
  1795. /**
  1796. * @deprecated since 3.1
  1797. */
  1798. function tag_cron() {
  1799. throw new coding_exception('tag_cron() can not be used anymore. Please use ' .
  1800. 'use \core\task\tag_cron_task::execute().');
  1801. }
  1802. /**
  1803. * @deprecated since 3.1
  1804. */
  1805. function tag_find_tags() {
  1806. throw new coding_exception('tag_find_tags() can not be used anymore.');
  1807. }
  1808. /**
  1809. * @deprecated since 3.1
  1810. */
  1811. function tag_get_name() {
  1812. throw new coding_exception('tag_get_name() can not be used anymore.');
  1813. }
  1814. /**
  1815. * @deprecated since 3.1
  1816. */
  1817. function tag_get_correlated() {
  1818. throw new coding_exception('tag_get_correlated() can not be used anymore. Please use ' .
  1819. 'use core_tag_tag::get_correlated_tags().');
  1820. }
  1821. /**
  1822. * @deprecated since 3.1
  1823. */
  1824. function tag_cloud_sort() {
  1825. throw new coding_exception('tag_cloud_sort() can not be used anymore. Similar method can ' .
  1826. 'be found in core_tag_collection::cloud_sort().');
  1827. }
  1828. /**
  1829. * @deprecated since Moodle 3.1
  1830. */
  1831. function events_load_def() {
  1832. throw new coding_exception('events_load_def() has been deprecated along with all Events 1 API in favour of Events 2 API.');
  1833. }
  1834. /**
  1835. * @deprecated since Moodle 3.1
  1836. */
  1837. function events_queue_handler() {
  1838. throw new coding_exception('events_queue_handler() has been deprecated along with all Events 1 API in favour of Events 2 API.');
  1839. }
  1840. /**
  1841. * @deprecated since Moodle 3.1
  1842. */
  1843. function events_dispatch() {
  1844. throw new coding_exception('events_dispatch() has been deprecated along with all Events 1 API in favour of Events 2 API.');
  1845. }
  1846. /**
  1847. * @deprecated since Moodle 3.1
  1848. */
  1849. function events_process_queued_handler() {
  1850. throw new coding_exception(
  1851. 'events_process_queued_handler() has been deprecated along with all Events 1 API in favour of Events 2 API.'
  1852. );
  1853. }
  1854. /**
  1855. * @deprecated since Moodle 3.1
  1856. */
  1857. function events_update_definition() {
  1858. throw new coding_exception(
  1859. 'events_update_definition has been deprecated along with all Events 1 API in favour of Events 2 API.'
  1860. );
  1861. }
  1862. /**
  1863. * @deprecated since Moodle 3.1
  1864. */
  1865. function events_cron() {
  1866. throw new coding_exception('events_cron() has been deprecated along with all Events 1 API in favour of Events 2 API.');
  1867. }
  1868. /**
  1869. * @deprecated since Moodle 3.1
  1870. */
  1871. function events_trigger_legacy() {
  1872. throw new coding_exception('events_trigger_legacy() has been deprecated along with all Events 1 API in favour of Events 2 API.');
  1873. }
  1874. /**
  1875. * @deprecated since Moodle 3.1
  1876. */
  1877. function events_is_registered() {
  1878. throw new coding_exception('events_is_registered() has been deprecated along with all Events 1 API in favour of Events 2 API.');
  1879. }
  1880. /**
  1881. * @deprecated since Moodle 3.1
  1882. */
  1883. function events_pending_count() {
  1884. throw new coding_exception('events_pending_count() has been deprecated along with all Events 1 API in favour of Events 2 API.');
  1885. }
  1886. /**
  1887. * @deprecated since Moodle 3.0 - this is a part of clamav plugin now.
  1888. */
  1889. function clam_message_admins() {
  1890. throw new coding_exception('clam_message_admins() can not be used anymore. Please use ' .
  1891. 'message_admins() method of \antivirus_clamav\scanner class.');
  1892. }
  1893. /**
  1894. * @deprecated since Moodle 3.0 - this is a part of clamav plugin now.
  1895. */
  1896. function get_clam_error_code() {
  1897. throw new coding_exception('get_clam_error_code() can not be used anymore. Please use ' .
  1898. 'get_clam_error_code() method of \antivirus_clamav\scanner class.');
  1899. }
  1900. /**
  1901. * @deprecated since 3.1
  1902. */
  1903. function course_get_cm_rename_action() {
  1904. throw new coding_exception('course_get_cm_rename_action() can not be used anymore. Please use ' .
  1905. 'inplace_editable https://docs.moodle.org/dev/Inplace_editable.');
  1906. }
  1907. /**
  1908. * @deprecated since Moodle 3.1
  1909. */
  1910. function course_scale_used() {
  1911. throw new coding_exception('course_scale_used() can not be used anymore. Plugins can ' .
  1912. 'implement <modname>_scale_used_anywhere, all implementations of <modname>_scale_used are now ignored');
  1913. }
  1914. /**
  1915. * @deprecated since Moodle 3.1
  1916. */
  1917. function site_scale_used() {
  1918. throw new coding_exception('site_scale_used() can not be used anymore. Plugins can implement ' .
  1919. '<modname>_scale_used_anywhere, all implementations of <modname>_scale_used are now ignored');
  1920. }
  1921. /**
  1922. * @deprecated since Moodle 3.1. Use external_api::external_function_info().
  1923. */
  1924. function external_function_info() {
  1925. throw new coding_exception('external_function_info() can not be used any'.
  1926. 'more. Please use external_api::external_function_info() instead.');
  1927. }
  1928. /**
  1929. * @deprecated since Moodle 3.2
  1930. * @see csv_import_reader::load_csv_content()
  1931. */
  1932. function get_records_csv() {
  1933. throw new coding_exception('get_records_csv() can not be used anymore. Please use ' .
  1934. 'lib/csvlib.class.php csv_import_reader() instead.');
  1935. }
  1936. /**
  1937. * @deprecated since Moodle 3.2
  1938. * @see download_as_dataformat (lib/dataformatlib.php)
  1939. */
  1940. function put_records_csv() {
  1941. throw new coding_exception('put_records_csv() can not be used anymore. Please use ' .
  1942. 'lib/dataformatlib.php download_as_dataformat() instead.');
  1943. }
  1944. /**
  1945. * @deprecated since Moodle 3.2
  1946. */
  1947. function css_is_colour() {
  1948. throw new coding_exception('css_is_colour() can not be used anymore.');
  1949. }
  1950. /**
  1951. * @deprecated since Moodle 3.2
  1952. */
  1953. function css_is_width() {
  1954. throw new coding_exception('css_is_width() can not be used anymore.');
  1955. }
  1956. /**
  1957. * @deprecated since Moodle 3.2
  1958. */
  1959. function css_sort_by_count() {
  1960. throw new coding_exception('css_sort_by_count() can not be used anymore.');
  1961. }
  1962. /**
  1963. * @deprecated since Moodle 3.2
  1964. */
  1965. function message_get_course_contexts() {
  1966. throw new coding_exception('message_get_course_contexts() can not be used anymore.');
  1967. }
  1968. /**
  1969. * @deprecated since Moodle 3.2
  1970. */
  1971. function message_remove_url_params() {
  1972. throw new coding_exception('message_remove_url_params() can not be used anymore.');
  1973. }
  1974. /**
  1975. * @deprecated since Moodle 3.2
  1976. */
  1977. function message_count_messages() {
  1978. throw new coding_exception('message_count_messages() can not be used anymore.');
  1979. }
  1980. /**
  1981. * @deprecated since Moodle 3.2
  1982. */
  1983. function message_count_blocked_users() {
  1984. throw new coding_exception('message_count_blocked_users() can not be used anymore. Please use ' .
  1985. '\core_message\api::count_blocked_users() instead.');
  1986. }
  1987. /**
  1988. * @deprecated since Moodle 3.2
  1989. */
  1990. function message_contact_link() {
  1991. throw new coding_exception('message_contact_link() can not be used anymore.');
  1992. }
  1993. /**
  1994. * @deprecated since Moodle 3.2
  1995. */
  1996. function message_get_recent_notifications() {
  1997. throw new coding_exception('message_get_recent_notifications() can not be used anymore.');
  1998. }
  1999. /**
  2000. * @deprecated since Moodle 3.2
  2001. */
  2002. function message_history_link() {
  2003. throw new coding_exception('message_history_link() can not be used anymore.');
  2004. }
  2005. /**
  2006. * @deprecated since Moodle 3.2
  2007. */
  2008. function message_search() {
  2009. throw new coding_exception('message_search() can not be used anymore.');
  2010. }
  2011. /**
  2012. * @deprecated since Moodle 3.2
  2013. */
  2014. function message_shorten_message() {
  2015. throw new coding_exception('message_shorten_message() can not be used anymore.');
  2016. }
  2017. /**
  2018. * @deprecated since Moodle 3.2
  2019. */
  2020. function message_get_fragment() {
  2021. throw new coding_exception('message_get_fragment() can not be used anymore.');
  2022. }
  2023. /**
  2024. * @deprecated since Moodle 3.2
  2025. */
  2026. function message_get_history() {
  2027. throw new coding_exception('message_get_history() can not be used anymore.');
  2028. }
  2029. /**
  2030. * @deprecated since Moodle 3.2
  2031. */
  2032. function message_get_contact_add_remove_link() {
  2033. throw new coding_exception('message_get_contact_add_remove_link() can not be used anymore.');
  2034. }
  2035. /**
  2036. * @deprecated since Moodle 3.2
  2037. */
  2038. function message_get_contact_block_link() {
  2039. throw new coding_exception('message_get_contact_block_link() can not be used anymore.');
  2040. }
  2041. /**
  2042. * @deprecated since Moodle 3.2
  2043. */
  2044. function message_mark_messages_read() {
  2045. throw new coding_exception('message_mark_messages_read() can not be used anymore. Please use ' .
  2046. '\core_message\api::mark_all_messages_as_read() instead.');
  2047. }
  2048. /**
  2049. * @deprecated since Moodle 3.2
  2050. */
  2051. function message_page_type_list() {
  2052. throw new coding_exception('message_page_type_list() can not be used anymore.');
  2053. }
  2054. /**
  2055. * @deprecated since Moodle 3.2
  2056. */
  2057. function message_can_post_message() {
  2058. throw new coding_exception('message_can_post_message() can not be used anymore. Please use ' .
  2059. '\core_message\api::can_send_message() instead.');
  2060. }
  2061. /**
  2062. * @deprecated since Moodle 3.2
  2063. */
  2064. function message_is_user_non_contact_blocked() {
  2065. throw new coding_exception('message_is_user_non_contact_blocked() can not be used anymore. Please use ' .
  2066. '\core_message\api::is_user_non_contact_blocked() instead.');
  2067. }
  2068. /**
  2069. * @deprecated since Moodle 3.2
  2070. */
  2071. function message_is_user_blocked() {
  2072. throw new coding_exception('message_is_user_blocked() can not be used anymore. Please use ' .
  2073. '\core_message\api::is_user_blocked() instead.');
  2074. }
  2075. /**
  2076. * @deprecated since Moodle 3.2
  2077. */
  2078. function print_log() {
  2079. throw new coding_exception('print_log() can not be used anymore. Please use the ' .
  2080. 'report_log framework instead.');
  2081. }
  2082. /**
  2083. * @deprecated since Moodle 3.2
  2084. */
  2085. function print_mnet_log() {
  2086. throw new coding_exception('print_mnet_log() can not be used anymore. Please use the ' .
  2087. 'report_log framework instead.');
  2088. }
  2089. /**
  2090. * @deprecated since Moodle 3.2
  2091. */
  2092. function print_log_csv() {
  2093. throw new coding_exception('print_log_csv() can not be used anymore. Please use the ' .
  2094. 'report_log framework instead.');
  2095. }
  2096. /**
  2097. * @deprecated since Moodle 3.2
  2098. */
  2099. function print_log_xls() {
  2100. throw new coding_exception('print_log_xls() can not be used anymore. Please use the ' .
  2101. 'report_log framework instead.');
  2102. }
  2103. /**
  2104. * @deprecated since Moodle 3.2
  2105. */
  2106. function print_log_ods() {
  2107. throw new coding_exception('print_log_ods() can not be used anymore. Please use the ' .
  2108. 'report_log framework instead.');
  2109. }
  2110. /**
  2111. * @deprecated since Moodle 3.2
  2112. */
  2113. function build_logs_array() {
  2114. throw new coding_exception('build_logs_array() can not be used anymore. Please use the ' .
  2115. 'report_log framework instead.');
  2116. }
  2117. /**
  2118. * @deprecated since Moodle 3.2
  2119. */
  2120. function get_logs_usercourse() {
  2121. throw new coding_exception('get_logs_usercourse() can not be used anymore. Please use the ' .
  2122. 'report_log framework instead.');
  2123. }
  2124. /**
  2125. * @deprecated since Moodle 3.2
  2126. */
  2127. function get_logs_userday() {
  2128. throw new coding_exception('get_logs_userday() can not be used anymore. Please use the ' .
  2129. 'report_log framework instead.');
  2130. }
  2131. /**
  2132. * @deprecated since Moodle 3.2
  2133. */
  2134. function get_logs() {
  2135. throw new coding_exception('get_logs() can not be used anymore. Please use the ' .
  2136. 'report_log framework instead.');
  2137. }
  2138. /**
  2139. * @deprecated since Moodle 3.2
  2140. */
  2141. function prevent_form_autofill_password() {
  2142. throw new coding_exception('prevent_form_autofill_password() can not be used anymore.');
  2143. }
  2144. /**
  2145. * @deprecated since Moodle 3.3 MDL-57370
  2146. */
  2147. function message_get_recent_conversations($userorid, $limitfrom = 0, $limitto = 100) {
  2148. throw new coding_exception('message_get_recent_conversations() can not be used any more. ' .
  2149. 'Please use \core_message\api::get_conversations() instead.', DEBUG_DEVELOPER);
  2150. }
  2151. /**
  2152. * @deprecated since Moodle 3.2
  2153. */
  2154. function calendar_preferences_button() {
  2155. throw new coding_exception('calendar_preferences_button() can not be used anymore. The calendar ' .
  2156. 'preferences are now linked to the user preferences page.');
  2157. }
  2158. /**
  2159. * @deprecated since 3.3
  2160. */
  2161. function calendar_wday_name() {
  2162. throw new coding_exception('Function calendar_wday_name() is removed and no longer used in core.');
  2163. }
  2164. /**
  2165. * @deprecated since 3.3
  2166. */
  2167. function calendar_get_block_upcoming() {
  2168. throw new coding_exception('Function calendar_get_block_upcoming() is removed,' .
  2169. 'Please see block_calendar_upcoming::get_content() for the correct API usage.');
  2170. }
  2171. /**
  2172. * @deprecated since 3.3
  2173. */
  2174. function calendar_print_month_selector() {
  2175. throw new coding_exception('Function calendar_print_month_selector() is removed and can no longer used in core.');
  2176. }
  2177. /**
  2178. * @deprecated since 3.3
  2179. */
  2180. function calendar_cron() {
  2181. throw new coding_exception('Function calendar_cron() is removed. Please use the core\task\calendar_cron_task instead.');
  2182. }
  2183. /**
  2184. * @deprecated since Moodle 3.4 and removed immediately. MDL-49398.
  2185. */
  2186. function load_course_context() {
  2187. throw new coding_exception('load_course_context() is removed. Do not use private functions or data structures.');
  2188. }
  2189. /**
  2190. * @deprecated since Moodle 3.4 and removed immediately. MDL-49398.
  2191. */
  2192. function load_role_access_by_context() {
  2193. throw new coding_exception('load_role_access_by_context() is removed. Do not use private functions or data structures.');
  2194. }
  2195. /**
  2196. * @deprecated since Moodle 3.4 and removed immediately. MDL-49398.
  2197. */
  2198. function dedupe_user_access() {
  2199. throw new coding_exception('dedupe_user_access() is removed. Do not use private functions or data structures.');
  2200. }
  2201. /**
  2202. * @deprecated since Moodle 3.4. MDL-49398.
  2203. */
  2204. function get_user_access_sitewide() {
  2205. throw new coding_exception('get_user_access_sitewide() is removed. Do not use private functions or data structures.');
  2206. }
  2207. /**
  2208. * @deprecated since Moodle 3.4. MDL-59333
  2209. */
  2210. function calendar_get_mini() {
  2211. throw new coding_exception('calendar_get_mini() has been removed. Please update your code to use calendar_get_view.');
  2212. }
  2213. /**
  2214. * @deprecated since Moodle 3.4. MDL-59333
  2215. */
  2216. function calendar_get_upcoming() {
  2217. throw new coding_exception('calendar_get_upcoming() has been removed. ' .
  2218. 'Please see block_calendar_upcoming::get_content() for the correct API usage.');
  2219. }
  2220. /**
  2221. * @deprecated since Moodle 3.4. MDL-50666
  2222. */
  2223. function allow_override() {
  2224. throw new coding_exception('allow_override() has been removed. Please update your code to use core_role_set_override_allowed.');
  2225. }
  2226. /**
  2227. * @deprecated since Moodle 3.4. MDL-50666
  2228. */
  2229. function allow_assign() {
  2230. throw new coding_exception('allow_assign() has been removed. Please update your code to use core_role_set_assign_allowed.');
  2231. }
  2232. /**
  2233. * @deprecated since Moodle 3.4. MDL-50666
  2234. */
  2235. function allow_switch() {
  2236. throw new coding_exception('allow_switch() has been removed. Please update your code to use core_role_set_switch_allowed.');
  2237. }
  2238. /**
  2239. * @deprecated since Moodle 3.5. MDL-61132
  2240. */
  2241. function question_add_tops() {
  2242. throw new coding_exception(
  2243. 'question_add_tops() has been removed. You may want to pass $top = true to get_categories_for_contexts().'
  2244. );
  2245. }
  2246. /**
  2247. * @deprecated since Moodle 3.5. MDL-61132
  2248. */
  2249. function question_is_only_toplevel_category_in_context() {
  2250. throw new coding_exception('question_is_only_toplevel_category_in_context() has been removed. '
  2251. . 'Please update your code to use question_is_only_child_of_top_category_in_context() instead.');
  2252. }
  2253. /**
  2254. * @deprecated since Moodle 3.5
  2255. */
  2256. function message_move_userfrom_unread2read() {
  2257. throw new coding_exception('message_move_userfrom_unread2read() has been removed.');
  2258. }
  2259. /**
  2260. * @deprecated since Moodle 3.5
  2261. */
  2262. function message_get_blocked_users() {
  2263. throw new coding_exception(
  2264. 'message_get_blocked_users() has been removed, please use \core_message\api::get_blocked_users() instead.'
  2265. );
  2266. }
  2267. /**
  2268. * @deprecated since Moodle 3.5
  2269. */
  2270. function message_get_contacts() {
  2271. throw new coding_exception('message_get_contacts() has been removed.');
  2272. }
  2273. /**
  2274. * @deprecated since Moodle 3.5
  2275. */
  2276. function message_mark_message_read() {
  2277. throw new coding_exception('message_mark_message_read() has been removed, please use \core_message\api::mark_message_as_read()
  2278. or \core_message\api::mark_notification_as_read().');
  2279. }
  2280. /**
  2281. * @deprecated since Moodle 3.5
  2282. */
  2283. function message_can_delete_message() {
  2284. throw new coding_exception(
  2285. 'message_can_delete_message() has been removed, please use \core_message\api::can_delete_message() instead.'
  2286. );
  2287. }
  2288. /**
  2289. * @deprecated since Moodle 3.5
  2290. */
  2291. function message_delete_message() {
  2292. throw new coding_exception(
  2293. 'message_delete_message() has been removed, please use \core_message\api::delete_message() instead.'
  2294. );
  2295. }
  2296. /**
  2297. * Get all of the allowed types for all of the courses and groups
  2298. * the logged in user belongs to.
  2299. *
  2300. * The returned array will optionally have 5 keys:
  2301. * 'user' : true if the logged in user can create user events
  2302. * 'site' : true if the logged in user can create site events
  2303. * 'category' : array of course categories that the user can create events for
  2304. * 'course' : array of courses that the user can create events for
  2305. * 'group': array of groups that the user can create events for
  2306. * 'groupcourses' : array of courses that the groups belong to (can
  2307. * be different from the list in 'course'.
  2308. * @deprecated since 3.6
  2309. * @return array The array of allowed types.
  2310. */
  2311. function calendar_get_all_allowed_types() {
  2312. debugging('calendar_get_all_allowed_types() is deprecated. Please use calendar_get_allowed_types() instead.',
  2313. DEBUG_DEVELOPER);
  2314. global $CFG, $USER, $DB;
  2315. require_once($CFG->libdir . '/enrollib.php');
  2316. $types = [];
  2317. $allowed = new stdClass();
  2318. calendar_get_allowed_types($allowed);
  2319. if ($allowed->user) {
  2320. $types['user'] = true;
  2321. }
  2322. if ($allowed->site) {
  2323. $types['site'] = true;
  2324. }
  2325. if (core_course_category::has_manage_capability_on_any()) {
  2326. $types['category'] = core_course_category::make_categories_list('moodle/category:manage');
  2327. }
  2328. // This function warms the context cache for the course so the calls
  2329. // to load the course context in calendar_get_allowed_types don't result
  2330. // in additional DB queries.
  2331. $courses = calendar_get_default_courses(null, 'id, groupmode, groupmodeforce', true);
  2332. // We want to pre-fetch all of the groups for each course in a single
  2333. // query to avoid calendar_get_allowed_types from hitting the DB for
  2334. // each separate course.
  2335. $groups = groups_get_all_groups_for_courses($courses);
  2336. foreach ($courses as $course) {
  2337. $coursegroups = isset($groups[$course->id]) ? $groups[$course->id] : null;
  2338. calendar_get_allowed_types($allowed, $course, $coursegroups);
  2339. if (!empty($allowed->courses)) {
  2340. $types['course'][$course->id] = $course;
  2341. }
  2342. if (!empty($allowed->groups)) {
  2343. $types['groupcourses'][$course->id] = $course;
  2344. if (!isset($types['group'])) {
  2345. $types['group'] = array_values($allowed->groups);
  2346. } else {
  2347. $types['group'] = array_merge($types['group'], array_values($allowed->groups));
  2348. }
  2349. }
  2350. }
  2351. return $types;
  2352. }
  2353. /**
  2354. * Gets array of all groups in a set of course.
  2355. *
  2356. * @category group
  2357. * @param array $courses Array of course objects or course ids.
  2358. * @return array Array of groups indexed by course id.
  2359. */
  2360. function groups_get_all_groups_for_courses($courses) {
  2361. global $DB;
  2362. if (empty($courses)) {
  2363. return [];
  2364. }
  2365. $groups = [];
  2366. $courseids = [];
  2367. foreach ($courses as $course) {
  2368. $courseid = is_object($course) ? $course->id : $course;
  2369. $groups[$courseid] = [];
  2370. $courseids[] = $courseid;
  2371. }
  2372. $groupfields = [
  2373. 'g.id as gid',
  2374. 'g.courseid',
  2375. 'g.idnumber',
  2376. 'g.name',
  2377. 'g.description',
  2378. 'g.descriptionformat',
  2379. 'g.enrolmentkey',
  2380. 'g.picture',
  2381. 'g.hidepicture',
  2382. 'g.timecreated',
  2383. 'g.timemodified'
  2384. ];
  2385. $groupsmembersfields = [
  2386. 'gm.id as gmid',
  2387. 'gm.groupid',
  2388. 'gm.userid',
  2389. 'gm.timeadded',
  2390. 'gm.component',
  2391. 'gm.itemid'
  2392. ];
  2393. $concatidsql = $DB->sql_concat_join("'-'", ['g.id', 'COALESCE(gm.id, 0)']) . ' AS uniqid';
  2394. list($courseidsql, $params) = $DB->get_in_or_equal($courseids);
  2395. $groupfieldssql = implode(',', $groupfields);
  2396. $groupmembersfieldssql = implode(',', $groupsmembersfields);
  2397. $sql = "SELECT {$concatidsql}, {$groupfieldssql}, {$groupmembersfieldssql}
  2398. FROM {groups} g
  2399. LEFT JOIN {groups_members} gm
  2400. ON gm.groupid = g.id
  2401. WHERE g.courseid {$courseidsql}";
  2402. $results = $DB->get_records_sql($sql, $params);
  2403. // The results will come back as a flat dataset thanks to the left
  2404. // join so we will need to do some post processing to blow it out
  2405. // into a more usable data structure.
  2406. //
  2407. // This loop will extract the distinct groups from the result set
  2408. // and add it's list of members to the object as a property called
  2409. // 'members'. Then each group will be added to the result set indexed
  2410. // by it's course id.
  2411. //
  2412. // The resulting data structure for $groups should be:
  2413. // $groups = [
  2414. // '1' = [
  2415. // '1' => (object) [
  2416. // 'id' => 1,
  2417. // <rest of group properties>
  2418. // 'members' => [
  2419. // '1' => (object) [
  2420. // <group member properties>
  2421. // ],
  2422. // '2' => (object) [
  2423. // <group member properties>
  2424. // ]
  2425. // ]
  2426. // ],
  2427. // '2' => (object) [
  2428. // 'id' => 2,
  2429. // <rest of group properties>
  2430. // 'members' => [
  2431. // '1' => (object) [
  2432. // <group member properties>
  2433. // ],
  2434. // '3' => (object) [
  2435. // <group member properties>
  2436. // ]
  2437. // ]
  2438. // ]
  2439. // ]
  2440. // ]
  2441. //
  2442. foreach ($results as $key => $result) {
  2443. $groupid = $result->gid;
  2444. $courseid = $result->courseid;
  2445. $coursegroups = $groups[$courseid];
  2446. $groupsmembersid = $result->gmid;
  2447. $reducefunc = function($carry, $field) use ($result) {
  2448. // Iterate over the groups properties and pull
  2449. // them out into a separate object.
  2450. list($prefix, $field) = explode('.', $field);
  2451. if (property_exists($result, $field)) {
  2452. $carry[$field] = $result->{$field};
  2453. }
  2454. return $carry;
  2455. };
  2456. if (isset($coursegroups[$groupid])) {
  2457. $group = $coursegroups[$groupid];
  2458. } else {
  2459. $initial = [
  2460. 'id' => $groupid,
  2461. 'members' => []
  2462. ];
  2463. $group = (object) array_reduce(
  2464. $groupfields,
  2465. $reducefunc,
  2466. $initial
  2467. );
  2468. }
  2469. if (!empty($groupsmembersid)) {
  2470. $initial = ['id' => $groupsmembersid];
  2471. $groupsmembers = (object) array_reduce(
  2472. $groupsmembersfields,
  2473. $reducefunc,
  2474. $initial
  2475. );
  2476. $group->members[$groupsmembers->userid] = $groupsmembers;
  2477. }
  2478. $coursegroups[$groupid] = $group;
  2479. $groups[$courseid] = $coursegroups;
  2480. }
  2481. return $groups;
  2482. }
  2483. /**
  2484. * Gets the capabilities that have been cached in the database for this
  2485. * component.
  2486. * @deprecated since Moodle 3.6. Please use the Events 2 API.
  2487. * @todo final deprecation. To be removed in Moodle 4.0
  2488. *
  2489. * @access protected To be used from eventslib only
  2490. *
  2491. * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
  2492. * @return array of events
  2493. */
  2494. function events_get_cached($component) {
  2495. global $DB;
  2496. debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
  2497. DEBUG_DEVELOPER);
  2498. $cachedhandlers = array();
  2499. if ($storedhandlers = $DB->get_records('events_handlers', array('component'=>$component))) {
  2500. foreach ($storedhandlers as $handler) {
  2501. $cachedhandlers[$handler->eventname] = array (
  2502. 'id' => $handler->id,
  2503. 'handlerfile' => $handler->handlerfile,
  2504. 'handlerfunction' => $handler->handlerfunction,
  2505. 'schedule' => $handler->schedule,
  2506. 'internal' => $handler->internal);
  2507. }
  2508. }
  2509. return $cachedhandlers;
  2510. }
  2511. /**
  2512. * Remove all event handlers and queued events
  2513. * @deprecated since Moodle 3.6. Please use the Events 2 API.
  2514. * @todo final deprecation. To be removed in Moodle 4.0
  2515. *
  2516. * @category event
  2517. * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
  2518. */
  2519. function events_uninstall($component) {
  2520. debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
  2521. DEBUG_DEVELOPER);
  2522. $cachedhandlers = events_get_cached($component);
  2523. events_cleanup($component, $cachedhandlers);
  2524. events_get_handlers('reset');
  2525. }
  2526. /**
  2527. * Deletes cached events that are no longer needed by the component.
  2528. * @deprecated since Moodle 3.6. Please use the Events 2 API.
  2529. * @todo final deprecation. To be removed in Moodle 4.0
  2530. *
  2531. * @access protected To be used from eventslib only
  2532. *
  2533. * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
  2534. * @param array $cachedhandlers array of the cached events definitions that will be
  2535. * @return int number of unused handlers that have been removed
  2536. */
  2537. function events_cleanup($component, $cachedhandlers) {
  2538. global $DB;
  2539. debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
  2540. DEBUG_DEVELOPER);
  2541. $deletecount = 0;
  2542. foreach ($cachedhandlers as $eventname => $cachedhandler) {
  2543. if ($qhandlers = $DB->get_records('events_queue_handlers', array('handlerid'=>$cachedhandler['id']))) {
  2544. //debugging("Removing pending events from queue before deleting of event handler: $component - $eventname");
  2545. foreach ($qhandlers as $qhandler) {
  2546. events_dequeue($qhandler);
  2547. }
  2548. }
  2549. $DB->delete_records('events_handlers', array('eventname'=>$eventname, 'component'=>$component));
  2550. $deletecount++;
  2551. }
  2552. return $deletecount;
  2553. }
  2554. /**
  2555. * Removes this queued handler from the events_queued_handler table
  2556. *
  2557. * Removes events_queue record from events_queue if no more references to this event object exists
  2558. * @deprecated since Moodle 3.6. Please use the Events 2 API.
  2559. * @todo final deprecation. To be removed in Moodle 4.0
  2560. *
  2561. * @access protected To be used from eventslib only
  2562. *
  2563. * @param stdClass $qhandler A row from the events_queued_handler table
  2564. */
  2565. function events_dequeue($qhandler) {
  2566. global $DB;
  2567. debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
  2568. DEBUG_DEVELOPER);
  2569. // first delete the queue handler
  2570. $DB->delete_records('events_queue_handlers', array('id'=>$qhandler->id));
  2571. // if no more queued handler is pointing to the same event - delete the event too
  2572. if (!$DB->record_exists('events_queue_handlers', array('queuedeventid'=>$qhandler->queuedeventid))) {
  2573. $DB->delete_records('events_queue', array('id'=>$qhandler->queuedeventid));
  2574. }
  2575. }
  2576. /**
  2577. * Returns handlers for given event. Uses caching for better perf.
  2578. * @deprecated since Moodle 3.6. Please use the Events 2 API.
  2579. * @todo final deprecation. To be removed in Moodle 4.0
  2580. *
  2581. * @access protected To be used from eventslib only
  2582. *
  2583. * @staticvar array $handlers
  2584. * @param string $eventname name of event or 'reset'
  2585. * @return array|false array of handlers or false otherwise
  2586. */
  2587. function events_get_handlers($eventname) {
  2588. global $DB;
  2589. static $handlers = array();
  2590. debugging('Events API using $handlers array has been deprecated in favour of Events 2 API, please use it instead.',
  2591. DEBUG_DEVELOPER);
  2592. if ($eventname === 'reset') {
  2593. $handlers = array();
  2594. return false;
  2595. }
  2596. if (!array_key_exists($eventname, $handlers)) {
  2597. $handlers[$eventname] = $DB->get_records('events_handlers', array('eventname'=>$eventname));
  2598. }
  2599. return $handlers[$eventname];
  2600. }
  2601. /**
  2602. * This function finds the roles assigned directly to this context only
  2603. * i.e. no roles in parent contexts
  2604. *
  2605. * @deprecated since Moodle 3.6. Please use the get_roles_used_in_context().
  2606. * @todo final deprecation. To be removed in Moodle 4.0
  2607. * @param context $context
  2608. * @return array
  2609. */
  2610. function get_roles_on_exact_context(context $context) {
  2611. debugging('get_roles_on_exact_context() is deprecated, please use get_roles_used_in_context() instead.',
  2612. DEBUG_DEVELOPER);
  2613. return get_roles_used_in_context($context, false);
  2614. }
  2615. /**
  2616. * Find out which roles has assignment on this context
  2617. *
  2618. * @deprecated since Moodle 3.6. Please use the get_roles_used_in_context().
  2619. * @todo final deprecation. To be removed in Moodle 4.0
  2620. * @param context $context
  2621. * @return array
  2622. */
  2623. function get_roles_with_assignment_on_context(context $context) {
  2624. debugging('get_roles_with_assignment_on_context() is deprecated, please use get_roles_used_in_context() instead.',
  2625. DEBUG_DEVELOPER);
  2626. return get_roles_used_in_context($context, false);
  2627. }
  2628. /**
  2629. * Add the selected user as a contact for the current user
  2630. *
  2631. * @deprecated since Moodle 3.6
  2632. * @param int $contactid the ID of the user to add as a contact
  2633. * @param int $blocked 1 if you wish to block the contact
  2634. * @param int $userid the user ID of the user we want to add the contact for, defaults to current user if not specified.
  2635. * @return bool/int false if the $contactid isnt a valid user id. True if no changes made.
  2636. * Otherwise returns the result of update_record() or insert_record()
  2637. */
  2638. function message_add_contact($contactid, $blocked = 0, $userid = 0) {
  2639. debugging('message_add_contact() is deprecated. Please use \core_message\api::create_contact_request() instead. ' .
  2640. 'If you wish to block or unblock a user please use \core_message\api::is_blocked() and ' .
  2641. '\core_message\api::block_user() or \core_message\api::unblock_user() respectively.', DEBUG_DEVELOPER);
  2642. global $USER, $DB;
  2643. if (!$DB->record_exists('user', array('id' => $contactid))) {
  2644. return false;
  2645. }
  2646. if (empty($userid)) {
  2647. $userid = $USER->id;
  2648. }
  2649. // Check if a record already exists as we may be changing blocking status.
  2650. if (\core_message\api::is_contact($userid, $contactid)) {
  2651. $isblocked = \core_message\api::is_blocked($userid, $contactid);
  2652. // Check if blocking status has been changed.
  2653. if ($isblocked != $blocked) {
  2654. if ($blocked == 1) {
  2655. if (!$isblocked) {
  2656. \core_message\api::block_user($userid, $contactid);
  2657. }
  2658. } else {
  2659. \core_message\api::unblock_user($userid, $contactid);
  2660. }
  2661. return true;
  2662. } else {
  2663. // No change to blocking status.
  2664. return true;
  2665. }
  2666. } else {
  2667. if ($blocked == 1) {
  2668. if (!\core_message\api::is_blocked($userid, $contactid)) {
  2669. \core_message\api::block_user($userid, $contactid);
  2670. }
  2671. } else {
  2672. \core_message\api::unblock_user($userid, $contactid);
  2673. if (!\core_message\api::does_contact_request_exist($userid, $contactid)) {
  2674. \core_message\api::create_contact_request($userid, $contactid);
  2675. }
  2676. }
  2677. return true;
  2678. }
  2679. }
  2680. /**
  2681. * Remove a contact.
  2682. *
  2683. * @deprecated since Moodle 3.6
  2684. * @param int $contactid the user ID of the contact to remove
  2685. * @param int $userid the user ID of the user we want to remove the contacts for, defaults to current user if not specified.
  2686. * @return bool returns the result of delete_records()
  2687. */
  2688. function message_remove_contact($contactid, $userid = 0) {
  2689. debugging('message_remove_contact() is deprecated. Please use \core_message\api::remove_contact() instead.',
  2690. DEBUG_DEVELOPER);
  2691. global $USER;
  2692. if (empty($userid)) {
  2693. $userid = $USER->id;
  2694. }
  2695. \core_message\api::remove_contact($userid, $contactid);
  2696. return true;
  2697. }
  2698. /**
  2699. * Unblock a contact.
  2700. *
  2701. * @deprecated since Moodle 3.6
  2702. * @param int $contactid the user ID of the contact to unblock
  2703. * @param int $userid the user ID of the user we want to unblock the contact for, defaults to current user
  2704. * if not specified.
  2705. * @return bool returns the result of delete_records()
  2706. */
  2707. function message_unblock_contact($contactid, $userid = 0) {
  2708. debugging('message_unblock_contact() is deprecated. Please use \core_message\api::unblock_user() instead.',
  2709. DEBUG_DEVELOPER);
  2710. global $DB, $USER;
  2711. if (!$DB->record_exists('user', array('id' => $contactid))) {
  2712. return false;
  2713. }
  2714. if (empty($userid)) {
  2715. $userid = $USER->id;
  2716. }
  2717. \core_message\api::unblock_user($userid, $contactid);
  2718. return true;
  2719. }
  2720. /**
  2721. * Block a user.
  2722. *
  2723. * @deprecated since Moodle 3.6
  2724. * @param int $contactid the user ID of the user to block
  2725. * @param int $userid the user ID of the user we want to unblock the contact for, defaults to current user
  2726. * if not specified.
  2727. * @return bool
  2728. */
  2729. function message_block_contact($contactid, $userid = 0) {
  2730. debugging('message_block_contact() is deprecated. Please use \core_message\api::is_blocked() and ' .
  2731. '\core_message\api::block_user() instead.', DEBUG_DEVELOPER);
  2732. global $DB, $USER;
  2733. if (!$DB->record_exists('user', array('id' => $contactid))) {
  2734. return false;
  2735. }
  2736. if (empty($userid)) {
  2737. $userid = $USER->id;
  2738. }
  2739. if (!\core_message\api::is_blocked($userid, $contactid)) {
  2740. \core_message\api::block_user($userid, $contactid);
  2741. }
  2742. return true;
  2743. }
  2744. /**
  2745. * Load a user's contact record
  2746. *
  2747. * @deprecated since Moodle 3.6
  2748. * @param int $contactid the user ID of the user whose contact record you want
  2749. * @return array message contacts
  2750. */
  2751. function message_get_contact($contactid) {
  2752. debugging('message_get_contact() is deprecated. Please use \core_message\api::get_contact() instead.',
  2753. DEBUG_DEVELOPER);
  2754. global $USER;
  2755. return \core_message\api::get_contact($USER->id, $contactid);
  2756. }
  2757. /**
  2758. * Returns list of courses, for whole site, or category
  2759. *
  2760. * Similar to get_courses, but allows paging
  2761. * Important: Using c.* for fields is extremely expensive because
  2762. * we are using distinct. You almost _NEVER_ need all the fields
  2763. * in such a large SELECT
  2764. *
  2765. * @deprecated since Moodle 3.7
  2766. * @todo The final deprecation of this function will take place in Moodle 41 - see MDL-65319.
  2767. *
  2768. * @param string|int $categoryid Either a category id or 'all' for everything
  2769. * @param string $sort A field and direction to sort by
  2770. * @param string $fields The additional fields to return
  2771. * @param int $totalcount Reference for the number of courses
  2772. * @param string $limitfrom The course to start from
  2773. * @param string $limitnum The number of courses to limit to
  2774. * @return array Array of courses
  2775. */
  2776. function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c.*",
  2777. &$totalcount, $limitfrom="", $limitnum="") {
  2778. debugging('Function get_courses_page() is deprecated. Please use core_course_category::get_courses() ' .
  2779. 'or core_course_category::search_courses()', DEBUG_DEVELOPER);
  2780. global $USER, $CFG, $DB;
  2781. $params = array();
  2782. $categoryselect = "";
  2783. if ($categoryid !== "all" && is_numeric($categoryid)) {
  2784. $categoryselect = "WHERE c.category = :catid";
  2785. $params['catid'] = $categoryid;
  2786. } else {
  2787. $categoryselect = "";
  2788. }
  2789. $ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
  2790. $ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
  2791. $params['contextlevel'] = CONTEXT_COURSE;
  2792. $totalcount = 0;
  2793. if (!$limitfrom) {
  2794. $limitfrom = 0;
  2795. }
  2796. $visiblecourses = array();
  2797. $sql = "SELECT $fields $ccselect
  2798. FROM {course} c
  2799. $ccjoin
  2800. $categoryselect
  2801. ORDER BY $sort";
  2802. // Pull out all course matching the cat.
  2803. $rs = $DB->get_recordset_sql($sql, $params);
  2804. // Iteration will have to be done inside loop to keep track of the limitfrom and limitnum.
  2805. foreach ($rs as $course) {
  2806. context_helper::preload_from_record($course);
  2807. if (core_course_category::can_view_course_info($course)) {
  2808. $totalcount++;
  2809. if ($totalcount > $limitfrom && (!$limitnum or count($visiblecourses) < $limitnum)) {
  2810. $visiblecourses [$course->id] = $course;
  2811. }
  2812. }
  2813. }
  2814. $rs->close();
  2815. return $visiblecourses;
  2816. }
  2817. /**
  2818. * Returns the models that generated insights in the provided context.
  2819. *
  2820. * @deprecated since Moodle 3.8 MDL-66091 - please do not use this function any more.
  2821. * @todo MDL-65799 This will be deleted in Moodle 4.2
  2822. * @see \core_analytics\manager::cached_models_with_insights
  2823. * @param \context $context
  2824. * @return int[]
  2825. */
  2826. function report_insights_context_insights(\context $context) {
  2827. debugging('report_insights_context_insights is deprecated. Please use ' .
  2828. '\core_analytics\manager::cached_models_with_insights instead', DEBUG_DEVELOPER);
  2829. return \core_analytics\manager::cached_models_with_insights($context);
  2830. }
  2831. /**
  2832. * Retrieve all metadata for the requested modules
  2833. *
  2834. * @deprecated since 3.9.
  2835. * @param object $course The Course
  2836. * @param array $modnames An array containing the list of modules and their
  2837. * names
  2838. * @param int $sectionreturn The section to return to
  2839. * @return array A list of stdClass objects containing metadata about each
  2840. * module
  2841. */
  2842. function get_module_metadata($course, $modnames, $sectionreturn = null) {
  2843. global $OUTPUT;
  2844. debugging('get_module_metadata is deprecated. Please use \core_course\local\service\content_item_service instead.');
  2845. // get_module_metadata will be called once per section on the page and courses may show
  2846. // different modules to one another
  2847. static $modlist = array();
  2848. if (!isset($modlist[$course->id])) {
  2849. $modlist[$course->id] = array();
  2850. }
  2851. $return = array();
  2852. $urlbase = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey()));
  2853. if ($sectionreturn !== null) {
  2854. $urlbase->param('sr', $sectionreturn);
  2855. }
  2856. foreach($modnames as $modname => $modnamestr) {
  2857. if (!course_allowed_module($course, $modname)) {
  2858. continue;
  2859. }
  2860. if (isset($modlist[$course->id][$modname])) {
  2861. // This module is already cached
  2862. $return += $modlist[$course->id][$modname];
  2863. continue;
  2864. }
  2865. $modlist[$course->id][$modname] = array();
  2866. // Create an object for a default representation of this module type in the activity chooser. It will be used
  2867. // if module does not implement callback get_shortcuts() and it will also be passed to the callback if it exists.
  2868. $defaultmodule = new stdClass();
  2869. $defaultmodule->title = $modnamestr;
  2870. $defaultmodule->name = $modname;
  2871. $defaultmodule->link = new moodle_url($urlbase, array('add' => $modname));
  2872. $defaultmodule->icon = $OUTPUT->pix_icon('icon', '', $defaultmodule->name, array('class' => 'icon'));
  2873. $sm = get_string_manager();
  2874. if ($sm->string_exists('modulename_help', $modname)) {
  2875. $defaultmodule->help = get_string('modulename_help', $modname);
  2876. if ($sm->string_exists('modulename_link', $modname)) { // Link to further info in Moodle docs.
  2877. $link = get_string('modulename_link', $modname);
  2878. $linktext = get_string('morehelp');
  2879. $defaultmodule->help .= html_writer::tag('div',
  2880. $OUTPUT->doc_link($link, $linktext, true), array('class' => 'helpdoclink'));
  2881. }
  2882. }
  2883. $defaultmodule->archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
  2884. // Each module can implement callback modulename_get_shortcuts() in its lib.php and return the list
  2885. // of elements to be added to activity chooser.
  2886. $items = component_callback($modname, 'get_shortcuts', array($defaultmodule), null);
  2887. if ($items !== null) {
  2888. foreach ($items as $item) {
  2889. // Add all items to the return array. All items must have different links, use them as a key in the return array.
  2890. if (!isset($item->archetype)) {
  2891. $item->archetype = $defaultmodule->archetype;
  2892. }
  2893. if (!isset($item->icon)) {
  2894. $item->icon = $defaultmodule->icon;
  2895. }
  2896. // If plugin returned the only one item with the same link as default item - cache it as $modname,
  2897. // otherwise append the link url to the module name.
  2898. $item->name = (count($items) == 1 &&
  2899. $item->link->out() === $defaultmodule->link->out()) ? $modname : $modname . ':' . $item->link;
  2900. // If the module provides the helptext property, append it to the help text to match the look and feel
  2901. // of the default course modules.
  2902. if (isset($item->help) && isset($item->helplink)) {
  2903. $linktext = get_string('morehelp');
  2904. $item->help .= html_writer::tag('div',
  2905. $OUTPUT->doc_link($item->helplink, $linktext, true), array('class' => 'helpdoclink'));
  2906. }
  2907. $modlist[$course->id][$modname][$item->name] = $item;
  2908. }
  2909. $return += $modlist[$course->id][$modname];
  2910. // If get_shortcuts() callback is defined, the default module action is not added.
  2911. // It is a responsibility of the callback to add it to the return value unless it is not needed.
  2912. continue;
  2913. }
  2914. // The callback get_shortcuts() was not found, use the default item for the activity chooser.
  2915. $modlist[$course->id][$modname][$modname] = $defaultmodule;
  2916. $return[$modname] = $defaultmodule;
  2917. }
  2918. core_collator::asort_objects_by_property($return, 'title');
  2919. return $return;
  2920. }