Skip to content

Commit

Permalink
MDL-81503 core_course: Improve section not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaia Anabitarte committed May 15, 2024
1 parent 462d5f0 commit 0f73bb6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
24 changes: 23 additions & 1 deletion course/section.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,29 @@
// This parameter is used by the classic theme to force editing on.
$edit = optional_param('edit', -1, PARAM_BOOL);

$section = $DB->get_record('course_sections', ['id' => $sectionid], '*', MUST_EXIST);
if (!$section = $DB->get_record('course_sections', ['id' => $sectionid], '*')) {
$url = new moodle_url('/');
$PAGE->set_context(\core\context\system::instance());
$PAGE->set_url($url);
$PAGE->set_pagelayout('course');
$PAGE->add_body_classes(['limitedwidth', 'single-section-page']);
$PAGE->set_title(get_string('notfound', 'error'));
$PAGE->set_heading($SITE->fullname);
echo $OUTPUT->header();

$errortext = new \core\output\notification(
get_string('sectioncantbefound', 'error'),
\core\output\notification::NOTIFY_ERROR
);
echo $OUTPUT->render($errortext);

$button = new single_button($url, get_string('gobacktosite'), 'get', single_button::BUTTON_PRIMARY);
$button->class = 'continuebutton';
echo $OUTPUT->render($button);

echo $OUTPUT->footer();
die();
}

// Defined here to avoid notices on errors.
$PAGE->set_url('/course/section.php', ['id' => $sectionid]);
Expand Down
2 changes: 2 additions & 0 deletions lang/en/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@
$string['nostatstodisplay'] = 'Sorry, there is no available data to display';
$string['notallowedtoupdateprefremotely'] = 'You are not allowed to update this user preference remotely';
$string['notavailable'] = 'That is not currently available';
$string['notfound'] = 'Not found';
$string['notlocalisederrormessage'] = '{$a}';
$string['notmemberofgroup'] = 'You are not a member of this course group';
$string['notownerofkey'] = 'You are not owner of this key';
Expand Down Expand Up @@ -529,6 +530,7 @@
$string['reverseproxyabused'] = 'Reverse proxy enabled so the server cannot be accessed directly.<br />Please contact the server administrator.';
$string['rpcerror'] = 'Ooops! Your MNET communication has failed! Here\'s that error message to pass on to your administrator: {$a}';
$string['secretalreadyused'] = 'Change password confirmation link was already used, password was not changed';
$string['sectioncantbefound'] = '<p><b>This content can\'t be found</b></p><p>It may have been deleted, or the URL may be incorrect.</p>';
$string['sectionnotexist'] = 'This section does not exist';
$string['sendmessage'] = 'Send message';
$string['sendmessagesent'] = 'Thanks for your feedback about:<br>{$a}';
Expand Down
1 change: 1 addition & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@
$string['geolocation'] = 'latitude - longitude';
$string['gettheselogs'] = 'Get these logs';
$string['go'] = 'Go';
$string['gobacktosite'] = 'Go back to site';
$string['gpl'] = 'Copyright (C) 1999 onwards Martin Dougiamas (https://moodle.com)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Expand Down

0 comments on commit 0f73bb6

Please sign in to comment.