Handle assigment for order delivery flow
This commit is contained in:
@@ -32,18 +32,17 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
|
||||
|
||||
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();
|
||||
|
||||
// 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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle organization assignee for step (Map users from organization as assignees to step)
|
||||
*
|
||||
* @param $assignees
|
||||
* @param Gravity_Flow_Step $step
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function maybe_assign_organization_to_step($assignees, Gravity_Flow_Step $step) {
|
||||
|
||||
$mapped_assignees = array();
|
||||
@@ -78,46 +77,6 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
|
||||
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) {
|
||||
|
||||
@@ -133,34 +92,6 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
|
||||
return $choices;
|
||||
}
|
||||
|
||||
public function ajax_get_form() {
|
||||
|
||||
$form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0;
|
||||
|
||||
$field_id = sanitize_text_field( rgget( 'field_id' ) );
|
||||
|
||||
$entry_id = absint( rgget( 'entry_id' ) );
|
||||
|
||||
$field_values = array( $field_id => $entry_id );
|
||||
|
||||
gravity_form_enqueue_scripts( $form_id, true );
|
||||
|
||||
$is_admin = isset( $_GET['is_admin'] );
|
||||
if ( $is_admin ) {
|
||||
wp_enqueue_style( 'common', site_url() . '/wp-admin/css/common.css', array(), $this->_version );
|
||||
} else {
|
||||
wp_enqueue_style( 'common', get_stylesheet_directory_uri() . '/style.css', array(), $this->_version );
|
||||
}
|
||||
|
||||
wp_print_styles();
|
||||
wp_print_scripts();
|
||||
// Render an AJAX-enabled form.
|
||||
// https://www.gravityhelp.com/documentation/article/embedding-a-form/#function-call
|
||||
$html = gravity_form( $form_id, true, false, false, $field_values, true, 1, false );
|
||||
printf( "<div id='wiaas-delivery-process-form' style='padding:10px;'>%s</div>", $html );
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends Gravity Form entry metadata with 'wiaas_delivery_process_id'
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user