GravityView  2.1.1
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes
GravityView_Widget_Search Class Reference
Inheritance diagram for GravityView_Widget_Search:
Widget

Public Member Functions

 __construct ()
 
 add_datepicker_js_dependency ( $js_dependencies)
 Require the datepicker script for the frontend GV script. More...
 
 add_datepicker_localization ( $localizations=array(), $view_data=array())
 Modify the array passed to wp_localize_script() More...
 
 add_no_permalink_fields ( $search_fields, $object, $widget_args=array())
 Display hidden fields to add support for sites using Default permalink structure. More...
 
 add_scripts_and_styles ( $hook)
 Add script to Views edit screen (admin) More...
 
 add_template_path ( $file_paths)
 Include this extension templates path. More...
 
 enqueue_datepicker ()
 Enqueue the datepicker script. More...
 
 filter_entries ( $search_criteria, $form_id=null, $args=array(), $force_search_criteria=false)
 — Frontend — More...
 
 get_search_method ()
 Returns the search method. More...
 
 gf_query_filter (&$query, $view, $request)
 Filters the with advanced logic. More...
 
 prepare_field_filter ( $filter_key, $value, $view)
 Prepare the field filters to GFAPI. More...
 
 register_no_conflict ( $allowed)
 Add admin script to the no-conflict scripts whitelist. More...
 
 register_scripts ()
 Register search widget scripts, including Flexibility. More...
 
- Public Member Functions inherited from Widget
 add_shortcode ()
 Add $this->shortcode_name shortcode to output self::render_frontend() More...
 
 as_configuration ()
 Return an array of the old format. More...
 
 assign_widget_options ( $options=array(), $template='', $widget='')
 Assign template specific widget options. More...
 
 get_setting ( $key)
 Get a setting by the setting key. More...
 
 get_settings ()
 Get the widget settings. More...
 
 get_widget_id ()
 Get the Widget ID. More...
 
 is_registered ()
 Whether this Widget's been registered already or not. More...
 
 maybe_do_shortcode ( $text, $widget=null)
 Do shortcode if the Widget's shortcode exists. More...
 
 pre_render_frontend ()
 General validations when rendering the widget. More...
 
 register_widget ( $widgets)
 Register widget to become available in admin. More...
 
 render_frontend ( $widget_args, $content='', $context='')
 Frontend logic. More...
 
 render_shortcode ( $atts, $content='', $context='')
 Shortcode. More...
 

Static Public Member Functions

static get_date_field_format (GF_Field_Date $field)
 Get the Field Format form GravityForms. More...
 
static get_formatted_date ( $value='', $format='Y-m-d', $value_format='Y-m-d')
 Format a date value. More...
 
static get_search_class ( $custom_class='')
 Get the search class for a search form. More...
 
static get_search_form_action ()
 Calculate the search form action. More...
 
static get_search_input_label ( $input_type)
 
static get_search_input_types ( $field_id='', $field_type=null)
 Assign an input type according to the form field type. More...
 
static get_searchable_fields ()
 Ajax Returns the form fields ( only the searchable ones ) More...
 
static getInstance ()
 
static render_searchable_fields ( $form_id=null, $current='')
 Generates html for the available Search Fields dropdown. More...
 
static the_clear_search_button ()
 Output the Clear Search Results button. More...
 
- Static Public Member Functions inherited from Widget
static from_configuration ( $configuration)
 Create the needed widget from a configuration array. More...
 
static get_default_widget_areas ()
 Default widget areas. More...
 
static registered ()
 Return all registered widgets. More...
 

Static Public Attributes

static $file
 
static $instance
 

Private Member Functions

 convert_request_key_to_filter_key ( $key)
 Convert $_GET/$_POST key to the field/meta ID. More...
 
 get_datepicker_format ( $date_format=false)
 Retrieve the datepicker format. More...
 
 get_search_filter_details ( $field)
 Prepare search fields to frontend render with other details (label, field type, searched values) More...
 
 get_view_searchable_fields ( $view, $with_full_field=false)
 Get the fields that are searchable for a View. More...
 
 has_date_field ( $search_fields)
 Check whether the configured search fields have a date field. More...
 
 maybe_enqueue_flexibility ()
 If the current visitor is running IE 8 or 9, enqueue Flexibility. More...
 
 rgget_or_rgpost ( $name)
 Based on the search method, fetch the value for a specific key. More...
 
 set_search_method ()
 Sets the search method to GET (default) or POST. More...
 

Static Private Member Functions

