Completed
Push — develop ( 5570a4...397201 )
by Gennady
20:15
created

Timestamp   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A add_hooks() 0 3 1
A modify_entry_value_workflow_current_status_timestamp() 0 9 2
A field_options() 0 9 2
1
<?php
2
/**
3
 * @file class-gravityview-field-workflow_current_status_timestamp.php
4
 * @since develop
5
 * @package GravityView
6
 * @subpackage includes\fields
7
 */
8
9
class GravityView_Field_Workflow_Current_Status_Timestamp extends GravityView_Field {
10
11
	var $name = 'workflow_current_status_timestamp';
12
13
	var $group = 'meta';
14
15
	var $contexts = array( 'multiple', 'single' );
16
17
	var $entry_meta_key = 'workflow_current_status_timestamp';
18
19
	var $is_numeric = true;
20
21
	public function __construct() {
22
		$this->label = esc_html__( 'Workflow Current Status Timestamp', 'gravityview' );
23
		$this->add_hooks();
24
		parent::__construct();
25
	}
26
27
	function add_hooks() {
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...
28
		add_filter( 'gravityview_field_entry_value_workflow_current_status_timestamp', array( $this, 'modify_entry_value_workflow_current_status_timestamp' ), 10, 4 );
29
	}
30
31
	/**
32
	 * Convert a timestamp into a nice format.
33
	 *
34
	 * @param string $output HTML value output
35
	 * @param array  $entry The GF entry array
36
	 * @param  array $field_settings Settings for the particular GV field,
37
	 * @param array $field Current field being displayed
38
	 *
39
	 * @since 1.17
40
	 *
41
	 * @return string If Gravity Flow not found, or entry not processed yet, returns initial value. Otherwise, returns name of workflow step.
42
	 */
43
	function modify_entry_value_workflow_current_status_timestamp( $output, $entry, $field_settings, $field ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
44
		$timestamp = gform_get_meta( $entry['id'], 'workflow_current_status_timestamp' );
45
46
		if ( ! $timestamp ) {
47
			return $timestamp;
48
		}
49
50
		return GVCommon::format_date( date( 'Y-m-d H:i:s', $timestamp ), 'format=' . \GV\Utils::get( $field_settings, 'date_display' ) );
51
	}
52
53
	public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) {
54
		if ( $context == 'edit' ) {
55
			return $field_options;
56
		}
57
58
		$this->add_field_support( 'date_display', $field_options );
59
60
		return $field_options;
61
	}
62
}
63
64
new GravityView_Field_Workflow_Current_Status_Timestamp;
65