PageRenderTime 67ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/deprecatedlib.php

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