Completed
Push — develop ( c08328...40b6cc )
by Zack
08:12 queued 03:54
created

GravityView_Field_Date_Created::format()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 34
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 34
rs 8.8571
cc 3
eloc 9
nc 4
nop 3
1
<?php
2
3
class GravityView_Field_Date_Created extends GravityView_Field {
4
5
	var $name = 'date_created';
6
7
	var $search_operators = array( 'less_than', 'greater_than', 'is', 'isnot' );
8
9
	var $group = 'meta';
10
11
	var $contexts = array( 'single', 'multiple', 'export' );
12
13
	/**
14
	 * GravityView_Field_Date_Created constructor.
15
	 */
16
	public function __construct() {
17
		$this->label = esc_attr__( 'Date Created', '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...
18
		$this->description = esc_attr__( 'The date the entry was created.', 'gravityview' );
0 ignored issues
show
Bug introduced by
The property description 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...
19
		parent::__construct();
20
	}
21
22
	function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
23
24
		if( 'edit' === $context ) {
25
			return $field_options;
26
		}
27
28
		$this->add_field_support('date_display', $field_options );
29
30
		return $field_options;
31
	}
32
33
	public static function format( $value, $format = '', $context = 'display' ) {
34
35
		/**
36
		 * @filter `gravityview_date_created_adjust_timezone` Whether to adjust the timezone for entries. \n
37
		 * date_created is stored in UTC format. Convert search date into UTC (also used on templates/fields/date_created.php)
38
		 * @since 1.16
39
		 * @param[out,in] boolean $adjust_tz  Use timezone-adjusted datetime? If true, adjusts date based on blog's timezone setting. If false, uses UTC setting. Default: true
40
		 * @param[in] string $context Where the filter is being called from. `display` in this case.
41
		 */
42
		$adjust_tz = apply_filters( 'gravityview_date_created_adjust_timezone', true, $context );
43
44
		/**
45
		 * date_created is stored in UTC format. Fetch in the current blog's timezone if $adjust_tz is true
46
		 */
47
		$tz_value = $adjust_tz ? get_date_from_gmt( $value ) : $value;
48
49
		if( $format ) {
50
51
			$output = date_i18n( $format, strtotime( $tz_value ) );
52
53
		} else {
54
55
			/**
56
			 * @filter `gravityview_date_format` Whether to override the Gravity Forms date format with a PHP date format
57
			 * @see https://codex.wordpress.org/Formatting_Date_and_Time
58
			 * @param null|string Date Format (default: $field->dateFormat)
59
			 */
60
			$format = apply_filters( 'gravityview_date_format', rgar($field, "dateFormat") );
0 ignored issues
show
Bug introduced by
The variable $field does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
61
62
			$output = GFCommon::date_display( $tz_value, $format );
63
		}
64
65
		return $output;
66
	}
67
68
}
69
70
new GravityView_Field_Created_By;
71