Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes reversing issue #2157

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions includes/fields/class-gravityview-field-survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,36 @@ public static function get_choice_score( $field, $value, $input_id = 0 ) {
return is_array( $value ) ? '' : $value;
}

/**
* Gets field choices directly from the database (To avoid issues where choices are reversed by the survey plugin).
*
* @since TBD
*
* @param int $form_id The ID of the form.
* @param int $field_id The ID of the field.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@omarkasem, please align param descriptions:

* @param int $form_id  The ID of the form.
* @param int $field_id The ID of the field.

*
* @return array The choices for the field.
*/
public static function get_field_choices($form_id, $field_id) {
global $wpdb;
$table_name = GFFormsModel::get_meta_table_name();
$form_row = $wpdb->get_row( $wpdb->prepare( "SELECT display_meta FROM {$table_name} WHERE form_id=%d", $form_id ), ARRAY_A );
$form_meta = GFFormsModel::unserialize( rgar( $form_row, 'display_meta' ) );

if ( ! $form_meta ) {
return [];
}

foreach ( $form_meta['fields'] as $form_field ) {
if ( $form_field['id'] == $field_id ) {
return $form_field['choices'];
}
}

return [];
}


public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) {

unset( $field_options['search_filter'] );
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Beautifully display your Gravity Forms entries. Learn more on [gravitykit.com](h
* Fixed: Resending notifications from the Entries screen did not work when sending to all entries filtered by approval status.
* Fixed: Conflict with the Wordfence plugin caused a fatal error when redirecting users after deleting an entry.
* Fixed: Fatal error when rendering a GravityView View field with a non-existent View ID.
* Fixed: Survey field (Rating type) values displaying in reverse order when a View is embedded inside another View.

= 2.29 on October 1, 2024 =

Expand Down
4 changes: 3 additions & 1 deletion templates/fields/field-survey-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
$field = $gravityview->field;
$display_value = $gravityview->display_value;
$input_id = gravityview_get_input_id_from_id( $field->ID );
$form_id = $gravityview->view->form->ID;

// Used in filters below.
$return_true = function () {
Expand Down Expand Up @@ -142,7 +143,8 @@
return;
}

$choices = $field->field->choices;
$choices = GravityView_Field_Survey::get_field_choices( $form_id, $field->ID );

$choice_values = wp_list_pluck( $choices, 'value', $gravityview->value );
$starred_index = array_search( $gravityview->value, $choice_values );
$star_a11y_label = $starred_index !== false
Expand Down