GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gv-collection-entry-filter-gravityforms.php
Go to the documentation of this file.
1 <?php
2 namespace GV;
3 
4 /** If this file is called directly, abort. */
5 if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6  die();
7 }
8 
9 /**
10  * Entry filtering settings Gravity Forms style.
11  *
12  * The good old $search_criteria in object form.
13  */
15 
16  /**
17  * @var array $search_criteria The $search_criteria array used by Gravity Forms
18  */
19  private $search_criteria = array();
20 
21  /**
22  * Create a filter from this criteria.
23  *
24  * @param array $search_criteria The Gravity Forms search criteria.
25  * @see GFAPI::search_entries
26  *
27  * @return \GV\GF_Entry_Filter The filter.
28  */
29  public static function from_search_criteria( $search_criteria ) {
30  $filter = new self();
31  $filter->search_criteria = $search_criteria;
32  return $filter;
33  }
34 
35  /**
36  * Merge two search criteria arrays.
37  *
38  * If two values collide, $b always wins.
39  *
40  * @param array $a One Gravity Forms search criteria.
41  * @param array $a Another Gravity Forms search criteria.
42  *
43  * @see GFAPI::search_entries
44  *
45  * @return array Merged search criteria.
46  */
47  public static function merge_search_criteria( $a, $b ) {
48  $search_criteria = array();
49 
50  foreach ( array( 'field_filters', 'start_date', 'end_date', 'status' ) as $key ) {
51  switch ( $key ):
52  case 'field_filters':
53  $field_filters = array_merge( empty( $a[ $key ] ) ? array() : $a[ $key ], empty( $b[ $key ] ) ? array() : $b[ $key ] );
54  if ( ! empty( $field_filters ) ) {
55  $search_criteria[ $key ] = $field_filters;
56  }
57 
58  if ( ! empty( $b[ $key ]['mode'] ) ) {
59  $search_criteria[ $key ]['mode' ] = $b[ $key ]['mode'];
60  } else if ( ! empty( $a[ $key ]['mode'] ) ) {
61  $search_criteria[ $key ]['mode' ] = $a[ $key ]['mode'];
62  }
63  break;
64  case 'start_date':
65  case 'end_date':
66  case 'status':
67  if ( isset( $b[ $key ] ) ) {
68  $search_criteria[ $key ] = $b[ $key ];
69  } else if ( isset( $a[ $key ] ) ) {
70  $search_criteria[ $key ] = $a[ $key ];
71  }
72  break;
73  endswitch;
74  }
75 
76  return $search_criteria;
77  }
78 
79  /**
80  * Get the $search_criteria.
81  *
82  * @see GFAPI::search_entries
83  *
84  * @return array $search_criteria The Gravity Forms search criteria.
85  */
86  public function as_search_criteria() {
87  return $this->search_criteria;
88  }
89 }
static from_search_criteria( $search_criteria)
Create a filter from this criteria.
If this file is called directly, abort.
static merge_search_criteria( $a, $b)
Merge two search criteria arrays.
If this file is called directly, abort.
as_search_criteria()
Get the $search_criteria.