static get_created_by_choices ()
 Calculate the search choices for the users. More...
 
static get_field_label ( $field, $form_field=array())
 Get the label for a search form field. More...
 

Private Attributes

 $search_filters = array()
 
 $search_method = 'get'
 

Additional Inherited Members

- Data Fields inherited from Widget
 $configuration
 
 $position = ''
 
 $UID = ''
 
- Protected Member Functions inherited from Widget
 get_default_settings ()
 Define general widget settings. More...
 
- Protected Attributes inherited from Widget
 $defaults = array()
 
 $settings = array()
 
 $shortcode_name
 
 $widget_description = ''
 
 $widget_id = ''
 
 $widget_label = ''
 
 $widget_subtitle = ''
 

Detailed Description

Definition at line 16 of file class-search-widget.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Member Function Documentation

◆ add_datepicker_js_dependency()

add_datepicker_js_dependency (   $js_dependencies)

Require the datepicker script for the frontend GV script.

Parameters
array$js_dependenciesArray of existing required scripts for the fe-views.js script
Returns
array Array required scripts, with jquery-ui-datepicker added

Definition at line 1366 of file class-search-widget.php.

◆ add_datepicker_localization()

add_datepicker_localization (   $localizations = array(),
  $view_data = array() 
)

Modify the array passed to wp_localize_script()

Parameters
array$js_localizationThe data padded to the Javascript file
array$view_dataView data array with View settings
Returns
array
Runs Filter:
gravityview_datepicker_settings Modify the datepicker settings
See also
http://api.jqueryui.com/datepicker/ Learn what settings are available
http://www.renegadetechconsulting.com/tutorials/jquery-datepicker-and-wordpress-i18n Thanks for the helpful information on $wp_locale
Parameters
array$js_localizationThe data padded to the Javascript file
array$view_dataView data array with View settings

Definition at line 1381 of file class-search-widget.php.

◆ add_no_permalink_fields()

add_no_permalink_fields (   $search_fields,
  $object,
  $widget_args = array() 
)

Display hidden fields to add support for sites using Default permalink structure.

Since
1.8
Returns
array Search fields, modified if not using permalinks

WP_Rewrite $wp_rewrite

Definition at line 413 of file class-search-widget.php.

References $value, and gravityview_get_permalink_query_args().

◆ add_scripts_and_styles()

add_scripts_and_styles (   $hook)

Add script to Views edit screen (admin)

Parameters
mixed$hook

Definition at line 216 of file class-search-widget.php.

References gravityview().

◆ add_template_path()

add_template_path (   $file_paths)

Include this extension templates path.

Parameters
array$file_pathsList of template paths ordered

Definition at line 1020 of file class-search-widget.php.

◆ convert_request_key_to_filter_key()

convert_request_key_to_filter_key (   $key)
private

Convert $_GET/$_POST key to the field/meta ID.

Examples:

  • filter_is_starred => is_starred
  • filter_1_2 => 1.2
  • filter_5 => 5
Since
2.0
Parameters
string$key$_GET/_$_POST search key
Returns
string

Definition at line 772 of file class-search-widget.php.

References $field_id.

Referenced by filter_entries().

◆ enqueue_datepicker()

enqueue_datepicker ( )

Enqueue the datepicker script.

It sets the $gravityview->datepicker_class parameter

Returns
void
Runs Filter:
gravityview_search_datepicker_class Modify the CSS class for the datepicker, used by the CSS class is used by Gravity Forms' javascript to determine the format for the date picker. The gv-datepicker class is required by the GravityView datepicker javascript.
Parameters
string$css_classCSS class to use. Default: gv-datepicker datepicker mdy
Options are:
  • mdy (mm/dd/yyyy)
  • dmy (dd/mm/yyyy)
  • dmy_dash (dd-mm-yyyy)
  • dmy_dot (dd.mm.yyyy)
  • ymd_slash (yyyy/mm/dd)
  • ymd_dash (yyyy-mm-dd)
  • ymd_dot (yyyy.mm.dd)

Definition at line 1452 of file class-search-widget.php.

References $gravityview_view, get_datepicker_format(), and GravityView_View\getInstance().

Referenced by has_date_field().

◆ filter_entries()

filter_entries (   $search_criteria,
  $form_id = null,
  $args = array(),
  $force_search_criteria = false 
)

— Frontend —

Calculate the search criteria to filter entries

