diff --git a/admin/tool/generator/lib.php b/admin/tool/generator/lib.php index 18e8a0905fe..a27de5f3c4c 100644 --- a/admin/tool/generator/lib.php +++ b/admin/tool/generator/lib.php @@ -53,7 +53,7 @@ function tool_generator_pluginfile($course, $cm, $context, $filearea, $args, $fo $file = $fs->get_file($context->id, 'tool_generator', $filearea, $args[0], '/', $args[1]); // Send the file, always forcing download, we don't want options. - session_get_instance()->write_close(); + \core\session\manager::write_close(); send_stored_file($file, 0, 0, true); } diff --git a/admin/tool/phpunit/webrunner.php b/admin/tool/phpunit/webrunner.php index b565ae1f021..482d39ee5e4 100644 --- a/admin/tool/phpunit/webrunner.php +++ b/admin/tool/phpunit/webrunner.php @@ -35,7 +35,7 @@ navigation_node::override_active_url(new moodle_url('/admin/tool/phpunit/index.p admin_externalpage_setup('toolphpunitwebrunner'); if (!$CFG->debugdeveloper) { - error('Not available on production sites, sorry.'); + print_error('notlocalisederrormessage', 'error', '', null, 'Not available on production sites, sorry.'); } core_php_time_limit::raise(60*30); diff --git a/calendar/lib.php b/calendar/lib.php index 3951df8efc2..5a40c690e1f 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -2174,8 +2174,8 @@ class calendar_event { * Pass in a object containing the event properties and this function will * insert it into the database and deal with any associated files * - * @see add_event() - * @see update_event() + * @see self::create() + * @see self::update() * * @param stdClass $data object of event * @param bool $checkcapability if moodle should check calendar managing capability or not @@ -2391,7 +2391,7 @@ class calendar_event { * This function deletes an event, any associated events if $deleterepeated=true, * and cleans up any files associated with the events. * - * @see delete_event() + * @see self::delete() * * @param bool $deleterepeated delete event repeatedly * @return bool succession of deleting event diff --git a/cohort/tests/cohortlib_test.php b/cohort/tests/cohortlib_test.php index 0b662bf5084..7403355493a 100644 --- a/cohort/tests/cohortlib_test.php +++ b/cohort/tests/cohortlib_test.php @@ -343,95 +343,6 @@ class core_cohort_cohortlib_testcase extends advanced_testcase { $this->assertTrue(cohort_is_member($cohort->id, $user->id)); } - public function test_cohort_get_visible_list() { - global $DB; - - $this->resetAfterTest(); - - $category1 = $this->getDataGenerator()->create_category(); - $category2 = $this->getDataGenerator()->create_category(); - - $course1 = $this->getDataGenerator()->create_course(array('category'=>$category1->id)); - $course2 = $this->getDataGenerator()->create_course(array('category'=>$category2->id)); - $course3 = $this->getDataGenerator()->create_course(); - - $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($category1->id)->id)); - $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($category2->id)->id)); - $cohort3 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_system::instance()->id)); - $cohort4 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_system::instance()->id)); - - $user1 = $this->getDataGenerator()->create_user(); - $user2 = $this->getDataGenerator()->create_user(); - $user3 = $this->getDataGenerator()->create_user(); - $user4 = $this->getDataGenerator()->create_user(); - $user5 = $this->getDataGenerator()->create_user(); - - $manualenrol = enrol_get_plugin('manual'); - $enrol1 = $DB->get_record('enrol', array('courseid'=>$course1->id, 'enrol'=>'manual')); - $enrol2 = $DB->get_record('enrol', array('courseid'=>$course2->id, 'enrol'=>'manual')); - - $manualenrol->enrol_user($enrol1, $user1->id); - $manualenrol->enrol_user($enrol1, $user3->id); - $manualenrol->enrol_user($enrol1, $user4->id); - $manualenrol->enrol_user($enrol2, $user2->id); - - cohort_add_member($cohort1->id, $user1->id); - cohort_add_member($cohort3->id, $user1->id); - cohort_add_member($cohort1->id, $user3->id); - cohort_add_member($cohort2->id, $user2->id); - - // Cohort1 (Cat1) has 2 users total, 2 user enrolled in course1, 0 users enrolled in course2. - // Cohort2 (Cat2) has 1 users total, 0 user enrolled in course1, 1 users enrolled in course2. - // Cohort3 (Syst) has 1 users total, 1 user enrolled in course1, 0 users enrolled in course2. - // Cohort4 (Syst) has 0 users total. - - $list = cohort_get_visible_list($course1); - $this->assertDebuggingCalled(); - $this->assertEquals(2, count($list)); - $this->assertNotEmpty($list[$cohort1->id]); - $this->assertRegExp('/\(2\)$/', $list[$cohort1->id]); - $this->assertNotEmpty($list[$cohort3->id]); - $this->assertRegExp('/\(1\)$/', $list[$cohort3->id]); - - $list = cohort_get_visible_list($course1, false); - $this->assertDebuggingCalled(); - $this->assertEquals(3, count($list)); - $this->assertNotEmpty($list[$cohort1->id]); - $this->assertRegExp('/\(2\)$/', $list[$cohort1->id]); - $this->assertNotEmpty($list[$cohort3->id]); - $this->assertRegExp('/\(1\)$/', $list[$cohort3->id]); - $this->assertNotEmpty($list[$cohort4->id]); - $this->assertRegExp('/[^\)]$/', $list[$cohort4->id]); - - $list = cohort_get_visible_list($course2); - $this->assertDebuggingCalled(); - $this->assertEquals(1, count($list)); - $this->assertNotEmpty($list[$cohort2->id]); - $this->assertRegExp('/\(1\)$/', $list[$cohort2->id]); - - $list = cohort_get_visible_list($course2, false); - $this->assertDebuggingCalled(); - $this->assertEquals(3, count($list)); - $this->assertNotEmpty($list[$cohort2->id]); - $this->assertRegExp('/\(1\)$/', $list[$cohort2->id]); - $this->assertNotEmpty($list[$cohort3->id]); - $this->assertRegExp('/[^\)]$/', $list[$cohort3->id]); - $this->assertNotEmpty($list[$cohort4->id]); - $this->assertRegExp('/[^\)]$/', $list[$cohort4->id]); - - $list = cohort_get_visible_list($course3); - $this->assertDebuggingCalled(); - $this->assertEquals(0, count($list)); - - $list = cohort_get_visible_list($course3, false); - $this->assertDebuggingCalled(); - $this->assertEquals(2, count($list)); - $this->assertNotEmpty($list[$cohort3->id]); - $this->assertRegExp('/[^\)]$/', $list[$cohort3->id]); - $this->assertNotEmpty($list[$cohort4->id]); - $this->assertRegExp('/[^\)]$/', $list[$cohort4->id]); - } - public function test_cohort_get_cohorts() { global $DB; diff --git a/completion/criteria/completion_criteria.php b/completion/criteria/completion_criteria.php index a87abd3d676..3275587803a 100644 --- a/completion/criteria/completion_criteria.php +++ b/completion/criteria/completion_criteria.php @@ -168,7 +168,7 @@ abstract class completion_criteria extends data_object { global $CFG, $COMPLETION_CRITERIA_TYPES; if (!isset($params['criteriatype']) || !isset($COMPLETION_CRITERIA_TYPES[$params['criteriatype']])) { - error('invalidcriteriatype', 'completion'); + print_error('invalidcriteriatype', 'completion'); } $class = 'completion_criteria_'.$COMPLETION_CRITERIA_TYPES[$params['criteriatype']]; diff --git a/grade/edit/tree/lib.php b/grade/edit/tree/lib.php index a2bc4f44567..0efde54da38 100644 --- a/grade/edit/tree/lib.php +++ b/grade/edit/tree/lib.php @@ -861,7 +861,7 @@ class grade_edit_tree_column_select extends grade_edit_tree_column { public function get_item_cell($item, $params) { if (empty($params['itemtype']) || empty($params['eid'])) { - error('Array key (itemtype or eid) missing from 2nd param of grade_edit_tree_column_select::get_item_cell($item, $params)'); + print_error('missingitemtypeoreid', 'core_grades'); } $itemcell = parent::get_item_cell($item, $params); diff --git a/lang/en/grades.php b/lang/en/grades.php index e7fed94bf3a..444357cfa79 100644 --- a/lang/en/grades.php +++ b/lang/en/grades.php @@ -466,6 +466,7 @@ $string['minmaxupgradefixbutton'] = 'Resolve inconsistencies'; $string['minmaxupgradewarning'] = 'Note: An inconsistency has been detected with some grades due to a change in the minimum and maximum grades used when calculating the grade displayed in the gradebook. It is recommended that the inconsistency is resolved by clicking the button below, though this will result in some grades being changed.'; $string['minimum_show'] = 'Show minimum grade'; $string['minimum_show_help'] = 'Minimum grade is used in calculating grades and weights. If not shown, minimum grade will default to zero and cannot be edited.'; +$string['missingitemtypeoreid'] = 'Array key (itemtype or eid) missing from 2nd param of grade_edit_tree_column_select::get_item_cell($item, $params)'; $string['missingscale'] = 'Scale must be selected'; $string['mode'] = 'Mode'; $string['modgradeerrorbadpoint'] = 'Invalid Grade Value. This must be an integer between 0 and {$a}'; diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 963c818c8ab..9010cb52a64 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -30,99 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -/** - * Convert region timezone to php supported timezone - * - * @deprecated since Moodle 2.9 - * @param string $tz value from ical file - * @return string $tz php supported timezone - */ -function calendar_normalize_tz($tz) { - debugging('calendar_normalize_tz() is deprecated, use core_date::normalise_timezone() instead', DEBUG_DEVELOPER); - return core_date::normalise_timezone($tz); -} - -/** - * Returns a float which represents the user's timezone difference from GMT in hours - * Checks various settings and picks the most dominant of those which have a value - * @deprecated since Moodle 2.9 - * @param float|int|string $tz timezone user timezone - * @return float - */ -function get_user_timezone_offset($tz = 99) { - debugging('get_user_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER); - $tz = core_date::get_user_timezone($tz); - $date = new DateTime('now', new DateTimeZone($tz)); - return ($date->getOffset() - dst_offset_on(time(), $tz)) / (3600.0); -} - -/** - * Returns an int which represents the systems's timezone difference from GMT in seconds - * @deprecated since Moodle 2.9 - * @param float|int|string $tz timezone for which offset is required. - * {@link http://docs.moodle.org/dev/Time_API#Timezone} - * @return int|bool if found, false is timezone 99 or error - */ -function get_timezone_offset($tz) { - debugging('get_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER); - $date = new DateTime('now', new DateTimeZone(core_date::normalise_timezone($tz))); - return $date->getOffset() - dst_offset_on(time(), $tz); -} - -/** - * Returns a list of timezones in the current language. - * @deprecated since Moodle 2.9 - * @return array - */ -function get_list_of_timezones() { - debugging('get_list_of_timezones() is deprecated, use core_date::get_list_of_timezones() instead', DEBUG_DEVELOPER); - return core_date::get_list_of_timezones(); -} - -/** - * Previous internal API, it was not supposed to be used anywhere. - * @deprecated since Moodle 2.9 - * @param array $timezones - */ -function update_timezone_records($timezones) { - debugging('update_timezone_records() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER); -} - -/** - * Previous internal API, it was not supposed to be used anywhere. - * @deprecated since Moodle 2.9 - * @param int $fromyear - * @param int $toyear - * @param mixed $strtimezone - * @return bool - */ -function calculate_user_dst_table($fromyear = null, $toyear = null, $strtimezone = null) { - debugging('calculate_user_dst_table() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER); - return false; -} - -/** - * Previous internal API, it was not supposed to be used anywhere. - * @deprecated since Moodle 2.9 - * @param int|string $year - * @param mixed $timezone - * @return null - */ -function dst_changes_for_year($year, $timezone) { - debugging('dst_changes_for_year() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER); - return null; -} - -/** - * Previous internal API, it was not supposed to be used anywhere. - * @deprecated since Moodle 2.9 - * @param string $timezonename - * @return array - */ -function get_timezone_record($timezonename) { - debugging('get_timezone_record() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER); - return array(); -} +/* === Functions that needs to be kept longer in deprecated lib than normal time period === */ /** * Add an entry to the legacy log table. @@ -149,231 +57,6 @@ function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user } } -/** - * Adds a file upload to the log table so that clam can resolve the filename to the user later if necessary - * - * @deprecated since 2.7 - use new file picker instead - * - */ -function clam_log_upload($newfilepath, $course=null, $nourl=false) { - throw new coding_exception('clam_log_upload() can not be used any more, please use file picker instead'); -} - -/** - * This function logs to error_log and to the log table that an infected file has been found and what's happened to it. - * - * @deprecated since 2.7 - use new file picker instead - * - */ -function clam_log_infected($oldfilepath='', $newfilepath='', $userid=0) { - throw new coding_exception('clam_log_infected() can not be used any more, please use file picker instead'); -} - -/** - * Some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path. - * - * @deprecated since 2.7 - use new file picker instead - * - */ -function clam_change_log($oldpath, $newpath, $update=true) { - throw new coding_exception('clam_change_log() can not be used any more, please use file picker instead'); -} - -/** - * Replaces the given file with a string. - * - * @deprecated since 2.7 - infected files are now deleted in file picker - * - */ -function clam_replace_infected_file($file) { - throw new coding_exception('clam_replace_infected_file() can not be used any more, please use file picker instead'); -} - -/** - * Deals with an infected file - either moves it to a quarantinedir - * (specified in CFG->quarantinedir) or deletes it. - * - * If moving it fails, it deletes it. - * - * @deprecated since 2.7 - */ -function clam_handle_infected_file($file, $userid=0, $basiconly=false) { - throw new coding_exception('clam_handle_infected_file() can not be used any more, please use file picker instead'); -} - -/** - * If $CFG->runclamonupload is set, we scan a given file. (called from {@link preprocess_files()}) - * - * @deprecated since 2.7 - */ -function clam_scan_moodle_file(&$file, $course) { - throw new coding_exception('clam_scan_moodle_file() can not be used any more, please use file picker instead'); -} - - -/** - * Checks whether the password compatibility library will work with the current - * version of PHP. This cannot be done using PHP version numbers since the fix - * has been backported to earlier versions in some distributions. - * - * See https://github.com/ircmaxell/password_compat/issues/10 for more details. - * - * @deprecated since 2.7 PHP 5.4.x should be always compatible. - * - * @return bool always returns false - */ -function password_compat_not_supported() { - debugging('Do not use password_compat_not_supported() - bcrypt is now always available', DEBUG_DEVELOPER); - return false; -} - -/** - * Factory method that was returning moodle_session object. - * - * @deprecated since 2.6 - * @return \core\session\manager - */ -function session_get_instance() { - // Note: the new session manager includes all methods from the original session class. - static $deprecatedinstance = null; - - debugging('session_get_instance() is deprecated, use \core\session\manager instead', DEBUG_DEVELOPER); - - if (!$deprecatedinstance) { - $deprecatedinstance = new \core\session\manager(); - } - - return $deprecatedinstance; -} - -/** - * Returns true if legacy session used. - * - * @deprecated since 2.6 - * @return bool - */ -function session_is_legacy() { - debugging('session_is_legacy() is deprecated, do not use any more', DEBUG_DEVELOPER); - return false; -} - -/** - * Terminates all sessions, auth hooks are not executed. - * Useful in upgrade scripts. - * - * @deprecated since 2.6 - */ -function session_kill_all() { - debugging('session_kill_all() is deprecated, use \core\session\manager::kill_all_sessions() instead', DEBUG_DEVELOPER); - \core\session\manager::kill_all_sessions(); -} - -/** - * Mark session as accessed, prevents timeouts. - * - * @deprecated since 2.6 - * @param string $sid - */ -function session_touch($sid) { - debugging('session_touch() is deprecated, use \core\session\manager::touch_session() instead', DEBUG_DEVELOPER); - \core\session\manager::touch_session($sid); -} - -/** - * Terminates one sessions, auth hooks are not executed. - * - * @deprecated since 2.6 - * @param string $sid session id - */ -function session_kill($sid) { - debugging('session_kill() is deprecated, use \core\session\manager::kill_session() instead', DEBUG_DEVELOPER); - \core\session\manager::kill_session($sid); -} - -/** - * Terminates all sessions of one user, auth hooks are not executed. - * NOTE: This can not work for file based sessions! - * - * @deprecated since 2.6 - * @param int $userid user id - */ -function session_kill_user($userid) { - debugging('session_kill_user() is deprecated, use \core\session\manager::kill_user_sessions() instead', DEBUG_DEVELOPER); - \core\session\manager::kill_user_sessions($userid); -} - -/** - * Setup $USER object - called during login, loginas, etc. - * - * Call sync_user_enrolments() manually after log-in, or log-in-as. - * - * @deprecated since 2.6 - * @param stdClass $user full user record object - * @return void - */ -function session_set_user($user) { - debugging('session_set_user() is deprecated, use \core\session\manager::set_user() instead', DEBUG_DEVELOPER); - \core\session\manager::set_user($user); -} - -/** - * Is current $USER logged-in-as somebody else? - * @deprecated since 2.6 - * @return bool - */ -function session_is_loggedinas() { - debugging('session_is_loggedinas() is deprecated, use \core\session\manager::is_loggedinas() instead', DEBUG_DEVELOPER); - return \core\session\manager::is_loggedinas(); -} - -/** - * Returns the $USER object ignoring current login-as session - * @deprecated since 2.6 - * @return stdClass user object - */ -function session_get_realuser() { - debugging('session_get_realuser() is deprecated, use \core\session\manager::get_realuser() instead', DEBUG_DEVELOPER); - return \core\session\manager::get_realuser(); -} - -/** - * Login as another user - no security checks here. - * @deprecated since 2.6 - * @param int $userid - * @param stdClass $context - * @return void - */ -function session_loginas($userid, $context) { - debugging('session_loginas() is deprecated, use \core\session\manager::loginas() instead', DEBUG_DEVELOPER); - \core\session\manager::loginas($userid, $context); -} - -/** - * Minify JavaScript files. - * - * @deprecated since 2.6 - * - * @param array $files - * @return string - */ -function js_minify($files) { - debugging('js_minify() is deprecated, use core_minify::js_files() or core_minify::js() instead.'); - return core_minify::js_files($files); -} - -/** - * Minify CSS files. - * - * @deprecated since 2.6 - * - * @param array $files - * @return string - */ -function css_minify_css($files) { - debugging('css_minify_css() is deprecated, use core_minify::css_files() or core_minify::css() instead.'); - return core_minify::css_files($files); -} - /** * Function to call all event handlers when triggering an event * @@ -555,52 +238,231 @@ function get_component_directory($component) { return core_component::get_component_directory($component); } +/** + * Get the context instance as an object. This function will create the + * context instance if it does not exist yet. + * + * @deprecated since 2.2, use context_course::instance() or other relevant class instead + * @todo This will be deleted in Moodle 2.8, refer MDL-34472 + * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE. + * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id, + * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0 + * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; + * MUST_EXIST means throw exception if no record or multiple records found + * @return context The context object. + */ +function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) { + + debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER); + + $instances = (array)$instance; + $contexts = array(); + + $classname = context_helper::get_class_for_level($contextlevel); + + // we do not load multiple contexts any more, PAGE should be responsible for any preloading + foreach ($instances as $inst) { + $contexts[$inst] = $classname::instance($inst, $strictness); + } + + if (is_array($instance)) { + return $contexts; + } else { + return $contexts[$instance]; + } +} +/* === End of long term deprecated api list === */ + +/** + * Adds a file upload to the log table so that clam can resolve the filename to the user later if necessary + * + * @deprecated since 2.7 - use new file picker instead + * + */ +function clam_log_upload($newfilepath, $course=null, $nourl=false) { + throw new coding_exception('clam_log_upload() can not be used any more, please use file picker instead'); +} + +/** + * This function logs to error_log and to the log table that an infected file has been found and what's happened to it. + * + * @deprecated since 2.7 - use new file picker instead + * + */ +function clam_log_infected($oldfilepath='', $newfilepath='', $userid=0) { + throw new coding_exception('clam_log_infected() can not be used any more, please use file picker instead'); +} + +/** + * Some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path. + * + * @deprecated since 2.7 - use new file picker instead + * + */ +function clam_change_log($oldpath, $newpath, $update=true) { + throw new coding_exception('clam_change_log() can not be used any more, please use file picker instead'); +} + +/** + * Replaces the given file with a string. + * + * @deprecated since 2.7 - infected files are now deleted in file picker + * + */ +function clam_replace_infected_file($file) { + throw new coding_exception('clam_replace_infected_file() can not be used any more, please use file picker instead'); +} + +/** + * Deals with an infected file - either moves it to a quarantinedir + * (specified in CFG->quarantinedir) or deletes it. + * + * If moving it fails, it deletes it. + * + * @deprecated since 2.7 + */ +function clam_handle_infected_file($file, $userid=0, $basiconly=false) { + throw new coding_exception('clam_handle_infected_file() can not be used any more, please use file picker instead'); +} + +/** + * If $CFG->runclamonupload is set, we scan a given file. (called from {@link preprocess_files()}) + * + * @deprecated since 2.7 + */ +function clam_scan_moodle_file(&$file, $course) { + throw new coding_exception('clam_scan_moodle_file() can not be used any more, please use file picker instead'); +} + + +/** + * Checks whether the password compatibility library will work with the current + * version of PHP. This cannot be done using PHP version numbers since the fix + * has been backported to earlier versions in some distributions. + * + * See https://github.com/ircmaxell/password_compat/issues/10 for more details. + * + * @deprecated since 2.7 PHP 5.4.x should be always compatible. + * + */ +function password_compat_not_supported() { + throw new coding_exception('Do not use password_compat_not_supported() - bcrypt is now always available'); +} + +/** + * Factory method that was returning moodle_session object. + * + * @deprecated since 2.6 + */ +function session_get_instance() { + throw new coding_exception('session_get_instance() is removed, use \core\session\manager instead'); +} + +/** + * Returns true if legacy session used. + * + * @deprecated since 2.6 + */ +function session_is_legacy() { + throw new coding_exception('session_is_legacy() is removed, do not use any more'); +} + +/** + * Terminates all sessions, auth hooks are not executed. + * + * @deprecated since 2.6 + */ +function session_kill_all() { + throw new coding_exception('session_kill_all() is removed, use \core\session\manager::kill_all_sessions() instead'); +} + +/** + * Mark session as accessed, prevents timeouts. + * + * @deprecated since 2.6 + */ +function session_touch($sid) { + throw new coding_exception('session_touch() is removed, use \core\session\manager::touch_session() instead'); +} + +/** + * Terminates one sessions, auth hooks are not executed. + * + * @deprecated since 2.6 + */ +function session_kill($sid) { + throw new coding_exception('session_kill() is removed, use \core\session\manager::kill_session() instead'); +} + +/** + * Terminates all sessions of one user, auth hooks are not executed. + * + * @deprecated since 2.6 + */ +function session_kill_user($userid) { + throw new coding_exception('session_kill_user() is removed, use \core\session\manager::kill_user_sessions() instead'); +} + +/** + * Setup $USER object - called during login, loginas, etc. + * + * Call sync_user_enrolments() manually after log-in, or log-in-as. + * + * @deprecated since 2.6 + */ +function session_set_user($user) { + throw new coding_exception('session_set_user() is removed, use \core\session\manager::set_user() instead'); +} + +/** + * Is current $USER logged-in-as somebody else? + * @deprecated since 2.6 + */ +function session_is_loggedinas() { + throw new coding_exception('session_is_loggedinas() is removed, use \core\session\manager::is_loggedinas() instead'); +} + +/** + * Returns the $USER object ignoring current login-as session + * @deprecated since 2.6 + */ +function session_get_realuser() { + throw new coding_exception('session_get_realuser() is removed, use \core\session\manager::get_realuser() instead'); +} + +/** + * Login as another user - no security checks here. + * @deprecated since 2.6 + */ +function session_loginas($userid, $context) { + throw new coding_exception('session_loginas() is removed, use \core\session\manager::loginas() instead'); +} + +/** + * Minify JavaScript files. + * + * @deprecated since 2.6 + */ +function js_minify($files) { + throw new coding_exception('js_minify() is removed, use core_minify::js_files() or core_minify::js() instead.'); +} + +/** + * Minify CSS files. + * + * @deprecated since 2.6 + */ +function css_minify_css($files) { + throw new coding_exception('css_minify_css() is removed, use core_minify::css_files() or core_minify::css() instead.'); +} // === Deprecated before 2.6.0 === /** * Hack to find out the GD version by parsing phpinfo output - * - * @return int GD version (1, 2, or 0) */ function check_gd_version() { - // TODO: delete function in Moodle 2.7 - debugging('check_gd_version() is deprecated, GD extension is always available now'); - - $gdversion = 0; - - if (function_exists('gd_info')){ - $gd_info = gd_info(); - if (substr_count($gd_info['GD Version'], '2.')) { - $gdversion = 2; - } else if (substr_count($gd_info['GD Version'], '1.')) { - $gdversion = 1; - } - - } else { - ob_start(); - phpinfo(INFO_MODULES); - $phpinfo = ob_get_contents(); - ob_end_clean(); - - $phpinfo = explode("\n", $phpinfo); - - - foreach ($phpinfo as $text) { - $parts = explode('', $text); - foreach ($parts as $key => $val) { - $parts[$key] = trim(strip_tags($val)); - } - if ($parts[0] == 'GD Version') { - if (substr_count($parts[1], '2.0')) { - $parts[1] = '2.0'; - } - $gdversion = intval($parts[1]); - } - } - } - - return $gdversion; // 1, 2 or 0 + throw new coding_exception('check_gd_version() is removed, GD extension is always available now'); } /** @@ -609,8 +471,7 @@ function check_gd_version() { * @deprecated */ function update_login_count() { - // TODO: delete function in Moodle 2.6 - debugging('update_login_count() is deprecated, all calls need to be removed'); + throw new coding_exception('update_login_count() is removed, all calls need to be removed'); } /** @@ -618,26 +479,15 @@ function update_login_count() { * @deprecated */ function reset_login_count() { - // TODO: delete function in Moodle 2.6 - debugging('reset_login_count() is deprecated, all calls need to be removed'); + throw new coding_exception('reset_login_count() is removed, all calls need to be removed'); } /** - * Insert or update log display entry. Entry may already exist. - * $module, $action must be unique * @deprecated - * - * @param string $module - * @param string $action - * @param string $mtable - * @param string $field - * @return void - * */ function update_log_display_entry($module, $action, $mtable, $field) { - global $DB; - debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.'); + throw new coding_exception('The update_log_display_entry() is removed, please use db/log.php description file instead.'); } /** @@ -729,33 +579,10 @@ function is_course_participant($userid, $courseid) { } /** - * Searches logs to find all enrolments since a certain date - * - * used to print recent activity - * - * @param int $courseid The course in question. - * @param int $timestart The date to check forward of - * @return object|false {@link $USER} records or false if error. + * @deprecated */ function get_recent_enrolments($courseid, $timestart) { - global $DB; - - debugging('get_recent_enrolments() is deprecated as it returned inaccurate results.', DEBUG_DEVELOPER); - - $context = context_course::instance($courseid); - $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time) - FROM {user} u, {role_assignments} ra, {log} l - WHERE l.time > ? - AND l.course = ? - AND l.module = 'course' - AND l.action = 'enrol' - AND ".$DB->sql_cast_char2int('l.info')." = u.id - AND u.id = ra.userid - AND ra.contextid ".get_related_contexts_string($context)." - GROUP BY u.id, u.firstname, u.lastname - ORDER BY MAX(l.time) ASC"; - $params = array($timestart, $courseid); - return $DB->get_records_sql($sql, $params); + throw new coding_exception('get_recent_enrolments() is removed as it returned inaccurate results.'); } /** @@ -939,6 +766,7 @@ function groupmode($course, $cm=null) { * Does not do any permission checking. * * @global object + * @global object * @param int $courseid The course being examined - relates to id field in * 'course' table. * @param int $groupid The group being examined. @@ -949,7 +777,6 @@ function set_current_group($courseid, $groupid) { return $SESSION->currentgroup[$courseid] = $groupid; } - /** * Gets the current group - either from the session variable or from the database. * @@ -990,66 +817,29 @@ function get_current_group($courseid, $full = false) { } /** - * Filter a user list and return only the users that can see the course module based on - * groups/permissions etc. It is assumed that the users are pre-filtered to those who are enrolled in the course. - * - * @category group - * @param stdClass|cm_info $cm The course module - * @param array $users An array of users, indexed by userid - * @return array A filtered list of users that can see the module, indexed by userid. * @deprecated Since Moodle 2.8 */ function groups_filter_users_by_course_module_visible($cm, $users) { - debugging('groups_filter_users_by_course_module_visible() is deprecated. ' . + throw new coding_exception('groups_filter_users_by_course_module_visible() is removed. ' . 'Replace with a call to \core_availability\info_module::filter_user_list(), ' . 'which does basically the same thing but includes other restrictions such ' . - 'as profile restrictions.', DEBUG_DEVELOPER); - if (empty($users)) { - return $users; - } - // Since this function allows stdclass, let's play it safe and ensure we - // do have a cm_info. - if (!($cm instanceof cm_info)) { - $modinfo = get_fast_modinfo($cm->course); - $cm = $modinfo->get_cm($cm->id); - } - $info = new \core_availability\info_module($cm); - return $info->filter_user_list($users); + 'as profile restrictions.'); } /** - * Determine if a course module is currently visible to a user - * - * Deprecated (it was never very useful as it only took into account the - * groupmembersonly option and no other way of hiding activities). Always - * returns true. - * - * @category group - * @param stdClass|cm_info $cm The course module - * @param int $userid The user to check against the group. - * @return bool True * @deprecated Since Moodle 2.8 */ function groups_course_module_visible($cm, $userid=null) { - debugging('groups_course_module_visible() is deprecated and always returns ' . - 'true; use $cm->uservisible to decide whether the current user can ' . - 'access an activity.', DEBUG_DEVELOPER); - return true; + throw new coding_exception('groups_course_module_visible() is removed, use $cm->uservisible to decide whether the current + user can ' . 'access an activity.', DEBUG_DEVELOPER); } /** - * Inndicates fatal error. This function was originally printing the - * error message directly, since 2.0 it is throwing exception instead. - * The error printing is handled in default exception handler. - * - * Old method, don't call directly in new code - use print_error instead. - * - * @param string $message The message to display to the user about the error. - * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page. - * @return void, always throws moodle_exception + * @deprecated since 2.0 */ function error($message, $link='') { - throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()'); + throw new coding_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a removed, please call + print_error() instead of error()'); } @@ -1061,15 +851,10 @@ function current_theme() { } /** - * Prints some red text using echo - * * @deprecated - * @param string $error The text to be displayed in red */ function formerr($error) { - debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).'); - global $OUTPUT; - echo $OUTPUT->error_text($error); + throw new coding_exception('formerr() is removed. Please change your code to use $OUTPUT->error_text($string).'); } /** @@ -1217,40 +1002,6 @@ function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='' echo $str; } -/** - * Returns a string of html with an image of a help icon linked to a help page on a number of help topics. - * Should be used only with htmleditor or textarea. - * - * @global object - * @global object - * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for - * helpbutton. - * @return string Link to help button - */ -function editorhelpbutton(){ - return ''; - - /// TODO: MDL-21215 -} - -/** - * Print a help button. - * - * Prints a special help button for html editors (htmlarea in this case) - * - * @todo Write code into this function! detect current editor and print correct info - * @global object - * @return string Only returns an empty string at the moment - */ -function editorshortcutshelpbutton() { - /// TODO: MDL-21215 - - global $CFG; - //TODO: detect current editor and print correct info - return ''; -} - - /** * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please * provide this function with the language strings for sortasc and sortdesc. @@ -1309,59 +1060,13 @@ function print_arrow($direction='up', $strsort=null, $return=false) { } /** - * Given an array of values, output the HTML for a select element with those options. - * * @deprecated since Moodle 2.0 - * - * Normally, you only need to use the first few parameters. - * - * @param array $options The options to offer. An array of the form - * $options[{value}] = {text displayed for that option}; - * @param string $name the name of this form control, as in <select name="..." ... - * @param string $selected the option to select initially, default none. - * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose'). - * Set this to '' if you don't want a 'nothing is selected' option. - * @param string $script if not '', then this is added to the <select> element as an onchange handler. - * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0. - * @param boolean $return if false (the default) the the output is printed directly, If true, the - * generated HTML is returned as a string. - * @param boolean $disabled if true, the select is generated in a disabled state. Default, false. - * @param int $tabindex if give, sets the tabindex attribute on the <select> element. Default none. - * @param string $id value to use for the id attribute of the <select> element. If none is given, - * then a suitable one is constructed. - * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box. - * By default, the list box will have a number of rows equal to min(10, count($options)), but if - * $listbox is an integer, that number is used for size instead. - * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used - * when $listbox display is enabled - * @param string $class value to use for the class attribute of the <select> element. If none is given, - * then a suitable one is constructed. - * @return string|void If $return=true returns string, else echo's and returns void */ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false, $disabled=false, $tabindex=0, $id='', $listbox=false, $multiple=false, $class='') { + throw new coding_exception('choose_from_menu() is removed. Please change your code to use html_writer::select().'); - global $OUTPUT; - debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().'); - - if ($script) { - debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER); - } - $attributes = array(); - $attributes['disabled'] = $disabled ? 'disabled' : null; - $attributes['tabindex'] = $tabindex ? $tabindex : null; - $attributes['multiple'] = $multiple ? $multiple : null; - $attributes['class'] = $class ? $class : null; - $attributes['id'] = $id ? $id : null; - - $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes); - - if ($return) { - return $output; - } else { - echo $output; - } } /** @@ -1438,21 +1143,10 @@ function navmenu($course, $cm=NULL, $targetwindow='self') { } /** - * Call this function to update an event in the calendar table - * the event will be identified by the id field of the $event object. - * - * @param object $event An object representing an event from the calendar table. The event will be identified by the id field. - * @return bool Success * @deprecated please calendar_event->update() instead. */ function update_event($event) { - global $CFG; - require_once($CFG->dirroot.'/calendar/lib.php'); - - debugging('update_event() is deprecated, please use calendar_event->update() instead.', DEBUG_DEVELOPER); - $event = (object)$event; - $calendarevent = calendar_event::load($event->id); - return $calendarevent->update($event); + throw new coding_exception('update_event() is removed, please use calendar_event->update() instead.'); } /** @@ -1480,9 +1174,6 @@ function show_event($event) { } /** - * Original singleton helper function, please use static methods instead, - * ex: core_text::convert(). - * * @deprecated since Moodle 2.2 use core_text::xxxx() instead. * @see core_text */ @@ -1492,21 +1183,13 @@ function textlib_get_instance() { } /** - * Gets the generic section name for a courses section - * - * The global function is deprecated. Each course format can define their own generic section name - * * @deprecated since 2.4 * @see get_section_name() * @see format_base::get_section_name() - * - * @param string $format Course format ID e.g. 'weeks' $course->format - * @param stdClass $section Section object from database - * @return Display name that the course format prefers, e.g. "Week 2" + */ function get_generic_section_name($format, stdClass $section) { - debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER); - return get_string('sectionname', "format_$format") . ' ' . $section->section; + throw new coding_exception('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base'); } /** @@ -1531,33 +1214,21 @@ function get_generic_section_name($format, stdClass $section) { * {@link course_modinfo::get_section_info()} * * @deprecated since 2.4 - * - * @param int $courseid - * @return array Array of section_info objects */ function get_all_sections($courseid) { - global $DB; - debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER); - return get_fast_modinfo($courseid)->get_section_info_all(); + + throw new coding_exception('get_all_sections() is removed. See phpdocs for this function'); } /** - * Given a full mod object with section and course already defined, adds this module to that section. - * * This function is deprecated, please use {@link course_add_cm_to_section()} * Note that course_add_cm_to_section() also updates field course_modules.section and * calls rebuild_course_cache() * * @deprecated since 2.4 - * - * @param object $mod - * @param int $beforemod An existing ID which we will insert the new module before - * @return int The course_sections ID where the mod is inserted */ function add_mod_to_section($mod, $beforemod = null) { - debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER); - global $DB; - return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod); + throw new coding_exception('Function add_mod_to_section() is removed, please use course_add_cm_to_section()'); } /** @@ -1577,22 +1248,9 @@ function add_mod_to_section($mod, $beforemod = null) { * * * @deprecated since 2.4 - * - * @param int $courseid id of the course to get info about - * @param array $mods (return) list of course modules - * @param array $modnames (return) list of names of all module types installed and available - * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form - * @param array $modnamesused (return) list of names of all module types used in the course */ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { - debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER); - - global $COURSE; - $modnames = get_module_types_names(); - $modnamesplural= get_module_types_names(true); - $modinfo = get_fast_modinfo($courseid); - $mods = $modinfo->get_cms(); - $modnamesused = $modinfo->get_used_module_names(); + throw new coding_exception('Function get_all_mods() is removed. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details'); } /** @@ -1606,54 +1264,21 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname * @see course_create_sections_if_missing() * @see get_fast_modinfo() * @deprecated since 2.4 - * - * @param int $section relative section number (field course_sections.section) - * @param int $courseid - * @return stdClass record from table {course_sections} */ function get_course_section($section, $courseid) { - global $DB; - debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER); - - if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) { - return $cw; - } - $cw = new stdClass(); - $cw->course = $courseid; - $cw->section = $section; - $cw->summary = ""; - $cw->summaryformat = FORMAT_HTML; - $cw->sequence = ""; - $id = $DB->insert_record("course_sections", $cw); - rebuild_course_cache($courseid, true); - return $DB->get_record("course_sections", array("id"=>$id)); + throw new coding_exception('Function get_course_section() is removed. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.'); } /** - * Return the start and end date of the week in Weekly course format - * - * It is not recommended to use this function outside of format_weeks plugin - * * @deprecated since 2.4 * @see format_weeks::get_section_dates() - * - * @param stdClass $section The course_section entry from the DB - * @param stdClass $course The course entry from DB - * @return stdClass property start for startdate, property end for enddate */ function format_weeks_get_section_dates($section, $course) { - debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'. - ' use it outside of format_weeks plugin', DEBUG_DEVELOPER); - if (isset($course->format) && $course->format === 'weeks') { - return course_get_format($course)->get_section_dates($section); - } - return null; + throw new coding_exception('Function format_weeks_get_section_dates() is removed. It is not recommended to'. + ' use it outside of format_weeks plugin'); } /** - * Obtains shared data that is used in print_section when displaying a - * course-module entry. - * * Deprecated. Instead of: * list($content, $name) = get_print_section_cm_text($cm, $course); * use: @@ -1663,25 +1288,13 @@ function format_weeks_get_section_dates($section, $course) { * @deprecated since 2.5 * @see cm_info::get_formatted_content() * @see cm_info::get_formatted_name() - * - * This data is also used in other areas of the code. - * @param cm_info $cm Course-module data (must come from get_fast_modinfo) - * @param object $course (argument not used) - * @return array An array with the following values in this order: - * $content (optional extra content for after link), - * $instancename (text of link) */ function get_print_section_cm_text(cm_info $cm, $course) { - debugging('Function get_print_section_cm_text() is deprecated. Please use '. - 'cm_info::get_formatted_content() and cm_info::get_formatted_name()', - DEBUG_DEVELOPER); - return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)), - $cm->get_formatted_name()); + throw new coding_exception('Function get_print_section_cm_text() is removed. Please use '. + 'cm_info::get_formatted_content() and cm_info::get_formatted_name()'); } /** - * Prints the menus to add activities and resources. - * * Deprecated. Please use: * $courserenderer = $PAGE->get_renderer('core', 'course'); * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn, @@ -1690,34 +1303,13 @@ function get_print_section_cm_text(cm_info $cm, $course) { * * @deprecated since 2.5 * @see core_course_renderer::course_section_add_cm_control() - * - * @param stdClass $course course object, must be the same as set on the page - * @param int $section relative section number (field course_sections.section) - * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument - * @param bool $vertical Vertical orientation - * @param bool $return Return the menus or send them to output - * @param int $sectionreturn The section to link back to - * @return void|string depending on $return */ function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) { - global $PAGE; - debugging('Function print_section_add_menus() is deprecated. Please use course renderer '. - 'function course_section_add_cm_control()', DEBUG_DEVELOPER); - $output = ''; - $courserenderer = $PAGE->get_renderer('core', 'course'); - $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn, - array('inblock' => $vertical)); - if ($return) { - return $output; - } else { - echo $output; - return !empty($output); - } + throw new coding_exception('Function print_section_add_menus() is removed. Please use course renderer '. + 'function course_section_add_cm_control()'); } /** - * Produces the editing buttons for a module - * * Deprecated. Please use: * $courserenderer = $PAGE->get_renderer('core', 'course'); * $actions = course_get_cm_edit_actions($mod, $indent, $section); @@ -1726,34 +1318,13 @@ function print_section_add_menus($course, $section, $modnames = null, $vertical= * @deprecated since 2.5 * @see course_get_cm_edit_actions() * @see core_course_renderer->course_section_cm_edit_actions() - * - * @param stdClass $mod The module to produce editing buttons for - * @param bool $absolute_ignored (argument ignored) - all links are absolute - * @param bool $moveselect (argument ignored) - * @param int $indent The current indenting - * @param int $section The section to link back to - * @return string XHTML for the editing buttons */ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) { - global $PAGE; - debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '. - 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER); - if (!($mod instanceof cm_info)) { - $modinfo = get_fast_modinfo($mod->course); - $mod = $modinfo->get_cm($mod->id); - } - $actions = course_get_cm_edit_actions($mod, $indent, $section); - - $courserenderer = $PAGE->get_renderer('core', 'course'); - // The space added before the is a ugly hack but required to set the CSS property white-space: nowrap - // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of - // the course page HTML will allow this to be removed. - return ' ' . $courserenderer->course_section_cm_edit_actions($actions); + throw new coding_exception('Function make_editing_buttons() is removed, please see PHPdocs in '. + 'lib/deprecatedlib.php on how to replace it'); } /** - * Prints a section full of activity modules - * * Deprecated. Please use: * $courserenderer = $PAGE->get_renderer('core', 'course'); * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, @@ -1761,455 +1332,71 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele * * @deprecated since 2.5 * @see core_course_renderer::course_section_cm_list() - * - * @param stdClass $course The course - * @param stdClass|section_info $section The section object containing properties id and section - * @param array $mods (argument not used) - * @param array $modnamesused (argument not used) - * @param bool $absolute (argument not used) - * @param string $width (argument not used) - * @param bool $hidecompletion Hide completion status - * @param int $sectionreturn The section to return to - * @return void */ function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) { - global $PAGE; - debugging('Function print_section() is deprecated. Please use course renderer function '. - 'course_section_cm_list() instead.', DEBUG_DEVELOPER); - $displayoptions = array('hidecompletion' => $hidecompletion); - $courserenderer = $PAGE->get_renderer('core', 'course'); - echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions); + throw new coding_exception('Function print_section() is removed. Please use course renderer function '. + 'course_section_cm_list() instead.'); } /** - * Displays the list of courses with user notes - * - * This function is not used in core. It was replaced by block course_overview - * * @deprecated since 2.5 - * - * @param array $courses - * @param array $remote_courses */ function print_overview($courses, array $remote_courses=array()) { - global $CFG, $USER, $DB, $OUTPUT; - debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER); - - $htmlarray = array(); - if ($modules = $DB->get_records('modules')) { - foreach ($modules as $mod) { - if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) { - include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php'); - $fname = $mod->name.'_print_overview'; - if (function_exists($fname)) { - $fname($courses,$htmlarray); - } - } - } - } - foreach ($courses as $course) { - $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id))); - echo $OUTPUT->box_start('coursebox'); - $attributes = array('title' => s($fullname)); - if (empty($course->visible)) { - $attributes['class'] = 'dimmed'; - } - echo $OUTPUT->heading(html_writer::link( - new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3); - if (array_key_exists($course->id,$htmlarray)) { - foreach ($htmlarray[$course->id] as $modname => $html) { - echo $html; - } - } - echo $OUTPUT->box_end(); - } - - if (!empty($remote_courses)) { - echo $OUTPUT->heading(get_string('remotecourses', 'mnet')); - } - foreach ($remote_courses as $course) { - echo $OUTPUT->box_start('coursebox'); - $attributes = array('title' => s($course->fullname)); - echo $OUTPUT->heading(html_writer::link( - new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)), - format_string($course->shortname), - $attributes) . ' (' . format_string($course->hostname) . ')', 3); - echo $OUTPUT->box_end(); - } + throw new coding_exception('Function print_overview() is removed. Use block course_overview to display this information'); } /** - * This function trawls through the logs looking for - * anything new since the user's last login - * - * This function was only used to print the content of block recent_activity - * All functionality is moved into class {@link block_recent_activity} - * and renderer {@link block_recent_activity_renderer} - * * @deprecated since 2.5 - * @param stdClass $course */ function print_recent_activity($course) { - // $course is an object - global $CFG, $USER, $SESSION, $DB, $OUTPUT; - debugging('Function print_recent_activity() is deprecated. It is not recommended to'. - ' use it outside of block_recent_activity', DEBUG_DEVELOPER); - - $context = context_course::instance($course->id); - - $viewfullnames = has_capability('moodle/site:viewfullnames', $context); - - $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds - - if (!isguestuser()) { - if (!empty($USER->lastcourseaccess[$course->id])) { - if ($USER->lastcourseaccess[$course->id] > $timestart) { - $timestart = $USER->lastcourseaccess[$course->id]; - } - } - } - - echo '
'; - echo get_string('activitysince', '', userdate($timestart)); - echo '
'; - echo '
'; - - echo ''.get_string('recentactivityreport').''; - - echo "
\n"; - - $content = false; - -/// Firstly, have there been any new enrolments? - - $users = get_recent_enrolments($course->id, $timestart); - - //Accessibility: new users now appear in an
    list. - if ($users) { - echo '
    '; - echo $OUTPUT->heading(get_string("newusers").':', 3); - $content = true; - echo "
      \n"; - foreach ($users as $user) { - $fullname = fullname($user, $viewfullnames); - echo '
    1. wwwroot/user/view.php?id=$user->id&course=$course->id\">$fullname
    2. \n"; - } - echo "
    \n
    \n"; - } - -/// Next, have there been any modifications to the course structure? - - $modinfo = get_fast_modinfo($course); - - $changelist = array(); - - $logs = $DB->get_records_select('log', "time > ? AND course = ? AND - module = 'course' AND - (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')", - array($timestart, $course->id), "id ASC"); - - if ($logs) { - $actions = array('add mod', 'update mod', 'delete mod'); - $newgones = array(); // added and later deleted items - foreach ($logs as $key => $log) { - if (!in_array($log->action, $actions)) { - continue; - } - $info = explode(' ', $log->info); - - // note: in most cases I replaced hardcoding of label with use of - // $cm->has_view() but it was not possible to do this here because - // we don't necessarily have the $cm for it - if ($info[0] == 'label') { // Labels are ignored in recent activity - continue; - } - - if (count($info) != 2) { - debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER); - continue; - } - - $modname = $info[0]; - $instanceid = $info[1]; - - if ($log->action == 'delete mod') { - // unfortunately we do not know if the mod was visible - if (!array_key_exists($log->info, $newgones)) { - $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname)); - $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted); - } - } else { - if (!isset($modinfo->instances[$modname][$instanceid])) { - if ($log->action == 'add mod') { - // do not display added and later deleted activities - $newgones[$log->info] = true; - } - continue; - } - $cm = $modinfo->instances[$modname][$instanceid]; - if (!$cm->uservisible) { - continue; - } - - if ($log->action == 'add mod') { - $stradded = get_string('added', 'moodle', get_string('modulename', $modname)); - $changelist[$log->info] = array('operation' => 'add', 'text' => "$stradded:
    wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true).""); - - } else if ($log->action == 'update mod' and empty($changelist[$log->info])) { - $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname)); - $changelist[$log->info] = array('operation' => 'update', 'text' => "$strupdated:
    wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true).""); - } - } - } - } - - if (!empty($changelist)) { - echo $OUTPUT->heading(get_string("courseupdates").':', 3); - $content = true; - foreach ($changelist as $changeinfo => $change) { - echo '

    '.$change['text'].'

    '; - } - } - -/// Now display new things from each module - - $usedmodules = array(); - foreach($modinfo->cms as $cm) { - if (isset($usedmodules[$cm->modname])) { - continue; - } - if (!$cm->uservisible) { - continue; - } - $usedmodules[$cm->modname] = $cm->modname; - } - - foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them - if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) { - include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php'); - $print_recent_activity = $modname.'_print_recent_activity'; - if (function_exists($print_recent_activity)) { - // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames! - $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content; - } - } else { - debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module"); - } - } - - if (! $content) { - echo '

    '.get_string('nothingnew').'

    '; - } + throw new coding_exception('Function print_recent_activity() is removed. It is not recommended to'. + ' use it outside of block_recent_activity'); } /** - * Delete a course module and any associated data at the course level (events) - * Until 1.5 this function simply marked a deleted flag ... now it - * deletes it completely. - * * @deprecated since 2.5 - * - * @param int $id the course module id - * @return boolean true on success, false on failure */ function delete_course_module($id) { - debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER); - - global $CFG, $DB; - - require_once($CFG->libdir.'/gradelib.php'); - require_once($CFG->dirroot.'/blog/lib.php'); - - if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) { - return true; - } - $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module)); - //delete events from calendar - if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) { - foreach($events as $event) { - delete_event($event->id); - } - } - //delete grade items, outcome items and grades attached to modules - if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename, - 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) { - foreach ($grade_items as $grade_item) { - $grade_item->delete('moddelete'); - } - } - // Delete completion and availability data; it is better to do this even if the - // features are not turned on, in case they were turned on previously (these will be - // very quick on an empty table) - $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id)); - $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id, - 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY)); - - delete_context(CONTEXT_MODULE, $cm->id); - return $DB->delete_records('course_modules', array('id'=>$cm->id)); + throw new coding_exception('Function delete_course_module() is removed. Please use course_delete_module() instead.'); } /** - * Prints the turn editing on/off button on course/index.php or course/category.php. - * * @deprecated since 2.5 - * - * @param integer $categoryid The id of the category we are showing, or 0 for system context. - * @return string HTML of the editing button, or empty string, if this user is not allowed - * to see it. */ function update_category_button($categoryid = 0) { - global $CFG, $PAGE, $OUTPUT; - debugging('Function update_category_button() is deprecated. Pages to view '. - 'and edit courses are now separate and no longer depend on editing mode.', - DEBUG_DEVELOPER); - - // Check permissions. - if (!can_edit_in_category($categoryid)) { - return ''; - } - - // Work out the appropriate action. - if ($PAGE->user_is_editing()) { - $label = get_string('turneditingoff'); - $edit = 'off'; - } else { - $label = get_string('turneditingon'); - $edit = 'on'; - } - - // Generate the button HTML. - $options = array('categoryedit' => $edit, 'sesskey' => sesskey()); - if ($categoryid) { - $options['id'] = $categoryid; - $page = 'category.php'; - } else { - $page = 'index.php'; - } - return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get'); + throw new coding_exception('Function update_category_button() is removed. Pages to view '. + 'and edit courses are now separate and no longer depend on editing mode.'); } /** - * This function recursively travels the categories, building up a nice list - * for display. It also makes an array that list all the parents for each - * category. - * - * For example, if you have a tree of categories like: - * Miscellaneous (id = 1) - * Subcategory (id = 2) - * Sub-subcategory (id = 4) - * Other category (id = 3) - * Then after calling this function you will have - * $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory', - * 4 => 'Miscellaneous / Subcategory / Sub-subcategory', - * 3 => 'Other category'); - * $parents = array(2 => array(1), 4 => array(1, 2)); - * - * If you specify $requiredcapability, then only categories where the current - * user has that capability will be added to $list, although all categories - * will still be added to $parents, and if you only have $requiredcapability - * in a child category, not the parent, then the child catgegory will still be - * included. - * - * If you specify the option $excluded, then that category, and all its children, - * are omitted from the tree. This is useful when you are doing something like - * moving categories, where you do not want to allow people to move a category - * to be the child of itself. - * * This function is deprecated! For list of categories use * coursecat::make_all_categories($requiredcapability, $excludeid, $separator) * For parents of one particular category use * coursecat::get($id)->get_parents() * * @deprecated since 2.5 - * - * @param array $list For output, accumulates an array categoryid => full category path name - * @param array $parents For output, accumulates an array categoryid => list of parent category ids. - * @param string/array $requiredcapability if given, only categories where the current - * user has this capability will be added to $list. Can also be an array of capabilities, - * in which case they are all required. - * @param integer $excludeid Omit this category and its children from the lists built. - * @param object $category Not used - * @param string $path Not used */ function make_categories_list(&$list, &$parents, $requiredcapability = '', $excludeid = 0, $category = NULL, $path = "") { - global $CFG, $DB; - require_once($CFG->libdir.'/coursecatlib.php'); - - debugging('Global function make_categories_list() is deprecated. Please use '. - 'coursecat::make_categories_list() and coursecat::get_parents()', - DEBUG_DEVELOPER); - - // For categories list use just this one function: - if (empty($list)) { - $list = array(); - } - $list += coursecat::make_categories_list($requiredcapability, $excludeid); - - // Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed. - // Usually user needs only parents for one particular category, in which case should be used: - // coursecat::get($categoryid)->get_parents() - if (empty($parents)) { - $parents = array(); - } - $all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder'); - foreach ($all as $record) { - if ($record->parent) { - $parents[$record->id] = array_merge($parents[$record->parent], array($record->parent)); - } else { - $parents[$record->id] = array(); - } - } + throw new coding_exception('Global function make_categories_list() is removed. Please use '. + 'coursecat::make_categories_list() and coursecat::get_parents()'); } /** - * Delete category, but move contents to another category. - * - * This function is deprecated. Please use - * coursecat::get($category->id)->delete_move($newparentid, $showfeedback); - * - * @see coursecat::delete_move() * @deprecated since 2.5 - * - * @param object $category - * @param int $newparentid category id - * @return bool status */ function category_delete_move($category, $newparentid, $showfeedback=true) { - global $CFG; - require_once($CFG->libdir.'/coursecatlib.php'); - - debugging('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.'); - - return coursecat::get($category->id)->delete_move($newparentid, $showfeedback); + throw new coding_exception('Function category_delete_move() is removed. Please use coursecat::delete_move() instead.'); } /** - * Recursively delete category including all subcategories and courses. - * - * This function is deprecated. Please use - * coursecat::get($category->id)->delete_full($showfeedback); - * - * @see coursecat::delete_full() * @deprecated since 2.5 - * - * @param stdClass $category - * @param boolean $showfeedback display some notices - * @return array return deleted courses */ function category_delete_full($category, $showfeedback=true) { - global $CFG, $DB; - require_once($CFG->libdir.'/coursecatlib.php'); - - debugging('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.'); - - return coursecat::get($category->id)->delete_full($showfeedback); + throw new coding_exception('Function category_delete_full() is removed. Please use coursecat::delete_full() instead.'); } /** - * Efficiently moves a category - NOTE that this can have - * a huge impact access-control-wise... - * * This function is deprecated. Please use * $coursecat = coursecat::get($category->id); * if ($coursecat->can_change_parent($newparentcat->id)) { @@ -2219,69 +1406,37 @@ function category_delete_full($category, $showfeedback=true) { * Alternatively you can use * $coursecat->update(array('parent' => $newparentcat->id)); * - * Function update() also updates field course_categories.timemodified - * * @see coursecat::change_parent() * @see coursecat::update() * @deprecated since 2.5 - * - * @param stdClass|coursecat $category - * @param stdClass|coursecat $newparentcat */ function move_category($category, $newparentcat) { - global $CFG; - require_once($CFG->libdir.'/coursecatlib.php'); - - debugging('Function move_category() is deprecated. Please use coursecat::change_parent() instead.'); - - return coursecat::get($category->id)->change_parent($newparentcat->id); + throw new coding_exception('Function move_category() is removed. Please use coursecat::change_parent() instead.'); } /** - * Hide course category and child course and subcategories - * * This function is deprecated. Please use * coursecat::get($category->id)->hide(); * * @see coursecat::hide() * @deprecated since 2.5 - * - * @param stdClass $category - * @return void */ function course_category_hide($category) { - global $CFG; - require_once($CFG->libdir.'/coursecatlib.php'); - - debugging('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.'); - - coursecat::get($category->id)->hide(); + throw new coding_exception('Function course_category_hide() is removed. Please use coursecat::hide() instead.'); } /** - * Show course category and child course and subcategories - * * This function is deprecated. Please use * coursecat::get($category->id)->show(); * * @see coursecat::show() * @deprecated since 2.5 - * - * @param stdClass $category - * @return void */ function course_category_show($category) { - global $CFG; - require_once($CFG->libdir.'/coursecatlib.php'); - - debugging('Function course_category_show() is deprecated. Please use coursecat::show() instead.'); - - coursecat::get($category->id)->show(); + throw new coding_exception('Function course_category_show() is removed. Please use coursecat::show() instead.'); } /** - * Return specified category, default if given does not exist - * * This function is deprecated. * To get the category with the specified it please use: * coursecat::get($catid, IGNORE_MISSING); @@ -2291,86 +1446,23 @@ function course_category_show($category) { * To get the first available category please use * coursecat::get_default(); * - * class coursecat will also make sure that at least one category exists in DB - * * @deprecated since 2.5 - * @see coursecat::get() - * @see coursecat::get_default() - * - * @param int $catid course category id - * @return object caregory */ function get_course_category($catid=0) { - global $DB; - - debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details'); - - $category = false; - - if (!empty($catid)) { - $category = $DB->get_record('course_categories', array('id'=>$catid)); - } - - if (!$category) { - // the first category is considered default for now - if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) { - $category = reset($category); - - } else { - $cat = new stdClass(); - $cat->name = get_string('miscellaneous'); - $cat->depth = 1; - $cat->sortorder = MAX_COURSES_IN_CATEGORY; - $cat->timemodified = time(); - $catid = $DB->insert_record('course_categories', $cat); - // make sure category context exists - context_coursecat::instance($catid); - mark_context_dirty('/'.SYSCONTEXTID); - fix_course_sortorder(); // Required to build course_categories.depth and .path. - $category = $DB->get_record('course_categories', array('id'=>$catid)); - } - } - - return $category; + throw new coding_exception('Function get_course_category() is removed. Please use coursecat::get(), see phpdocs for more details'); } /** - * Create a new course category and marks the context as dirty - * - * This function does not set the sortorder for the new category and - * {@link fix_course_sortorder()} should be called after creating a new course - * category - * - * Please note that this function does not verify access control. - * * This function is deprecated. It is replaced with the method create() in class coursecat. * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action * * @deprecated since 2.5 - * - * @param object $category All of the data required for an entry in the course_categories table - * @return object new course category */ function create_course_category($category) { - global $DB; - - debugging('Function create_course_category() is deprecated. Please use coursecat::create(), see phpdocs for more details', DEBUG_DEVELOPER); - - $category->timemodified = time(); - $category->id = $DB->insert_record('course_categories', $category); - $category = $DB->get_record('course_categories', array('id' => $category->id)); - - // We should mark the context as dirty - $category->context = context_coursecat::instance($category->id); - $category->context->mark_dirty(); - - return $category; + throw new coding_exception('Function create_course_category() is removed. Please use coursecat::create(), see phpdocs for more details'); } /** - * Returns an array of category ids of all the subcategories for a given - * category. - * * This function is deprecated. * * To get visible children categories of the given category use: @@ -2382,31 +1474,13 @@ function create_course_category($category) { * @see coursecat::get_children() * * @deprecated since 2.5 - * - * @global object - * @param int $catid - The id of the category whose subcategories we want to find. - * @return array of category ids. */ function get_all_subcategories($catid) { - global $DB; - - debugging('Function get_all_subcategories() is deprecated. Please use appropriate methods() of coursecat class. See phpdocs for more details', - DEBUG_DEVELOPER); - - $subcats = array(); - - if ($categories = $DB->get_records('course_categories', array('parent' => $catid))) { - foreach ($categories as $cat) { - array_push($subcats, $cat->id); - $subcats = array_merge($subcats, get_all_subcategories($cat->id)); - } - } - return $subcats; + throw new coding_exception('Function get_all_subcategories() is removed. Please use appropriate methods() of coursecat + class. See phpdocs for more details'); } /** - * Gets the child categories of a given courses category - * * This function is deprecated. Please use functions in class coursecat: * - coursecat::get($parentid)->has_children() * tells if the category has children (visible or not to the current user) @@ -2425,37 +1499,13 @@ function get_all_subcategories($catid) { * returns the first category (usually to be used if count_all() == 1) * * @deprecated since 2.5 - * - * @param int $parentid the id of a course category. - * @return array all the child course categories. */ function get_child_categories($parentid) { - global $DB; - debugging('Function get_child_categories() is deprecated. Use coursecat::get_children() or see phpdocs for more details.', - DEBUG_DEVELOPER); - - $rv = array(); - $sql = context_helper::get_preload_record_columns_sql('ctx'); - $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ". - "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder", - array(CONTEXT_COURSECAT, $parentid)); - foreach ($records as $category) { - context_helper::preload_from_record($category); - if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) { - continue; - } - $rv[] = $category; - } - return $rv; + throw new coding_exception('Function get_child_categories() is removed. Use coursecat::get_children() or see phpdocs for + more details.'); } /** - * Returns a sorted list of categories. - * - * When asking for $parent='none' it will return all the categories, regardless - * of depth. Wheen asking for a specific parent, the default is to return - * a "shallow" resultset. Pass false to $shallow and it will return all - * the child categories as well. * * @deprecated since 2.5 * @@ -2482,100 +1532,23 @@ function get_child_categories($parentid) { * * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()}, * {@link coursecat::get_default()} - * - * The code of this deprecated function is left as it is because coursecat::get_children() - * returns categories as instances of coursecat and not stdClass. Also there is no - * substitute for retrieving the category with all it's subcategories. Plugin developers - * may re-use the code/queries from this function in their plugins if really necessary. - * - * @param string $parent The parent category if any - * @param string $sort the sortorder - * @param bool $shallow - set to false to get the children too - * @return array of categories */ function get_categories($parent='none', $sort=NULL, $shallow=true) { - global $DB; - - debugging('Function get_categories() is deprecated. Please use coursecat::get_children() or see phpdocs for other alternatives', - DEBUG_DEVELOPER); - - if ($sort === NULL) { - $sort = 'ORDER BY cc.sortorder ASC'; - } elseif ($sort ==='') { - // leave it as empty - } else { - $sort = "ORDER BY $sort"; - } - - list($ccselect, $ccjoin) = context_instance_preload_sql('cc.id', CONTEXT_COURSECAT, 'ctx'); - - if ($parent === 'none') { - $sql = "SELECT cc.* $ccselect - FROM {course_categories} cc - $ccjoin - $sort"; - $params = array(); - - } elseif ($shallow) { - $sql = "SELECT cc.* $ccselect - FROM {course_categories} cc - $ccjoin - WHERE cc.parent=? - $sort"; - $params = array($parent); - - } else { - $sql = "SELECT cc.* $ccselect - FROM {course_categories} cc - $ccjoin - JOIN {course_categories} ccp - ON ((cc.parent = ccp.id) OR (cc.path LIKE ".$DB->sql_concat('ccp.path',"'/%'").")) - WHERE ccp.id=? - $sort"; - $params = array($parent); - } - $categories = array(); - - $rs = $DB->get_recordset_sql($sql, $params); - foreach($rs as $cat) { - context_helper::preload_from_record($cat); - $catcontext = context_coursecat::instance($cat->id); - if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) { - $categories[$cat->id] = $cat; - } - } - $rs->close(); - return $categories; + throw new coding_exception('Function get_categories() is removed. Please use coursecat::get_children() or see phpdocs for other alternatives'); } /** -* Displays a course search form -* * This function is deprecated, please use course renderer: * $renderer = $PAGE->get_renderer('core', 'course'); * echo $renderer->course_search_form($value, $format); * * @deprecated since 2.5 -* -* @param string $value default value to populate the search field -* @param bool $return if true returns the value, if false - outputs -* @param string $format display format - 'plain' (default), 'short' or 'navbar' -* @return null|string */ function print_course_search($value="", $return=false, $format="plain") { - global $PAGE; - debugging('Function print_course_search() is deprecated, please use course renderer', DEBUG_DEVELOPER); - $renderer = $PAGE->get_renderer('core', 'course'); - if ($return) { - return $renderer->course_search_form($value, $format); - } else { - echo $renderer->course_search_form($value, $format); - } + throw new coding_exception('Function print_course_search() is removed, please use course renderer'); } /** - * Prints custom user information on the home page - * * This function is deprecated, please use: * $renderer = $PAGE->get_renderer('core', 'course'); * echo $renderer->frontpage_my_courses() @@ -2583,16 +1556,10 @@ function print_course_search($value="", $return=false, $format="plain") { * @deprecated since 2.5 */ function print_my_moodle() { - global $PAGE; - debugging('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()', DEBUG_DEVELOPER); - - $renderer = $PAGE->get_renderer('core', 'course'); - echo $renderer->frontpage_my_courses(); + throw new coding_exception('Function print_my_moodle() is removed, please use course renderer function frontpage_my_courses()'); } /** - * Prints information about one remote course - * * This function is deprecated, it is replaced with protected function * {@link core_course_renderer::frontpage_remote_course()} * It is only used from function {@link core_course_renderer::frontpage_my_courses()} @@ -2600,34 +1567,10 @@ function print_my_moodle() { * @deprecated since 2.5 */ function print_remote_course($course, $width="100%") { - global $CFG, $USER; - debugging('Function print_remote_course() is deprecated, please use course renderer', DEBUG_DEVELOPER); - - $linkcss = ''; - - $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}"; - - echo '
    '; - echo '
    '; - echo '
    ' - . format_string($course->fullname) .'
    ' - . format_string($course->hostname) . ' : ' - . format_string($course->cat_name) . ' : ' - . format_string($course->shortname). '
    '; - echo '
    '; - $options = new stdClass(); - $options->noclean = true; - $options->para = false; - $options->overflowdiv = true; - echo format_text($course->summary, $course->summaryformat, $options); - echo '
    '; - echo '
    '; + throw new coding_exception('Function print_remote_course() is removed, please use course renderer'); } /** - * Prints information about one remote host - * * This function is deprecated, it is replaced with protected function * {@link core_course_renderer::frontpage_remote_host()} * It is only used from function {@link core_course_renderer::frontpage_my_courses()} @@ -2635,69 +1578,26 @@ function print_remote_course($course, $width="100%") { * @deprecated since 2.5 */ function print_remote_host($host, $width="100%") { - global $OUTPUT; - debugging('Function print_remote_host() is deprecated, please use course renderer', DEBUG_DEVELOPER); - - $linkcss = ''; - - echo '
    '; - echo '
    '; - echo '
    '; - echo ''.get_string('course').''; - echo '' - . s($host['name']).' - '; - echo $host['count'] . ' ' . get_string('courses'); - echo '
    '; - echo '
    '; - echo '
    '; + throw new coding_exception('Function print_remote_host() is removed, please use course renderer'); } /** - * Recursive function to print out all the categories in a nice format - * with or without courses included - * * @deprecated since 2.5 * * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 */ function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) { - global $PAGE; - debugging('Function print_whole_category_list() is deprecated, please use course renderer', DEBUG_DEVELOPER); - - $renderer = $PAGE->get_renderer('core', 'course'); - if ($showcourses && $category) { - echo $renderer->course_category($category); - } else if ($showcourses) { - echo $renderer->frontpage_combo_list(); - } else { - echo $renderer->frontpage_categories_list(); - } + throw new coding_exception('Function print_whole_category_list() is removed, please use course renderer'); } /** - * Prints the category information. - * * @deprecated since 2.5 - * - * This function was only used by {@link print_whole_category_list()} but now - * all course category rendering is moved to core_course_renderer. - * - * @param stdClass $category - * @param int $depth The depth of the category. - * @param bool $showcourses If set to true course information will also be printed. - * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet. */ function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) { - global $PAGE; - debugging('Function print_category_info() is deprecated, please use course renderer', DEBUG_DEVELOPER); - - $renderer = $PAGE->get_renderer('core', 'course'); - echo $renderer->course_category($category); + throw new coding_exception('Function print_category_info() is removed, please use course renderer'); } /** - * This function generates a structured array of courses and categories. - * * @deprecated since 2.5 * * This function is not used any more in moodle core and course renderer does not have render function for it. @@ -2712,76 +1612,13 @@ function print_category_info($category, $depth = 0, $showcourses = false, array * coursecat::get($id)->get_courses() * * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 - * - * @param int $id - * @param int $depth */ function get_course_category_tree($id = 0, $depth = 0) { - global $DB, $CFG; - if (!$depth) { - debugging('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class, see function phpdocs for more info', DEBUG_DEVELOPER); - } - - $categories = array(); - $categoryids = array(); - $sql = context_helper::get_preload_record_columns_sql('ctx'); - $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ". - "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder", - array(CONTEXT_COURSECAT, $id)); - foreach ($records as $category) { - context_helper::preload_from_record($category); - if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) { - continue; - } - $categories[] = $category; - $categoryids[$category->id] = $category; - if (empty($CFG->maxcategorydepth) || $depth <= $CFG->maxcategorydepth) { - list($category->categories, $subcategories) = get_course_category_tree($category->id, $depth+1); - foreach ($subcategories as $subid=>$subcat) { - $categoryids[$subid] = $subcat; - } - $category->courses = array(); - } - } - - if ($depth > 0) { - // This is a recursive call so return the required array - return array($categories, $categoryids); - } - - if (empty($categoryids)) { - // No categories available (probably all hidden). - return array(); - } - - // The depth is 0 this function has just been called so we can finish it off - - list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); - list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids)); - $sql = "SELECT - c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category - $ccselect - FROM {course} c - $ccjoin - WHERE c.category $catsql ORDER BY c.sortorder ASC"; - if ($courses = $DB->get_records_sql($sql, $catparams)) { - // loop throught them - foreach ($courses as $course) { - if ($course->id == SITEID) { - continue; - } - context_helper::preload_from_record($course); - if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) { - $categoryids[$course->category]->courses[$course->id] = $course; - } - } - } - return $categories; + throw new coding_exception('Function get_course_category_tree() is removed, please use course renderer or coursecat class, + see function phpdocs for more info'); } /** - * Print courses in category. If category is 0 then all courses are printed. - * * @deprecated since 2.5 * * To print a generic list of courses use: @@ -2795,69 +1632,24 @@ function get_course_category_tree($id = 0, $depth = 0) { * To print list of courses inside category: * $renderer = $PAGE->get_renderer('core', 'course'); * echo $renderer->course_category($category); // this will also print subcategories - * - * @param int|stdClass $category category object or id. - * @return bool true if courses found and printed, else false. */ function print_courses($category) { - global $CFG, $OUTPUT, $PAGE; - require_once($CFG->libdir. '/coursecatlib.php'); - debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER); - - if (!is_object($category) && $category==0) { - $courses = coursecat::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true)); - } else { - $courses = coursecat::get($category->id)->get_courses(array('summary' => true, 'coursecontacts' => true)); - } - - if ($courses) { - $renderer = $PAGE->get_renderer('core', 'course'); - echo $renderer->courses_list($courses); - } else { - echo $OUTPUT->heading(get_string("nocoursesyet")); - $context = context_system::instance(); - if (has_capability('moodle/course:create', $context)) { - $options = array(); - if (!empty($category->id)) { - $options['category'] = $category->id; - } else { - $options['category'] = $CFG->defaultrequestcategory; - } - echo html_writer::start_tag('div', array('class'=>'addcoursebutton')); - echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse")); - echo html_writer::end_tag('div'); - return false; - } - } - return true; + throw new coding_exception('Function print_courses() is removed, please use course renderer'); } /** - * Print a description of a course, suitable for browsing in a list. - * * @deprecated since 2.5 * * Please use course renderer to display a course information box. * $renderer = $PAGE->get_renderer('core', 'course'); * echo $renderer->courses_list($courses); // will print list of courses * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox - * - * @param object $course the course object. - * @param string $highlightterms Ignored in this deprecated function! */ function print_course($course, $highlightterms = '') { - global $PAGE; - - debugging('Function print_course() is deprecated, please use course renderer', DEBUG_DEVELOPER); - $renderer = $PAGE->get_renderer('core', 'course'); - // Please note, correct would be to use $renderer->coursecat_coursebox() but this function is protected. - // To print list of courses use $renderer->courses_list(); - echo $renderer->course_info_box($course); + throw new coding_exception('Function print_course() is removed, please use course renderer'); } /** - * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category. - * * @deprecated since 2.5 * * This function is not used any more in moodle core and course renderer does not have render function for it. @@ -2870,104 +1662,26 @@ function print_course($course, $highlightterms = '') { * coursecat::get($id)->get_children() * To get list of courses use: * coursecat::get($id)->get_courses() - * - * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5 - * - * @param int $categoryid - * @return array */ function get_category_courses_array($categoryid = 0) { - debugging('Function get_category_courses_array() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER); - $tree = get_course_category_tree($categoryid); - $flattened = array(); - foreach ($tree as $category) { - get_category_courses_array_recursively($flattened, $category); - } - return $flattened; + throw new coding_exception('Function get_category_courses_array() is removed, please use methods of coursecat class'); } /** - * Recursive function to help flatten the course category tree. - * * @deprecated since 2.5 - * - * Was intended to be called from {@link get_category_courses_array()} - * - * @param array &$flattened An array passed by reference in which to store courses for each category. - * @param stdClass $category The category to get courses for. */ function get_category_courses_array_recursively(array &$flattened, $category) { - debugging('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER); - $flattened[$category->id] = $category->courses; - foreach ($category->categories as $childcategory) { - get_category_courses_array_recursively($flattened, $childcategory); - } + throw new coding_exception('Function get_category_courses_array_recursively() is removed, please use methods of coursecat class', DEBUG_DEVELOPER); } /** - * Returns a URL based on the context of the current page. - * This URL points to blog/index.php and includes filter parameters appropriate for the current page. - * - * @param stdclass $context * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more. - * @todo Remove this in 2.7 - * @return string */ function blog_get_context_url($context=null) { - global $CFG; - - debugging('Function blog_get_context_url() is deprecated, getting params from context is not reliable for blogs.', DEBUG_DEVELOPER); - $viewblogentriesurl = new moodle_url('/blog/index.php'); - - if (empty($context)) { - global $PAGE; - $context = $PAGE->context; - } - - // Change contextlevel to SYSTEM if viewing the site course - if ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) { - $context = context_system::instance(); - } - - $filterparam = ''; - $strlevel = ''; - - switch ($context->contextlevel) { - case CONTEXT_SYSTEM: - case CONTEXT_BLOCK: - case CONTEXT_COURSECAT: - break; - case CONTEXT_COURSE: - $filterparam = 'courseid'; - $strlevel = get_string('course'); - break; - case CONTEXT_MODULE: - $filterparam = 'modid'; - $strlevel = $context->get_context_name(); - break; - case CONTEXT_USER: - $filterparam = 'userid'; - $strlevel = get_string('user'); - break; - } - - if (!empty($filterparam)) { - $viewblogentriesurl->param($filterparam, $context->instanceid); - } - - return $viewblogentriesurl; + throw new coding_exception('Function blog_get_context_url() is removed, getting params from context is not reliable for blogs.'); } /** - * Retrieve course records with the course managers and other related records - * that we need for print_course(). This allows print_courses() to do its job - * in a constant number of DB queries, regardless of the number of courses, - * role assignments, etc. - * - * The returned array is indexed on c.id, and each course will have - * - $course->managers - array containing RA objects that include a $user obj - * with the minimal fields needed for fullname() - * * @deprecated since 2.5 * * To get list of all courses with course contacts ('managers') use @@ -2978,378 +1692,33 @@ function blog_get_context_url($context=null) { * * Additionally you can specify sort order, offset and maximum number of courses, * see {@link coursecat::get_courses()} - * - * Please note that code of this function is not changed to use coursecat class because - * coursecat::get_courses() returns result in slightly different format. Also note that - * get_courses_wmanagers() DOES NOT check that users are enrolled in the course and - * coursecat::get_courses() does. - * - * @global object - * @global object - * @global object - * @uses CONTEXT_COURSE - * @uses CONTEXT_SYSTEM - * @uses CONTEXT_COURSECAT - * @uses SITEID - * @param int|string $categoryid Either the categoryid for the courses or 'all' - * @param string $sort A SQL sort field and direction - * @param array $fields An array of additional fields to fetch - * @return array */ function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) { - /* - * The plan is to - * - * - Grab the courses JOINed w/context - * - * - Grab the interesting course-manager RAs - * JOINed with a base user obj and add them to each course - * - * So as to do all the work in 2 DB queries. The RA+user JOIN - * ends up being pretty expensive if it happens over _all_ - * courses on a large site. (Are we surprised!?) - * - * So this should _never_ get called with 'all' on a large site. - * - */ - global $USER, $CFG, $DB; - debugging('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()', DEBUG_DEVELOPER); - - $params = array(); - $allcats = false; // bool flag - if ($categoryid === 'all') { - $categoryclause = ''; - $allcats = true; - } elseif (is_numeric($categoryid)) { - $categoryclause = "c.category = :catid"; - $params['catid'] = $categoryid; - } else { - debugging("Could not recognise categoryid = $categoryid"); - $categoryclause = ''; - } - - $basefields = array('id', 'category', 'sortorder', - 'shortname', 'fullname', 'idnumber', - 'startdate', 'visible', - 'newsitems', 'groupmode', 'groupmodeforce'); - - if (!is_null($fields) && is_string($fields)) { - if (empty($fields)) { - $fields = $basefields; - } else { - // turn the fields from a string to an array that - // get_user_courses_bycap() will like... - $fields = explode(',',$fields); - $fields = array_map('trim', $fields); - $fields = array_unique(array_merge($basefields, $fields)); - } - } elseif (is_array($fields)) { - $fields = array_merge($basefields,$fields); - } - $coursefields = 'c.' .join(',c.', $fields); - - if (empty($sort)) { - $sortstatement = ""; - } else { - $sortstatement = "ORDER BY $sort"; - } - - $where = 'WHERE c.id != ' . SITEID; - if ($categoryclause !== ''){ - $where = "$where AND $categoryclause"; - } - - // pull out all courses matching the cat - list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); - $sql = "SELECT $coursefields $ccselect - FROM {course} c - $ccjoin - $where - $sortstatement"; - - $catpaths = array(); - $catpath = NULL; - if ($courses = $DB->get_records_sql($sql, $params)) { - // loop on courses materialising - // the context, and prepping data to fetch the - // managers efficiently later... - foreach ($courses as $k => $course) { - context_helper::preload_from_record($course); - $coursecontext = context_course::instance($course->id); - $courses[$k] = $course; - $courses[$k]->managers = array(); - if ($allcats === false) { - // single cat, so take just the first one... - if ($catpath === NULL) { - $catpath = preg_replace(':/\d+$:', '', $coursecontext->path); - } - } else { - // chop off the contextid of the course itself - // like dirname() does... - $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path); - } - } - } else { - return array(); // no courses! - } - - $CFG->coursecontact = trim($CFG->coursecontact); - if (empty($CFG->coursecontact)) { - return $courses; - } - - $managerroles = explode(',', $CFG->coursecontact); - $catctxids = ''; - if (count($managerroles)) { - if ($allcats === true) { - $catpaths = array_unique($catpaths); - $ctxids = array(); - foreach ($catpaths as $cpath) { - $ctxids = array_merge($ctxids, explode('/',substr($cpath,1))); - } - $ctxids = array_unique($ctxids); - $catctxids = implode( ',' , $ctxids); - unset($catpaths); - unset($cpath); - } else { - // take the ctx path from the first course - // as all categories will be the same... - $catpath = substr($catpath,1); - $catpath = preg_replace(':/\d+$:','',$catpath); - $catctxids = str_replace('/',',',$catpath); - } - if ($categoryclause !== '') { - $categoryclause = "AND $categoryclause"; - } - /* - * Note: Here we use a LEFT OUTER JOIN that can - * "optionally" match to avoid passing a ton of context - * ids in an IN() clause. Perhaps a subselect is faster. - * - * In any case, this SQL is not-so-nice over large sets of - * courses with no $categoryclause. - * - */ - $sql = "SELECT ctx.path, ctx.instanceid, ctx.contextlevel, - r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname, - rn.name AS rolecoursealias, u.id AS userid, u.firstname, u.lastname - FROM {role_assignments} ra - JOIN {context} ctx ON ra.contextid = ctx.id - JOIN {user} u ON ra.userid = u.id - JOIN {role} r ON ra.roleid = r.id - LEFT JOIN {role_names} rn ON (rn.contextid = ctx.id AND rn.roleid = r.id) - LEFT OUTER JOIN {course} c - ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.") - WHERE ( c.id IS NOT NULL"; - // under certain conditions, $catctxids is NULL - if($catctxids == NULL){ - $sql .= ") "; - }else{ - $sql .= " OR ra.contextid IN ($catctxids) )"; - } - - $sql .= "AND ra.roleid IN ({$CFG->coursecontact}) - $categoryclause - ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC"; - $rs = $DB->get_recordset_sql($sql, $params); - - // This loop is fairly stupid as it stands - might get better - // results doing an initial pass clustering RAs by path. - foreach($rs as $ra) { - $user = new stdClass; - $user->id = $ra->userid; unset($ra->userid); - $user->firstname = $ra->firstname; unset($ra->firstname); - $user->lastname = $ra->lastname; unset($ra->lastname); - $ra->user = $user; - if ($ra->contextlevel == CONTEXT_SYSTEM) { - foreach ($courses as $k => $course) { - $courses[$k]->managers[] = $ra; - } - } else if ($ra->contextlevel == CONTEXT_COURSECAT) { - if ($allcats === false) { - // It always applies - foreach ($courses as $k => $course) { - $courses[$k]->managers[] = $ra; - } - } else { - foreach ($courses as $k => $course) { - $coursecontext = context_course::instance($course->id); - // Note that strpos() returns 0 as "matched at pos 0" - if (strpos($coursecontext->path, $ra->path.'/') === 0) { - // Only add it to subpaths - $courses[$k]->managers[] = $ra; - } - } - } - } else { // course-level - if (!array_key_exists($ra->instanceid, $courses)) { - //this course is not in a list, probably a frontpage course - continue; - } - $courses[$ra->instanceid]->managers[] = $ra; - } - } - $rs->close(); - } - - return $courses; + throw new coding_exception('Function get_courses_wmanagers() is removed, please use coursecat::get_courses()'); } /** - * Converts a nested array tree into HTML ul:li [recursive] - * * @deprecated since 2.5 - * - * @param array $tree A tree array to convert - * @param int $row Used in identifying the iteration level and in ul classes - * @return string HTML structure */ function convert_tree_to_html($tree, $row=0) { - debugging('Function convert_tree_to_html() is deprecated since Moodle 2.5. Consider using class tabtree and core_renderer::render_tabtree()', DEBUG_DEVELOPER); - - $str = "\n".''."\n"; - - return $str; + throw new coding_exception('Function convert_tree_to_html() is removed. Consider using class tabtree and core_renderer::render_tabtree()'); } /** - * Convert nested tabrows to a nested array - * * @deprecated since 2.5 - * - * @param array $tabrows A [nested] array of tab row objects - * @param string $selected The tabrow to select (by id) - * @param array $inactive An array of tabrow id's to make inactive - * @param array $activated An array of tabrow id's to make active - * @return array The nested array */ function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) { - - debugging('Function convert_tabrows_to_tree() is deprecated since Moodle 2.5. Consider using class tabtree', DEBUG_DEVELOPER); - - // Work backwards through the rows (bottom to top) collecting the tree as we go. - $tabrows = array_reverse($tabrows); - - $subtree = array(); - - foreach ($tabrows as $row) { - $tree = array(); - - foreach ($row as $tab) { - $tab->inactive = in_array((string)$tab->id, $inactive); - $tab->active = in_array((string)$tab->id, $activated); - $tab->selected = (string)$tab->id == $selected; - - if ($tab->active || $tab->selected) { - if ($subtree) { - $tab->subtree = $subtree; - } - } - $tree[] = $tab; - } - $subtree = $tree; - } - - return $subtree; + throw new coding_exception('Function convert_tabrows_to_tree() is removed. Consider using class tabtree'); } /** - * Can handle rotated text. Whether it is safe to use the trickery in textrotate.js. - * * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically - * @return bool True for yes, false for no */ function can_use_rotated_text() { - debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.', DEBUG_DEVELOPER); - return true; + debugging('can_use_rotated_text() is removed. JS feature detection is used automatically.'); } /** - * Get the context instance as an object. This function will create the - * context instance if it does not exist yet. - * - * @deprecated since 2.2, use context_course::instance() or other relevant class instead - * @todo This will be deleted in Moodle 2.8, refer MDL-34472 - * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE. - * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id, - * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0 - * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; - * MUST_EXIST means throw exception if no record or multiple records found - * @return context The context object. - */ -function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) { - - debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER); - - $instances = (array)$instance; - $contexts = array(); - - $classname = context_helper::get_class_for_level($contextlevel); - - // we do not load multiple contexts any more, PAGE should be responsible for any preloading - foreach ($instances as $inst) { - $contexts[$inst] = $classname::instance($inst, $strictness); - } - - if (is_array($instance)) { - return $contexts; - } else { - return $contexts[$instance]; - } -} - -/** - * Get a context instance as an object, from a given context id. - * * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more. * @see context::instance_by_id($id) */ @@ -3371,190 +1740,91 @@ function get_system_context($cache = true) { } /** - * Recursive function which, given a context, find all parent context ids, - * and return the array in reverse order, i.e. parent first, then grand - * parent, etc. - * * @see context::get_parent_context_ids() * @deprecated since 2.2, use $context->get_parent_context_ids() instead - * @param context $context - * @param bool $includeself optional, defaults to false - * @return array */ function get_parent_contexts(context $context, $includeself = false) { - debugging('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER); - return $context->get_parent_context_ids($includeself); + throw new coding_exception('get_parent_contexts() is removed, please use $context->get_parent_context_ids() instead.'); } /** - * Return the id of the parent of this context, or false if there is no parent (only happens if this - * is the site context.) - * * @deprecated since Moodle 2.2 * @see context::get_parent_context() - * @param context $context - * @return integer the id of the parent context. */ function get_parent_contextid(context $context) { - debugging('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER); - - if ($parent = $context->get_parent_context()) { - return $parent->id; - } else { - return false; - } + throw new coding_exception('get_parent_contextid() is removed, please use $context->get_parent_context() instead.'); } /** - * Recursive function which, given a context, find all its children contexts. - * - * For course category contexts it will return immediate children only categories and courses. - * It will NOT recurse into courses or child categories. - * If you want to do that, call it on the returned courses/categories. - * - * When called for a course context, it will return the modules and blocks - * displayed in the course page. - * - * If called on a user/course/module context it _will_ populate the cache with the appropriate - * contexts ;-) - * * @see context::get_child_contexts() * @deprecated since 2.2 - * @param context $context - * @return array Array of child records */ function get_child_contexts(context $context) { - debugging('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER); - return $context->get_child_contexts(); + throw new coding_exception('get_child_contexts() is removed, please use $context->get_child_contexts() instead.'); } /** - * Precreates all contexts including all parents. - * * @see context_helper::create_instances() * @deprecated since 2.2 - * @param int $contextlevel empty means all - * @param bool $buildpaths update paths and depths - * @return void */ function create_contexts($contextlevel = null, $buildpaths = true) { - debugging('create_contexts() is deprecated, please use context_helper::create_instances() instead.', DEBUG_DEVELOPER); - context_helper::create_instances($contextlevel, $buildpaths); + throw new coding_exception('create_contexts() is removed, please use context_helper::create_instances() instead.'); } /** - * Remove stale context records. - * * @see context_helper::cleanup_instances() * @deprecated since 2.2 - * @return bool */ function cleanup_contexts() { - debugging('cleanup_contexts() is deprecated, please use context_helper::cleanup_instances() instead.', DEBUG_DEVELOPER); - context_helper::cleanup_instances(); - return true; + throw new coding_exception('cleanup_contexts() is removed, please use context_helper::cleanup_instances() instead.'); } /** * Populate context.path and context.depth where missing. * - * @see context_helper::build_all_paths() * @deprecated since 2.2 - * @param bool $force force a complete rebuild of the path and depth fields, defaults to false - * @return void */ function build_context_path($force = false) { - debugging('build_context_path() is deprecated, please use context_helper::build_all_paths() instead.', DEBUG_DEVELOPER); - context_helper::build_all_paths($force); + throw new coding_exception('build_context_path() is removed, please use context_helper::build_all_paths() instead.'); } /** - * Rebuild all related context depth and path caches. - * - * @see context::reset_paths() * @deprecated since 2.2 - * @param array $fixcontexts array of contexts, strongtyped - * @return void */ function rebuild_contexts(array $fixcontexts) { - debugging('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.', DEBUG_DEVELOPER); - foreach ($fixcontexts as $fixcontext) { - $fixcontext->reset_paths(false); - } - context_helper::build_all_paths(false); + throw new coding_exception('rebuild_contexts() is removed, please use $context->reset_paths(true) instead.'); } /** - * Preloads all contexts relating to a course: course, modules. Block contexts - * are no longer loaded here. The contexts for all the blocks on the current - * page are now efficiently loaded by {@link block_manager::load_blocks()}. - * * @deprecated since Moodle 2.2 * @see context_helper::preload_course() - * @param int $courseid Course ID - * @return void */ function preload_course_contexts($courseid) { - debugging('preload_course_contexts() is deprecated, please use context_helper::preload_course() instead.', DEBUG_DEVELOPER); - context_helper::preload_course($courseid); + throw new coding_exception('preload_course_contexts() is removed, please use context_helper::preload_course() instead.'); } /** - * Update the path field of the context and all dep. subcontexts that follow - * - * Update the path field of the context and - * all the dependent subcontexts that follow - * the move. - * - * The most important thing here is to be as - * DB efficient as possible. This op can have a - * massive impact in the DB. - * * @deprecated since Moodle 2.2 * @see context::update_moved() - * @param context $context context obj - * @param context $newparent new parent obj - * @return void */ function context_moved(context $context, context $newparent) { - debugging('context_moved() is deprecated, please use context::update_moved() instead.', DEBUG_DEVELOPER); - $context->update_moved($newparent); + throw new coding_exception('context_moved() is removed, please use context::update_moved() instead.'); } /** - * Extracts the relevant capabilities given a contextid. - * All case based, example an instance of forum context. - * Will fetch all forum related capabilities, while course contexts - * Will fetch all capabilities - * - * capabilities - * `name` varchar(150) NOT NULL, - * `captype` varchar(50) NOT NULL, - * `contextlevel` int(10) NOT NULL, - * `component` varchar(100) NOT NULL, - * * @see context::get_capabilities() * @deprecated since 2.2 - * @param context $context - * @return array */ function fetch_context_capabilities(context $context) { - debugging('fetch_context_capabilities() is deprecated, please use $context->get_capabilities() instead.', DEBUG_DEVELOPER); - return $context->get_capabilities(); + throw new coding_exception('fetch_context_capabilities() is removed, please use $context->get_capabilities() instead.'); } /** - * Preloads context information from db record and strips the cached info. - * The db request has to contain both the $join and $select from context_instance_preload_sql() - * * @deprecated since 2.2 * @see context_helper::preload_from_record() - * @param stdClass $rec - * @return void (modifies $rec) */ function context_instance_preload(stdClass $rec) { - debugging('context_instance_preload() is deprecated, please use context_helper::preload_from_record() instead.', DEBUG_DEVELOPER); - context_helper::preload_from_record($rec); + throw new coding_exception('context_instance_preload() is removed, please use context_helper::preload_from_record() instead.'); } /** @@ -3562,216 +1832,80 @@ function context_instance_preload(stdClass $rec) { * * @deprecated since 2.2 * @see context_helper::get_level_name() - * @param integer $contextlevel $context->context level. One of the CONTEXT_... constants. - * @return string the name for this type of context. */ function get_contextlevel_name($contextlevel) { - debugging('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER); - return context_helper::get_level_name($contextlevel); + throw new coding_exception('get_contextlevel_name() is removed, please use context_helper::get_level_name() instead.'); } /** - * Prints human readable context identifier. - * * @deprecated since 2.2 * @see context::get_context_name() - * @param context $context the context. - * @param boolean $withprefix whether to prefix the name of the context with the - * type of context, e.g. User, Course, Forum, etc. - * @param boolean $short whether to user the short name of the thing. Only applies - * to course contexts - * @return string the human readable context name. */ function print_context_name(context $context, $withprefix = true, $short = false) { - debugging('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER); - return $context->get_context_name($withprefix, $short); + throw new coding_exception('print_context_name() is removed, please use $context->get_context_name() instead.'); } /** - * Mark a context as dirty (with timestamp) so as to force reloading of the context. - * * @deprecated since 2.2, use $context->mark_dirty() instead * @see context::mark_dirty() - * @param string $path context path */ function mark_context_dirty($path) { - global $CFG, $USER, $ACCESSLIB_PRIVATE; - debugging('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER); - - if (during_initial_install()) { - return; - } - - // only if it is a non-empty string - if (is_string($path) && $path !== '') { - set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+$CFG->sessiontimeout); - if (isset($ACCESSLIB_PRIVATE->dirtycontexts)) { - $ACCESSLIB_PRIVATE->dirtycontexts[$path] = 1; - } else { - if (CLI_SCRIPT) { - $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1); - } else { - if (isset($USER->access['time'])) { - $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $USER->access['time']-2); - } else { - $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1); - } - // flags not loaded yet, it will be done later in $context->reload_if_dirty() - } - } - } + throw new coding_exception('mark_context_dirty() is removed, please use $context->mark_dirty() instead.'); } /** - * Remove a context record and any dependent entries, - * removes context from static context cache too - * * @deprecated since Moodle 2.2 * @see context_helper::delete_instance() or context::delete_content() - * @param int $contextlevel - * @param int $instanceid - * @param bool $deleterecord false means keep record for now - * @return bool returns true or throws an exception */ function delete_context($contextlevel, $instanceid, $deleterecord = true) { if ($deleterecord) { - debugging('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER); - context_helper::delete_instance($contextlevel, $instanceid); + throw new coding_exception('delete_context() is removed, please use context_helper::delete_instance() instead.'); } else { - debugging('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER); - $classname = context_helper::get_class_for_level($contextlevel); - if ($context = $classname::instance($instanceid, IGNORE_MISSING)) { - $context->delete_content(); - } + throw new coding_exception('delete_context() is removed, please use $context->delete_content() instead.'); } - - return true; } /** - * Get a URL for a context, if there is a natural one. For example, for - * CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the - * user profile page. - * * @deprecated since 2.2 * @see context::get_url() - * @param context $context the context - * @return moodle_url */ function get_context_url(context $context) { - debugging('get_context_url() is deprecated, please use $context->get_url() instead.', DEBUG_DEVELOPER); - return $context->get_url(); + throw new coding_exception('get_context_url() is removed, please use $context->get_url() instead.'); } /** - * Is this context part of any course? if yes return course context, - * if not return null or throw exception. - * * @deprecated since 2.2 * @see context::get_course_context() - * @param context $context - * @return context_course context of the enclosing course, null if not found or exception */ function get_course_context(context $context) { - debugging('get_course_context() is deprecated, please use $context->get_course_context(true) instead.', DEBUG_DEVELOPER); - return $context->get_course_context(true); + throw new coding_exception('get_course_context() is removed, please use $context->get_course_context(true) instead.'); } /** - * Get an array of courses where cap requested is available - * and user is enrolled, this can be relatively slow. - * * @deprecated since 2.2 * @see enrol_get_users_courses() - * @param int $userid A user id. By default (null) checks the permissions of the current user. - * @param string $cap - name of the capability - * @param array $accessdata_ignored - * @param bool $doanything_ignored - * @param string $sort - sorting fields - prefix each fieldname with "c." - * @param array $fields - additional fields you are interested in... - * @param int $limit_ignored - * @return array $courses - ordered array of course objects - see notes above */ function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) { - debugging('get_user_courses_bycap() is deprecated, please use enrol_get_users_courses() instead.', DEBUG_DEVELOPER); - $courses = enrol_get_users_courses($userid, true, $fields, $sort); - foreach ($courses as $id=>$course) { - $context = context_course::instance($id); - if (!has_capability($cap, $context, $userid)) { - unset($courses[$id]); - } - } - - return $courses; + throw new coding_exception('get_user_courses_bycap() is removed, please use enrol_get_users_courses() instead.'); } /** - * This is really slow!!! do not use above course context level - * * @deprecated since Moodle 2.2 - * @param int $roleid - * @param context $context - * @return array */ function get_role_context_caps($roleid, context $context) { - global $DB; - debugging('get_role_context_caps() is deprecated, it is really slow. Don\'t use it.', DEBUG_DEVELOPER); - - // This is really slow!!!! - do not use above course context level. - $result = array(); - $result[$context->id] = array(); - - // First emulate the parent context capabilities merging into context. - $searchcontexts = array_reverse($context->get_parent_context_ids(true)); - foreach ($searchcontexts as $cid) { - if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) { - foreach ($capabilities as $cap) { - if (!array_key_exists($cap->capability, $result[$context->id])) { - $result[$context->id][$cap->capability] = 0; - } - $result[$context->id][$cap->capability] += $cap->permission; - } - } - } - - // Now go through the contexts below given context. - $searchcontexts = array_keys($context->get_child_contexts()); - foreach ($searchcontexts as $cid) { - if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) { - foreach ($capabilities as $cap) { - if (!array_key_exists($cap->contextid, $result)) { - $result[$cap->contextid] = array(); - } - $result[$cap->contextid][$cap->capability] = $cap->permission; - } - } - } - - return $result; + throw new coding_exception('get_role_context_caps() is removed, it is really slow. Don\'t use it.'); } /** - * Returns current course id or false if outside of course based on context parameter. - * * @see context::get_course_context() * @deprecated since 2.2 - * @param context $context - * @return int|bool related course id or false */ function get_courseid_from_context(context $context) { - debugging('get_courseid_from_context() is deprecated, please use $context->get_course_context(false) instead.', DEBUG_DEVELOPER); - if ($coursecontext = $context->get_course_context(false)) { - return $coursecontext->instanceid; - } else { - return false; - } + throw new coding_exception('get_courseid_from_context() is removed, please use $context->get_course_context(false) instead.'); } /** - * Preloads context information together with instances. - * Use context_instance_preload() to strip the context info from the record and cache the context instance. - * * If you are using this methid, you should have something like this: * * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); @@ -3786,208 +1920,114 @@ function get_courseid_from_context(context $context) { * ^ * @see context_helper:;get_preload_record_columns_sql() * @deprecated since 2.2 - * @param string $joinon for example 'u.id' - * @param string $contextlevel context level of instance in $joinon - * @param string $tablealias context table alias - * @return array with two values - select and join part */ function context_instance_preload_sql($joinon, $contextlevel, $tablealias) { - debugging('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.', DEBUG_DEVELOPER); - $select = ", " . context_helper::get_preload_record_columns_sql($tablealias); - $join = "LEFT JOIN {context} $tablealias ON ($tablealias.instanceid = $joinon AND $tablealias.contextlevel = $contextlevel)"; - return array($select, $join); + throw new coding_exception('context_instance_preload_sql() is removed, please use context_helper::get_preload_record_columns_sql() instead.'); } /** - * Gets a string for sql calls, searching for stuff in this context or above. - * * @deprecated since 2.2 * @see context::get_parent_context_ids() - * @param context $context - * @return string */ function get_related_contexts_string(context $context) { - debugging('get_related_contexts_string() is deprecated, please use $context->get_parent_context_ids(true) instead.', DEBUG_DEVELOPER); - if ($parents = $context->get_parent_context_ids()) { - return (' IN ('.$context->id.','.implode(',', $parents).')'); - } else { - return (' ='.$context->id); - } + throw new coding_exception('get_related_contexts_string() is removed, please use $context->get_parent_context_ids(true) instead.'); } /** - * Get a list of all the plugins of a given type that contain a particular file. - * - * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'. - * @param string $file the name of file that must be present in the plugin. - * (e.g. 'view.php', 'db/install.xml'). - * @param bool $include if true (default false), the file will be include_once-ed if found. - * @return array with plugin name as keys (e.g. 'forum', 'courselist') and the path - * to the file relative to dirroot as value (e.g. "$CFG->dirroot/mod/forum/view.php"). * @deprecated since 2.6 * @see core_component::get_plugin_list_with_file() */ function get_plugin_list_with_file($plugintype, $file, $include = false) { - debugging('get_plugin_list_with_file() is deprecated, please use core_component::get_plugin_list_with_file() instead.', - DEBUG_DEVELOPER); - return core_component::get_plugin_list_with_file($plugintype, $file, $include); + throw new coding_exception('get_plugin_list_with_file() is removed, please use core_component::get_plugin_list_with_file() instead.'); } /** - * Checks to see if is the browser operating system matches the specified brand. - * - * Known brand: 'Windows','Linux','Macintosh','SGI','SunOS','HP-UX' - * * @deprecated since 2.6 - * @param string $brand The operating system identifier being tested - * @return bool true if the given brand below to the detected operating system */ function check_browser_operating_system($brand) { - debugging('check_browser_operating_system has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER); - return core_useragent::check_browser_operating_system($brand); + throw new coding_exception('check_browser_operating_system is removed, please update your code to use core_useragent instead.'); } /** - * Checks to see if is a browser matches the specified - * brand and is equal or better version. - * * @deprecated since 2.6 - * @param string $brand The browser identifier being tested - * @param int $version The version of the browser, if not specified any version (except 5.5 for IE for BC reasons) - * @return bool true if the given version is below that of the detected browser */ function check_browser_version($brand, $version = null) { - debugging('check_browser_version has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER); - return core_useragent::check_browser_version($brand, $version); + throw new coding_exception('check_browser_version is removed, please update your code to use core_useragent instead.'); } /** - * Returns whether a device/browser combination is mobile, tablet, legacy, default or the result of - * an optional admin specified regular expression. If enabledevicedetection is set to no or not set - * it returns default - * * @deprecated since 2.6 - * @return string device type */ function get_device_type() { - debugging('get_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER); - return core_useragent::get_device_type(); + throw new coding_exception('get_device_type is removed, please update your code to use core_useragent instead.'); } /** - * Returns a list of the device types supporting by Moodle - * * @deprecated since 2.6 - * @param boolean $incusertypes includes types specified using the devicedetectregex admin setting - * @return array $types */ function get_device_type_list($incusertypes = true) { - debugging('get_device_type_list has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER); - return core_useragent::get_device_type_list($incusertypes); + throw new coding_exception('get_device_type_list is removed, please update your code to use core_useragent instead.'); } /** - * Returns the theme selected for a particular device or false if none selected. - * * @deprecated since 2.6 - * @param string $devicetype - * @return string|false The name of the theme to use for the device or the false if not set */ function get_selected_theme_for_device_type($devicetype = null) { - debugging('get_selected_theme_for_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER); - return core_useragent::get_device_type_theme($devicetype); + throw new coding_exception('get_selected_theme_for_device_type is removed, please update your code to use core_useragent instead.'); } /** - * Returns the name of the device type theme var in $CFG because there is not a convention to allow backwards compatibility. - * * @deprecated since 2.6 - * @param string $devicetype - * @return string The config variable to use to determine the theme */ function get_device_cfg_var_name($devicetype = null) { - debugging('get_device_cfg_var_name has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER); - return core_useragent::get_device_type_cfg_var_name($devicetype); + throw new coding_exception('get_device_cfg_var_name is removed, please update your code to use core_useragent instead.'); } /** - * Allows the user to switch the device they are seeing the theme for. - * This allows mobile users to switch back to the default theme, or theme for any other device. - * * @deprecated since 2.6 - * @param string $newdevice The device the user is currently using. - * @return string The device the user has switched to */ function set_user_device_type($newdevice) { - debugging('set_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER); - return core_useragent::set_user_device_type($newdevice); + throw new coding_exception('set_user_device_type is removed, please update your code to use core_useragent instead.'); } /** - * Returns the device the user is currently using, or if the user has chosen to switch devices - * for the current device type the type they have switched to. - * * @deprecated since 2.6 - * @return string The device the user is currently using or wishes to use */ function get_user_device_type() { - debugging('get_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER); - return core_useragent::get_user_device_type(); + throw new coding_exception('get_user_device_type is removed, please update your code to use core_useragent instead.'); } /** - * Returns one or several CSS class names that match the user's browser. These can be put - * in the body tag of the page to apply browser-specific rules without relying on CSS hacks - * * @deprecated since 2.6 - * @return array An array of browser version classes */ function get_browser_version_classes() { - debugging('get_browser_version_classes has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER); - return core_useragent::get_browser_version_classes(); + throw new coding_exception('get_browser_version_classes is removed, please update your code to use core_useragent instead.'); } /** - * Generate a fake user for emails based on support settings - * * @deprecated since Moodle 2.6 * @see core_user::get_support_user() - * @return stdClass user info */ function generate_email_supportuser() { - debugging('generate_email_supportuser is deprecated, please use core_user::get_support_user'); - return core_user::get_support_user(); + throw new coding_exception('generate_email_supportuser is removed, please use core_user::get_support_user'); } /** - * Get issued badge details for assertion URL - * * @deprecated since Moodle 2.6 - * @param string $hash Unique hash of a badge - * @return array Information about issued badge. */ function badges_get_issued_badge_info($hash) { - debugging('Function badges_get_issued_badge_info() is deprecated. Please use core_badges_assertion class and methods to generate badge assertion.', DEBUG_DEVELOPER); - $assertion = new core_badges_assertion($hash); - return $assertion->get_badge_assertion(); + throw new coding_exception('Function badges_get_issued_badge_info() is removed. Please use core_badges_assertion class and methods to generate badge assertion.'); } /** - * Does the user want and can edit using rich text html editor? - * This function does not make sense anymore because a user can directly choose their preferred editor. - * * @deprecated since 2.6 - * @return bool */ function can_use_html_editor() { - debugging('can_use_html_editor has been deprecated please update your code to assume it returns true.', DEBUG_DEVELOPER); - return true; + throw new coding_exception('can_use_html_editor is removed, please update your code to assume it returns true.'); } /** - * Returns an object with counts of failed login attempts. - * * @deprecated since Moodle 2.7, use {@link user_count_login_failures()} instead. */ function count_login_failures($mode, $username, $lastlogin) { @@ -3995,8 +2035,6 @@ function count_login_failures($mode, $username, $lastlogin) { } /** - * It should no longer be required to work without JavaScript enabled. - * * @deprecated since 2.7 MDL-33099/MDL-44088 - please do not use this function any more. */ function ajaxenabled(array $browsers = null) { @@ -4004,8 +2042,6 @@ function ajaxenabled(array $browsers = null) { } /** - * Determine whether a course module is visible within a course. - * * @deprecated Since Moodle 2.7 MDL-44070 */ function coursemodule_visible_for_user($cm, $userid=0) { @@ -4014,187 +2050,49 @@ function coursemodule_visible_for_user($cm, $userid=0) { } /** - * Gets all the cohorts the user is able to view. - * * @deprecated since Moodle 2.8 MDL-36014, MDL-35618 this functionality is removed - * - * @param course_enrolment_manager $manager - * @return array */ function enrol_cohort_get_cohorts(course_enrolment_manager $manager) { - global $CFG; - debugging('Function enrol_cohort_get_cohorts() is deprecated, use enrol_cohort_search_cohorts() or '. - 'cohort_get_available_cohorts() instead', DEBUG_DEVELOPER); - return enrol_cohort_search_cohorts($manager, 0, 0, ''); + throw new coding_exception('Function enrol_cohort_get_cohorts() is removed, use enrol_cohort_search_cohorts() or '. + 'cohort_get_available_cohorts() instead'); } /** - * Check if cohort exists and user is allowed to enrol it. - * * This function is deprecated, use {@link cohort_can_view_cohort()} instead since it also * takes into account current context * * @deprecated since Moodle 2.8 MDL-36014 please use cohort_can_view_cohort() - * - * @param int $cohortid Cohort ID - * @return boolean */ function enrol_cohort_can_view_cohort($cohortid) { - global $CFG; - require_once($CFG->dirroot . '/cohort/lib.php'); - debugging('Function enrol_cohort_can_view_cohort() is deprecated, use cohort_can_view_cohort() instead', - DEBUG_DEVELOPER); - return cohort_can_view_cohort($cohortid, null); + throw new coding_exception('Function enrol_cohort_can_view_cohort() is removed, use cohort_can_view_cohort() instead'); } /** - * Returns list of cohorts from course parent contexts. - * - * Note: this function does not implement any capability checks, - * it means it may disclose existence of cohorts, - * make sure it is displayed to users with appropriate rights only. - * * It is advisable to use {@link cohort_get_available_cohorts()} instead. * * @deprecated since Moodle 2.8 MDL-36014 use cohort_get_available_cohorts() instead - * - * @param stdClass $course - * @param bool $onlyenrolled true means include only cohorts with enrolled users - * @return array of cohort names with number of enrolled users */ function cohort_get_visible_list($course, $onlyenrolled=true) { - global $DB; - - debugging('Function cohort_get_visible_list() is deprecated. Please use function cohort_get_available_cohorts() ". - "that correctly checks capabilities.', DEBUG_DEVELOPER); - - $context = context_course::instance($course->id); - list($esql, $params) = get_enrolled_sql($context); - list($parentsql, $params2) = $DB->get_in_or_equal($context->get_parent_context_ids(), SQL_PARAMS_NAMED); - $params = array_merge($params, $params2); - - if ($onlyenrolled) { - $left = ""; - $having = "HAVING COUNT(u.id) > 0"; - } else { - $left = "LEFT"; - $having = ""; - } - - $sql = "SELECT c.id, c.name, c.contextid, c.idnumber, c.visible, COUNT(u.id) AS cnt - FROM {cohort} c - $left JOIN ({cohort_members} cm - JOIN ($esql) u ON u.id = cm.userid) ON cm.cohortid = c.id - WHERE c.contextid $parentsql - GROUP BY c.id, c.name, c.contextid, c.idnumber, c.visible - $having - ORDER BY c.name, c.idnumber, c.visible"; - - $cohorts = $DB->get_records_sql($sql, $params); - - foreach ($cohorts as $cid=>$cohort) { - $cohorts[$cid] = format_string($cohort->name, true, array('context'=>$cohort->contextid)); - if ($cohort->cnt) { - $cohorts[$cid] .= ' (' . $cohort->cnt . ')'; - } - } - - return $cohorts; + throw new coding_exception('Function cohort_get_visible_list() is removed. Please use function cohort_get_available_cohorts() ". + "that correctly checks capabilities.'); } /** - * Enrols all of the users in a cohort through a manual plugin instance. - * - * In order for this to succeed the course must contain a valid manual - * enrolment plugin instance that the user has permission to enrol users through. - * * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed - * - * @global moodle_database $DB - * @param course_enrolment_manager $manager - * @param int $cohortid - * @param int $roleid - * @return int */ function enrol_cohort_enrol_all_users(course_enrolment_manager $manager, $cohortid, $roleid) { - global $DB; - debugging('enrol_cohort_enrol_all_users() is deprecated. This functionality is moved to enrol_manual.', DEBUG_DEVELOPER); - - $context = $manager->get_context(); - require_capability('moodle/course:enrolconfig', $context); - - $instance = false; - $instances = $manager->get_enrolment_instances(); - foreach ($instances as $i) { - if ($i->enrol == 'manual') { - $instance = $i; - break; - } - } - $plugin = enrol_get_plugin('manual'); - if (!$instance || !$plugin || !$plugin->allow_enrol($instance) || !has_capability('enrol/'.$plugin->get_name().':enrol', $context)) { - return false; - } - $sql = "SELECT com.userid - FROM {cohort_members} com - LEFT JOIN ( - SELECT * - FROM {user_enrolments} ue - WHERE ue.enrolid = :enrolid - ) ue ON ue.userid=com.userid - WHERE com.cohortid = :cohortid AND ue.id IS NULL"; - $params = array('cohortid' => $cohortid, 'enrolid' => $instance->id); - $rs = $DB->get_recordset_sql($sql, $params); - $count = 0; - foreach ($rs as $user) { - $count++; - $plugin->enrol_user($instance, $user->userid, $roleid); - } - $rs->close(); - return $count; + throw new coding_exception('enrol_cohort_enrol_all_users() is removed. This functionality is moved to enrol_manual.'); } /** - * Gets cohorts the user is able to view. - * * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed - * - * @global moodle_database $DB - * @param course_enrolment_manager $manager - * @param int $offset limit output from - * @param int $limit items to output per load - * @param string $search search string - * @return array Array(more => bool, offset => int, cohorts => array) */ function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset = 0, $limit = 25, $search = '') { - global $CFG; - debugging('enrol_cohort_search_cohorts() is deprecated. This functionality is moved to enrol_manual.', DEBUG_DEVELOPER); - require_once($CFG->dirroot . '/cohort/lib.php'); - - $context = $manager->get_context(); - $cohorts = array(); - $instances = $manager->get_enrolment_instances(); - $enrolled = array(); - foreach ($instances as $instance) { - if ($instance->enrol === 'cohort') { - $enrolled[] = $instance->customint1; - } - } - - $rawcohorts = cohort_get_available_cohorts($context, COHORT_COUNT_MEMBERS, $offset, $limit, $search); - - // Produce the output respecting parameters. - foreach ($rawcohorts as $c) { - $cohorts[$c->id] = array( - 'cohortid' => $c->id, - 'name' => shorten_text(format_string($c->name, true, array('context'=>context::instance_by_id($c->contextid))), 35), - 'users' => $c->memberscnt, - 'enrolled' => in_array($c->id, $enrolled) - ); - } - return array('more' => !(bool)$limit, 'offset' => $offset, 'cohorts' => $cohorts); + throw new coding_exception('enrol_cohort_search_cohorts() is removed. This functionality is moved to enrol_manual.'); } +/* === Apis deprecated in since Moodle 2.9 === */ + /** * Is $USER one of the supplied users? * @@ -4351,3 +2249,100 @@ function useredit_shared_definition_preferences($user, &$mform, $editoroptions = $mform->setDefault('lang', $CFG->lang); } + + +/** + * Convert region timezone to php supported timezone + * + * @deprecated since Moodle 2.9 + * @param string $tz value from ical file + * @return string $tz php supported timezone + */ +function calendar_normalize_tz($tz) { + debugging('calendar_normalize_tz() is deprecated, use core_date::normalise_timezone() instead', DEBUG_DEVELOPER); + return core_date::normalise_timezone($tz); +} + +/** + * Returns a float which represents the user's timezone difference from GMT in hours + * Checks various settings and picks the most dominant of those which have a value + * @deprecated since Moodle 2.9 + * @param float|int|string $tz timezone user timezone + * @return float + */ +function get_user_timezone_offset($tz = 99) { + debugging('get_user_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER); + $tz = core_date::get_user_timezone($tz); + $date = new DateTime('now', new DateTimeZone($tz)); + return ($date->getOffset() - dst_offset_on(time(), $tz)) / (3600.0); +} + +/** + * Returns an int which represents the systems's timezone difference from GMT in seconds + * @deprecated since Moodle 2.9 + * @param float|int|string $tz timezone for which offset is required. + * {@link http://docs.moodle.org/dev/Time_API#Timezone} + * @return int|bool if found, false is timezone 99 or error + */ +function get_timezone_offset($tz) { + debugging('get_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER); + $date = new DateTime('now', new DateTimeZone(core_date::normalise_timezone($tz))); + return $date->getOffset() - dst_offset_on(time(), $tz); +} + +/** + * Returns a list of timezones in the current language. + * @deprecated since Moodle 2.9 + * @return array + */ +function get_list_of_timezones() { + debugging('get_list_of_timezones() is deprecated, use core_date::get_list_of_timezones() instead', DEBUG_DEVELOPER); + return core_date::get_list_of_timezones(); +} + +/** + * Previous internal API, it was not supposed to be used anywhere. + * @deprecated since Moodle 2.9 + * @param array $timezones + */ +function update_timezone_records($timezones) { + debugging('update_timezone_records() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER); +} + +/** + * Previous internal API, it was not supposed to be used anywhere. + * @deprecated since Moodle 2.9 + * @param int $fromyear + * @param int $toyear + * @param mixed $strtimezone + * @return bool + */ +function calculate_user_dst_table($fromyear = null, $toyear = null, $strtimezone = null) { + debugging('calculate_user_dst_table() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER); + return false; +} + +/** + * Previous internal API, it was not supposed to be used anywhere. + * @deprecated since Moodle 2.9 + * @param int|string $year + * @param mixed $timezone + * @return null + */ +function dst_changes_for_year($year, $timezone) { + debugging('dst_changes_for_year() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER); + return null; +} + +/** + * Previous internal API, it was not supposed to be used anywhere. + * @deprecated since Moodle 2.9 + * @param string $timezonename + * @return array + */ +function get_timezone_record($timezonename) { + debugging('get_timezone_record() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER); + return array(); +} + +/* === Apis deprecated since Moodle 3.0 === */ diff --git a/lib/simplepie/library/SimplePie/Enclosure.php b/lib/simplepie/library/SimplePie/Enclosure.php index 55674379c26..4b760ab684e 100644 --- a/lib/simplepie/library/SimplePie/Enclosure.php +++ b/lib/simplepie/library/SimplePie/Enclosure.php @@ -68,7 +68,7 @@ class SimplePie_Enclosure /** * @var array - * @see get_categories() + * @see coursecat::get_children() */ var $categories; diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index 91922d5f9ef..4534dde1fd6 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -2872,154 +2872,19 @@ class core_accesslib_testcase extends advanced_testcase { // Note: watch out, the fake site might be pretty borked already. $this->assertEquals(get_system_context(), context_system::instance()); + $this->assertDebuggingCalled('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER); foreach ($DB->get_records('context') as $contextid => $record) { $context = context::instance_by_id($contextid); $this->assertEquals($context, get_context_instance($record->contextlevel, $record->instanceid)); - $this->assertEquals($context->get_parent_context_ids(), get_parent_contexts($context)); - if ($context->id == SYSCONTEXTID) { - $this->assertFalse(get_parent_contextid($context)); - } else { - $this->assertSame($context->get_parent_context()->id, get_parent_contextid($context)); - } + $this->assertDebuggingCalled('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER); } - $children = get_child_contexts($systemcontext); - // Using assertEquals here as assertSame fails for some reason... - $this->assertEquals($children, $systemcontext->get_child_contexts()); - $this->assertEquals(count($children), $DB->count_records('context')-1); - $this->resetDebugging(); - unset($children); - // Make sure a debugging is thrown. get_context_instance($record->contextlevel, $record->instanceid); $this->assertDebuggingCalled('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER); get_system_context(); $this->assertDebuggingCalled('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER); - get_parent_contexts($context); - $this->assertDebuggingCalled('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER); - get_parent_contextid($context); - $this->assertDebuggingCalled('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER); - get_child_contexts($frontpagecontext); - $this->assertDebuggingCalled('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER); - - $DB->delete_records('context', array('contextlevel'=>CONTEXT_BLOCK)); - create_contexts(); - $this->assertDebuggingCalled('create_contexts() is deprecated, please use context_helper::create_instances() instead.', DEBUG_DEVELOPER); - $this->assertFalse($DB->record_exists('context', array('contextlevel'=>CONTEXT_BLOCK))); - - $DB->set_field('context', 'depth', 0, array('contextlevel'=>CONTEXT_BLOCK)); - build_context_path(); - $this->assertDebuggingCalled('build_context_path() is deprecated, please use context_helper::build_all_paths() instead.', DEBUG_DEVELOPER); - $this->assertFalse($DB->record_exists('context', array('depth'=>0))); - - $lastcourse = $DB->get_field_sql("SELECT MAX(id) FROM {course}"); - $DB->delete_records('course', array('id'=>$lastcourse)); - $lastcategory = $DB->get_field_sql("SELECT MAX(id) FROM {course_categories}"); - $DB->delete_records('course_categories', array('id'=>$lastcategory)); - $lastuser = $DB->get_field_sql("SELECT MAX(id) FROM {user} WHERE deleted=0"); - $DB->delete_records('user', array('id'=>$lastuser)); - $DB->delete_records('block_instances', array('parentcontextid'=>$frontpagepagecontext->id)); - $DB->delete_records('course_modules', array('id'=>$frontpagepagecontext->instanceid)); - cleanup_contexts(); - $this->assertDebuggingCalled('cleanup_contexts() is deprecated, please use context_helper::cleanup_instances() instead.', DEBUG_DEVELOPER); - $count = 1; // System. - $count += $DB->count_records('user', array('deleted'=>0)); - $count += $DB->count_records('course_categories'); - $count += $DB->count_records('course'); - $count += $DB->count_records('course_modules'); - $count += $DB->count_records('block_instances'); - $this->assertEquals($count, $DB->count_records('context')); - - // Test legacy rebuild_contexts(). - $context = context_course::instance($testcourses[2]); - rebuild_contexts(array($context)); - $this->assertDebuggingCalled('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.', DEBUG_DEVELOPER); - $context = context_course::instance($testcourses[2]); - $this->assertSame($context->path, $DB->get_field('context', 'path', array('id' => $context->id))); - $this->assertSame($context->depth, $DB->get_field('context', 'depth', array('id' => $context->id))); - $this->assertEquals(0, $DB->count_records('context', array('depth' => 0))); - $this->assertEquals(0, $DB->count_records('context', array('path' => null))); - - context_helper::reset_caches(); - preload_course_contexts($SITE->id); - $this->assertDebuggingCalled('preload_course_contexts() is deprecated, please use context_helper::preload_course() instead.', DEBUG_DEVELOPER); - $this->assertEquals(1 + $DB->count_records('course_modules', array('course' => $SITE->id)), - context_inspection::test_context_cache_size()); - - context_helper::reset_caches(); - list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSECAT, 'ctx'); - $this->assertDebuggingCalled('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.', DEBUG_DEVELOPER); - $this->assertEquals(', ' . context_helper::get_preload_record_columns_sql('ctx'), $select); - $this->assertEquals('LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = ' . CONTEXT_COURSECAT . ')', $join); - $sql = "SELECT c.id $select FROM {course_categories} c $join"; - $records = $DB->get_records_sql($sql); - foreach ($records as $record) { - context_instance_preload($record); - $this->assertDebuggingCalled('context_instance_preload() is deprecated, please use context_helper::preload_from_record() instead.', - DEBUG_DEVELOPER); - $record = (array)$record; - $this->assertEquals(1, count($record)); // Only id left. - } - $this->assertEquals(count($records), context_inspection::test_context_cache_size()); - - accesslib_clear_all_caches(true); - $DB->delete_records('cache_flags', array()); - mark_context_dirty($systemcontext->path); - $this->assertDebuggingCalled('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER); - $dirty = get_cache_flags('accesslib/dirtycontexts', time()-2); - $this->assertTrue(isset($dirty[$systemcontext->path])); - - accesslib_clear_all_caches(false); - $DB->delete_records('cache_flags', array()); - $course = $DB->get_record('course', array('id'=>$testcourses[2])); - $context = context_course::instance($course->id); - $oldpath = $context->path; - $miscid = $DB->get_field_sql("SELECT MIN(id) FROM {course_categories}"); - $categorycontext = context_coursecat::instance($miscid); - $course->category = $miscid; - $DB->update_record('course', $course); - context_moved($context, $categorycontext); - $this->assertDebuggingCalled('context_moved() is deprecated, please use context::update_moved() instead.', DEBUG_DEVELOPER); - $context = context_course::instance($course->id); - $this->assertEquals($categorycontext, $context->get_parent_context()); - - $this->assertTrue($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$testcourses[2]))); - delete_context(CONTEXT_COURSE, $testcourses[2]); - $this->assertDebuggingCalled('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER); - $this->assertFalse($DB->record_exists('context', array('contextlevel'=>CONTEXT_COURSE, 'instanceid'=>$testcourses[2]))); - delete_context(CONTEXT_COURSE, $testcourses[2], false); - $this->assertDebuggingCalled('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER); - - $name = get_contextlevel_name(CONTEXT_COURSE); - $this->assertDebuggingCalled('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER); - $this->assertFalse(empty($name)); - - $context = context_course::instance($testcourses[2]); - $name = print_context_name($context); - $this->assertDebuggingCalled('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER); - $this->assertFalse(empty($name)); - - $url1 = get_context_url($coursecontext); - $this->assertDebuggingCalled('get_context_url() is deprecated, please use $context->get_url() instead.', DEBUG_DEVELOPER); - $url2 = $coursecontext->get_url(); - $this->assertEquals($url1, $url2); - $this->assertInstanceOf('moodle_url', $url2); - - $pagecm = get_coursemodule_from_id('page', $testpages[7]); - $context = context_module::instance($testpages[7]); - $coursecontext1 = get_course_context($context); - $this->assertDebuggingCalled('get_course_context() is deprecated, please use $context->get_course_context(true) instead.', DEBUG_DEVELOPER); - $coursecontext2 = $context->get_course_context(true); - $this->assertEquals($coursecontext1, $coursecontext2); - $this->assertEquals(CONTEXT_COURSE, $coursecontext2->contextlevel); - $this->assertEquals($pagecm->course, get_courseid_from_context($context)); - $this->assertDebuggingCalled('get_courseid_from_context() is deprecated, please use $context->get_course_context(false) instead.', DEBUG_DEVELOPER); - - $caps = fetch_context_capabilities($systemcontext); - $this->assertDebuggingCalled('fetch_context_capabilities() is deprecated, please use $context->get_capabilities() instead.', DEBUG_DEVELOPER); - $this->assertEquals($caps, $systemcontext->get_capabilities()); - unset($caps); } /** diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 6430b1890c4..3bdd31ecb58 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -15,6 +15,112 @@ information provided here is intended especially for developers. ** core_group_external::get_groupings ** core_group_external::get_course_groupings ** core_group_external::get_course_user_groups +* Following functions are removed from core. See MDL-50049 for details. + password_compat_not_supported() + session_get_instance() + session_is_legacy() + session_kill_all() + session_touch($sid) + session_kill($sid) + session_kill_user() + session_set_user() + session_is_loggedinas() + session_get_realuser() + session_loginas() + js_minify() + css_minify_css() + update_login_count() + reset_login_count() + update_log_display_entry() + get_recent_enrolments() + groups_filter_users_by_course_module_visible() + groups_course_module_visible() + error() + formerr() + editorhelpbutton() + editorshortcutshelpbutton() + choose_from_menu() + update_event() + get_generic_section_name() + get_all_sections() + add_mod_to_section() + get_all_mods() + get_course_section() + format_weeks_get_section_dates() + get_print_section_cm_text() + print_section_add_menus() + make_editing_buttons() + print_section() + print_overview() + print_recent_activity() + delete_course_module() + update_category_button() + make_categories_list() + category_delete_move() + category_delete_full() + move_category() + course_category_hide() + course_category_show() + get_course_category() + create_course_category() + get_all_subcategories() + get_child_categories() + get_categories() + print_course_search() + print_my_moodle() + print_remote_course() + print_remote_host() + print_whole_category_list() + print_category_info() + get_course_category_tree() + print_courses() + print_course() + get_category_courses_array() + get_category_courses_array_recursively() + blog_get_context_url() + get_courses_wmanagers() + convert_tree_to_html() + convert_tabrows_to_tree() + can_use_rotated_text() + get_parent_contexts() + get_parent_contextid() + get_child_contexts() + create_contexts(() + cleanup_contexts() + build_context_path() + rebuild_contexts() + preload_course_contexts() + context_moved() + fetch_context_capabilities() + context_instance_preload() + get_contextlevel_name() + print_context_name() + mark_context_dirty() + delete_context() + get_context_url() + get_course_context() + get_user_courses_bycap() + get_role_context_caps() + get_courseid_from_context() + context_instance_preload_sql() + get_related_contexts_string() + get_plugin_list_with_file() + check_browser_operating_system() + check_browser_version() + get_device_type() + get_device_type_list() + get_selected_theme_for_device_type() + get_device_cfg_var_name() + get_user_device_type() + get_browser_version_classes() + generate_email_supportuser() + badges_get_issued_badge_info() + can_use_html_editor() + enrol_cohort_get_cohorts() + enrol_cohort_can_view_cohort() + cohort_get_visible_list() + enrol_cohort_enrol_all_users() + enrol_cohort_search_cohorts() === 2.9.1 === diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php index c67af051099..ecc34a55b26 100644 --- a/mod/scorm/lang/en/scorm.php +++ b/mod/scorm/lang/en/scorm.php @@ -72,6 +72,7 @@ $string['browsed'] = 'Browsed'; $string['browsemode'] = 'Preview mode'; $string['browserepository'] = 'Browse repository'; $string['calculatedweight'] = 'Calculated weight'; +$string['cannotaccess'] = 'You cannot call this script in that way'; $string['cannotfindsco'] = 'Could not find SCO'; $string['collapsetocwinsize'] = 'Collapse TOC when window size below'; $string['collapsetocwinsizedesc'] = 'This setting lets you specify the window size below which the TOC should automatically collapse.'; diff --git a/mod/scorm/report/userreporttabs.php b/mod/scorm/report/userreporttabs.php index 1cf2e1752b5..b54957b9c1e 100644 --- a/mod/scorm/report/userreporttabs.php +++ b/mod/scorm/report/userreporttabs.php @@ -23,7 +23,7 @@ */ if (empty($scorm)) { - error('You cannot call this script in that way'); + print_error('cannotaccess', 'mod_scorm'); } if (!isset($currenttab)) { $currenttab = ''; diff --git a/mod/scorm/tabs.php b/mod/scorm/tabs.php index b831a44f128..8062949c580 100644 --- a/mod/scorm/tabs.php +++ b/mod/scorm/tabs.php @@ -23,7 +23,7 @@ */ if (empty($scorm)) { - error('You cannot call this script in that way'); + print_error('cannotaccess', 'mod_scorm'); } if (!isset($currenttab)) { $currenttab = ''; diff --git a/report/completion/lang/en/report_completion.php b/report/completion/lang/en/report_completion.php index da96d5fc4c5..82b0a1026cb 100644 --- a/report/completion/lang/en/report_completion.php +++ b/report/completion/lang/en/report_completion.php @@ -29,6 +29,7 @@ $string['completion:view'] = 'View course completion report'; $string['completiondate'] = 'Completion date'; $string['id'] = 'ID'; $string['name'] = 'Name'; +$string['nocapability'] = 'Can not access user completion report'; $string['page-report-completion-x'] = 'Any completion report'; $string['page-report-completion-index'] = 'Course completion report'; $string['page-report-completion-user'] = 'User course completion report'; diff --git a/report/completion/user.php b/report/completion/user.php index 596a578e616..b73c9be1756 100644 --- a/report/completion/user.php +++ b/report/completion/user.php @@ -47,7 +47,7 @@ if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesrep if (!report_completion_can_access_user_report($user, $course, true)) { // this should never happen - error('Can not access user completion report'); + print_error('nocapability', 'report_completion'); } $stractivityreport = get_string('activityreport'); diff --git a/report/stats/lang/en/report_stats.php b/report/stats/lang/en/report_stats.php index e11c706cf91..1ee3034b9c7 100644 --- a/report/stats/lang/en/report_stats.php +++ b/report/stats/lang/en/report_stats.php @@ -25,6 +25,7 @@ $string['eventreportviewed'] = 'Statistics report viewed'; $string['eventuserreportviewed'] = 'User statistics report viewed'; +$string['nocapability'] = 'Can not access user statistics report'; $string['pluginname'] = 'Statistics'; $string['page-report-stats-x'] = 'Any statistics report'; $string['page-report-stats-index'] = 'Course statistics report'; diff --git a/report/stats/user.php b/report/stats/user.php index 48e151d0695..25fbf0a6965 100644 --- a/report/stats/user.php +++ b/report/stats/user.php @@ -53,7 +53,7 @@ if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesrep if (!report_stats_can_access_user_report($user, $course, true)) { // this should never happen - error('Can not access user statistics report'); + print_error('nocapability', 'report_stats'); } $stractivityreport = get_string('activityreport');