PATH:
home
/
letacommog
/
ldqm1
/
wp-content
/
plugins
/
facetwp
/
includes
/
facets
<?php class FacetWP_Facet_Radio_Core extends FacetWP_Facet { function __construct() { $this->label = __( 'Radio', 'fwp' ); } /** * Load the available choices */ function load_values( $params ) { global $wpdb; $facet = $params['facet']; $from_clause = $wpdb->prefix . 'facetwp_index f'; // Facet in "OR" mode $where_clause = $this->get_where_clause( $facet ); // Orderby $orderby = $this->get_orderby( $facet ); $orderby = apply_filters( 'facetwp_facet_orderby', $orderby, $facet ); $from_clause = apply_filters( 'facetwp_facet_from', $from_clause, $facet ); $where_clause = apply_filters( 'facetwp_facet_where', $where_clause, $facet ); // Limit $limit = $this->get_limit( $facet ); $sql = " SELECT f.facet_value, f.facet_display_value, f.term_id, f.parent_id, f.depth, COUNT(DISTINCT f.post_id) AS counter FROM $from_clause WHERE f.facet_name = '{$facet['name']}' $where_clause GROUP BY f.facet_value ORDER BY $orderby LIMIT $limit"; $output = $wpdb->get_results( $sql, ARRAY_A ); // Show "ghost" facet choices // For performance gains, only run if facets are in use $show_ghosts = FWP()->helper->facet_is( $facet, 'ghosts', 'yes' ); if ( $show_ghosts && FWP()->is_filtered ) { $raw_post_ids = implode( ',', FWP()->unfiltered_post_ids ); $sql = " SELECT f.facet_value, f.facet_display_value, f.term_id, f.parent_id, f.depth, 0 AS counter FROM $from_clause WHERE f.facet_name = '{$facet['name']}' AND post_id IN ($raw_post_ids) GROUP BY f.facet_value ORDER BY $orderby LIMIT $limit"; $ghost_output = $wpdb->get_results( $sql, ARRAY_A ); // Keep the facet placement intact if ( FWP()->helper->facet_is( $facet, 'preserve_ghosts', 'yes' ) ) { $tmp = []; foreach ( $ghost_output as $row ) { $tmp[ $row['facet_value'] . ' ' ] = $row; } foreach ( $output as $row ) { $tmp[ $row['facet_value'] . ' ' ] = $row; } $output = $tmp; } else { // Make the array key equal to the facet_value (for easy lookup) $tmp = []; foreach ( $output as $row ) { $tmp[ $row['facet_value'] . ' ' ] = $row; // Force a string array key } $output = $tmp; foreach ( $ghost_output as $row ) { $facet_value = $row['facet_value']; if ( ! isset( $output[ "$facet_value " ] ) ) { $output[ "$facet_value " ] = $row; } } } $output = array_splice( $output, 0, $limit ); $output = array_values( $output ); } return $output; } /** * Generate the facet HTML */ function render( $params ) { $output = ''; $facet = $params['facet']; $values = (array) $params['values']; $selected_values = (array) $params['selected_values']; $label_any = empty( $facet['label_any'] ) ? false : facetwp_i18n( $facet['label_any'] ); if ( $label_any ) { $selected = empty( $selected_values ) ? ' checked' : ''; $output .= '<div class="facetwp-radio' . $selected . '" data-value="">' . esc_attr( $label_any ) . '</div>'; } $key = 0; foreach ( $values as $key => $result ) { $selected = in_array( $result['facet_value'], $selected_values ) ? ' checked' : ''; $selected .= ( 0 == $result['counter'] && '' == $selected ) ? ' disabled' : ''; $output .= '<div class="facetwp-radio' . $selected . '" data-value="' . esc_attr( $result['facet_value'] ) . '">'; $output .= esc_html( $result['facet_display_value'] ) . ' <span class="facetwp-counter">(' . $result['counter'] . ')</span>'; $output .= '</div>'; } return $output; } /** * Filter the query based on selected values */ function filter_posts( $params ) { global $wpdb; $facet = $params['facet']; $selected_values = $params['selected_values']; $selected_values = is_array( $selected_values ) ? $selected_values[0] : $selected_values; $sql = " SELECT DISTINCT post_id FROM {$wpdb->prefix}facetwp_index WHERE facet_name = '{$facet['name']}' AND facet_value IN ('$selected_values')"; return facetwp_sql( $sql, $facet ); } /** * Output admin settings HTML */ function settings_html() { $this->render_setting( 'label_any' ); $this->render_setting( 'parent_term' ); $this->render_setting( 'modifiers' ); $this->render_setting( 'ghosts' ); $this->render_setting( 'orderby' ); $this->render_setting( 'count' ); ?> <div><input type="hidden" class="facet-operator" value="or" /></div> <?php } }
[+]
..
[-] slider.php
[edit]
[-] rating.php
[edit]
[-] radio.php
[edit]
[-] search.php
[edit]
[-] dropdown.php
[edit]
[-] fselect.php
[edit]
[-] base.php
[edit]
[-] number_range.php
[edit]
[-] date_range.php
[edit]
[-] checkboxes.php
[edit]
[-] autocomplete.php
[edit]
[-] hierarchy.php
[edit]
[-] proximity.php
[edit]
[-] pager.php
[edit]