Complex classes like GravityView_Widget_Search often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GravityView_Widget_Search, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class GravityView_Widget_Search extends \GV\Widget { |
||
17 | |||
18 | public static $file; |
||
19 | public static $instance; |
||
20 | |||
21 | private $search_filters = array(); |
||
22 | |||
23 | /** |
||
24 | * whether search method is GET or POST ( default: GET ) |
||
25 | * @since 1.16.4 |
||
26 | * @var string |
||
27 | */ |
||
28 | private $search_method = 'get'; |
||
29 | |||
30 | 39 | public function __construct() { |
|
31 | |||
32 | 39 | $this->widget_id = 'search_bar'; |
|
33 | 39 | $this->widget_description = esc_html__( 'Search form for searching entries.', 'gravityview' ); |
|
34 | |||
35 | 39 | self::$instance = &$this; |
|
36 | |||
37 | 39 | self::$file = plugin_dir_path( __FILE__ ); |
|
38 | |||
39 | 39 | $default_values = array( 'header' => 0, 'footer' => 0 ); |
|
40 | |||
41 | $settings = array( |
||
42 | 39 | 'search_layout' => array( |
|
43 | 39 | 'type' => 'radio', |
|
44 | 'full_width' => true, |
||
45 | 39 | 'label' => esc_html__( 'Search Layout', 'gravityview' ), |
|
46 | 39 | 'value' => 'horizontal', |
|
47 | 'options' => array( |
||
48 | 39 | 'horizontal' => esc_html__( 'Horizontal', 'gravityview' ), |
|
49 | 39 | 'vertical' => esc_html__( 'Vertical', 'gravityview' ), |
|
50 | ), |
||
51 | ), |
||
52 | 'search_clear' => array( |
||
53 | 39 | 'type' => 'checkbox', |
|
54 | 39 | 'label' => __( 'Show Clear button', 'gravityview' ), |
|
55 | 'value' => false, |
||
56 | ), |
||
57 | 'search_fields' => array( |
||
58 | 'type' => 'hidden', |
||
59 | 'label' => '', |
||
60 | 'class' => 'gv-search-fields-value', |
||
61 | 'value' => '[{"field":"search_all","input":"input_text"}]', // Default: Search Everything text box |
||
62 | ), |
||
63 | 'search_mode' => array( |
||
64 | 39 | 'type' => 'radio', |
|
65 | 'full_width' => true, |
||
66 | 39 | 'label' => esc_html__( 'Search Mode', 'gravityview' ), |
|
67 | 39 | 'desc' => __('Should search results match all search fields, or any?', 'gravityview'), |
|
68 | 39 | 'value' => 'any', |
|
69 | 39 | 'class' => 'hide-if-js', |
|
70 | 'options' => array( |
||
71 | 39 | 'any' => esc_html__( 'Match Any Fields', 'gravityview' ), |
|
72 | 39 | 'all' => esc_html__( 'Match All Fields', 'gravityview' ), |
|
73 | ), |
||
74 | ), |
||
75 | ); |
||
76 | |||
77 | 39 | if ( ! $this->is_registered() ) { |
|
78 | // frontend - filter entries |
||
79 | add_filter( 'gravityview_fe_search_criteria', array( $this, 'filter_entries' ), 10, 3 ); |
||
80 | |||
81 | // frontend - add template path |
||
82 | add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
||
83 | |||
84 | // admin - add scripts - run at 1100 to make sure GravityView_Admin_Views::add_scripts_and_styles() runs first at 999 |
||
85 | add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_and_styles' ), 1100 ); |
||
86 | add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts') ); |
||
87 | add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_no_conflict' ) ); |
||
88 | |||
89 | // ajax - get the searchable fields |
||
90 | add_action( 'wp_ajax_gv_searchable_fields', array( 'GravityView_Widget_Search', 'get_searchable_fields' ) ); |
||
91 | |||
92 | add_action( 'gravityview_search_widget_fields_after', array( $this, 'add_preview_inputs' ) ); |
||
93 | } |
||
94 | |||
95 | 39 | parent::__construct( esc_html__( 'Search Bar', 'gravityview' ), null, $default_values, $settings ); |
|
96 | |||
97 | // calculate the search method (POST / GET) |
||
98 | 39 | $this->set_search_method(); |
|
99 | 39 | } |
|
100 | |||
101 | /** |
||
102 | * @return GravityView_Widget_Search |
||
103 | */ |
||
104 | 6 | public static function getInstance() { |
|
105 | 6 | if ( empty( self::$instance ) ) { |
|
106 | self::$instance = new GravityView_Widget_Search; |
||
107 | } |
||
108 | 6 | return self::$instance; |
|
109 | } |
||
110 | |||
111 | /** |
||
112 | * Sets the search method to GET (default) or POST |
||
113 | * @since 1.16.4 |
||
114 | */ |
||
115 | 39 | private function set_search_method() { |
|
116 | /** |
||
117 | * @filter `gravityview/search/method` Modify the search form method (GET / POST) |
||
118 | * @since 1.16.4 |
||
119 | * @param string $search_method Assign an input type according to the form field type. Defaults: `boolean`, `multi`, `select`, `date`, `text` |
||
120 | * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
||
121 | */ |
||
122 | 39 | $method = apply_filters( 'gravityview/search/method', $this->search_method ); |
|
123 | |||
124 | 39 | $method = strtolower( $method ); |
|
125 | |||
126 | 39 | $this->search_method = in_array( $method, array( 'get', 'post' ) ) ? $method : 'get'; |
|
127 | 39 | } |
|
128 | |||
129 | /** |
||
130 | * Returns the search method |
||
131 | * @since 1.16.4 |
||
132 | * @return string |
||
133 | */ |
||
134 | 6 | public function get_search_method() { |
|
135 | 6 | return $this->search_method; |
|
136 | } |
||
137 | |||
138 | /** |
||
139 | * Get the input types available for different field types |
||
140 | * |
||
141 | * @since 1.17.5 |
||
142 | * |
||
143 | * @return array [field type name] => (array|string) search bar input types |
||
144 | */ |
||
145 | public static function get_input_types_by_field_type() { |
||
146 | /** |
||
147 | * Input Type groups |
||
148 | * @see admin-search-widget.js (getSelectInput) |
||
149 | * @var array |
||
150 | */ |
||
151 | $input_types = array( |
||
152 | 'text' => array( 'input_text' ), |
||
153 | 'address' => array( 'input_text' ), |
||
154 | 'number' => array( 'input_text' ), |
||
155 | 'date' => array( 'date', 'date_range' ), |
||
156 | 'boolean' => array( 'single_checkbox' ), |
||
157 | 'select' => array( 'select', 'radio', 'link' ), |
||
158 | 'multi' => array( 'select', 'multiselect', 'radio', 'checkbox', 'link' ), |
||
159 | |||
160 | // hybrids |
||
161 | 'created_by' => array( 'select', 'radio', 'checkbox', 'multiselect', 'link', 'input_text' ), |
||
162 | 'product' => array( 'select', 'radio', 'link', 'input_text' ), |
||
163 | ); |
||
164 | |||
165 | /** |
||
166 | * @filter `gravityview/search/input_types` Change the types of search fields available to a field type |
||
167 | * @see GravityView_Widget_Search::get_search_input_labels() for the available input types |
||
168 | * @param array $input_types Associative array: key is field `name`, value is array of GravityView input types (note: use `input_text` for `text`) |
||
169 | */ |
||
170 | $input_types = apply_filters( 'gravityview/search/input_types', $input_types ); |
||
171 | |||
172 | return $input_types; |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Get labels for different types of search bar inputs |
||
177 | * |
||
178 | * @since 1.17.5 |
||
179 | * |
||
180 | * @return array [input type] => input type label |
||
181 | */ |
||
182 | public static function get_search_input_labels() { |
||
208 | |||
209 | public static function get_search_input_label( $input_type ) { |
||
214 | |||
215 | /** |
||
216 | * Add script to Views edit screen (admin) |
||
217 | * @param mixed $hook |
||
218 | */ |
||
219 | public function add_scripts_and_styles( $hook ) { |
||
245 | |||
246 | /** |
||
247 | * Add admin script to the no-conflict scripts whitelist |
||
248 | * @param array $allowed Scripts allowed in no-conflict mode |
||
249 | * @return array Scripts allowed in no-conflict mode, plus the search widget script |
||
250 | */ |
||
251 | public function register_no_conflict( $allowed ) { |
||
255 | |||
256 | /** |
||
257 | * Ajax |
||
258 | * Returns the form fields ( only the searchable ones ) |
||
259 | * |
||
260 | * @access public |
||
261 | * @return void |
||
262 | */ |
||
263 | public static function get_searchable_fields() { |
||
291 | |||
292 | /** |
||
293 | * Generates html for the available Search Fields dropdown |
||
294 | * @param int $form_id |
||
295 | * @param string $current (for future use) |
||
296 | * @return string |
||
297 | */ |
||
298 | public static function render_searchable_fields( $form_id = null, $current = '' ) { |
||
376 | |||
377 | /** |
||
378 | * Assign an input type according to the form field type |
||
379 | * |
||
380 | * @see admin-search-widget.js |
||
381 | * |
||
382 | * @param string|int|float $field_id Gravity Forms field ID |
||
383 | * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
||
384 | * |
||
385 | * @return string GV field search input type ('multi', 'boolean', 'select', 'date', 'text') |
||
386 | */ |
||
387 | public static function get_search_input_types( $field_id = '', $field_type = null ) { |
||
388 | |||
389 | // @todo - This needs to be improved - many fields have . including products and addresses |
||
390 | if ( false !== strpos( (string) $field_id, '.' ) && in_array( $field_type, array( 'checkbox' ) ) || in_array( $field_id, array( 'is_fulfilled' ) ) ) { |
||
391 | $input_type = 'boolean'; // on/off checkbox |
||
392 | } elseif ( in_array( $field_type, array( 'checkbox', 'post_category', 'multiselect' ) ) ) { |
||
393 | $input_type = 'multi'; //multiselect |
||
394 | } elseif ( in_array( $field_type, array( 'select', 'radio' ) ) ) { |
||
395 | $input_type = 'select'; |
||
396 | } elseif ( in_array( $field_type, array( 'date' ) ) || in_array( $field_id, array( 'payment_date' ) ) ) { |
||
397 | $input_type = 'date'; |
||
398 | } elseif ( in_array( $field_type, array( 'number' ) ) || in_array( $field_id, array( 'payment_amount' ) ) ) { |
||
399 | $input_type = 'number'; |
||
400 | } elseif ( in_array( $field_type, array( 'product' ) ) ) { |
||
401 | $input_type = 'product'; |
||
402 | } else { |
||
403 | $input_type = 'text'; |
||
404 | } |
||
405 | |||
406 | /** |
||
407 | * @filter `gravityview/extension/search/input_type` Modify the search form input type based on field type |
||
408 | * @since 1.2 |
||
409 | * @since 1.19.2 Added $field_id parameter |
||
410 | * @param string $input_type Assign an input type according to the form field type. Defaults: `boolean`, `multi`, `select`, `date`, `text` |
||
411 | * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
||
412 | * @param string|int|float $field_id ID of the field being processed |
||
413 | */ |
||
414 | $input_type = apply_filters( 'gravityview/extension/search/input_type', $input_type, $field_type, $field_id ); |
||
415 | |||
416 | return $input_type; |
||
417 | } |
||
418 | |||
419 | /** |
||
420 | * Display hidden fields to add support for sites using Default permalink structure |
||
421 | * |
||
422 | * @since 1.8 |
||
423 | * @return array Search fields, modified if not using permalinks |
||
424 | */ |
||
425 | 4 | public function add_no_permalink_fields( $search_fields, $object, $widget_args = array() ) { |
|
458 | |||
459 | /** |
||
460 | * Get the fields that are searchable for a View |
||
461 | * |
||
462 | * @since 2.0 |
||
463 | * @since 2.0.9 Added $with_full_field parameter |
||
464 | * |
||
465 | * @param \GV\View|null $view |
||
466 | * @param bool $with_full_field Return full field array, or just field ID? Default: false (just field ID) |
||
467 | * |
||
468 | * TODO: Move to \GV\View, perhaps? And return a Field_Collection |
||
469 | * TODO: Use in gravityview()->request->is_search() to calculate whether a valid search |
||
470 | * |
||
471 | * @return array If no View, returns empty array. Otherwise, returns array of fields configured in widgets and Search Bar for a View |
||
472 | */ |
||
473 | 39 | private function get_view_searchable_fields( $view, $with_full_field = false ) { |
|
523 | |||
524 | /** --- Frontend --- */ |
||
525 | |||
526 | /** |
||
527 | * Calculate the search criteria to filter entries |
||
528 | * @param array $search_criteria The search criteria |
||
529 | * @param int $form_id The form ID |
||
530 | * @param array $args Some args |
||
531 | * |
||
532 | * @param bool $force_search_criteria Whether to suppress GF_Query filter, internally used in self::gf_query_filter |
||
533 | * |
||
534 | * @return array |
||
535 | */ |
||
536 | 86 | public function filter_entries( $search_criteria, $form_id = null, $args = array(), $force_search_criteria = false ) { |
|
733 | |||
734 | /** |
||
735 | * Filters the \GF_Query with advanced logic. |
||
736 | * |
||
737 | * Dropin for the legacy flat filters when \GF_Query is available. |
||
738 | * |
||
739 | * @param \GF_Query $query The current query object reference |
||
740 | * @param \GV\View $this The current view object |
||
741 | * @param \GV\Request $request The request object |
||
742 | */ |
||
743 | 65 | public function gf_query_filter( &$query, $view, $request ) { |
|
744 | /** |
||
745 | * This is a shortcut to get all the needed search criteria. |
||
746 | * We feed these into an new GF_Query and tack them onto the current object. |
||
747 | */ |
||
748 | 65 | $search_criteria = $this->filter_entries( array(), null, array( 'id' => $view->ID ), true /** force search_criteria */ ); |
|
749 | |||
750 | /** |
||
751 | * Call any userland filters that they might have. |
||
752 | */ |
||
753 | 65 | remove_filter( 'gravityview_fe_search_criteria', array( $this, 'filter_entries' ), 10, 3 ); |
|
754 | 65 | $search_criteria = apply_filters( 'gravityview_fe_search_criteria', $search_criteria, $view->form->ID, $view->settings->as_atts() ); |
|
755 | 65 | add_filter( 'gravityview_fe_search_criteria', array( $this, 'filter_entries' ), 10, 3 ); |
|
756 | |||
757 | 65 | $query_class = $view->get_query_class(); |
|
758 | |||
759 | 65 | if ( empty( $search_criteria['field_filters'] ) ) { |
|
760 | 57 | return; |
|
761 | } |
||
762 | |||
763 | 20 | $widgets = $view->widgets->by_id( $this->widget_id ); |
|
764 | 20 | if ( $widgets->count() ) { |
|
765 | 14 | $widgets = $widgets->all(); |
|
766 | 14 | $widget = $widgets[0]; |
|
767 | |||
768 | 14 | $search_fields = json_decode( $widget->configuration->get( 'search_fields' ), true ); |
|
769 | |||
770 | 14 | foreach ( (array) $search_fields as $search_field ) { |
|
771 | 14 | if ( 'created_by' === $search_field['field'] && 'input_text' === $search_field['input'] ) { |
|
772 | 1 | $created_by_text_mode = true; |
|
773 | } |
||
774 | } |
||
775 | } |
||
776 | |||
777 | 20 | $extra_conditions = array(); |
|
778 | 20 | $mode = 'any'; |
|
779 | |||
780 | 20 | foreach ( $search_criteria['field_filters'] as &$filter ) { |
|
781 | 20 | if ( ! is_array( $filter ) ) { |
|
782 | 20 | if ( in_array( strtolower( $filter ), array( 'any', 'all' ) ) ) { |
|
783 | 20 | $mode = $filter; |
|
784 | } |
||
785 | 20 | continue; |
|
786 | } |
||
787 | |||
788 | // Construct a manual query for unapproved statuses |
||
789 | 13 | if ( 'is_approved' === $filter['key'] && in_array( \GravityView_Entry_Approval_Status::UNAPPROVED, (array) $filter['value'] ) ) { |
|
790 | 2 | $_tmp_query = new $query_class( $view->form->ID, array( |
|
791 | 2 | 'field_filters' => array( |
|
792 | array( |
||
793 | 2 | 'operator' => 'in', |
|
794 | 2 | 'key' => 'is_approved', |
|
795 | 2 | 'value' => (array) $filter['value'], |
|
796 | ), |
||
797 | array( |
||
798 | 'operator' => 'is', |
||
799 | 'key' => 'is_approved', |
||
800 | 'value' => '', |
||
801 | ), |
||
802 | 2 | 'mode' => 'any' |
|
803 | ), |
||
804 | ) ); |
||
805 | 2 | $_tmp_query_parts = $_tmp_query->_introspect(); |
|
806 | |||
807 | 2 | $extra_conditions[] = $_tmp_query_parts['where']; |
|
808 | |||
809 | 2 | $filter = false; |
|
810 | 2 | continue; |
|
811 | } |
||
812 | |||
813 | // Construct manual query for text mode creator search |
||
814 | 13 | if ( 'created_by' === $filter['key'] && ! empty( $created_by_text_mode ) ) { |
|
815 | 1 | $extra_conditions[] = new GravityView_Widget_Search_Author_GF_Query_Condition( $filter, $view ); |
|
816 | 1 | $filter = false; |
|
817 | 1 | continue; |
|
818 | } |
||
819 | |||
820 | // By default, we want searches to be wildcard for each field. |
||
821 | 12 | $filter['operator'] = empty( $filter['operator'] ) ? 'contains' : $filter['operator']; |
|
822 | |||
823 | // For multichoice, let's have an in (OR) search. |
||
824 | 12 | if ( is_array( $filter['value'] ) ) { |
|
825 | 3 | $filter['operator'] = 'in'; // @todo what about in contains (OR LIKE chains)? |
|
826 | } |
||
827 | |||
828 | // Default form with joins functionality |
||
829 | 12 | if ( empty( $filter['form_id'] ) ) { |
|
830 | 5 | $filter['form_id'] = $view->form ? $view->form->ID : 0; |
|
831 | } |
||
832 | |||
833 | /** |
||
834 | * @filter `gravityview_search_operator` Modify the search operator for the field (contains, is, isnot, etc) |
||
835 | * @param string $operator Existing search operator |
||
836 | * @param array $filter array with `key`, `value`, `operator`, `type` keys |
||
837 | * @since develop |
||
838 | * @param \GV\View $view The View we're operating on. |
||
839 | */ |
||
840 | 12 | $filter['operator'] = apply_filters( 'gravityview_search_operator', $filter['operator'], $filter, $view ); |
|
841 | } |
||
842 | |||
843 | 20 | if ( ! empty( $search_criteria['start_date'] ) || ! empty( $search_criteria['end_date'] ) ) { |
|
844 | 1 | $date_criteria = array(); |
|
845 | |||
846 | 1 | if ( isset( $search_criteria['start_date'] ) ) { |
|
847 | 1 | $date_criteria['start_date'] = $search_criteria['start_date']; |
|
848 | } |
||
849 | |||
850 | 1 | if ( isset( $search_criteria['end_date'] ) ) { |
|
851 | 1 | $date_criteria['end_date'] = $search_criteria['end_date']; |
|
852 | } |
||
853 | |||
854 | 1 | $_tmp_query = new $query_class( $view->form->ID, $date_criteria ); |
|
855 | 1 | $_tmp_query_parts = $_tmp_query->_introspect(); |
|
856 | 1 | $extra_conditions[] = $_tmp_query_parts['where']; |
|
857 | } |
||
858 | |||
859 | 20 | $search_conditions = array(); |
|
860 | |||
861 | 20 | if ( $filters = array_filter( $search_criteria['field_filters'] ) ) { |
|
862 | 20 | foreach ( $filters as &$filter ) { |
|
863 | 20 | if ( ! is_array( $filter ) ) { |
|
864 | 20 | continue; |
|
865 | } |
||
866 | |||
867 | /** |
||
868 | * Parse the filter criteria to generate the needed |
||
869 | * WHERE condition. This is a trick to not write our own generation |
||
870 | * code by reusing what's inside GF_Query already as they |
||
871 | * take care of many small things like forcing numeric, etc. |
||
872 | */ |
||
873 | 12 | $_tmp_query = new $query_class( $filter['form_id'], array( 'mode' => 'any', 'field_filters' => array( $filter ) ) ); |
|
874 | 12 | $_tmp_query_parts = $_tmp_query->_introspect(); |
|
875 | 12 | $search_condition = $_tmp_query_parts['where']; |
|
876 | |||
877 | 12 | if ( empty( $filter['key'] ) && $search_condition->expressions ) { |
|
878 | 1 | $search_conditions[] = $search_condition; |
|
879 | } else { |
||
880 | 11 | $left = $search_condition->left; |
|
881 | 11 | $alias = $query->_alias( $left->field_id, $left->source, $left->is_entry_column() ? 't' : 'm' ); |
|
882 | |||
883 | 11 | if ( $view->joins && $left->field_id == GF_Query_Column::META ) { |
|
884 | 2 | foreach ( $view->joins as $_join ) { |
|
885 | 2 | $on = $_join->join_on; |
|
886 | 2 | $join = $_join->join; |
|
887 | |||
888 | 2 | $search_conditions[] = GF_Query_Condition::_or( |
|
889 | // Join |
||
890 | 2 | new GF_Query_Condition( |
|
891 | 2 | new GF_Query_Column( GF_Query_Column::META, $join->ID, $query->_alias( GF_Query_Column::META, $join->ID, 'm' ) ), |
|
892 | 2 | $search_condition->operator, |
|
893 | 2 | $search_condition->right |
|
894 | ), |
||
895 | // On |
||
896 | 2 | new GF_Query_Condition( |
|
897 | 2 | new GF_Query_Column( GF_Query_Column::META, $on->ID, $query->_alias( GF_Query_Column::META, $on->ID, 'm' ) ), |
|
898 | 2 | $search_condition->operator, |
|
899 | 2 | $search_condition->right |
|
900 | ) |
||
901 | ); |
||
902 | } |
||
903 | } else { |
||
904 | 9 | $search_conditions[] = new GF_Query_Condition( |
|
905 | 9 | new GF_Query_Column( $left->field_id, $left->source, $alias ), |
|
906 | 9 | $search_condition->operator, |
|
907 | 9 | $search_condition->right |
|
908 | ); |
||
909 | } |
||
910 | } |
||
911 | } |
||
912 | |||
913 | 20 | if ( $search_conditions ) { |
|
914 | 12 | $search_conditions = array( call_user_func_array( '\GF_Query_Condition::' . ( $mode == 'all' ? '_and' : '_or' ), $search_conditions ) ); |
|
915 | } |
||
916 | } |
||
917 | |||
918 | /** |
||
919 | * Grab the current clauses. We'll be combining them shortly. |
||
920 | */ |
||
921 | 20 | $query_parts = $query->_introspect(); |
|
922 | |||
923 | /** |
||
924 | * Combine the parts as a new WHERE clause. |
||
925 | */ |
||
926 | 20 | $where = call_user_func_array( '\GF_Query_Condition::_and', array_merge( array( $query_parts['where'] ), $search_conditions, $extra_conditions ) ); |
|
927 | 20 | $query->where( $where ); |
|
928 | 20 | } |
|
929 | |||
930 | /** |
||
931 | * Convert $_GET/$_POST key to the field/meta ID |
||
932 | * |
||
933 | * Examples: |
||
934 | * - `filter_is_starred` => `is_starred` |
||
935 | * - `filter_1_2` => `1.2` |
||
936 | * - `filter_5` => `5` |
||
937 | * |
||
938 | * @since 2.0 |
||
939 | * |
||
940 | * @param string $key $_GET/_$_POST search key |
||
941 | * |
||
942 | * @return string |
||
943 | */ |
||
944 | 17 | private function convert_request_key_to_filter_key( $key ) { |
|
955 | |||
956 | /** |
||
957 | * Prepare the field filters to GFAPI |
||
958 | * |
||
959 | * The type post_category, multiselect and checkbox support multi-select search - each value needs to be separated in an independent filter so we could apply the ANY search mode. |
||
960 | * |
||
961 | * Format searched values |
||
962 | * |
||
963 | * @param string $filter_key ID of the field, or entry meta key |
||
964 | * @param string $value $_GET/$_POST search value |
||
965 | * @param \GV\View $view The view we're looking at |
||
966 | * @param array[] $searchable_fields The searchable fields as configured by the widget. |
||
967 | * @param string[] $get The $_GET/$_POST array. |
||
968 | * |
||
969 | * @since develop Added 5th $get parameter for operator overrides. |
||
970 | * @todo Set function as private. |
||
971 | * |
||
972 | * @return array|false 1 or 2 deph levels, false if not allowed |
||
973 | */ |
||
974 | 17 | public function prepare_field_filter( $filter_key, $value, $view, $searchable_fields, $get = array() ) { |
|
1200 | |||
1201 | /** |
||
1202 | * Get the Field Format form GravityForms |
||
1203 | * |
||
1204 | * @param GF_Field_Date $field The field object |
||
1205 | * @since 1.10 |
||
1206 | * |
||
1207 | * @return string Format of the date in the database |
||
1208 | */ |
||
1209 | public static function get_date_field_format( GF_Field_Date $field ) { |
||
1227 | |||
1228 | /** |
||
1229 | * Format a date value |
||
1230 | * |
||
1231 | * @param string $value Date value input |
||
1232 | * @param string $format Wanted formatted date |
||
1233 | * |
||
1234 | * @since 2.1.2 |
||
1235 | * @param string $value_format The value format. Default: Y-m-d |
||
1236 | * |
||
1237 | * @return string |
||
1238 | */ |
||
1239 | 8 | public static function get_formatted_date( $value = '', $format = 'Y-m-d', $value_format = 'Y-m-d' ) { |
|
1249 | |||
1250 | |||
1251 | /** |
||
1252 | * Include this extension templates path |
||
1253 | * @param array $file_paths List of template paths ordered |
||
1254 | */ |
||
1255 | 1 | public function add_template_path( $file_paths ) { |
|
1262 | |||
1263 | /** |
||
1264 | * Check whether the configured search fields have a date field |
||
1265 | * |
||
1266 | * @since 1.17.5 |
||
1267 | * |
||
1268 | * @param array $search_fields |
||
1269 | * |
||
1270 | * @return bool True: has a `date` or `date_range` field |
||
1271 | */ |
||
1272 | 4 | private function has_date_field( $search_fields ) { |
|
1285 | |||
1286 | /** |
||
1287 | * Renders the Search Widget |
||
1288 | * @param array $widget_args |
||
1289 | * @param string $content |
||
1290 | * @param string $context |
||
1291 | * |
||
1292 | * @return void |
||
1293 | */ |
||
1294 | 4 | public function render_frontend( $widget_args, $content = '', $context = '' ) { |
|
1394 | |||
1395 | /** |
||
1396 | * Get the search class for a search form |
||
1397 | * |
||
1398 | * @since 1.5.4 |
||
1399 | * |
||
1400 | * @return string Sanitized CSS class for the search form |
||
1401 | */ |
||
1402 | 4 | public static function get_search_class( $custom_class = '' ) { |
|
1422 | |||
1423 | |||
1424 | /** |
||
1425 | * Calculate the search form action |
||
1426 | * @since 1.6 |
||
1427 | * |
||
1428 | * @return string |
||
1429 | */ |
||
1430 | 4 | public static function get_search_form_action() { |
|
1439 | |||
1440 | /** |
||
1441 | * Get the label for a search form field |
||
1442 | * @param array $field Field setting as sent by the GV configuration - has `field`, `input` (input type), and `label` keys |
||
1443 | * @param array $form_field Form field data, as fetched by `gravityview_get_field()` |
||
1444 | * @return string Label for the search form |
||
1445 | */ |
||
1446 | 4 | private static function get_field_label( $field, $form_field = array() ) { |
|
1494 | |||
1495 | /** |
||
1496 | * Prepare search fields to frontend render with other details (label, field type, searched values) |
||
1497 | * |
||
1498 | * @param array $field |
||
1499 | * @param \GV\Context $context |
||
1500 | * |
||
1501 | * @return array |
||
1502 | */ |
||
1503 | 4 | private function get_search_filter_details( $field, $context ) { |
|
1562 | |||
1563 | /** |
||
1564 | * Sieve filter choices to only ones that are used. |
||
1565 | * |
||
1566 | * @param array $filter The filter configuration. |
||
1567 | * @param \GV\Context $context The context |
||
1568 | * |
||
1569 | * @since develop |
||
1570 | * @internal |
||
1571 | * |
||
1572 | * @return array The filter choices. |
||
1573 | */ |
||
1574 | private function sieve_filter_choices( $filter, $context ) { |
||
1629 | |||
1630 | /** |
||
1631 | * Calculate the search choices for the users |
||
1632 | * |
||
1633 | * @param \GV\View $view The view |
||
1634 | * @since develop |
||
1635 | * |
||
1636 | * @since 1.8 |
||
1637 | * |
||
1638 | * @return array Array of user choices (value = ID, text = display name) |
||
1639 | */ |
||
1640 | private static function get_created_by_choices( $view ) { |
||
1666 | |||
1667 | /** |
||
1668 | * Calculate the search checkbox choices for approval status |
||
1669 | * |
||
1670 | * @since develop |
||
1671 | * |
||
1672 | * @return array Array of approval status choices (value = status, text = display name) |
||
1673 | */ |
||
1674 | private static function get_is_approved_choices() { |
||
1686 | |||
1687 | /** |
||
1688 | * Output the Clear Search Results button |
||
1689 | * @since 1.5.4 |
||
1690 | */ |
||
1691 | 4 | public static function the_clear_search_button() { |
|
1702 | |||
1703 | /** |
||
1704 | * Based on the search method, fetch the value for a specific key |
||
1705 | * |
||
1706 | * @since 1.16.4 |
||
1707 | * |
||
1708 | * @param string $name Name of the request key to fetch the value for |
||
1709 | * |
||
1710 | * @return mixed|string Value of request at $name key. Empty string if empty. |
||
1711 | */ |
||
1712 | 4 | private function rgget_or_rgpost( $name ) { |
|
1723 | |||
1724 | |||
1725 | /** |
||
1726 | * Require the datepicker script for the frontend GV script |
||
1727 | * @param array $js_dependencies Array of existing required scripts for the fe-views.js script |
||
1728 | * @return array Array required scripts, with `jquery-ui-datepicker` added |
||
1729 | */ |
||
1730 | public function add_datepicker_js_dependency( $js_dependencies ) { |
||
1736 | |||
1737 | /** |
||
1738 | * Modify the array passed to wp_localize_script() |
||
1739 | * |
||
1740 | * @param array $js_localization The data padded to the Javascript file |
||
1741 | * @param array $view_data View data array with View settings |
||
1742 | * |
||
1743 | * @return array |
||
1744 | */ |
||
1745 | public function add_datepicker_localization( $localizations = array(), $view_data = array() ) { |
||
1781 | |||
1782 | /** |
||
1783 | * Register search widget scripts, including Flexibility |
||
1784 | * |
||
1785 | * @see https://github.com/10up/flexibility |
||
1786 | * |
||
1787 | * @since 1.17 |
||
1788 | * |
||
1789 | * @return void |
||
1790 | */ |
||
1791 | public function register_scripts() { |
||
1794 | |||
1795 | /** |
||
1796 | * If the current visitor is running IE 8 or 9, enqueue Flexibility |
||
1797 | * |
||
1798 | * @since 1.17 |
||
1799 | * |
||
1800 | * @return void |
||
1801 | */ |
||
1802 | 4 | private function maybe_enqueue_flexibility() { |
|
1807 | |||
1808 | /** |
||
1809 | * Enqueue the datepicker script |
||
1810 | * |
||
1811 | * It sets the $gravityview->datepicker_class parameter |
||
1812 | * |
||
1813 | * @todo Use own datepicker javascript instead of GF datepicker.js - that way, we can localize the settings and not require the changeMonth and changeYear pickers. |
||
1814 | * @return void |
||
1815 | */ |
||
1816 | public function enqueue_datepicker() { |
||
1844 | |||
1845 | /** |
||
1846 | * Retrieve the datepicker format. |
||
1847 | * |
||
1848 | * @param bool $date_format Whether to return the PHP date format or the datpicker class name. Default: false. |
||
1849 | * |
||
1850 | * @see https://docs.gravityview.co/article/115-changing-the-format-of-the-search-widgets-date-picker |
||
1851 | * |
||
1852 | * @return string The datepicker format placeholder, or the PHP date format. |
||
1853 | */ |
||
1854 | 19 | private function get_datepicker_format( $date_format = false ) { |
|
1893 | |||
1894 | /** |
||
1895 | * If previewing a View or page with embedded Views, make the search work properly by adding hidden fields with query vars |
||
1896 | * |
||
1897 | * @since 2.2.1 |
||
1898 | * |
||
1899 | * @return void |
||
1900 | */ |
||
1901 | 4 | public function add_preview_inputs() { |
|
1914 | |||
1915 | /** |
||
1916 | * Get an operator URL override. |
||
1917 | * |
||
1918 | * @param array $get Where to look for the operator. |
||
1919 | * @param string $key The filter key to look for. |
||
1920 | * @param array $allowed The allowed operators (whitelist). |
||
1921 | * @param string $default The default operator. |
||
1922 | * |
||
1923 | * @return string The operator. |
||
1924 | */ |
||
1925 | 19 | private function get_operator( $get, $key, $allowed, $default ) { |
|
1941 | |||
1942 | |||
1943 | } // end class |
||
1944 | |||
2002 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.