From 6c1471c7552d4a2cfdd16877109e9f41bce8d3f3 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Mon, 3 Jul 2023 18:15:38 +0200 Subject: [PATCH] MDL-78288 core_course: Adding a link to edit availability settings AMOS BEGIN CPY [editsettings,moodle],[editsettings,core_availability] AMOS END --- .../tests/behat/edit_availability.feature | 40 +++++++++++++++++++ course/editsection.php | 2 +- .../output/local/content/cm/availability.php | 9 ++++- .../local/content/section/availability.php | 16 ++++---- .../local/content/availability.mustache | 11 ++++- course/modedit.php | 2 +- lang/en/availability.php | 1 + theme/boost/scss/moodle/course.scss | 15 +++++++ theme/boost/style/moodle.css | 12 ++++++ theme/classic/style/moodle.css | 12 ++++++ 10 files changed, 108 insertions(+), 12 deletions(-) diff --git a/availability/tests/behat/edit_availability.feature b/availability/tests/behat/edit_availability.feature index 61f5ca67035..1d7c6d40953 100644 --- a/availability/tests/behat/edit_availability.feature +++ b/availability/tests/behat/edit_availability.feature @@ -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" diff --git a/course/editsection.php b/course/editsection.php index e5d10f0d1c9..a63a0860c7e 100644 --- a/course/editsection.php +++ b/course/editsection.php @@ -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; } diff --git a/course/format/classes/output/local/content/cm/availability.php b/course/format/classes/output/local/content/cm/availability.php index 9776c9eccfc..1b409d14d93 100644 --- a/course/format/classes/output/local/content/cm/availability.php +++ b/course/format/classes/output/local/content/cm/availability.php @@ -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)]; } /** diff --git a/course/format/classes/output/local/content/section/availability.php b/course/format/classes/output/local/content/section/availability.php index 2d24ff1728c..c3c6bab636c 100644 --- a/course/format/classes/output/local/content/section/availability.php +++ b/course/format/classes/output/local/content/section/availability.php @@ -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'); } } diff --git a/course/format/templates/local/content/availability.mustache b/course/format/templates/local/content/availability.mustache index 1e899660226..ef88b91aef3 100644 --- a/course/format/templates/local/content/availability.mustache +++ b/course/format/templates/local/content/availability.mustache @@ -22,7 +22,9 @@ Example context (json): { "text": "Not available unless: ", - "excerpt": "Not available unless: It is on or after 8 June 2012" + "excerpt": "Not available unless: It is on or after 8 June 2012", + "editing": true, + "editurl": "/course/editsection.php?id=81&showonly=availabilityconditions" } }} {{^excerpt}} @@ -41,3 +43,10 @@ {{$expandedextraclasses}}py-2{{/expandedextraclasses}} {{/core/showmore }} {{/excerpt}} +{{#editing}} + {{#editurl}} +
+ {{#pix}} i/edit, core {{/pix}}{{#str}}editsettings, availability{{/str}} +
+ {{/editurl}} +{{/editing}} diff --git a/course/modedit.php b/course/modedit.php index 4cb5ee13dc3..82a4eed3e65 100644 --- a/course/modedit.php +++ b/course/modedit.php @@ -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); diff --git a/lang/en/availability.php b/lang/en/availability.php index 19a28288dec..40f259293ed 100644 --- a/lang/en/availability.php +++ b/lang/en/availability.php @@ -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.'; diff --git a/theme/boost/scss/moodle/course.scss b/theme/boost/scss/moodle/course.scss index 3fbe65b7023..eeda48b282a 100644 --- a/theme/boost/scss/moodle/course.scss +++ b/theme/boost/scss/moodle/course.scss @@ -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 { diff --git a/theme/boost/style/moodle.css b/theme/boost/style/moodle.css index 54c3f2c7a56..fc3d101159b 100644 --- a/theme/boost/style/moodle.css +++ b/theme/boost/style/moodle.css @@ -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; diff --git a/theme/classic/style/moodle.css b/theme/classic/style/moodle.css index 2c8445d995a..69cb7c284df 100644 --- a/theme/classic/style/moodle.css +++ b/theme/classic/style/moodle.css @@ -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;