From ed4dcf6dffb11faeae88f78efeffa495e4959db7 Mon Sep 17 00:00:00 2001 From: Ferran Recio Date: Wed, 14 Sep 2022 08:18:59 +0200 Subject: [PATCH] MDL-75211 mod_data: show batch select only if delcheck is present --- mod/data/classes/output/view_footer.php | 2 +- mod/data/classes/template.php | 10 +++++++++ mod/data/tests/behat/view_entries.feature | 27 +++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/mod/data/classes/output/view_footer.php b/mod/data/classes/output/view_footer.php index fe358116810..8113ab09d72 100644 --- a/mod/data/classes/output/view_footer.php +++ b/mod/data/classes/output/view_footer.php @@ -115,7 +115,7 @@ class view_footer extends sticky_footer { $this->baseurl ); - if ($parser->get_template_name() != 'singletemplate' && $canmanageentries) { + if ($parser->get_template_name() != 'singletemplate' && $parser->has_tag('delcheck') && $canmanageentries) { // Build the select/deselect all control. $selectallid = 'selectall-listview-entries'; $togglegroup = 'listview-entries'; diff --git a/mod/data/classes/template.php b/mod/data/classes/template.php index bc5c8a4e618..c97210b0fba 100644 --- a/mod/data/classes/template.php +++ b/mod/data/classes/template.php @@ -215,6 +215,16 @@ class template { $this->tags = $matches['tags']; } + /** + * Check if a tag is present in the template. + * + * @param bool $tagname the tag to check (without ##) + * @return bool if the tag is present + */ + public function has_tag(string $tagname): bool { + return in_array($tagname, $this->tags); + } + /** * Return the current template name. * diff --git a/mod/data/tests/behat/view_entries.feature b/mod/data/tests/behat/view_entries.feature index ecce57d3e50..e6f118ead52 100644 --- a/mod/data/tests/behat/view_entries.feature +++ b/mod/data/tests/behat/view_entries.feature @@ -130,3 +130,30 @@ Feature: Users can view and search database entries And I press "Save settings" And I should not see "Student entry 1" And I should see "Student entry 2" + + @javascript + Scenario: Database entries can be deleted in batch if delcheck is present + Given the following "mod_data > entries" exist: + | database | user | Test field name | Test field 2 name | Test field 3 name | + | data1 | student1 | Student entry 1 | Some student content 1 | http://moodle.com | + | data1 | teacher1 | Teacher entry 2 | Some teacher content 2 | http://moodle.com | + And I am on the "Test database name" "data activity" page logged in as teacher1 + And I navigate to "Templates" in current page administration + And I set the following fields to these values: + | Repeated entry | ##delcheck##[[Test field name]]! | + And I click on "Save" "button" in the "sticky-footer" "region" + When I navigate to "Database" in current page administration + When I click on "Select all" "button" + And I click on "Delete selected" "button" + And I press "Delete" + And I should see "No entries yet" + + @javascript + Scenario: Database entries cannot be deleted in batch if delcheck is not present + Given the following "mod_data > entries" exist: + | database | user | Test field name | Test field 2 name | Test field 3 name | + | data1 | student1 | Student entry 1 | Some student content 1 | http://moodle.com | + | data1 | teacher1 | Teacher entry 2 | Some teacher content 2 | http://moodle.com | + And I am on the "Test database name" "data activity" page logged in as teacher1 + Then I should not see "Select all" + And I should not see "Delete selected"