Completed
Pull Request — master (#716)
by Zack
09:51 queued 04:52
created

GravityView_Plugin_Hooks_Gravity_Flow::add_hooks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 9.4285
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 19 and the first side effect is on line 101.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

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

Loading history...
2
/**
3
 * Add Gravity Flow output to GravityView
4
 *
5
 * @file      class-gravityview-plugin-hooks-gravity-flow.php
6
 * @package   GravityView
7
 * @license   GPL2+
8
 * @author    Katz Web Services, Inc.
9
 * @link      https://gravityview.co
10
 * @copyright Copyright 2016, Katz Web Services, Inc.
11
 *
12
 * @since 1.17
13
 */
14
15
/**
16
 * @inheritDoc
17
 * @since 1.17
18
 */
19
class GravityView_Plugin_Hooks_Gravity_Flow extends GravityView_Plugin_and_Theme_Hooks {
20
21
	/**
22
	 * @var string Check for the class name, since that's needed by this class.
23
	 */
24
	protected $class_name = 'Gravity_Flow_API';
25
26
27
	/**
28
	 * Filter the values shown in GravityView frontend
29
	 *
30
	 * @since 1.17
31
	 */
32
	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...
33
34
		parent::add_hooks();
35
36
		add_filter( 'gravityview_field_entry_value_workflow_final_status', array( $this, 'modify_entry_value_workflow_final_status' ), 10, 4 );
37
38
		add_filter( 'gravityview_field_entry_value_workflow_step', array( $this, 'modify_entry_value_workflow_step' ), 10, 4 );
39
	}
40
41
	/**
42
	 * Convert the status key with the full status label. Uses custom labels, if set.
43
	 *
44
	 * @uses Gravity_Flow::translate_status_label()
45
	 *
46
	 * @param string $output HTML value output
47
	 * @param array  $entry The GF entry array
48
	 * @param  array $field_settings Settings for the particular GV field
49
	 * @param array $field Current field being displayed
50
	 *
51
	 * @since 1.17
52
	 *
53
	 * @return string If Gravity Flow not found, or entry not processed yet, returns initial value. Otherwise, returns name of workflow step.
54
	 */
55
	function modify_entry_value_workflow_final_status( $output, $entry, $field_settings, $field ) {
0 ignored issues
show
Unused Code introduced by
The parameter $entry 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...
Unused Code introduced by
The parameter $field_settings 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...
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...
56
57
		if( ! empty( $output ) ) {
58
			$output = gravity_flow()->translate_status_label( $output );
59
		}
60
61
		return $output;
62
	}
63
64
	/**
65
	 * Get the value of the Workflow Step based on the `workflow_step` entry meta int value
66
	 *
67
	 * @uses Gravity_Flow_API::get_current_step
68
	 *
69
	 * @param string $output HTML value output
70
	 * @param array  $entry The GF entry array
71
	 * @param  array $field_settings Settings for the particular GV field
72
	 * @param array $field Current field being displayed
73
	 *
74
	 * @since 1.17
75
	 *
76
	 * @return string If Gravity Flow not found, or entry not processed yet, returns initial value. Otherwise, returns name of workflow step.
77
	 */
78
	function modify_entry_value_workflow_step( $output, $entry, $field_settings, $field ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field_settings 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...
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...
79
80
		// If not set, the entry hasn't started a workflow
81
		$has_workflow_step = isset( $entry['workflow_step'] );
82
83
		if( $has_workflow_step ) {
84
85
			$GFlow = new Gravity_Flow_API( $entry['form_id'] );
86
87
			if ( $current_step = $GFlow->get_current_step( $entry ) ) {
88
				$output = esc_html( $current_step->get_name() );
89
			} else {
90
				$output = esc_html__( 'Workflow Complete', 'gravityview' );
91
			}
92
93
			unset( $GFlow );
94
		}
95
96
		return $output;
97
	}
98
99
}
100
101
new GravityView_Plugin_Hooks_Gravity_Flow;