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: