gravityflow_step_status_evaluation_approval

Allows the step status for the approval to be customised.

For situations where  the approval policy options of Any (only one approval required) or All (every approver must approve) do not meet your use case, you can use this filter to perform custom approval evaluation logic. 

Parameters

$step_status string The status of the step

$approvers Gravity_Flow_Assignee The array of Gravity_Flow_Assignee objects

$step Gravity_Flow_Step The current step

Example

This example would change the approval threshold for a specific step to require a minimum number of approvals (2) or a single rejection to complete the step.
The step assignee policy should be set to 'all' for the logic to apply.

<?php
add_filter( 'gravityflow_step_status_evaluation_approval', 'approval_status_evaluation', 10, 3 );
function approval_status_evaluation( $step_status, $approvers, $step ) {

	//Ensure you are only adjusting the desired step
	if ( $step->get_id() !== 58 ) {
		return $step_status;
	}

	//Modify this for your minimum number of approvals
	$approval_threshold = 2;

	$approval_count = 0;
	$pending_count = 0;

	$step_status = 'pending';

	foreach ( $approvers as $approver ) {

		$approver_status = $approver->get_status();

		if ( $approver_status == 'rejected' ) {
			$step_status = 'rejected';
			break;
		}
		if ( $step->assignee_policy == 'all' ) {
			if ( $approver_status == 'approved' ) {
				$approval_count++;
			} else {
				$pending_count++;
			}
		} else if ( empty( $approver_status ) || $approver_status == 'pending' ) {
			$step_status = 'pending';
		}
	}

	if( $step_status !== 'rejected') {
		gravity_flow()->log_debug( __METHOD__ . '(): Custom Evaluation Check: ' . $approval_count . ' approved with ' . $pending_count . ' outstanding.');
		if( $approval_count >= $approval_threshold ) {
			$step_status = 'approved';
			gravity_flow()->log_debug( __METHOD__ . '(): Does meet threshold criteria. Step approved.');
		} else {
			$step_status = 'pending';
			gravity_flow()->log_debug( __METHOD__ . '(): Does not meet threshold criteria.');
		}
	}

	return $step_status;
}

Placement

This code should be placed in the functions.php file of your active theme.

Since

This filter was added in version 2.2