Handle process visualization and going from one step to another

This commit is contained in:
Almira Krdzic
2018-11-01 10:43:15 +01:00
parent 308c836460
commit 3d16d5027b
19 changed files with 448 additions and 1786 deletions

View File

@@ -27,16 +27,112 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
public function init() {
parent::init();
add_filter('gravityflow_get_users_args', array ($this, 'allow_only_administrator_to_be_assigned_to_step'));
add_filter('gravityflow_assignee_choices', array ($this, 'add_orders_assignee_choices'));
add_filter('gravityflow_admin_actions_workflow_detail', array ($this, 'filter_process_send_to_step_options'), 10, 5);
add_filter('gravityflow_step_assignees', array ($this, 'maybe_assign_organization_to_step'), 10, 2);
}
public function init_ajax() {
parent::init_ajax();
add_action( 'wp_ajax_wiaas_get_action_entry', array( $this, 'ajax_get_action_entry' ) );
// this AJAX action is here and not in /admin folder because of Gravity Forms extension logic
add_action( 'wp_ajax_wiaas_delivery_get_form', array( $this, 'ajax_get_form' ) );
}
public function maybe_assign_organization_to_step($assignees, Gravity_Flow_Step $step) {
$mapped_assignees = array();
foreach ($assignees as $assignee) {
if (strpos($assignee->get_type(), 'wiaas_organization_order_') !== false) {
$organization_id = $assignee->get_id();
$user_ids = wiaas_get_organization_user_ids($organization_id);
if (empty($user_ids)) {
continue;
}
$user_id = $user_ids[0];
$mapped_assignees[] = $step->get_assignee( array(
'id' => $user_id,
'type' => 'user_id',
'editable_fields' => $assignee->get_editable_fields()
) );
continue;
}
$mapped_assignees[] = $assignee;
}
return $mapped_assignees;
}
public function filter_process_send_to_step_options($admin_actions, $current_step, $steps, $form, $entry) {
$delivery_process_actions = array();
if ( $current_step ) {
$previous_step_id = null;
// get previous step id for current step
foreach ($steps as $index => $step) {
$next_step = gravity_flow()->get_next_step($step, $entry, $form);
if ($next_step && $next_step->get_id() === $current_step->get_id()) {
$previous_step_id = $step->get_id();
}
}
if (! empty($previous_step_id)) {
$delivery_process_actions[] = array(
'label' => esc_html__( 'Previous step', 'wiaas' ),
'value' => 'send_to_step|' . $previous_step_id
);
}
// get next step id for current step
$next_step = gravity_flow()->get_next_step($current_step, $entry, $form);
if ($next_step) {
$delivery_process_actions[] = array(
'label' => esc_html__( 'Next step', 'wiaas' ),
'value' => 'send_to_step|' . $next_step->get_id()
);
}
}
return $delivery_process_actions;
}
public function allow_only_administrator_to_be_assigned_to_step($args) {
$args['role'] = 'administrator';
//$args['exclude'] = array( 1 ); // exclude super admin user
return $args;
}
public static function add_orders_assignee_choices($choices) {
return $choices;
}
public function ajax_get_form() {
$form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0;
@@ -65,14 +161,6 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
die();
}
public function ajax_get_action_entry() {
$form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0;
$entry_id = absint( rgget( 'entry_id' ) );
}
/**
* Extends Gravity Form entry metadata with 'wiaas_delivery_process_id'
*
@@ -223,7 +311,7 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
array( 'value' => '', 'label' => 'Select action code ...' ),
array( 'value' => 'customer-acceptance', 'label' => 'Customer acceptance' ),
array( 'value' => 'validate-questionnaire', 'label' => 'Validate Questionnaire' ),
array( 'value' => 'schedule-meeting', 'label' => 'Schedule meeting' )
array( 'value' => 'schedule-meeting', 'label' => 'Schedule meeting' ),
),
'after_select' => '<p class="description"> Choose action code for action form.</p>'
));