Parameters
array$search_criteriaThe search criteria
int$form_idThe form ID
array$argsSome args
bool$force_search_criteriaWhether to suppress GF_Query filter, internally used in self::gf_query_filter
Returns
array

If GF_Query is available, we can construct custom conditions with nested booleans on the query, giving up the old ways of flat search_criteria field_filters.

Runs Filter:
gravityview/search-all-split-words Search for each word separately or the whole phrase?
Since
1.20.2
Parameters
bool$split_wordsTrue: split a phrase into words; False: search whole word only [Default: true]

Get and normalize the dates according to the input format.

Override start and end dates if View is limited to some already.

Runs Filter:
gravityview_date_created_adjust_timezone Whether to adjust the timezone for entries.
date_created is stored in UTC format. Convert search date into UTC (also used on templates/fields/date_created.php)
Since
1.12
Parameters
[in,out]boolean$adjust_tzUse timezone-adjusted datetime? If true, adjusts date based on blog's timezone setting. If false, uses UTC setting. Default: true
[in]string$contextWhere the filter is being called from. search in this case.

Don't set $search_criteria['start_date'] if start_date is empty as it may lead to bad query results (GFAPI::get_entries)

Runs Filter:
gravityview/search/mode Set the Search Mode (all or any)
Since
1.5.1
Parameters
[in,out]string$modeSearch mode (any vs all)

Definition at line 510 of file class-search-widget.php.

References $filter, $search_criteria, $value, View\by_id(), convert_request_key_to_filter_key(), Utils\get(), GV\get(), get_datepicker_format(), get_view_searchable_fields(), gravityview(), gv_empty(), gv_map_deep(), and prepare_field_filter().

Referenced by gf_query_filter().

◆ get_created_by_choices()

static get_created_by_choices ( )
staticprivate

Calculate the search choices for the users.

Since
1.8
Returns
array Array of user choices (value = ID, text = display name)

filter gravityview/get_users/search_widget

See also
::get_users

Definition at line 1303 of file class-search-widget.php.

References $user, and GVCommon\get_users().

◆ get_date_field_format()

static get_date_field_format ( GF_Field_Date  $field)
static

Get the Field Format form GravityForms.

Parameters
GF_Field_Date$fieldThe field object
Since
1.10
Returns
string Format of the date in the database

Definition at line 974 of file class-search-widget.php.

References $format.

◆ get_datepicker_format()

get_datepicker_format (   $date_format = false)
private

Retrieve the datepicker format.

Parameters
bool$date_formatWhether to return the PHP date format or the datpicker class name. Default: false.
See also
https://docs.gravityview.co/article/115-changing-the-format-of-the-search-widgets-date-picker
Returns
string The datepicker format placeholder, or the PHP date format.
Runs Filter:
gravityview/widgets/search/datepicker/format
Since
2.1.1
Parameters
string$formatDefault: mdy Options are:
  • mdy (mm/dd/yyyy)
  • dmy (dd/mm/yyyy)
  • dmy_dash (dd-mm-yyyy)
  • dmy_dot (dd.mm.yyyy)
  • ymd_slash (yyyy/mm/dd)
  • ymd_dash (yyyy-mm-dd)
  • ymd_dot (yyyy.mm.dd)

Definition at line 1490 of file class-search-widget.php.

References $format, and GV\get().

Referenced by enqueue_datepicker(), filter_entries(), and prepare_field_filter().

◆ get_field_label()

static get_field_label (   $field,
  $form_field = array() 
)
staticprivate

Get the label for a search form field.

Parameters
array$fieldField setting as sent by the GV configuration - has field, input (input type), and label keys
array$form_fieldForm field data, as fetched by gravityview_get_field()
Returns
string Label for the search form
Runs Filter:
gravityview_search_field_label Modify the label for a search field. Supports returning HTML
Since
1.17.3 Added $field parameter
Parameters
[in,out]string$labelExisting label text, sanitized.
[in]array$form_fieldGravity Forms field array, as returned by GFFormsModel::get_field()
[in]array$fieldField setting as sent by the GV configuration - has field, input (input type), and label keys

Definition at line 1202 of file class-search-widget.php.

References $field, $label, $value, Utils\_GET(), and GV\get().

◆ get_formatted_date()

static get_formatted_date (   $value = '',
  $format = 'Y-m-d',
  $value_format = 'Y-m-d' 
)
static

Format a date value.

Parameters
string$valueDate value input
string$formatWanted formatted date
Since
2.1.2
Parameters
string$value_formatThe value format. Default: Y-m-d
Returns
string

