GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-field-payment-amount.php
Go to the documentation of this file.
1 <?php
2 /**
3  * @file class-gravityview-field-payment-amount.php
4  * @package GravityView
5  * @subpackage includes\fields
6  * @since 1.16
7  */
8 
10 
11  var $name = 'payment_amount';
12 
13  var $is_searchable = true;
14 
15  var $is_numeric = true;
16 
17  var $search_operators = array( 'is', 'isnot', 'greater_than', 'less_than', 'contains' );
18 
19  var $group = 'pricing';
20 
21  var $icon = 'dashicons-cart';
22 
23  var $_custom_merge_tag = 'payment_amount';
24 
25  /**
26  * GravityView_Field_Payment_Amount constructor.
27  */
28  public function __construct() {
29  $this->label = esc_html__( 'Payment Amount', 'gk-gravityview' );
30 
31  add_filter( 'gravityview_field_entry_value_' . $this->name . '_pre_link', array( $this, 'get_content' ), 10, 4 );
32  add_filter( 'gravityview/field/payment_amount/value', array( $this, 'get_value' ), 10, 6 );
33 
34  parent::__construct();
35  }
36 
37  /**
38  * Filter the value of the field
39  *
40  * @todo Consider how to add to parent class
41  *
42  * @since 1.16
43  *
44  * @param string $output HTML value output
45  * @param array $entry The GF entry array
46  * @param array $field_settings Settings for the particular GV field
47  * @param array $field Current field being displayed
48  *
49  * @return String values for this field based on the numeric values used by Gravity Forms
50  */
51  public function get_content( $output = '', $entry = array(), $field_settings = array(), $field = array() ) {
52 
53  /** Overridden by a template. */
54  if( ! empty( $field['field_path'] ) ) { return $output; }
55 
56  $amount = \GV\Utils::get( $entry, 'payment_amount' );
57  $return = GFCommon::to_money( $amount, \GV\Utils::get( $entry, 'currency' ) );
58 
59  return $return;
60  }
61 
62  /**
63  * Filter the value of the field, future.
64  *
65  * @since 2.0
66  *
67  * @param mixed $value The value of the field.
68  * @param \GV\Field $field The field as seen by future.
69  * @param \GV\View $view The view requested in.
70  * @param \GV\Source $source The data source (form).
71  * @param \GV\Entry $entry The entry.
72  * @param \GV\Request $request The request context.
73  *
74  * @return mixed $value The filtered value.
75  */
76  public function get_value( $value, $field, $view, $source, $entry, $request ) {
77  return $this->get_content( $value, $entry->as_entry(), $field->as_configuration() );
78  }
79 
80  /**
81  * Add {payment_amount} merge tag
82  *
83  * @since 1.16
84  **
85  * @param array $matches Array of Merge Tag matches found in text by preg_match_all
86  * @param string $text Text to replace
87  * @param array $form Gravity Forms form array
88  * @param array $entry Entry array
89  * @param bool $url_encode Whether to URL-encode output
90  *
91  * @return string Original text if {date_created} isn't found. Otherwise, replaced text.
92  */
93  public function replace_merge_tag( $matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) {
94 
95  $return = $text;
96 
97  foreach ( $matches as $match ) {
98 
99  $full_tag = $match[0];
100  $modifier = isset( $match[1] ) ? $match[1] : false;
101 
102  $amount = \GV\Utils::get( $entry, 'payment_amount' );
103 
104  $formatted_amount = ( 'raw' === $modifier ) ? $amount : GFCommon::to_money( $amount, \GV\Utils::get( $entry, 'currency' ) );
105 
106  $return = str_replace( $full_tag, $formatted_amount, $return );
107  }
108 
109  unset( $formatted_amount, $amount, $full_tag, $matches );
110 
111  return $return;
112  }
113 }
114 
Modify field settings by extending this class.
get_content( $output='', $entry=array(), $field_settings=array(), $field=array())
Filter the value of the field.
$field_settings['content']
Definition: custom.php:27
if(gravityview() ->plugin->is_GF_25()) $form
__construct()
GravityView_Field_Payment_Amount constructor.
replace_merge_tag( $matches=array(), $text='', $form=array(), $entry=array(), $url_encode=false, $esc_html=false)
Add {payment_amount} merge tag.
get_value( $value, $field, $view, $source, $entry, $request)
Filter the value of the field, future.
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
$entry
Definition: notes.php:27