diff --git a/admin/course/resetindentation.php b/admin/course/resetindentation.php new file mode 100644 index 0000000000000..1626bc59a8054 --- /dev/null +++ b/admin/course/resetindentation.php @@ -0,0 +1,78 @@ +. + +/** + * Reset course indentation + * + * @copyright 2023 Amaia Anabitarte + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once('../../config.php'); + +require_admin(); + +$format = required_param('format', PARAM_PLUGIN); +$confirm = optional_param('confirm', false, PARAM_BOOL); +$backurl = new moodle_url('/admin/settings.php', ['section' => 'formatsetting'.$format]); + +$PAGE->set_url('/admin/course/resetindentation.php', ['format' => $format]); +$PAGE->set_context(context_system::instance()); + +if ($confirm) { + require_sesskey(); + $courses = $DB->get_records('course', ['format' => $format], 'id', 'id'); + if (!empty($courses)) { + $courseids = array_keys($courses); + list($courseinsql, $courseparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED, 'course'); + $DB->set_field_select('course_modules', 'indent', '0', "course $courseinsql AND indent <> 0", $courseparams); + rebuild_course_cache(0, true); + } + redirect( + $backurl, + get_string('resetindentationsuccess', 'admin'), + null, + \core\output\notification::NOTIFY_SUCCESS + ); +} + +$strtitle = get_string('resetindentation', 'admin'); + +$PAGE->set_title($strtitle); +$PAGE->set_heading($strtitle); + +navigation_node::override_active_url(new moodle_url( + '/admin/course/resetindentation.php', + ['action' => 'confirm', 'format' => $format] +)); + +echo $OUTPUT->header(); + +$displayoptions = ['confirmtitle' => get_string('resetindentation_title', 'admin')]; +$confirmbutton = new single_button( + new moodle_url('/admin/course/resetindentation.php', ['confirm' => 1, 'format' => $format, 'sesskey' => sesskey()]), + get_string('resetindentation', 'admin'), + 'post' +); +$cancelbutton = new single_button($backurl, get_string('cancel')); +echo $OUTPUT->confirm( + get_string('resetindentation_help', 'admin', ['format' => get_string('pluginname', 'format_'.$format)]), + $confirmbutton, + $cancelbutton, + $displayoptions +); + +echo $OUTPUT->footer(); diff --git a/admin/tests/behat/resetindentation.feature b/admin/tests/behat/resetindentation.feature new file mode 100644 index 0000000000000..c536bc6cade5c --- /dev/null +++ b/admin/tests/behat/resetindentation.feature @@ -0,0 +1,113 @@ +@core @core_admin @core_course @javascript +Feature: Reset course indentation + In order to reset indentation in course modules + As a admin + I want change indent value for all the modules of a course format courses in one go + + Background: + Given the following "courses" exist: + | fullname | shortname | format | + | Topics Course 1 | T1 | topics | + | Topics Course 2 | T2 | topics | + | Weekly Course 1 | W1 | weeks | + | Weekly Course 2 | W2 | weeks | + And the following "activities" exist: + | activity | name | intro | course | idnumber | + | forum | Topics forum name | Topics forum description | T1 | forum1 | + | data | Topics database name | Topics database description | T1 | data1 | + | wiki | Topics wiki name | Topics wiki description | T2 | wiki1 | + | forum | Weekly forum name | Weekly forum description | W1 | forum2 | + | data | Weekly database name | Weekly database description | W1 | data2 | + | wiki | Weekly wiki name | Weekly wiki description | W2 | wiki2 | + And I log in as "admin" + And I am on "Topics Course 1" course homepage with editing mode on + And I open "Topics forum name" actions menu + And I click on "Move right" "link" in the "Topics forum name" activity + And I open "Topics forum name" actions menu + And "Move right" "link" in the "Topics forum name" "activity" should not be visible + And "Move left" "link" in the "Topics forum name" "activity" should be visible + And I press the escape key + And I open "Topics database name" actions menu + And "Move right" "link" in the "Topics database name" "activity" should be visible + And "Move left" "link" in the "Topics database name" "activity" should not be visible + And I am on "Topics Course 2" course homepage with editing mode on + And I open "Topics wiki name" actions menu + And I click on "Move right" "link" in the "Topics wiki name" activity + And I open "Topics wiki name" actions menu + And "Move right" "link" in the "Topics wiki name" "activity" should not be visible + And "Move left" "link" in the "Topics wiki name" "activity" should be visible + And I am on "Weekly Course 1" course homepage with editing mode on + And I open "Weekly forum name" actions menu + And I click on "Move right" "link" in the "Weekly forum name" activity + And I open "Weekly forum name" actions menu + And "Move right" "link" in the "Weekly forum name" "activity" should not be visible + And "Move left" "link" in the "Weekly forum name" "activity" should be visible + And I press the escape key + And I open "Weekly database name" actions menu + And "Move right" "link" in the "Weekly database name" "activity" should be visible + And "Move left" "link" in the "Weekly database name" "activity" should not be visible + And I am on "Weekly Course 2" course homepage with editing mode on + And I open "Weekly wiki name" actions menu + And I click on "Move right" "link" in the "Weekly wiki name" activity + And I open "Weekly wiki name" actions menu + And "Move right" "link" in the "Weekly wiki name" "activity" should not be visible + And "Move left" "link" in the "Weekly wiki name" "activity" should be visible + + Scenario Outline: Apply course indentation reset + Given I navigate to "Plugins > Course formats > format" in site administration + And I wait "5" seconds + And "Reset indentation" "link" should exist + When I click on "Reset indentation" "link" + And I should see "Reset indentation on course page" + And "Reset indentation" "button" should exist + And I click on "Reset indentation" "button" + Then I should see "Indentation reset" + And I am on " Course 1" course homepage with editing mode on + And I open " forum name" actions menu + And "Move right" "link" in the " forum name" "activity" should be visible + And "Move left" "link" in the " forum name" "activity" should not be visible + And I press the escape key + And I open " database name" actions menu + And "Move right" "link" in the " database name" "activity" should be visible + And "Move left" "link" in the " database name" "activity" should not be visible + And I am on " Course 2" course homepage with editing mode on + And I open " wiki name" actions menu + And "Move right" "link" in the " wiki name" "activity" should be visible + And "Move left" "link" in the " wiki name" "activity" should not be visible +# Check other course formats had not been reset + And I am on " Course 1" course homepage with editing mode on + And I open " forum name" actions menu + And "Move right" "link" in the " forum name" "activity" should not be visible + And "Move left" "link" in the " forum name" "activity" should be visible + + Examples: + | format | other | + | Topics | Weekly | + | Weekly | Topics | + + Scenario Outline: Cancel course indentation reset + Given I navigate to "Plugins > Course formats > format" in site administration + And "Reset indentation" "link" should exist + When I click on "Reset indentation" "link" + And I should see "Reset indentation on course page" + And "Reset indentation" "button" should exist + And "Cancel" "button" should exist + And I click on "Cancel" "button" + Then I should not see "Indentation reset" + And I am on " Course 1" course homepage with editing mode on + And I open " forum name" actions menu + And "Move right" "link" in the " forum name" "activity" should not be visible + And "Move left" "link" in the " forum name" "activity" should be visible + And I press the escape key + And I open " database name" actions menu + And "Move right" "link" in the " database name" "activity" should be visible + And "Move left" "link" in the " database name" "activity" should not be visible + And I am on " Course 2" course homepage with editing mode on + And I open " wiki name" actions menu + And "Move right" "link" in the " wiki name" "activity" should not be visible + And "Move left" "link" in the " wiki name" "activity" should be visible + + Examples: + | format | + | Topics | + | Weekly | diff --git a/course/format/topics/settings.php b/course/format/topics/settings.php index 6239705b869c0..e28600d3715ed 100644 --- a/course/format/topics/settings.php +++ b/course/format/topics/settings.php @@ -25,10 +25,12 @@ defined('MOODLE_INTERNAL') || die; if ($ADMIN->fulltree) { + $url = new moodle_url('/admin/course/resetindentation.php', ['format' => 'topics']); + $link = html_writer::link($url, get_string('resetindentation', 'admin')); $settings->add(new admin_setting_configcheckbox( 'format_topics/indentation', new lang_string('indentation', 'format_topics'), - new lang_string('indentation_help', 'format_topics'), + new lang_string('indentation_help', 'format_topics').'
'.$link, 1 )); } diff --git a/course/format/weeks/settings.php b/course/format/weeks/settings.php index 9ffff443c1f90..036e5aad869a0 100644 --- a/course/format/weeks/settings.php +++ b/course/format/weeks/settings.php @@ -25,10 +25,12 @@ defined('MOODLE_INTERNAL') || die; if ($ADMIN->fulltree) { + $url = new moodle_url('/admin/course/resetindentation.php', ['format' => 'weeks']); + $link = html_writer::link($url, get_string('resetindentation', 'admin')); $settings->add(new admin_setting_configcheckbox( 'format_weeks/indentation', new lang_string('indentation', 'format_weeks'), - new lang_string('indentation_help', 'format_weeks'), + new lang_string('indentation_help', 'format_weeks').'
'.$link, 1 )); } diff --git a/lang/en/admin.php b/lang/en/admin.php index 7d5a93c9cc42f..32125d4c1596c 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -1120,6 +1120,10 @@ $string['referrernone'] = 'Browser default'; $string['referrerpolicy'] = 'Referrer policy'; $string['referrerpolicydesc'] = 'Set the referrer policy header to be included with responses from your site.'; +$string['resetindentation_title'] = 'Reset indentation on course page?'; +$string['resetindentation_help'] = 'This will remove any indentation previously set for courses in {$a->format}.'; +$string['resetindentation'] = 'Reset indentation'; +$string['resetindentationsuccess'] = 'Indentation reset'; $string['restorecourse'] = 'Restore course'; $string['restorernewroleid'] = 'Restorers\' role in courses'; $string['restorernewroleid_help'] = 'If the user does not already have the permission to manage the newly restored course, the user is automatically assigned this role and enrolled if necessary. Select "None" if you do not want restorers to be able to manage every restored course.';