Definition at line 1004 of file class-search-widget.php.

References $format, $value, and gravityview().

◆ get_search_class()

static get_search_class (   $custom_class = '')
static

Get the search class for a search form.

Since
1.5.4
Returns
string Sanitized CSS class for the search form
Runs Filter:
gravityview_search_class Modify the CSS class for the search form
Parameters
string$search_classThe CSS class for the search form

Definition at line 1158 of file class-search-widget.php.

References $gravityview_view, GravityView_frontend\getInstance(), and GravityView_View\getInstance().

◆ get_search_filter_details()

get_search_filter_details (   $field)
private

Prepare search fields to frontend render with other details (label, field type, searched values)

Parameters
array$field
Returns
array

Definition at line 1257 of file class-search-widget.php.

References $field, $filter, GV\$form, $gravityview_view, $name, $value, GravityView_View\getInstance(), gravityview_get_field(), gravityview_get_terms_choices(), and rgget_or_rgpost().

Referenced by has_date_field().

◆ get_search_form_action()

static get_search_form_action ( )
static

Calculate the search form action.

Since
1.6
Returns
string

Definition at line 1186 of file class-search-widget.php.

References $gravityview_view, $url, and GravityView_View\getInstance().

◆ get_search_input_label()

static get_search_input_label (   $input_type)
static

Definition at line 206 of file class-search-widget.php.

References $labels, and GV\get().

◆ get_search_input_types()

static get_search_input_types (   $field_id = '',
  $field_type = null 
)
static

Assign an input type according to the form field type.

See also
admin-search-widget.js
Parameters
string | int | float$field_idGravity Forms field ID
string$field_typeGravity Forms field type (also the name parameter of GravityView_Field classes)
Returns
string GV field search input type ('multi', 'boolean', 'select', 'date', 'text')
Runs Filter:
gravityview/extension/search/input_type Modify the search form input type based on field type
Since
1.2
1.19.2 Added $field_id parameter
Parameters
string$input_typeAssign an input type according to the form field type. Defaults: boolean, multi, select, date, text
string$field_typeGravity Forms field type (also the name parameter of GravityView_Field classes)
string | int | float$field_idID of the field being processed

Definition at line 377 of file class-search-widget.php.

References $field_id.

Referenced by GravityView_Migrate\get_search_fields().

◆ get_search_method()

get_search_method ( )

Returns the search method.

Since
1.16.4
Returns
string

Definition at line 135 of file class-search-widget.php.

References $search_method.

◆ get_searchable_fields()

static get_searchable_fields ( )
static

Ajax Returns the form fields ( only the searchable ones )

public

Returns
void

Definition at line 260 of file class-search-widget.php.

References GV\$form, gravityview_get_form_id(), and GravityView_Ajax\pre_get_form_fields().

◆ get_view_searchable_fields()

get_view_searchable_fields (   $view,
  $with_full_field = false 
)
private

Get the fields that are searchable for a View.

Since
2.0
2.0.9 Added $with_full_field parameter
Parameters
\GV\View | null$view
bool$with_full_fieldReturn full field array, or just field ID? Default: false (just field ID)

TODO: Move to , perhaps? And return a Field_Collection TODO: Use in gravityview()->request->is_search() to calculate whether a valid search

Returns
array If no View, returns empty array. Otherwise, returns array of fields configured in widgets and Search Bar for a View

Find all search widgets on the view and get the searchable fields settings.

Include the sidebar Widgets.

Definition at line 461 of file class-search-widget.php.

References $field, and GV\all().

Referenced by filter_entries(), and prepare_field_filter().

◆ getInstance()

static getInstance ( )
static

◆ gf_query_filter()

gf_query_filter ( $query,
  $view,
  $request 
)

Filters the with advanced logic.

Dropin for the legacy flat filters when is available.

Parameters
\GF_Query$queryThe current query object reference
\GV\View$thisThe current view object
\GV\Request$requestThe request object

This is a shortcut to get all the needed search criteria. We feed these into an new GF_Query and tack them onto the current object.

force search_criteria

Runs Filter:
gravityview_search_operator Modify the search operator for the field (contains, is, isnot, etc)
Parameters
string$operatorExisting search operator
array$filterarray with key, value, operator, type keys

Parse the filter criteria to generate the needed WHERE clauses. This is a trick to not write our own generation code by reusing what's inside GF_Query already.

Grab the current clauses. We'll be combining them shortly.

Combine the parts as a new WHERE clause.

Definition at line 712 of file class-search-widget.php.

