|
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 Gravity Flow constant |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $constant_name = 'GRAVITY_FLOW_VERSION'; |
|
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/search/searchable_fields', array( $this, 'modify_search_bar_fields_dropdown'), 10, 2 ); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Get the available status choices from Gravity Flow |
|
43
|
|
|
* |
|
44
|
|
|
* @uses Gravity_Flow::get_entry_meta() |
|
45
|
|
|
* |
|
46
|
|
|
* @since 1.17.3 |
|
47
|
|
|
* |
|
48
|
|
|
* @param int $form_id |
|
49
|
|
|
* @param string $status_key By default, get all statuses |
|
50
|
|
|
* |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
|
public static function get_status_options( $form_id = 0, $status_key = 'workflow_final_status' ) { |
|
54
|
|
|
|
|
55
|
|
|
if( empty( $form_id ) ) { |
|
56
|
|
|
$form_id = GravityView_View::getInstance()->getFormId(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$entry_meta = gravity_flow()->get_entry_meta( array(), $form_id ); |
|
60
|
|
|
|
|
61
|
|
|
return (array) rgars( $entry_meta, $status_key . '/filter/choices' ); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Get the list of active Workflow Steps and Workflow Step Statuses |
|
67
|
|
|
* |
|
68
|
|
|
* @since 1.17.3 |
|
69
|
|
|
* |
|
70
|
|
|
* @uses Gravity_Flow_API::get_current_step |
|
71
|
|
|
* |
|
72
|
|
|
* @param array $fields Array of searchable fields |
|
73
|
|
|
* @param int $form_id |
|
74
|
|
|
* |
|
75
|
|
|
* @return array Updated Array of searchable fields |
|
76
|
|
|
*/ |
|
77
|
|
|
function modify_search_bar_fields_dropdown( $fields, $form_id ) { |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
$GFlow = new Gravity_Flow_API( $form_id ); |
|
80
|
|
|
|
|
81
|
|
|
$workflow_steps = $GFlow->get_steps(); |
|
82
|
|
|
|
|
83
|
|
|
if( $workflow_steps ) { |
|
84
|
|
|
|
|
85
|
|
|
foreach ( $workflow_steps as $step ) { |
|
86
|
|
|
|
|
87
|
|
|
$step_id = sprintf( 'workflow_step_status_%d', $step->get_id() ); |
|
88
|
|
|
|
|
89
|
|
|
$fields[ $step_id ] = array( |
|
90
|
|
|
'label' => sprintf( _x( 'Status: %s', 'Gravity Flow Workflow Step Status', 'gravityview' ), $step->get_name() ), |
|
91
|
|
|
'type' => 'select', |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$fields['workflow_step'] = array( |
|
96
|
|
|
'label' => esc_html__( 'Workflow Step', 'gravityview' ), |
|
97
|
|
|
'type' => 'select', |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
$fields['workflow_final_status'] = array( |
|
101
|
|
|
'label' => esc_html__( 'Workflow Status', 'gravityview' ), |
|
102
|
|
|
'type' => 'select', |
|
103
|
|
|
); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $fields; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
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.