Skip to content

Commit

Permalink
MDL-76991 core_course: New course format setting to enable/disable in…
Browse files Browse the repository at this point in the history
…dentation in weeks and topics
  • Loading branch information
Amaia Anabitarte committed Mar 13, 2023
1 parent 5e1df25 commit a7c6459
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 10 deletions.
Expand Up @@ -106,7 +106,7 @@ public function export_for_template(\renderer_base $output): stdClass {
'extraclasses' => $mod->extraclasses,
'cmformat' => $item->export_for_template($output),
'hasinfo' => $hasinfo,
'indent' => $mod->indent,
'indent' => ($format->uses_indentation()) ? $mod->indent : 0,
];
}
}
2 changes: 1 addition & 1 deletion course/format/classes/output/local/state/cm.php
Expand Up @@ -90,7 +90,7 @@ public function export_for_template(renderer_base $output): stdClass {
'uservisible' => $cm->uservisible,
'hascmrestrictions' => $this->get_has_restrictions(),
'modname' => get_string('pluginname', 'mod_' . $cm->modname),
'indent' => $cm->indent,
'indent' => ($format->uses_indentation()) ? $cm->indent : 0,
'module' => $cm->modname,
'plugin' => 'mod_' . $cm->modname,
];
Expand Down
11 changes: 11 additions & 0 deletions course/format/topics/db/upgrade.php
Expand Up @@ -42,5 +42,16 @@ function xmldb_format_topics_upgrade($oldversion) {
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.

if ($oldversion < 2023030700) {
// For sites migrating from 4.0.x or 4.1.x where the indentation was removed,
// we are disabling 'indentation' value by default.
if ($oldversion >= 2022041900) {
set_config('indentation', 0, 'format_topics');
} else {
set_config('indentation', 1, 'format_topics');
}
upgrade_plugin_savepoint(true, 2023030700, 'format', 'topics');
}

return true;
}
2 changes: 2 additions & 0 deletions course/format/topics/lang/en/format_topics.php
Expand Up @@ -36,3 +36,5 @@
$string['hidefromothers'] = 'Hide topic';
$string['showfromothers'] = 'Show topic';
$string['privacy:metadata'] = 'The Topics format plugin does not store any personal data.';
$string['indentation'] = 'Allow indentation on course page';
$string['indentation_help'] = 'Allow teachers, and other users with the manage activities capability, to indent items on the course page.';
4 changes: 4 additions & 0 deletions course/format/topics/lib.php
Expand Up @@ -50,6 +50,10 @@ public function uses_course_index() {
return true;
}

public function uses_indentation(): bool {
return (get_config('format_topics', 'indentation')) ? true : false;
}

/**
* Returns the display name of the given section that the course prefers.
*
Expand Down
34 changes: 34 additions & 0 deletions course/format/topics/settings.php
@@ -0,0 +1,34 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Settings for format_topics
*
* @package format_topics
* @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die;

if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configcheckbox(
'format_topics/indentation',
new lang_string('indentation', 'format_topics'),
new lang_string('indentation_help', 'format_topics'),
1
));
}
2 changes: 1 addition & 1 deletion course/format/topics/version.php
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2022112800; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2023030700; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2022111800; // Requires this Moodle version.
$plugin->component = 'format_topics'; // Full name of the plugin (used for diagnostics).
11 changes: 11 additions & 0 deletions course/format/weeks/db/upgrade.php
Expand Up @@ -42,5 +42,16 @@ function xmldb_format_weeks_upgrade($oldversion) {
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.

if ($oldversion < 2023030700) {
// For sites migrating from 4.0.x or 4.1.x where the indentation was removed,
// we are disabling 'indentation' value by default.
if ($oldversion >= 2022041900) {
set_config('indentation', 0, 'format_weeks');
} else {
set_config('indentation', 1, 'format_weeks');
}
upgrade_plugin_savepoint(true, 2023030700, 'format', 'weeks');
}

return true;
}
2 changes: 2 additions & 0 deletions course/format/weeks/lang/en/format_weeks.php
Expand Up @@ -39,3 +39,5 @@
$string['automaticenddate'] = 'Calculate the end date from the number of sections';
$string['automaticenddate_help'] = 'If enabled, the end date for the course will be automatically calculated from the number of sections and the course start date.';
$string['privacy:metadata'] = 'The Weekly format plugin does not store any personal data.';
$string['indentation'] = 'Allow indentation on course page';
$string['indentation_help'] = 'Allow teachers, and other users with the manage activities capability, to indent items on the course page.';
4 changes: 4 additions & 0 deletions course/format/weeks/lib.php
Expand Up @@ -49,6 +49,10 @@ public function uses_course_index() {
return true;
}

public function uses_indentation(): bool {
return (get_config('format_weeks', 'indentation')) ? true : false;
}

/**
* Generate the title for this section page
* @return string the page title
Expand Down
34 changes: 34 additions & 0 deletions course/format/weeks/settings.php
@@ -0,0 +1,34 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Settings for format_weeks
*
* @package format_weeks
* @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die;

if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configcheckbox(
'format_weeks/indentation',
new lang_string('indentation', 'format_weeks'),
new lang_string('indentation_help', 'format_weeks'),
1
));
}
2 changes: 1 addition & 1 deletion course/format/weeks/version.php
Expand Up @@ -25,6 +25,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2022112800; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2023030700; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2022111800; // Requires this Moodle version.
$plugin->component = 'format_weeks'; // Full name of the plugin (used for diagnostics).
26 changes: 26 additions & 0 deletions course/tests/behat/course_controls.feature
Expand Up @@ -178,3 +178,29 @@ Feature: Course activity controls works as expected
| courseformat |
| topics |
| weeks |

@javascript
Scenario Outline: Admins could disable indentation
Given the following "courses" exist:
| fullname | shortname | format | coursedisplay | numsections | startdate |
| Course 1 | C1 | <courseformat> | <coursedisplay> | 5 | 0 |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| forum | Test forum name | Test forum description | C1 | forum1 |
And I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
And I open "Test forum name" actions menu
And "Move right" "link" should be visible
And "Move left" "link" should not be visible
And I click on "Move right" "link" in the "Test forum name" activity
When the following config values are set as admin:
| indentation | 0 | format_<courseformat> |
And I am on "Course 1" course homepage with editing mode on
And I open "Test forum name" actions menu
Then "Move right" "link" should not exist
And "Move left" "link" should not exist

Examples:
| courseformat |
| topics |
| weeks |
20 changes: 14 additions & 6 deletions course/tests/externallib_test.php
Expand Up @@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use \core_external\external_api;

defined('MOODLE_INTERNAL') || die();

global $CFG;
Expand Down Expand Up @@ -2730,13 +2732,19 @@ public function test_get_courses_by_field() {
// Expect to receive all the fields.
$this->assertCount(41, $result['courses'][0]);
// Check default values for course format topics.
$this->assertCount(2, $result['courses'][0]['courseformatoptions']);
$this->assertCount(3, $result['courses'][0]['courseformatoptions']);
foreach ($result['courses'][0]['courseformatoptions'] as $option) {
if ($option['name'] == 'hiddensections') {
$this->assertEquals(1, $option['value']);
} else {
$this->assertEquals('coursedisplay', $option['name']);
$this->assertEquals(0, $option['value']);
switch ($option['name']) {
case 'hiddensections':
$this->assertEquals(1, $option['value']);
break;
case 'coursedisplay':
$this->assertEquals(0, $option['value']);
break;
case 'indentation':
$this->assertEquals(1, $option['value']);
break;
default:
}
}

Expand Down

0 comments on commit a7c6459

Please sign in to comment.