|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* @file class-gravityview-field-workflow_final_status.php |
|
4
|
|
|
* @since 1.17.2 |
|
5
|
|
|
* @package GravityView |
|
6
|
|
|
* @subpackage includes\fields |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
class GravityView_Field_Workflow_Final_Status extends GravityView_Field { |
|
10
|
|
|
|
|
11
|
|
|
var $name = 'workflow_final_status'; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
var $group = 'meta'; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
public function __construct() { |
|
16
|
|
|
$this->label = esc_html__( 'Workflow Status', 'gravityview' ); |
|
17
|
|
|
$this->default_search_label = $this->label; |
|
18
|
|
|
$this->add_hooks(); |
|
19
|
|
|
parent::__construct(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
function add_hooks() { |
|
|
|
|
|
|
23
|
|
|
add_filter( 'gravityview_widget_search_filters', array( $this, 'modify_search_filters' ), 10, 3 ); |
|
24
|
|
|
|
|
25
|
|
|
add_filter( 'gravityview_field_entry_value_workflow_final_status', array( $this, 'modify_entry_value_workflow_final_status' ), 10, 4 ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Convert the status key with the full status label. Uses custom labels, if set. |
|
30
|
|
|
* |
|
31
|
|
|
* @uses Gravity_Flow::translate_status_label() |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $output HTML value output |
|
34
|
|
|
* @param array $entry The GF entry array |
|
35
|
|
|
* @param array $field_settings Settings for the particular GV field |
|
36
|
|
|
* @param array $field Current field being displayed |
|
37
|
|
|
* |
|
38
|
|
|
* @since 1.17 |
|
39
|
|
|
* |
|
40
|
|
|
* @return string If Gravity Flow not found, or entry not processed yet, returns initial value. Otherwise, returns name of workflow step. |
|
41
|
|
|
*/ |
|
42
|
|
|
function modify_entry_value_workflow_final_status( $output, $entry, $field_settings, $field ) { |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
if( ! empty( $output ) ) { |
|
45
|
|
|
$output = gravity_flow()->translate_status_label( $output ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $output; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Populate the Final Status Search Bar field dropdown with all the statuses in Gravity Flow |
|
54
|
|
|
* |
|
55
|
|
|
* @since 1.17.3 |
|
56
|
|
|
* |
|
57
|
|
|
* @param array $search_fields |
|
58
|
|
|
* @param GravityView_Widget_Search $widget |
|
59
|
|
|
* @param array $widget_args |
|
60
|
|
|
* |
|
61
|
|
|
* @return array |
|
62
|
|
|
*/ |
|
63
|
|
|
function modify_search_filters( $search_fields = array(), GravityView_Widget_Search $widget, $widget_args = array() ) { |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
foreach ( $search_fields as & $search_field ) { |
|
66
|
|
|
if ( $this->name === $search_field['key'] ) { |
|
67
|
|
|
$search_field['choices'] = GravityView_Plugin_Hooks_Gravity_Flow::get_status_options(); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $search_fields; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
new GravityView_Field_Workflow_Final_Status; |
|
77
|
|
|
|
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.