PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
elasticpress / includes / classes / Feature / Facets / Renderer.php

Renderer.php in ElasticPress 5.3.5, at includes/classes/Feature/Facets/Renderer.php

80 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Abstract Facet Renderer class.
4 *
5 * @since 4.7.0
6 * @package elasticpress
7 */
8
9 namespace ElasticPress\Feature\Facets;
10
11 /**
12 * Abstract Facet Renderer class.
13 */
14 abstract class Renderer {
15 /**
16 * Whether the term count should be displayed or not.
17 *
18 * @var bool
19 */
20 protected $display_count;
21
22 /**
23 * Method to render the facet.
24 *
25 * @param array $args Widget args
26 * @param array $instance Instance settings
27 */
28 abstract public function render( $args, $instance );
29
30 /**
31 * Whether the facet should be rendered or not.
32 *
33 * @return bool
34 */
35 protected function should_render(): bool {
36 return true;
37 }
38
39 /**
40 * Given an array of values, reorder them.
41 *
42 * @param array $values Multidimensional array of values. Each value should have (string) `name`, (int) `count`, and (bool) `is_selected`.
43 * @param string $orderby Key to be used to order.
44 * @param string $order ASC or DESC.
45 * @return array
46 */
47 protected function order_values( array $values, string $orderby = 'count', $order = 'desc' ): array {
48 $orderby = strtolower( $orderby );
49 $orderby = in_array( $orderby, [ 'name', 'count' ], true ) ? $orderby : 'count';
50
51 $order = strtoupper( $order );
52 $order = in_array( $order, [ 'ASC', 'DESC' ], true ) ? $order : 'DESC';
53
54 $values = wp_list_sort( $values, $orderby, $order, true );
55
56 $selected = [];
57 foreach ( $values as $key => $value ) {
58 if ( $value['is_selected'] ) {
59 $selected[ $key ] = $value;
60 unset( $values[ $key ] );
61 }
62 }
63 $values = $selected + $values;
64
65 return $values;
66 }
67
68 /**
69 * Get the markup for an individual facet item.
70 *
71 * @param array|object $item Facet item.
72 * @param string $url URL for the facet item.
73 * @return string|null
74 */
75 public function get_facet_item_value_html( $item, string $url ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
76 // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
77 return null;
78 }
79 }
80