GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-field-is-fulfilled.php
Go to the documentation of this file.
1 <?php
2 /**
3  * @file class-gravityview-field-is-fulfilled.php
4  * @package GravityView
5  * @subpackage includes\fields
6  * @since 1.16
7  */
8 
10 
11  var $name = 'is_fulfilled';
12 
13  var $is_searchable = true;
14 
15  var $is_numeric = false;
16 
17  var $search_operators = array( 'is', 'isnot' );
18 
19  var $group = 'pricing';
20 
21  var $_custom_merge_tag = 'is_fulfilled';
22 
23  /**
24  * @var int The value used by Gravity Forms when the order has not been fulfilled
25  */
26  const NOT_FULFILLED = 0;
27 
28  /**
29  * @var int The value used by Gravity Forms when the order has been fulfilled
30  */
31  const FULFILLED = 1;
32 
33  /**
34  * GravityView_Field_Is_Fulfilled constructor.
35  */
36  public function __construct() {
37  $this->label = esc_html__( 'Is Fulfilled', 'gk-gravityview' );
38  $this->description = esc_html__( 'Indicates if the entry or order has been fulfilled.', 'gk-gravityview' );
39  $this->default_search_label = $this->label;
40 
41  add_filter( 'gravityview_field_entry_value_' . $this->name . '_pre_link', array( $this, 'get_content' ), 10, 4 );
42  add_filter( 'gravityview/field/is_fulfilled/value', array( $this, 'get_value' ), 10 );
43 
44  parent::__construct();
45  }
46 
47  /**
48  * Filter the value of the field
49  *
50  * @todo Consider how to add to parent class
51  *
52  * @since 1.16
53  *
54  * @param string $output HTML value output
55  * @param array $entry The GF entry array
56  * @param array $field_settings Settings for the particular GV field
57  * @param array $field Current field being displayed
58  *
59  * @return String values for this field based on the numeric values used by Gravity Forms
60  */
61  public function get_content( $output, $entry = array(), $field_settings = array(), $field = array() ) {
62 
63  /** Overridden by a template. */
64  if( ! empty( $field['field_path'] ) ) { return $output; }
65 
66  return $this->get_string_from_value( $output );
67  }
68 
69  /**
70  * Filter the value of the field (future)
71  *
72  * @since 2.0
73  *
74  * @param mixed $value The value in.
75  *
76  * @return mixed The value out.
77  */
78  public function get_value( $value ) {
79  return $this->get_string_from_value( $value );
80  }
81 
82  /**
83  * Get the string output based on the numeric value used by Gravity Forms
84  *
85  * @since 1.16
86  *
87  * @param int|string $value Number value for the field
88  *
89  * @return string
90  */
91  private function get_string_from_value( $value ) {
92 
93  switch ( intval( $value ) ) {
94  case self::NOT_FULFILLED:
95  default:
96  $return = __('Not Fulfilled', 'gk-gravityview');
97  break;
98 
99  case self::FULFILLED:
100  $return = __('Fulfilled', 'gk-gravityview');
101  break;
102  }
103 
104  return $return;
105  }
106 
107  /**
108  * Add {is_fulfilled} merge tag
109  *
110  * @since 1.16
111  **
112  * @param array $matches Array of Merge Tag matches found in text by preg_match_all
113  * @param string $text Text to replace
114  * @param array $form Gravity Forms form array
115  * @param array $entry Entry array
116  * @param bool $url_encode Whether to URL-encode output
117  *
118  * @return string Original text if {is_fulfilled} isn't found. Otherwise, "Not Fulfilled" or "Fulfilled"
119  */
120  public function replace_merge_tag( $matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) {
121 
122  $return = $text;
123 
124  foreach ( $matches as $match ) {
125 
126  $full_tag = $match[0];
127 
128  $fulfilled = \GV\Utils::get( $entry, 'is_fulfilled' );
129 
130  $value = $this->get_string_from_value( $fulfilled );
131 
132  $return = str_replace( $full_tag, $value, $return );
133  }
134 
135  unset( $formatted_amount, $value, $amount, $full_tag, $matches );
136 
137  return $return;
138  }
139 }
140 
Modify field settings by extending this class.
get_value( $value)
Filter the value of the field (future)
get_content( $output, $entry=array(), $field_settings=array(), $field=array())
Filter the value of the field.
$field_settings['content']
Definition: custom.php:27
__construct()
GravityView_Field_Is_Fulfilled constructor.
replace_merge_tag( $matches=array(), $text='', $form=array(), $entry=array(), $url_encode=false, $esc_html=false)
Add {is_fulfilled} merge tag.
if(gravityview() ->plugin->is_GF_25()) $form
scale description p description
get_string_from_value( $value)
Get the string output based on the numeric value used by Gravity Forms.
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
$entry
Definition: notes.php:27