|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @file class-gravityview-field-payment-amount.php |
|
4
|
|
|
* @package GravityView |
|
5
|
|
|
* @subpackage includes\fields |
|
6
|
|
|
* @since 1.16 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
class GravityView_Field_Payment_Amount extends GravityView_Field { |
|
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 $_custom_merge_tag = 'payment_amount'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* GravityView_Field_Payment_Amount constructor. |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct() { |
|
27
|
|
|
$this->label = esc_attr__( 'Payment Amount', 'gravityview' ); |
|
28
|
|
|
|
|
29
|
|
|
add_filter( 'gravityview_field_entry_value_' . $this->name . '_pre_link', array( $this, 'get_content' ), 10, 4 ); |
|
30
|
|
|
|
|
31
|
|
|
parent::__construct(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Filter the value of the field |
|
36
|
|
|
* |
|
37
|
|
|
* @todo Consider how to add to parent class |
|
38
|
|
|
* |
|
39
|
|
|
* @since 1.16 |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $output HTML value output |
|
42
|
|
|
* @param array $entry The GF entry array |
|
43
|
|
|
* @param array $field_settings Settings for the particular GV field |
|
44
|
|
|
* @param array $field Current field being displayed |
|
45
|
|
|
* |
|
46
|
|
|
* @return String values for this field based on the numeric values used by Gravity Forms |
|
47
|
|
|
*/ |
|
48
|
|
|
public function get_content( $output = '', $entry = array(), $field_settings = array(), $field = array() ) { |
|
49
|
|
|
|
|
50
|
|
|
/** Overridden by a template. */ |
|
51
|
|
|
if( ! empty( $field['field_path'] ) ) { return $output; } |
|
52
|
|
|
|
|
53
|
|
|
$amount = rgar( $entry, 'payment_amount' ); |
|
54
|
|
|
$return = GFCommon::to_money( $amount, rgar( $entry, 'currency' ) ); |
|
55
|
|
|
|
|
56
|
|
|
return $return; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Add {payment_amount} merge tag |
|
61
|
|
|
* |
|
62
|
|
|
* @since 1.16 |
|
63
|
|
|
** |
|
64
|
|
|
* @param array $matches Array of Merge Tag matches found in text by preg_match_all |
|
65
|
|
|
* @param string $text Text to replace |
|
66
|
|
|
* @param array $form Gravity Forms form array |
|
67
|
|
|
* @param array $entry Entry array |
|
68
|
|
|
* @param bool $url_encode Whether to URL-encode output |
|
69
|
|
|
* |
|
70
|
|
|
* @return string Original text if {date_created} isn't found. Otherwise, replaced text. |
|
71
|
|
|
*/ |
|
72
|
|
|
public function replace_merge_tag( $matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) { |
|
73
|
|
|
|
|
74
|
|
|
$return = $text; |
|
75
|
|
|
|
|
76
|
|
|
foreach ( $matches as $match ) { |
|
77
|
|
|
|
|
78
|
|
|
$full_tag = $match[0]; |
|
79
|
|
|
$modifier = isset( $match[1] ) ? $match[1] : false; |
|
80
|
|
|
|
|
81
|
|
|
$amount = rgar( $entry, 'payment_amount' ); |
|
82
|
|
|
|
|
83
|
|
|
$formatted_amount = ( 'raw' === $modifier ) ? $amount : GFCommon::to_money( $amount, rgar( $entry, 'currency' ) ); |
|
84
|
|
|
|
|
85
|
|
|
$return = str_replace( $full_tag, $formatted_amount, $return ); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
unset( $formatted_amount, $amount, $full_tag, $matches ); |
|
89
|
|
|
|
|
90
|
|
|
return $return; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
new GravityView_Field_Payment_Amount; |
|
95
|
|
|
|