mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
Merge branch 'MDL-82613-main-v02' of https://github.com/ferranrecio/moodle
This commit is contained in:
commit
1af718f3ee
@ -153,6 +153,8 @@ class section implements named_templatable, renderable {
|
||||
'sitehome' => $course->id == SITEID,
|
||||
'editing' => $PAGE->user_is_editing(),
|
||||
'displayonesection' => ($course->id != SITEID && $format->get_sectionid() == $section->id),
|
||||
// Section name is used as data attribute is to facilitate behat locators.
|
||||
'sectionname' => $format->get_section_name($section),
|
||||
];
|
||||
|
||||
$haspartials = [];
|
||||
|
@ -21,6 +21,7 @@ use core\output\local\dropdown\status;
|
||||
use core\output\named_templatable;
|
||||
use core_courseformat\base as course_format;
|
||||
use core_courseformat\output\local\courseformat_named_templatable;
|
||||
use core_courseformat\sectiondelegatemodule;
|
||||
use pix_icon;
|
||||
use renderable;
|
||||
use section_info;
|
||||
@ -60,40 +61,77 @@ class visibility implements named_templatable, renderable {
|
||||
*/
|
||||
public function export_for_template(\renderer_base $output): ?stdClass {
|
||||
global $USER;
|
||||
|
||||
if ($this->section->visible) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$context = context_course::instance($this->section->course);
|
||||
$data = new stdClass();
|
||||
$data->editing = $this->format->show_editor();
|
||||
if (!$this->section->visible) {
|
||||
|
||||
if (!has_capability('moodle/course:sectionvisibility', $context, $USER)) {
|
||||
$data->notavailable = true;
|
||||
if (has_capability('moodle/course:sectionvisibility', $context, $USER)) {
|
||||
$data->hiddenfromstudents = true;
|
||||
$data->notavailable = false;
|
||||
$badgetext = $output->sr_text(get_string('availability'));
|
||||
$badgetext .= get_string("hiddenfromstudents");
|
||||
$icon = $this->get_icon('hide');
|
||||
$choice = new choicelist();
|
||||
$choice->add_option(
|
||||
'show',
|
||||
get_string("availability_show", 'core_courseformat'),
|
||||
$this->get_option_data('show', 'sectionShow')
|
||||
);
|
||||
$choice->add_option(
|
||||
'hide',
|
||||
get_string('availability_hide', 'core_courseformat'),
|
||||
$this->get_option_data('hide', 'sectionHide')
|
||||
);
|
||||
$choice->set_selected_value('hide');
|
||||
$dropdown = new status(
|
||||
$output->render($icon) . ' ' . $badgetext,
|
||||
$choice,
|
||||
['dialogwidth' => status::WIDTH['big']],
|
||||
);
|
||||
$data->dropwdown = $dropdown->export_for_template($output);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data->editing = $this->format->show_editor();
|
||||
|
||||
$data->notavailable = false;
|
||||
$data->hiddenfromstudents = true;
|
||||
if ($data->editing && $this->is_section_visibility_editable()) {
|
||||
$data->dropwdown = $this->get_visibility_dropdown($output);
|
||||
} else {
|
||||
// The user is editing but cannot edit the visibility on this specific section,
|
||||
$data->editing = false;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the section visibility is editable.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_section_visibility_editable(): bool {
|
||||
// Delegated section inside a hidden sections are not editable.
|
||||
$parentsection = $this->section->get_component_instance()?->get_parent_section();
|
||||
if ($parentsection && !$parentsection->visible) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the section visibility dropdown.
|
||||
* @param \renderer_base $output typically, the renderer that's calling this function
|
||||
* @return array
|
||||
*/
|
||||
protected function get_visibility_dropdown(\renderer_base $output): array {
|
||||
$badgetext = $output->sr_text(get_string('availability'));
|
||||
$badgetext .= get_string('hiddenfromstudents');
|
||||
$icon = $this->get_icon('hide');
|
||||
|
||||
$choice = new choicelist();
|
||||
$choice->add_option(
|
||||
'show',
|
||||
get_string('availability_show', 'core_courseformat'),
|
||||
$this->get_option_data('show', 'sectionShow')
|
||||
);
|
||||
$choice->add_option(
|
||||
'hide',
|
||||
get_string('availability_hide', 'core_courseformat'),
|
||||
$this->get_option_data('hide', 'sectionHide')
|
||||
);
|
||||
$choice->set_selected_value('hide');
|
||||
|
||||
$dropdown = new status(
|
||||
$output->render($icon) . ' ' . $badgetext,
|
||||
$choice,
|
||||
['dialogwidth' => status::WIDTH['big']],
|
||||
);
|
||||
return $dropdown->export_for_template($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data for the option.
|
||||
*
|
||||
|
@ -26,6 +26,7 @@
|
||||
{
|
||||
"num": 3,
|
||||
"id": 35,
|
||||
"sectionname": "Section title",
|
||||
"controlmenu": "[tools menu]",
|
||||
"header": {
|
||||
"name": "Section title",
|
||||
@ -83,6 +84,7 @@
|
||||
data-for="section"
|
||||
data-id="{{id}}"
|
||||
data-number="{{num}}"
|
||||
data-sectionname="{{sectionname}}"
|
||||
>
|
||||
<div class="section-item">
|
||||
{{$ core_courseformat/local/content/section/content }}
|
||||
|
@ -26,6 +26,7 @@
|
||||
{
|
||||
"num": 3,
|
||||
"id": 35,
|
||||
"sectionname": "Section title",
|
||||
"controlmenu": "[tools menu]",
|
||||
"header": {
|
||||
"name": "Section title",
|
||||
@ -95,6 +96,7 @@
|
||||
data-for="section"
|
||||
data-id="{{id}}"
|
||||
data-number="{{num}}"
|
||||
data-sectionname="{{sectionname}}"
|
||||
>
|
||||
<div class="section-item">
|
||||
{{$ core_courseformat/local/content/section/content }}
|
||||
|
@ -64,7 +64,7 @@
|
||||
}
|
||||
}}
|
||||
{{#editing}}
|
||||
<div class="order-2" data-region="visibility">
|
||||
<div class="order-2" data-region="sectionvisibility">
|
||||
{{#dropwdown}}
|
||||
{{< core/local/dropdown/status}}
|
||||
{{$ buttonclasses }} badge rounded-pill bg-secondary text-dark dropdown-toggle border-0{{/ buttonclasses }}
|
||||
|
@ -47,6 +47,9 @@ class behat_courseformat extends behat_base {
|
||||
new behat_component_named_selector('Activity icon', [
|
||||
".//*[@data-activityname=%locator%]//*[@data-region='activity-icon']",
|
||||
]),
|
||||
new behat_component_named_selector('Section visibility', [
|
||||
".//*[@data-sectionname=%locator%]//*[@data-region='sectionvisibility']",
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
@mod @mod_subsection
|
||||
Feature: Subsections visibility badges
|
||||
In order to use subsections
|
||||
As an teacher
|
||||
I need to see edit visibility from the section card badges 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 | 2 | 1 |
|
||||
And the following "activity" exists:
|
||||
| activity | subsection |
|
||||
| name | Subsection1 |
|
||||
| course | C1 |
|
||||
| idnumber | subsection1 |
|
||||
| section | 1 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And I log in as "teacher1"
|
||||
|
||||
@javascript
|
||||
Scenario: Hide/Show subsection badge on the course page
|
||||
Given I am on "Course 1" course homepage with editing mode on
|
||||
And I hide section "Subsection1"
|
||||
And I should see "Hidden from students" in the "Subsection1" "core_courseformat > Section visibility"
|
||||
When I click on "Hidden from students" "button" in the "Subsection1" "core_courseformat > Section visibility"
|
||||
And I click on "Show on course page" "link" in the "Subsection1" "core_courseformat > Section visibility"
|
||||
Then I should not see "Hidden from students" in the "Subsection1" "activity"
|
||||
|
||||
@javascript
|
||||
Scenario: Hide/Show subsection badge on the parent section page
|
||||
Given I am on "Course 1" course homepage with editing mode on
|
||||
And I hide section "Subsection1"
|
||||
When I am on the "Course 1 > Section 1" "course > section" page
|
||||
And I should see "Hidden from students" in the "Subsection1" "core_courseformat > Section visibility"
|
||||
And I click on "Hidden from students" "button" in the "Subsection1" "core_courseformat > Section visibility"
|
||||
And I click on "Show on course page" "link" in the "Subsection1" "core_courseformat > Section visibility"
|
||||
Then I should not see "Hidden from students" in the "Subsection1" "activity"
|
||||
|
||||
@javascript
|
||||
Scenario: Hide/Show subsection badge on the subsection page
|
||||
Given I am on "Course 1" course homepage with editing mode on
|
||||
And I hide section "Subsection1"
|
||||
When I am on the "Course 1 > Subsection1" "course > section" page
|
||||
And I should see "Hidden from students" in the "Subsection1" "core_courseformat > Section visibility"
|
||||
And I click on "Hidden from students" "button" in the "Subsection1" "core_courseformat > Section visibility"
|
||||
And I click on "Show on course page" "link" in the "Subsection1" "core_courseformat > Section visibility"
|
||||
Then I should not see "Hidden from students"
|
||||
|
||||
@javascript
|
||||
Scenario: Subsection visibility badge is not editable when parent section is hidden
|
||||
Given I am on "Course 1" course homepage with editing mode on
|
||||
When I hide section "Section 1"
|
||||
And I should see "Hidden from students" in the "Section 1" "core_courseformat > Section visibility"
|
||||
And I should see "Hidden from students" in the "Subsection1" "activity"
|
||||
Then "Hidden from students" "button" should not exist in the "Subsection1" "activity"
|
||||
And I am on the "Course 1 > Section 1" "course > section" page
|
||||
And I should see "Hidden from students" in the "Subsection1" "activity"
|
||||
And "Hidden from students" "button" should not exist in the "Subsection1" "activity"
|
||||
And I am on the "Course 1 > Subsection1" "course > section" page
|
||||
And I should see "Hidden from students"
|
||||
And "Hidden from students" "button" should not exist
|
Loading…
x
Reference in New Issue
Block a user