From f309a6c2bbe97aa4b1327bef6b3153cd6da55302 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Mon, 8 Jul 2024 11:45:50 +0200 Subject: [PATCH] handling rating forms change on lables and functionnalities --- includes/forms/field-HomegradeRating.php | 11 +++--- includes/forms/form-satisfaction.php | 36 ++++++++----------- .../components/forms/field-classic-rating.css | 3 +- .../forms/field-homegrade-rating.css | 4 ++- 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/includes/forms/field-HomegradeRating.php b/includes/forms/field-HomegradeRating.php index d8a348b..2890177 100644 --- a/includes/forms/field-HomegradeRating.php +++ b/includes/forms/field-HomegradeRating.php @@ -6,35 +6,34 @@ if (class_exists('GF_Field')) { public $choices = [ [ - 'text' => 'Non', + 'text' => 'Pas du tout utile', 'value' => 1, 'isSelected' => false, ], [ - 'text' => 'Un peu', + 'text' => 'Peu utile', 'value' => 2, 'isSelected' => false, 'price' => '' ], [ - 'text' => 'Moyen', + 'text' => 'Moyennement utile', 'value' => 3, 'isSelected' => false, ], [ - 'text' => 'Beaucoup', + 'text' => 'Assez utile', 'value' => 4, 'isSelected' => false, ], [ - 'text' => 'Parfait', + 'text' => 'Très utile', 'value' => 5, 'isSelected' => false, ], ]; - public function get_form_editor_field_title() { return esc_attr__('Notation Satisfaction Homegrade', 'homegrade-theme__texte-fonctionnel'); diff --git a/includes/forms/form-satisfaction.php b/includes/forms/form-satisfaction.php index 1fc4cf8..8882f07 100644 --- a/includes/forms/form-satisfaction.php +++ b/includes/forms/form-satisfaction.php @@ -2,31 +2,25 @@ function populate_note_comment_based_on_rating($form) { + + if ($form['id'] != 24) return; - $commented_string_notes = array( - 1 => 'Non', - 2 => 'Un peu', - 3 => 'Moyen', - 4 => 'Beaucoup', - 5 => 'Parfait' - ); - - // ## GLOBAL RATING - $original_global_rating_field_id = 16; - $hidden_copy_global_rating_field_id = 20; - $global_user_rating = rgpost("input_{$original_global_rating_field_id}"); - - $stringified_global_rating = isset($commented_string_notes[$global_user_rating]) ? $commented_string_notes[$global_user_rating] : ''; - $_POST["input_{$hidden_copy_global_rating_field_id}"] = $stringified_global_rating; - // ## INFORMATION ACCESSIBILITY RATING - $original_information_accessibility_rating_field_id = 15; - $hidden_copy_information_accessibility_rating_field_id = 21; - $information_accessibility_user_rating = rgpost("input_{$original_information_accessibility_rating_field_id}"); + foreach ($form['fields'] as $key => $field) { + if ($field->type !== "homegrade-rating" && $field->type !== "classic-rating") continue; - $stringified_information_accessibility_rating = isset($commented_string_notes[$information_accessibility_user_rating]) ? $commented_string_notes[$information_accessibility_user_rating] : ''; - $_POST["input_{$hidden_copy_information_accessibility_rating_field_id}"] = $stringified_information_accessibility_rating; + $user_rating = rgpost("input_{$field->id}"); + + $nextHiddenLabelField = $form["fields"][$key + 1] ?? null; + $stringified_information_accessibility_rating = isset($field["choices"][$user_rating - 1]['text']) ? $field["choices"][$user_rating - 1]['text'] : ''; + + + if (!$nextHiddenLabelField || $nextHiddenLabelField->type !== "hidden" || !$stringified_information_accessibility_rating) continue; + + + $_POST["input_{$nextHiddenLabelField->id}"] = $stringified_information_accessibility_rating; + } } add_action('gform_pre_submission', 'populate_note_comment_based_on_rating'); diff --git a/resources/css/components/forms/field-classic-rating.css b/resources/css/components/forms/field-classic-rating.css index eecdb3c..0c270ca 100644 --- a/resources/css/components/forms/field-classic-rating.css +++ b/resources/css/components/forms/field-classic-rating.css @@ -3,7 +3,8 @@ @apply pb-6 !text-2xl text-center; } .gfield_radio { - @apply grid grid-cols-2 sm:flex justify-between max-w-lg text-center mx-auto; + @apply grid grid-cols-2 sm:flex justify-between max-w-lg text-center mx-auto items-start; + @apply gap-0 sm:gap-4 md:gap-6; @media screen and (max-width: 400px) { grid-template-columns: auto auto; diff --git a/resources/css/components/forms/field-homegrade-rating.css b/resources/css/components/forms/field-homegrade-rating.css index 3915f41..5e8b1b2 100644 --- a/resources/css/components/forms/field-homegrade-rating.css +++ b/resources/css/components/forms/field-homegrade-rating.css @@ -3,13 +3,15 @@ @apply pb-6 !text-2xl text-center; } .gfield_radio { - @apply grid sm:flex justify-between max-w-lg text-center mx-auto; + @apply grid sm:flex md:justify-between max-w-lg text-center mx-auto items-start; + @apply gap-0 sm:gap-2 md:gap-6; @media screen and (max-width: 400px) { grid-template-columns: auto auto; width: fit-content; column-gap: 1rem; } + .gchoice { @apply flex flex-col justify-center items-center; &:last-child {