GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-plugin-hooks-gravity-flow.php
Go to the documentation of this file.
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 GravityView <[email protected]>
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  */
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  add_filter( 'gravityview/admin/available_fields', array( $this, 'maybe_add_non_default_fields' ), 10, 3 );
39 
40  add_filter( 'gravityview/adv_filter/field_filters', array( $this, 'maybe_add_non_default_filter_fields' ), 10, 2 );
41 
42  add_action( 'gravityflow_post_process_workflow', array( $this, 'clear_cache_after_workflow' ), 10, 4 );
43  }
44 
45  /**
46  * Clears GravityView entry cache after running a Gravity Flow Workflow
47  *
48  * @param array $form
49  * @param int $entry_id
50  * @param int $step_id
51  * @param int $starting_step_id
52  *
53  * @return void
54  */
55  public function clear_cache_after_workflow( $form, $entry_id, $step_id, $starting_step_id ) {
56  do_action( 'gravityview_clear_form_cache', $form['id'] );
57  }
58 
59  /**
60  * Get the available status choices from Gravity Flow
61  *
62  * @uses Gravity_Flow::get_entry_meta()
63  *
64  * @since 1.17.3
65  *
66  * @param int $form_id
67  * @param string $status_key By default, get all statuses
68  *
69  * @return array
70  */
71  public static function get_status_options( $form_id = 0, $status_key = 'workflow_final_status' ) {
72 
73  if( empty( $form_id ) ) {
74  $form_id = GravityView_View::getInstance()->getFormId();
75  }
76 
77  $entry_meta = gravity_flow()->get_entry_meta( array(), $form_id );
78 
79  return (array) \GV\Utils::get( $entry_meta, $status_key . '/filter/choices' );
80  }
81 
82 
83  /**
84  * Get the list of active Workflow Steps and Workflow Step Statuses
85  *
86  * @since 1.17.3
87  *
88  * @uses Gravity_Flow_API::get_current_step
89  *
90  * @param array $fields Array of searchable fields
91  * @param int $form_id
92  *
93  * @return array Updated Array of searchable fields
94  */
95  public function modify_search_bar_fields_dropdown( $fields, $form_id ) {
96 
97  $GFlow = new Gravity_Flow_API( $form_id );
98 
99  $workflow_steps = $GFlow->get_steps();
100 
101  if( $workflow_steps ) {
102 
103  foreach ( $workflow_steps as $step ) {
104 
105  $step_id = sprintf( 'workflow_step_status_%d', $step->get_id() );
106 
107  $fields[ $step_id ] = array(
108  'label' => sprintf( _x( 'Status: %s', 'Gravity Flow Workflow Step Status', 'gk-gravityview' ), $step->get_name() ),
109  'type' => 'select',
110  );
111  }
112 
113  $fields['workflow_step'] = array(
114  'label' => esc_html__( 'Workflow Step', 'gk-gravityview' ),
115  'type' => 'select',
116  );
117 
118  $fields['workflow_final_status'] = array(
119  'label' => esc_html__( 'Workflow Status', 'gk-gravityview' ),
120  'type' => 'select',
121  );
122  }
123 
124  return $fields;
125  }
126 
127  /**
128  * Add the current status timestamp field to available Advanced Filters.
129  */
130  public function maybe_add_non_default_filter_fields( $fields, $view_id ) {
131  if ( ( $insert_at = array_search( 'workflow_final_status', wp_list_pluck( $fields, 'key' ) ) ) !== false ) {
132  $fields_end = array_splice( $fields, $insert_at + 1 );
133 
134  $fields[] = array(
135  'text' => __( 'Workflow Current Status Timestamp', 'gk-gravityview' ),
136  'operators' => array( '>', '<' ),
137  'placeholder' => 'yyyy-mm-dd',
138  'cssClass' => 'datepicker ymd_dash',
139  'key' => 'workflow_current_status_timestamp',
140  'preventMultiple' => false,
141  );
142 
143  $fields = array_merge( $fields, $fields_end );
144  }
145  return $fields;
146  }
147 
148  /**
149  * Add the current status timestamp field to available View configuration fields.
150  */
151  public function maybe_add_non_default_fields( $fields, $form, $zone ) {
152  if ( strpos( implode( ' ', array_keys( $fields ) ), 'workflow' ) !== false ) {
153  $keys = array_keys( $fields );
154  $values = array_values( $fields );
155 
156  if ( ( $insert_at = array_search( 'workflow_final_status', $keys ) ) !== false ) {
157  $keys_end = array_splice( $keys, $insert_at + 1 );
158  $values_end = array_splice( $values, $insert_at + 1 );
159 
160  $keys[] = 'workflow_current_status_timestamp';
161  $values[] = array(
162  'label' => __( 'Workflow Current Status Timestamp', 'gk-gravityview' ),
163  'type' => 'workflow_current_status_timestamp',
164  );
165 
166  $fields = array_combine( $keys, $values ) + array_combine( $keys_end, $values_end );
167  }
168  }
169 
170  return $fields;
171  }
172 
173 }
174 
maybe_add_non_default_fields( $fields, $form, $zone)
Add the current status timestamp field to available View configuration fields.
static getInstance( $passed_post=NULL)
clear_cache_after_workflow( $form, $entry_id, $step_id, $starting_step_id)
Clears GravityView entry cache after running a Gravity Flow Workflow.
static get_status_options( $form_id=0, $status_key='workflow_final_status')
Get the available status choices from Gravity Flow.
if(gravityview() ->plugin->is_GF_25()) $form
if(empty( $created_by)) $form_id
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
modify_search_bar_fields_dropdown( $fields, $form_id)
Get the list of active Workflow Steps and Workflow Step Statuses.
Abstract class that makes it easy for plugins and themes to register no-conflict scripts and styles...
add_hooks()
Filter the values shown in GravityView frontend.
maybe_add_non_default_filter_fields( $fields, $view_id)
Add the current status timestamp field to available Advanced Filters.