References $filter, $search_criteria, and filter_entries().

◆ has_date_field()

has_date_field (   $search_fields)
private

Check whether the configured search fields have a date field.

Since
1.17.5
Parameters
array$search_fields
Returns
bool True: has a date or date_range field

Definition at line 1037 of file class-search-widget.php.

References $content, $field, $gravityview_view, enqueue_datepicker(), get_search_filter_details(), GravityView_View\getInstance(), gravityview(), maybe_enqueue_flexibility(), Widget\render_frontend(), and rgget_or_rgpost().

◆ maybe_enqueue_flexibility()

maybe_enqueue_flexibility ( )
private

If the current visitor is running IE 8 or 9, enqueue Flexibility.

Since
1.17
Returns
void

Definition at line 1438 of file class-search-widget.php.

Referenced by has_date_field().

◆ prepare_field_filter()

prepare_field_filter (   $filter_key,
  $value,
  $view 
)

Prepare the field filters to GFAPI.

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.

Format searched values

Parameters
string$filter_keyID of the field, or entry meta key
string$value$_GET/$_POST search value
\GV\View$viewThe view we're looking at
Returns
array 1 or 2 deph levels
Since
1.16.3 Safeguard until GF implements '<=' operator

Definition at line 797 of file class-search-widget.php.

References $filter, $value, Internal_Field\by_id(), GF_Field\by_id(), get_datepicker_format(), get_view_searchable_fields(), and gravityview_get_input_id_from_id().

Referenced by filter_entries().

◆ register_no_conflict()

register_no_conflict (   $allowed)

Add admin script to the no-conflict scripts whitelist.

Parameters
array$allowedScripts allowed in no-conflict mode
Returns
array Scripts allowed in no-conflict mode, plus the search widget script

Definition at line 248 of file class-search-widget.php.

◆ register_scripts()

register_scripts ( )

Register search widget scripts, including Flexibility.

See also
https://github.com/10up/flexibility
Since
1.17
Returns
void

Definition at line 1427 of file class-search-widget.php.

References GRAVITYVIEW_FILE.

◆ render_searchable_fields()

static render_searchable_fields (   $form_id = null,
  $current = '' 
)
static

Generates html for the available Search Fields dropdown.

Parameters
int$form_id
string$current(for future use)
Returns
string
Runs Filter:
gravityview/search/searchable_fields Modify the fields that are displayed as searchable in the Search Bar dropdown
Since
1.17
See also
gravityview_get_form_fields() Used to fetch the fields
GravityView_Widget_Search::get_search_input_types See this method to modify the type of input types allowed for a field
Parameters
array$fieldsArray of searchable fields, as fetched by gravityview_get_form_fields()
int$form_id

Definition at line 295 of file class-search-widget.php.

References $field, $form_id, $output, and gravityview_get_form_fields().

◆ rgget_or_rgpost()

rgget_or_rgpost (   $name)
private

Based on the search method, fetch the value for a specific key.

Since
1.16.4
Parameters
string$nameName of the request key to fetch the value for
Returns
mixed|string Value of request at $name key. Empty string if empty.

Definition at line 1348 of file class-search-widget.php.

References $name, $value, Utils\_REQUEST(), and gv_map_deep().

Referenced by get_search_filter_details(), and has_date_field().

◆ set_search_method()

set_search_method ( )
private

Sets the search method to GET (default) or POST.

Since
1.16.4
Runs Filter:
gravityview/search/method Modify the search form method (GET / POST)
Since
1.16.4
Parameters
string$search_methodAssign an input type according to the form field type. Defaults: boolean, multi, select, date, text
string$field_typeGravity Forms field type (also the name parameter of GravityView_Field classes)

Definition at line 116 of file class-search-widget.php.

Referenced by __construct().

◆ the_clear_search_button()

static the_clear_search_button ( )
static

Output the Clear Search Results button.

Since
1.5.4

Definition at line 1327 of file class-search-widget.php.

References $gravityview_view, $url, GravityView_View\getInstance(), and gravityview_get_link().

Field Documentation

◆ $file

$file
static

Definition at line 18 of file class-search-widget.php.

◆ $instance

$instance
static

Definition at line 19 of file class-search-widget.php.

◆ $search_filters

$search_filters = array()
private

Definition at line 21 of file class-search-widget.php.

◆ $search_method

$search_method = 'get'
private

Definition at line 28 of file class-search-widget.php.

Referenced by get_search_method().


The documentation for this class was generated from the following file: