MDL-78288 core_course: Adding a link to edit availability settings

AMOS BEGIN
  CPY [editsettings,moodle],[editsettings,core_availability]
AMOS END
This commit is contained in:
Amaia Anabitarte 2023-07-03 18:15:38 +02:00
parent b9a840f638
commit 6c1471c755
10 changed files with 108 additions and 12 deletions

View File

@ -224,3 +224,43 @@ Feature: edit_availability
# And check it's still active if I delete the condition.
And I click on "Delete" "link" in the "Restrict access" "fieldset"
And the "Add group/grouping access restriction" "button" should be enabled
@javascript
Scenario: Edit section availability using course page link
# Setting a restriction up
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I edit the section "1"
And I expand all fieldsets
And I press "Add restriction..."
And I click on "Date" "button" in the "Add restriction..." "dialogue"
And I press "Save changes"
# Testing edit settings link
And "Edit settings" "link" should exist in the "section-1" "core_availability > Section availability"
When I click on "Edit settings" "link" in the "section-1" "core_availability > Section availability"
Then I should see "Restrict access"
And I should not see "General"
And I should see "Collapse all"
And I should not see "Expand all"
And I click on "Cancel" "button"
And I am on "Course 1" course homepage with editing mode off
And I should not see "Edit settings"
@javascript
Scenario: Edit activity availability using course page link
# Setting a restriction up
Given I am on the "MyForum" "forum activity editing" page logged in as teacher1
And I expand all fieldsets
And I press "Add restriction..."
And I click on "Date" "button" in the "Add restriction..." "dialogue"
When I press "Save and return to course"
# Edit settings link not displayed when editing mode is off.
Then "Edit settings" "link" should not exist in the "MyForum" "core_availability > Activity availability"
# Testing edit settings link
But I am on "Course 1" course homepage with editing mode on
And "Edit settings" "link" should exist in the "MyForum" "core_availability > Activity availability"
And I click on "Edit settings" "link" in the "MyForum" "core_availability > Activity availability"
And I should see "Restrict access"
And I should not see "Content"
And I should see "Collapse all"
And I should not see "Expand all"

View File

@ -32,7 +32,7 @@ $sectionreturn = optional_param('sr', 0, PARAM_INT);
$deletesection = optional_param('delete', 0, PARAM_BOOL);
$showonly = optional_param('showonly', 0, PARAM_TAGLIST);
$params = ['id'=>$id, 'sr'=> $sectionreturn];
$params = ['id' => $id, 'sr' => $sectionreturn];
if (!empty($showonly)) {
$params['showonly'] = $showonly;
}

View File

