PATH:
home
/
letacommog
/
ldqm1
/
wp-content
/
plugins
/
facetwp
/
includes
/
facets
<?php class FacetWP_Facet_fSelect extends FacetWP_Facet { function __construct() { $this->label = __( 'fSelect', 'fwp' ); } /** * Load the available choices */ function load_values( $params ) { global $wpdb; $facet = $params['facet']; $from_clause = $wpdb->prefix . 'facetwp_index f'; $where_clause = $params['where_clause']; // Preserve options for single-select or when in "OR" mode $is_single = FWP()->helper->facet_is( $facet, 'multiple', 'no' ); $using_or = FWP()->helper->facet_is( $facet, 'operator', 'or' ); if ( $is_single || $using_or ) { $where_clause = $this->get_where_clause( $facet ); } // Orderby $orderby = $this->get_orderby( $facet ); // Limit $limit = $this->get_limit( $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 ); $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']; if ( FWP()->helper->facet_is( $facet, 'hierarchical', 'yes' ) ) { $values = FWP()->helper->sort_taxonomy_values( $params['values'], $facet['orderby'] ); } $multiple = FWP()->helper->facet_is( $facet, 'multiple', 'yes' ) ? ' multiple="multiple"' : ''; $label_any = empty( $facet['label_any'] ) ? __( 'Any', 'fwp-front' ) : $facet['label_any']; $label_any = facetwp_i18n( $label_any ); $output .= '<select class="facetwp-dropdown"' . $multiple . '>'; $output .= '<option value="">' . esc_html( $label_any ) . '</option>'; foreach ( $values as $result ) { $selected = in_array( $result['facet_value'], $selected_values ) ? ' selected' : ''; $selected .= ( 0 == $result['counter'] && '' == $selected ) ? ' disabled' : ''; // Determine whether to show counts $display_value = esc_html( $result['facet_display_value'] ); $show_counts = apply_filters( 'facetwp_facet_dropdown_show_counts', true, [ 'facet' => $facet ] ); if ( $show_counts ) { $display_value .= ' {{(' . $result['counter'] . ')}}'; } $output .= '<option value="' . esc_attr( $result['facet_value'] ) . '" class="d' . $result['depth'] . '"' . $selected . '>' . $display_value . '</option>'; } $output .= '</select>'; return $output; } /** * Filter the query based on selected values */ function filter_posts( $params ) { global $wpdb; $output = []; $facet = $params['facet']; $selected_values = $params['selected_values']; $sql = $wpdb->prepare( "SELECT DISTINCT post_id FROM {$wpdb->prefix}facetwp_index WHERE facet_name = %s", $facet['name'] ); // Match ALL values if ( 'and' == $facet['operator'] ) { foreach ( $selected_values as $key => $value ) { $results = facetwp_sql( $sql . " AND facet_value IN ('$value')", $facet ); $output = ( $key > 0 ) ? array_intersect( $output, $results ) : $results; if ( empty( $output ) ) { break; } } } // Match ANY value else { $selected_values = implode( "','", $selected_values ); $output = facetwp_sql( $sql . " AND facet_value IN ('$selected_values')", $facet ); } return $output; } /** * (Front-end) Attach settings to the AJAX response */ function settings_js( $params ) { $facet = $params['facet']; $label_any = empty( $facet['label_any'] ) ? __( 'Any', 'fwp-front' ) : $facet['label_any']; $label_any = facetwp_i18n( $label_any ); return [ 'placeholder' => $label_any, 'overflowText' => __( '{n} selected', 'fwp-front' ), 'searchText' => __( 'Search', 'fwp-front' ), 'noResultsText' => __( 'No results found', 'fwp-front' ), 'operator' => $facet['operator'] ]; } /** * Output any front-end scripts */ function front_scripts() { FWP()->display->assets['fSelect.css'] = FACETWP_URL . '/assets/vendor/fSelect/fSelect.css'; FWP()->display->assets['fSelect.js'] = FACETWP_URL . '/assets/vendor/fSelect/fSelect.js'; } /** * Output admin settings HTML */ function settings_html() { $this->render_setting( 'label_any' ); $this->render_setting( 'parent_term' ); $this->render_setting( 'modifiers' ); $this->render_setting( 'hierarchical' ); $this->render_setting( 'multiple' ); $this->render_setting( 'ghosts' ); $this->render_setting( 'operator' ); $this->render_setting( 'orderby' ); $this->render_setting( 'count' ); } }
[+]
..
[-] 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]