Completed
Push — develop ( 416feb...3f2c38 )
by Zack
08:43 queued 01:46
created

get_status_options()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 10
rs 9.4285
c 1
b 0
f 1
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 111.

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 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() {
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/search/searchable_fields', array( $this, 'modify_search_bar_fields_dropdown'), 10, 2 );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
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 ) {
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...
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;