Displaying "Other" in Results
-
We have 4.9.1 installed.
Our client would like to have “Other” in the results display. We don’t want the specific Other answers, just the word “Other” with the number of Other responses.
Otherwise, this is working well for them.
Suggestions?
-
Does anyone have any ideas for this one? My client is getting antsy and wants a resolution ASAP. Short of going into the code itself, I can’t find any way to do this.
Beht
Hi Beht,
Sorry it took so long to get back to you.
Please edit yop_poll_model.php and replace the answer_result_replace_callback() function with the code below:
public function answer_result_replace_callback( $m ) { $other_percentages_votes=0; $other_percentages_result=0; $poll_id = $this->poll['id']; $unique_id = $this->unique_id; $poll_options = $this->poll_options; $return_string = ''; $is_voted = $this->is_voted(); if ( $this->is_view_poll_results() ){ $display_other_answers_values = false; if( 'yes' == $poll_options['allow_other_answers'] ){ if ( 'yes' == $poll_options['display_other_answers_values'] ){ $display_other_answers_values = true; } } $answers_types = array( 'default' ); if( 'yes' == $poll_options['allow_other_answers'] ){ if ( 'yes' == $poll_options['add_other_answers_to_default_answers'] ){ $answers_types = array( 'default', 'other' ); } } $percentages_decimals = 0; if ( isset( $poll_options['percentages_decimals'] ) ){ $percentages_decimals = $poll_options['percentages_decimals']; } if ( isset( $poll_options['sorting_results'] ) ){ if ( 'exact' == $poll_options['sorting_results'] ){ $order_dir = 'asc'; if ( isset( $poll_options['sorting_results_direction'] ) ){ $order_dir = ( 'asc' == $poll_options['sorting_results_direction'] ) ? 'asc' : 'desc'; } $answers = self::get_poll_answers( $poll_id, $answers_types, 'id', $order_dir, $display_other_answers_values, $percentages_decimals ); } elseif ( 'alphabetical' == $poll_options['sorting_results'] ) { $order_dir = 'asc'; if ( isset( $poll_options['sorting_results_direction'] ) ){ $order_dir = ( 'asc' == $poll_options['sorting_results_direction'] ) ? 'asc' : 'desc'; } $answers = self::get_poll_answers( $poll_id, $answers_types, 'answer', $order_dir, $display_other_answers_values, $percentages_decimals ); } elseif ( 'random' == $poll_options['sorting_results'] ) { $answers = self::get_poll_answers( $poll_id, $answers_types, 'rand()', '', $display_other_answers_values, $percentages_decimals ); } elseif ( 'votes' == $poll_options['sorting_results'] ) { $order_dir = 'asc'; if ( isset( $poll_options['sorting_results_direction'] ) ){ $order_dir = ( 'asc' == $poll_options['sorting_results_direction'] ) ? 'asc' : 'desc'; } $answers = self::get_poll_answers( $poll_id, $answers_types, 'votes', $order_dir, $display_other_answers_values, $percentages_decimals ); } else { $order_dir = 'asc'; if ( isset( $poll_options['sorting_results_direction'] ) ){ $order_dir = ( 'asc' == $poll_options['sorting_results_direction'] ) ? 'asc' : 'desc'; } $answers = self::get_poll_answers( $poll_id, $answers_types, 'id', $order_dir, $display_other_answers_values, $percentages_decimals ); } } else { $order_dir = 'asc'; if ( isset( $poll_options['sorting_results_direction'] ) ){ $order_dir = ( 'asc' == $poll_options['sorting_results_direction'] ) ? 'asc' : 'desc'; } $answers = self::get_poll_answers( $poll_id, $answers_types, 'id', $order_dir, $display_other_answers_values, $percentages_decimals ); } $answers = self::get_poll_answers( $poll_id, $answers_types, 'id', $order_dir, 1, $percentages_decimals ); if ( count( $answers ) > 0 ){ foreach ( $answers as $answer ) { if ( function_exists( 'icl_translate' ) ){ $answer['answer'] = icl_translate( 'yop_poll', $answer['id'] . '_answer', $answer['answer'] ); } $poll_options = $this->poll_options; $answer_options = get_yop_poll_answer_meta( $answer['id'], 'options', true ); if ( $answer_options ){ foreach ( $answer_options as $option_name => $option_value ) { if ( isset( $poll_options[$option_name] ) ){ if ( $option_value != $poll_options[$option_name] ){ $poll_options[$option_name] = $option_value; } } else { $poll_options[$option_name] = $option_value; } } } if($answer['type']=="other") { $other_percentages_votes+= $answer['votes']; } else { $other_percentages_result+=str_replace("%","",self::display_poll_result_percentages( $answer, $poll_options )); $temp_string = str_ireplace( '%POLL-ANSWER-RESULT-VOTES%', self::display_poll_result_votes( $answer, $poll_options ), $m[5] ); $temp_string = str_ireplace( '%POLL-ANSWER-RESULT-PERCENTAGES%', self::display_poll_result_percentages( $answer, $poll_options ), $temp_string ); if ( 'yes' == $poll_options['poll_answer_html_tags'] ){ $temp_string = str_ireplace( '%POLL-ANSWER-LABEL%', yop_poll_kses( stripslashes( $answer['answer'] ) ), $temp_string ); } else { $temp_string = str_ireplace( '%POLL-ANSWER-LABEL%', yop_poll_kses( esc_html( stripslashes( $answer['answer'] ) ) ), $temp_string ); } $temp_string = str_ireplace( '%POLL-ANSWER-RESULT-BAR%', self::display_poll_result_bar( $poll_id, $answer['id'], $answer['procentes'], $poll_options, $unique_id ), $temp_string ); $return_string .= $temp_string; } } $other_percentages_result=100-$other_percentages_result ; $temp_string = str_ireplace( '%POLL-ANSWER-RESULT-VOTES%',$other_percentages_votes.' votes', $m[5] ); $temp_string = str_ireplace( '%POLL-ANSWER-RESULT-PERCENTAGES%', $other_percentages_result.'%', $temp_string ); if ( 'yes' == $poll_options['poll_answer_html_tags'] ){ $temp_string = str_ireplace( '%POLL-ANSWER-LABEL%', yop_poll_kses( stripslashes( 'Other') ), $temp_string ); } else { $temp_string = str_ireplace( '%POLL-ANSWER-LABEL%', yop_poll_kses( esc_html( stripslashes( 'Other' ) ) ), $temp_string ); } $temp_string = str_ireplace( '%POLL-ANSWER-RESULT-BAR%', self::display_poll_result_bar( $poll_id, '212q',$other_percentages_result, $poll_options, $unique_id ), $temp_string ); $return_string .= $temp_string;} } return $return_string; }
Let us know if you need more help.
Best wishes,
YOP Team
Thank you!
This is very close. The Other bar is showing 100% of the answers were Other. It is live on https://www.wellocracy.com if you want to take a look.
Beth
Hey Beth
Please go to Edit Poll and on Results Display choose by Votes Number and Percentages.
Best Wishes,
YOP TeamThank you! That did it.
Much appreciated.
Beth
- The topic ‘Displaying "Other" in Results’ is closed to new replies.