Created
March 17, 2018 18:49
-
-
Save Idealien/e48e9e3dd1990c61e3cfdd67e9658037 to your computer and use it in GitHub Desktop.
Gravity Flow - Custom Column for status table based on creator, assignee, etc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'gravityflow_columns_status_table', 'custom_column_titles', 10, 3 ); | |
function custom_column_titles( $columns, $args, $table ) { | |
$new_column = array( | |
'user_action' => 'User Action', | |
); | |
$pre_columns = array_slice( $columns, 0, 2 ); | |
$post_columns = array_slice( $columns, 2 ); | |
$columns = array_merge( $pre_columns, $new_column, $post_columns ); | |
return $columns; | |
} | |
add_filter( 'gravityflow_field_value_status_table', 'custom_column_field_values', 10, 4 ); | |
function custom_column_field_values( $value, $form_id, $column_name, $entry ) { | |
if ( $column_name == 'user_action' ) { | |
$value = 'View / Edit'; | |
$api = new Gravity_Flow_API( $form_id ); | |
$step = $api->get_current_step( $entry ); | |
$assignees = $step->get_assignees(); | |
$current_user = wp_get_current_user(); | |
if ( $entry['created_by'] == $current_user->ID ) { | |
switch ( $step->get_type() ) : | |
case 'approval': | |
$value = 'View'; | |
gravity_flow()->log_debug( __METHOD__ . '(): JO: ' . 'Approval' ); | |
break; | |
case 'user_input': | |
gravity_flow()->log_debug( __METHOD__ . '(): JO: ' . 'User Input' ); | |
$value = 'Edit'; | |
break; | |
endswitch; | |
} | |
if ( $assignees ) { | |
$current_assignee = false; | |
foreach( $assignees as $assignee) { | |
switch( $assignee->get_type() ){ | |
case 'user_id': | |
if( $assignee->get_ID() == $current_user->ID ) { | |
$current_assignee = true; | |
} | |
break; | |
case 'role': | |
if( in_array( $assignee->get_ID(), $current_user->roles, TRUE) ) { | |
$current_assignee = true; | |
} | |
break; | |
} | |
} | |
if( $current_assignee == true ) { | |
switch ( $step->get_type() ) : | |
case 'approval': | |
$value = 'Assess'; | |
break; | |
case 'user_input': | |
$value = 'View'; | |
break; | |
endswitch; | |
} | |
} | |
} | |
if ( $column_name == 'date_created' ) { | |
$value = date( 'm/d/Y', strtotime( $entry['date_created'] ) ); | |
} | |
return $value; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment