1
|
|
|
<?php |
|
|
|
|
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() { |
|
|
|
|
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 ) { |
|
|
|
|
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 ) { |
|
|
|
|
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; |
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.