From c3cb6f82411e4caacd108c3167a81f891782e844 Mon Sep 17 00:00:00 2001 From: Kordan Date: Fri, 12 Jan 2024 07:33:55 +0100 Subject: [PATCH] Format items and autofill no longer can be child items I always postponed this intervention saying "parent child relation is useless for those items and none will never use it" but now I found an issue in autofill items that make it convenient, from the development point of view, to fix this issue now. The issue in autofill items is fixwd in the next PR. I guess it will #914. Format items and autofill no longer can be child items I always postponed this intervention saying "parent child relation is useless for those items and none will never use it" but now I found an issue in autofill items that make it convenient, from the development point of view, to fix this issue now. The issue in autofill items is fixwd in the next PR. I guess it will #914. --- field/autofill/classes/item.php | 1 + field/autofill/db/upgrade.php | 14 ++++++++++- field/autofill/tests/behat/itemform.feature | 24 ++++++++----------- field/autofill/version.php | 2 +- .../behat/settings_configuration_02.feature | 2 +- .../behat/settings_configuration_03.feature | 8 +++---- .../behat/settings_configuration_04.feature | 4 ++-- .../behat/settings_configuration_05.feature | 8 +++---- .../tests/behat/submit_attachment.feature | 8 +++---- field/integer/tests/behat/itemform.feature | 4 ++-- .../behat/settings_configuration_01.feature | 4 ++-- format/fieldset/classes/item.php | 1 + format/fieldset/db/upgrade.php | 14 ++++++++++- format/fieldset/version.php | 2 +- format/fieldsetend/classes/item.php | 1 + format/fieldsetend/db/upgrade.php | 14 ++++++++++- format/fieldsetend/version.php | 2 +- format/label/classes/item.php | 1 + format/label/db/upgrade.php | 14 ++++++++++- format/label/version.php | 2 +- 20 files changed, 89 insertions(+), 41 deletions(-) diff --git a/field/autofill/classes/item.php b/field/autofill/classes/item.php index a163878750a..bdffea40dae 100644 --- a/field/autofill/classes/item.php +++ b/field/autofill/classes/item.php @@ -202,6 +202,7 @@ public function __construct($cm, $surveypro, $itemid, $getparentcontent) { $this->insetupform['trimonsave'] = false; $this->insetupform['required'] = false; $this->insetupform['hideinstructions'] = false; + $this->insetupform['parentid'] = false; if (!empty($itemid)) { $this->item_load($itemid, $getparentcontent); diff --git a/field/autofill/db/upgrade.php b/field/autofill/db/upgrade.php index db45b4b4576..6f7c5a07b9f 100644 --- a/field/autofill/db/upgrade.php +++ b/field/autofill/db/upgrade.php @@ -54,6 +54,18 @@ function xmldb_surveyprofield_autofill_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2014051701, 'surveyprofield', 'autofill'); } + if ($oldversion < 2024011101) { + // Drop any parent child relation in EACH past surveypro. + // I am confident I woll not find any. + $sql = 'UPDATE {surveypro_item} + SET parentid = :parentid, parentvalue = :parentvalue + WHERE plugin = :plugin'; + $whereparams = ['parentid' => null, 'parentvalue' => null, 'plugin' => 'autofill']; + $DB->execute($sql, $whereparams); + + // Surveypro savepoint reached. + upgrade_plugin_savepoint(true, 2024011101, 'surveyprofield', 'autofill'); + } + return true; } - diff --git a/field/autofill/tests/behat/itemform.feature b/field/autofill/tests/behat/itemform.feature index c31a4d179ae..7e36bb8d035 100644 --- a/field/autofill/tests/behat/itemform.feature +++ b/field/autofill/tests/behat/itemform.feature @@ -29,18 +29,16 @@ Feature: Create an autofill item And I expand all fieldsets And I set the following fields to these values: - | Content | Your user ID | - | Indent | 1 | - | Question position | left | - | Element number | II.a | - | Variable | A1 | - | Additional note | Additional note | - | Hidden | 1 | - | Search form | 1 | - | Reserved | 1 | - | Parent element | Boolean [1]: Is it true? | - | Parent content | 1 | - | id_element01select | user ID | + | Content | Your user ID | + | Indent | 1 | + | Question position | left | + | Element number | II.a | + | Variable | A1 | + | Additional note | Additional note | + | Hidden | 1 | + | Search form | 1 | + | Reserved | 1 | + | id_element01select | user ID | And I press "Add" And I follow "edit_item_2" @@ -53,8 +51,6 @@ Feature: Create an autofill item Then the field "Hidden" matches value "1" Then the field "Search form" matches value "1" Then the field "Reserved" matches value "1" - Then the field "Parent element" matches value "Boolean [1]: Is it true?" - Then the field "Parent content" matches value "1" Then the field "element01select" matches value "user ID" And I press "Cancel" diff --git a/field/autofill/version.php b/field/autofill/version.php index 5822880a3f5..1d4482b7ea8 100644 --- a/field/autofill/version.php +++ b/field/autofill/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017112201; +$plugin->version = 2024011101; $plugin->release = '1.0'; $plugin->requires = 2015111600; // Requires this Moodle version. $plugin->component = 'surveyprofield_autofill'; // Full name of the plugin (used for diagnostics). diff --git a/field/character/tests/behat/settings_configuration_02.feature b/field/character/tests/behat/settings_configuration_02.feature index 89cf54d9718..e41a3551a7a 100644 --- a/field/character/tests/behat/settings_configuration_02.feature +++ b/field/character/tests/behat/settings_configuration_02.feature @@ -14,7 +14,7 @@ Feature: Submit using character item and check form validation (2 of 7) | teacher1 | Teacher | teacher | teacher1@nowhere.net | | student1 | Student1 | user1 | student1@nowhere.net | And the following "course enrolments" exist: - | user | course | role | + | user | course | role | | teacher1 | Character item | editingteacher | | student1 | Character item | student | And the following "activities" exist: diff --git a/field/checkbox/tests/behat/settings_configuration_03.feature b/field/checkbox/tests/behat/settings_configuration_03.feature index b30a140ad00..029e00191af 100644 --- a/field/checkbox/tests/behat/settings_configuration_03.feature +++ b/field/checkbox/tests/behat/settings_configuration_03.feature @@ -58,8 +58,8 @@ Feature: Submit using checkbox item and check form validation (3 of 4) # Test number 2: Student submits a standard answer And I press "New response" And I set the following fields to these values: - | id_surveypro_field_checkbox_1_0 | 1 | - | id_surveypro_field_checkbox_1_3 | 1 | + | id_surveypro_field_checkbox_1_0 | 1 | + | id_surveypro_field_checkbox_1_3 | 1 | And I press "Submit" And I press "Continue to responses list" Then I should see "2" submissions @@ -104,8 +104,8 @@ Feature: Submit using checkbox item and check form validation (3 of 4) And I press "New response" Then I should see "At least 2 checkboxes have to be selected" And I set the following fields to these values: - | id_surveypro_field_checkbox_1_0 | 1 | - | id_surveypro_field_checkbox_1_3 | 1 | + | id_surveypro_field_checkbox_1_0 | 1 | + | id_surveypro_field_checkbox_1_3 | 1 | And I press "Submit" And I press "Continue to responses list" Then I should see "2" submissions diff --git a/field/checkbox/tests/behat/settings_configuration_04.feature b/field/checkbox/tests/behat/settings_configuration_04.feature index af3aeffaba1..5c51c9d35d2 100644 --- a/field/checkbox/tests/behat/settings_configuration_04.feature +++ b/field/checkbox/tests/behat/settings_configuration_04.feature @@ -58,8 +58,8 @@ Feature: Submit using checkbox item and check form validation (4 of 4) # Test number 2: Student submits a standard answer And I press "New response" And I set the following fields to these values: - | id_surveypro_field_checkbox_1_0 | 1 | - | id_surveypro_field_checkbox_1_3 | 1 | + | id_surveypro_field_checkbox_1_0 | 1 | + | id_surveypro_field_checkbox_1_3 | 1 | And I press "Submit" And I press "Continue to responses list" Then I should see "2" submissions diff --git a/field/checkbox/tests/behat/settings_configuration_05.feature b/field/checkbox/tests/behat/settings_configuration_05.feature index d48555f1704..5e2fa3f8476 100644 --- a/field/checkbox/tests/behat/settings_configuration_05.feature +++ b/field/checkbox/tests/behat/settings_configuration_05.feature @@ -27,8 +27,8 @@ Feature: Submit using checkbox item and check form validation @javascript Scenario: Test checkbox element having maximumrequired = 0 Given I set the following fields to these values: - | Content | What do you usually get for breakfast? | - | Maximum allowed options | Unlimited | + | Content | What do you usually get for breakfast? | + | Maximum allowed options | Unlimited | And I set the multiline field "Options" to "milk\ncoffee\nbutter\nbread" And I press "Add" @@ -40,8 +40,8 @@ Feature: Submit using checkbox item and check form validation And I press "New response" Then I should not see "No more than" And I set the following fields to these values: - | id_surveypro_field_checkbox_1_0 | 1 | - | id_surveypro_field_checkbox_1_3 | 1 | + | id_surveypro_field_checkbox_1_0 | 1 | + | id_surveypro_field_checkbox_1_3 | 1 | And I press "Submit" And I press "Continue to responses list" Then I should see "1" submissions diff --git a/field/fileupload/tests/behat/submit_attachment.feature b/field/fileupload/tests/behat/submit_attachment.feature index a66234afb64..a6ebc777d51 100644 --- a/field/fileupload/tests/behat/submit_attachment.feature +++ b/field/fileupload/tests/behat/submit_attachment.feature @@ -30,10 +30,10 @@ Feature: Submit using a fileupload item And I expand all fieldsets And I set the following fields to these values: - | Content | Please upload your CV | - | Required | 1 | - | Indent | 0 | - | Question position | left | + | Content | Please upload your CV | + | Required | 1 | + | Indent | 0 | + | Question position | left | And I press "Add" And I log out diff --git a/field/integer/tests/behat/itemform.feature b/field/integer/tests/behat/itemform.feature index 9f1c7a5fc76..ec353ed5610 100644 --- a/field/integer/tests/behat/itemform.feature +++ b/field/integer/tests/behat/itemform.feature @@ -56,8 +56,8 @@ Feature: Create an integer item Then I should see "Default does not fall within the specified range" Then I should see "Lower and upper bounds must be different" And I set the following fields to these values: - | id_lowerbound | 3 | - | id_upperbound | 21 | + | id_lowerbound | 3 | + | id_upperbound | 21 | And I press "Add" Then I should see "Default does not fall within the specified range" diff --git a/field/multiselect/tests/behat/settings_configuration_01.feature b/field/multiselect/tests/behat/settings_configuration_01.feature index ad943d7dc57..5f1923a6a56 100644 --- a/field/multiselect/tests/behat/settings_configuration_01.feature +++ b/field/multiselect/tests/behat/settings_configuration_01.feature @@ -65,8 +65,8 @@ Feature: Submit using multiselect item and check form validation (1 of 4) # Test number 3: Student chooses "No answer" And I press "New response" And I set the following fields to these values: - | id_surveypro_field_multiselect_1 |milk, bread | - | No answer | 1 | + | id_surveypro_field_multiselect_1 | milk, bread | + | No answer | 1 | And I press "Submit" And I press "Continue to responses list" Then I should see "3" submissions diff --git a/format/fieldset/classes/item.php b/format/fieldset/classes/item.php index e5fef3b3205..834bdcbbfdc 100644 --- a/format/fieldset/classes/item.php +++ b/format/fieldset/classes/item.php @@ -85,6 +85,7 @@ public function __construct($cm, $surveypro, $itemid, $getparentcontent) { $this->insetupform['variable'] = false; $this->insetupform['indent'] = false; $this->insetupform['hideinstructions'] = false; + $this->insetupform['parentid'] = false; if (!empty($itemid)) { $this->item_load($itemid, $getparentcontent); diff --git a/format/fieldset/db/upgrade.php b/format/fieldset/db/upgrade.php index 926a729f6d9..f0525362def 100644 --- a/format/fieldset/db/upgrade.php +++ b/format/fieldset/db/upgrade.php @@ -68,6 +68,18 @@ function xmldb_surveyproformat_fieldset_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2018091301, 'surveyproformat', 'fieldset'); } + if ($oldversion < 2024011101) { + // Drop any parent child relation in EACH past surveypro. + // I am confident I woll not find any. + $sql = 'UPDATE {surveypro_item} + SET parentid = :parentid, parentvalue = :parentvalue + WHERE plugin = :plugin'; + $whereparams = ['parentid' => null, 'parentvalue' => null, 'plugin' => 'fieldset']; + $DB->execute($sql, $whereparams); + + // Surveypro savepoint reached. + upgrade_plugin_savepoint(true, 2024011101, 'surveyproformat', 'fieldset'); + } + return true; } - diff --git a/format/fieldset/version.php b/format/fieldset/version.php index 3ec8f3c378e..18aa98b2687 100644 --- a/format/fieldset/version.php +++ b/format/fieldset/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2018091301; +$plugin->version = 2024011101; $plugin->release = '1.0'; $plugin->requires = 2015111600; // Requires this Moodle version. $plugin->component = 'surveyproformat_fieldset'; // Full name of the plugin (used for diagnostics). diff --git a/format/fieldsetend/classes/item.php b/format/fieldsetend/classes/item.php index 90cb1fd781c..1495ddc7f96 100644 --- a/format/fieldsetend/classes/item.php +++ b/format/fieldsetend/classes/item.php @@ -82,6 +82,7 @@ public function __construct($cm, $surveypro, $itemid, $getparentcontent) { $this->insetupform['variable'] = false; $this->insetupform['indent'] = false; $this->insetupform['hideinstructions'] = false; + $this->insetupform['parentid'] = false; if (!empty($itemid)) { $this->item_load($itemid, $getparentcontent); diff --git a/format/fieldsetend/db/upgrade.php b/format/fieldsetend/db/upgrade.php index 0a3dad49545..ca09709b247 100644 --- a/format/fieldsetend/db/upgrade.php +++ b/format/fieldsetend/db/upgrade.php @@ -67,6 +67,18 @@ function xmldb_surveyproformat_fieldsetend_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2019031901, 'surveyproformat', 'fieldsetend'); } + if ($oldversion < 2024011101) { + // Drop any parent child relation in EACH past surveypro. + // I am confident I woll not find any. + $sql = 'UPDATE {surveypro_item} + SET parentid = :parentid, parentvalue = :parentvalue + WHERE plugin = :plugin'; + $whereparams = ['parentid' => null, 'parentvalue' => null, 'plugin' => 'fieldsetend']; + $DB->execute($sql, $whereparams); + + // Surveypro savepoint reached. + upgrade_plugin_savepoint(true, 2024011101, 'surveyproformat', 'fieldsetend'); + } + return true; } - diff --git a/format/fieldsetend/version.php b/format/fieldsetend/version.php index b928146eac2..cb30671f171 100644 --- a/format/fieldsetend/version.php +++ b/format/fieldsetend/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019031901; +$plugin->version = 2024011101; $plugin->release = '1.0'; $plugin->requires = 2015111600; // Requires this Moodle version. $plugin->component = 'surveyproformat_fieldsetend'; // Full name of the plugin (used for diagnostics). diff --git a/format/label/classes/item.php b/format/label/classes/item.php index c838effc102..af2f2970ace 100644 --- a/format/label/classes/item.php +++ b/format/label/classes/item.php @@ -110,6 +110,7 @@ public function __construct($cm, $surveypro, $itemid, $getparentcontent) { $this->insetupform['required'] = false; $this->insetupform['variable'] = false; $this->insetupform['hideinstructions'] = false; + $this->insetupform['parentid'] = false; if (!empty($itemid)) { $this->item_load($itemid, $getparentcontent); diff --git a/format/label/db/upgrade.php b/format/label/db/upgrade.php index 081c74b74dc..a540bb92415 100644 --- a/format/label/db/upgrade.php +++ b/format/label/db/upgrade.php @@ -54,6 +54,18 @@ function xmldb_surveyproformat_label_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2014051701, 'surveyproformat', 'label'); } + if ($oldversion < 2024011101) { + // Drop any parent child relation in EACH past surveypro. + // I am confident I woll not find any. + $sql = 'UPDATE {surveypro_item} + SET parentid = :parentid, parentvalue = :parentvalue + WHERE plugin = :plugin'; + $whereparams = ['parentid' => null, 'parentvalue' => null, 'plugin' => 'label']; + $DB->execute($sql, $whereparams); + + // Surveypro savepoint reached. + upgrade_plugin_savepoint(true, 2024011101, 'surveyproformat', 'label'); + } + return true; } - diff --git a/format/label/version.php b/format/label/version.php index af066af5227..c7abe1c8304 100644 --- a/format/label/version.php +++ b/format/label/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017112201; +$plugin->version = 2024011101; $plugin->release = '1.0'; $plugin->requires = 2015111600; // Requires this Moodle version. $plugin->component = 'surveyproformat_label'; // Full name of the plugin (used for diagnostics).