Skip to content

Commit

Permalink
Merge branch 'MDL-81798-main' of https://github.com/ferranrecio/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 committed Jul 10, 2024
2 parents 6d3ee65 + 0766976 commit 5f37f86
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion course/classes/local/service/content_item_service.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,11 @@ public function get_content_items_for_user_in_course(\stdClass $user, \stdClass
return course_allowed_module($course, explode('_', $parents[$contentitem->get_component_name()])[1], $user);
});

$format = course_get_format($course);
$maxsectionsreached = ($format->get_last_section_number() >= $format->get_max_sections());

// Now, check there is no delegated section into a delegated section.
if (is_null($sectioninfo) || $sectioninfo->is_delegated()) {
if (is_null($sectioninfo) || $sectioninfo->is_delegated() || $maxsectionsreached) {
$availablecontentitems = array_filter($availablecontentitems, function($contentitem){
return !sectiondelegate::has_delegate_class($contentitem->get_component_name());
});
Expand Down
31 changes: 31 additions & 0 deletions mod/subsection/tests/behat/subsection_limit.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@mod @mod_subsection
Feature: Teacher can only add subsection when certain conditions are met
In order to limit subsections
As an teacher
I need to create subsections only when possible

Background:
Given I enable "subsection" "mod" plugin
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | category | numsections | initsections |
| Course 1 | C1 | 0 | 5 | 1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |

@javascript
Scenario: The activity chooser filter subsections when section limit is reached
Given the following config values are set as admin:
| maxsections | 10 | moodlecourse |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I click on "Add an activity or resource" "button" in the "Section 1" "section"
And I should see "Subsection" in the "Add an activity or resource" "dialogue"
When the following config values are set as admin:
| maxsections | 4 | moodlecourse |
And I am on "Course 1" course homepage
Then I click on "Add an activity or resource" "button" in the "Section 1" "section"
And I should not see "Subsection" in the "Add an activity or resource" "dialogue"

0 comments on commit 5f37f86

Please sign in to comment.