Completed
Push — develop ( bd6ad5...7b688d )
by Zack
04:29
created

GravityView_Field_Payment_Amount   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A replace_merge_tag() 0 20 4
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' );
0 ignored issues
show
Bug introduced by
The property label cannot be accessed from this context as it is declared private in class GravityView_Field.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
28
		parent::__construct();
29
	}
30
31
	/**
32
	 * Add {payment_amount} merge tag
33
	 *
34
	 * @since 1.16
35
	 **
36
	 * @param array $matches Array of Merge Tag matches found in text by preg_match_all
37
	 * @param string $text Text to replace
38
	 * @param array $form Gravity Forms form array
39
	 * @param array $entry Entry array
40
	 * @param bool $url_encode Whether to URL-encode output
41
	 *
42
	 * @return string Original text if {date_created} isn't found. Otherwise, replaced text.
43
	 */
44
	public function replace_merge_tag( $matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false  ) {
45
46
		$return = $text;
47
48
		foreach ( $matches as $match ) {
49
50
			$full_tag = $match[0];
51
			$modifier = isset( $match[1] ) ? $match[1] : false;
52
53
			$amount = rgar( $entry, 'payment_amount' );
54
55
			$formatted_amount = ( 'raw' === $modifier ) ? $amount : GFCommon::to_money( $amount, rgar( $entry, 'currency' ) );
56
57
			$return = str_replace( $full_tag, $formatted_amount, $return );
58
		}
59
60
		unset( $formatted_amount, $amount, $full_tag, $matches );
61
62
		return $return;
63
	}
64
}
65
66
new GravityView_Field_Payment_Amount;
67