@ -86,11 +86,16 @@ class availability extends section_avalability {
// Nothing to be displayed to the user.
return [];
}
if (!$this->mod->uservisible) {
return $this->user_availability_info($output);
return ['info' => $this->user_availability_info($output)];
}
return $this->conditional_availability_info($output);
$editurl = new \moodle_url(
'/course/modedit.php',
['update' => $this->mod->id, 'showonly' => 'availabilityconditionsheader']
);
return ['editurl' => $editurl->out(false), 'info' => $this->conditional_availability_info($output)];
}
/**

View File

@ -106,9 +106,7 @@ class availability implements named_templatable, renderable {
return;
}
$data = (object)[
'info' => $this->get_info($output),
];
$data = (object) $this->get_info($output);
$attributename = $this->hasavailabilityname;
$data->$attributename = !empty($data->info);
@ -139,21 +137,25 @@ class availability implements named_templatable, renderable {
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context, $USER);
$info = [];
$editurl = new \moodle_url(
'/course/editsection.php',
['id' => $this->section->id, 'showonly' => 'availabilityconditions']
);
$info = ['editurl' => $editurl->out(false)];
if (!$section->visible) {
$info = [];
return [];
} else if (!$section->uservisible) {
if ($section->availableinfo) {
// Note: We only get to this function if availableinfo is non-empty,
// so there is definitely something to print.
$info[] = $this->get_availability_data($output, $section->availableinfo, 'isrestricted');
$info['info'] = $this->get_availability_data($output, $section->availableinfo, 'isrestricted');
}
} else if ($canviewhidden && !empty($CFG->enableavailability)) {
// Check if there is an availability restriction.
$ci = new info_section($section);
$fullinfo = $ci->get_full_information();
if ($fullinfo) {
$info[] = $this->get_availability_data($output, $fullinfo, 'isrestricted isfullinfo');
$info['info'] = $this->get_availability_data($output, $fullinfo, 'isrestricted isfullinfo');
}
}

View File

@ -22,7 +22,9 @@
Example context (json):
{
"text": "Not available unless: <ul><li>It is on or after <strong>8 June 2012</strong></li><li>You achieve higher than a certain score in <strong>Course total</strong></li></ul>",
"excerpt": "Not available unless: It is on or after <strong>8 June 2012</strong>"
"excerpt": "Not available unless: It is on or after <strong>8 June 2012</strong>",
"editing": true,
"editurl": "/course/editsection.php?id=81&showonly=availabilityconditions"
}
}}
{{^excerpt}}
@ -41,3 +43,10 @@
{{$expandedextraclasses}}py-2{{/expandedextraclasses}}
{{/core/showmore }}
{{/excerpt}}
{{#editing}}
{{#editurl}}
<div class="editavailability border-top mt-2 py-2">
<a href="{{editurl}}" class="p-1">{{#pix}} i/edit, core {{/pix}}{{#str}}editsettings, availability{{/str}}</a>
</div>
{{/editurl}}
{{/editing}}

View File

@ -37,7 +37,7 @@ $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.ph
$type = optional_param('type', '', PARAM_ALPHANUM); //TODO: hopefully will be removed in 2.0
$sectionreturn = optional_param('sr', null, PARAM_INT);
$beforemod = optional_param('beforemod', 0, PARAM_INT);
$showonly = optional_param('showonly', '', PARAM_ALPHANUM); // Settings group to show expanded and hide the rest.
$showonly = optional_param('showonly', '', PARAM_TAGLIST); // Settings group to show expanded and hide the rest.
$url = new moodle_url('/course/modedit.php');
$url->param('sr', $sectionreturn);

View File

@ -28,6 +28,7 @@ $string['and'] = 'and';
$string['condition_group'] = 'Restriction set';
$string['condition_group_info'] = 'Add a set of nested restrictions to apply complex logic.';
$string['disabled_verb'] = 'Cannot be changed as ruleset includes a rule containing private data.';
$string['editsettings'] = 'Edit settings';
$string['enableavailability'] = 'Enable restricted access';
$string['enableavailability_desc'] = 'If enabled, conditions (based on date, grade, completion etc.) may be set to control whether an activity or resource can be accessed.';
$string['error_list_nochildren'] = 'Restriction sets should contain at least one condition.';

View File

@ -1362,6 +1362,21 @@ $activity-add-hover: theme-color-level('primary', -10) !default;
padding: map-get($spacers, 1) map-get($spacers, 3);
background-color: $gray-200;
@include border-radius($activity-item-border-radius);
.editavailability {
padding: map-get($spacers, 1) map-get($spacers, 3);
@include border-radius(1rem);
:hover {
background-color: $gray-400;
}
a {
@include border-radius(0.5rem);
color: $body-color;
text-decoration: none;
}
}
}
&.section-summary {

View File

@ -29002,6 +29002,18 @@ span.editinstructions .alert-link {
background-color: #e9ecef;
border-radius: 1rem;
}
.course-section .availabilityinfo .editavailability {
padding: 0.25rem 1rem;
border-radius: 1rem;
}
.course-section .availabilityinfo .editavailability :hover {
background-color: #ced4da;
}
.course-section .availabilityinfo .editavailability a {
border-radius: 0.5rem;
color: #1d2125;
text-decoration: none;
}
.course-section.section-summary {
padding-left: 1rem;
padding-right: 1rem;

View File

@ -29002,6 +29002,18 @@ span.editinstructions .alert-link {
background-color: #e9ecef;
border-radius: 1rem;
}
.course-section .availabilityinfo .editavailability {
padding: 0.25rem 1rem;
border-radius: 1rem;
}
.course-section .availabilityinfo .editavailability :hover {
background-color: #ced4da;
}
.course-section .availabilityinfo .editavailability a {
border-radius: 0.5rem;
color: #1d2125;
text-decoration: none;
}
.course-section.section-summary {
padding-left: 1rem;
padding-right: 1rem;