GravityView  1.19.4
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', 'gravityview' );
38  $this->default_search_label = $this->label;
39 
40  add_filter( 'gravityview_field_entry_value_' . $this->name . '_pre_link', array( $this, 'get_content' ), 10, 4 );
41 
42  parent::__construct();
43  }
44 
45  /**
46  * Filter the value of the field
47  *
48  * @todo Consider how to add to parent class
49  *
50  * @since 1.16
51  *
52  * @param string $output HTML value output
53  * @param array $entry The GF entry array
54  * @param array $field_settings Settings for the particular GV field
55  * @param array $field Current field being displayed
56  *
57  * @return String values for this field based on the numeric values used by Gravity Forms
58  */
59  public function get_content( $output, $entry = array(), $field_settings = array(), $field = array() ) {
60 
61  /** Overridden by a template. */
62  if( ! empty( $field['field_path'] ) ) { return $output; }
63 
64  return $this->get_string_from_value( $output );
65  }
66 
67  /**
68  * Get the string output based on the numeric value used by Gravity Forms
69  *
70  * @since 1.16
71  *
72  * @param int|string $value Number value for the field
73  *
74  * @return string
75  */
76  private function get_string_from_value( $value ) {
77 
78  switch ( intval( $value ) ) {
79  case self::NOT_FULFILLED:
80  default:
81  $return = __('Not Fulfilled', 'gravityview');
82  break;
83 
84  case self::FULFILLED:
85  $return = __('Fulfilled', 'gravityview');
86  break;
87  }
88 
89  return $return;
90  }
91 
92  /**
93  * Add {is_fulfilled} merge tag
94  *
95  * @since 1.16
96  **
97  * @param array $matches Array of Merge Tag matches found in text by preg_match_all
98  * @param string $text Text to replace
99  * @param array $form Gravity Forms form array
100  * @param array $entry Entry array
101  * @param bool $url_encode Whether to URL-encode output
102  *
103  * @return string Original text if {is_fulfilled} isn't found. Otherwise, "Not Fulfilled" or "Fulfilled"
104  */
105  public function replace_merge_tag( $matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) {
106 
107  $return = $text;
108 
109  foreach ( $matches as $match ) {
110 
111  $full_tag = $match[0];
112 
113  $fulfilled = rgar( $entry, 'is_fulfilled' );
114 
115  $value = $this->get_string_from_value( $fulfilled );
116 
117  $return = str_replace( $full_tag, $value, $return );
118  }
119 
120  unset( $formatted_amount, $value, $amount, $full_tag, $matches );
121 
122  return $return;
123  }
124 }
125 
Modify field settings by extending this class.
__construct()
GravityView_Field_Is_Fulfilled constructor.
$field_settings['content']
Definition: custom.php:27
get_content($output, $entry=array(), $field_settings=array(), $field=array())
Filter the value of the field.
replace_merge_tag($matches=array(), $text= '', $form=array(), $entry=array(), $url_encode=false, $esc_html=false)
Add {is_fulfilled} merge tag.
$entry
Definition: notes.php:27
$field
Definition: gquiz_grade.php:11
get_string_from_value($value)
Get the string output based on the numeric value used by Gravity Forms.