Completed
Push — develop ( 7592b8...3eb7c5 )
by Zack
14:44
created

fields/class-gravityview-field-date-created.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @file class-gravityview-field-date-created.php
4
 * @package GravityView
5
 * @subpackage includes\fields
6
 */
7
8
class GravityView_Field_Date_Created extends GravityView_Field {
9
10
	var $name = 'date_created';
0 ignored issues
show
The visibility should be declared for property $name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
11
12
	var $is_searchable = true;
13
14
	var $search_operators = array( 'less_than', 'greater_than', 'is', 'isnot' );
15
16
	var $group = 'meta';
17
18
	var $contexts = array( 'single', 'multiple', 'export' );
19
20
	var $_custom_merge_tag = 'date_created';
21
22
	/**
23
	 * GravityView_Field_Date_Created constructor.
24
	 */
25
	public function __construct() {
26
27
		$this->label = esc_html__( 'Date Created', 'gravityview' );
28
		$this->default_search_label = $this->label;
29
		$this->description = esc_html__( 'The date the entry was created.', 'gravityview' );
30
31
		add_filter( 'gravityview_field_entry_value_' . $this->name . '_pre_link', array( $this, 'get_content' ), 10, 4 );
32
33
		parent::__construct();
34
	}
35
36
	function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
37
38
		if( 'edit' === $context ) {
39
			return $field_options;
40
		}
41
42
		$this->add_field_support('date_display', $field_options );
43
44
		return $field_options;
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 GVCommon::format_date( $field['value'], 'format='.rgar( $field_settings, 'date_display' ) );
67
	}
68
69
	/**
70
	 * Add {date_created} merge tag and format the values using format_date
71
	 *
72
	 * @since 1.16
73
	 *
74
	 * @see http://docs.gravityview.co/article/331-date-created-merge-tag for usage information
75
	 *
76
	 * @param array $matches Array of Merge Tag matches found in text by preg_match_all
77
	 * @param string $text Text to replace
78
	 * @param array $form Gravity Forms form array
79
	 * @param array $entry Entry array
80
	 * @param bool $url_encode Whether to URL-encode output
81
	 *
82
	 * @return string Original text if {date_created} isn't found. Otherwise, replaced text.
83
	 */
84 1
	public function replace_merge_tag( $matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false  ) {
85
86 1
		$return = $text;
87
88
		/** Use $this->name instead of date_created because Payment Date uses this as well*/
89 1
		$date_created = rgar( $entry, $this->name );
90
91 1
		foreach ( $matches as $match ) {
92
93 1
			$full_tag          = $match[0];
94 1
			$property          = $match[1];
95
96 1
			$formatted_date = GravityView_Merge_Tags::format_date( $date_created, $property );
97
98 1
			$return = str_replace( $full_tag, $formatted_date, $return );
99
		}
100
101 1
		return $return;
102
	}
103
104
}
105
106
new GravityView_Field_Date_Created;