Handle process visualization and going from one step to another
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
class Wiaas_Dates_List_Field extends GF_Field_List {
|
||||
|
||||
public $type = 'wiaas_date_list';
|
||||
|
||||
|
||||
public function get_form_editor_field_title() {
|
||||
return esc_attr__( 'Date List', 'wiaas' );
|
||||
}
|
||||
|
||||
public function sanitize_settings() {
|
||||
|
||||
parent::sanitize_settings();
|
||||
|
||||
//$this->inputType = 'date';
|
||||
}
|
||||
|
||||
public function get_list_input($has_columns, $column, $value, $form_id) {
|
||||
|
||||
$tabindex = $this->get_tabindex();
|
||||
$disabled = $this->is_form_editor() ? 'disabled' : '';
|
||||
|
||||
return "<input type='date' name='input_{$this->id}[]' value='" . esc_attr( $value ) . "' {$tabindex} {$disabled}/>";
|
||||
}
|
||||
|
||||
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
|
||||
|
||||
return $this->get_value_entry_detail($value, '', false, 'html', 'screen' );
|
||||
}
|
||||
}
|
||||
|
||||
GF_Fields::register( new Wiaas_Dates_List_Field() );
|
||||
@@ -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>'
|
||||
));
|
||||
|
||||
@@ -7,24 +7,6 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
* @var string
|
||||
*/
|
||||
public $_step_type = 'wiaas_delivery_step';
|
||||
|
||||
private static $delivery_action_form_title_prefix = 'DELIVERY ACTION TYPE:';
|
||||
|
||||
private static $delivery_action_types = array(
|
||||
'DELIVERY ACTION TYPE: Customer acceptance' => 'customer-acceptance',
|
||||
'DELIVERY ACTION TYPE: Validate Questionnaire' => 'validate-questionnaire',
|
||||
'DELIVERY ACTION TYPE: Manual' => 'manual',
|
||||
'DELIVERY ACTION TYPE: Schedule meeting' => 'schedule-meeting'
|
||||
);
|
||||
|
||||
public static function get_delivery_action_types() {
|
||||
return array_keys(self::$delivery_action_types);
|
||||
}
|
||||
|
||||
public static function get_delivery_action_type_prefix() {
|
||||
return self::$delivery_action_form_title_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns label for Wiass Delivery Process Step
|
||||
* @return string
|
||||
@@ -44,7 +26,17 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
$forms = $this->get_action_forms_choices();
|
||||
$form_choices[] = array( 'label' => esc_html__( 'Select a Form', 'wiaas' ), 'value' => '' );
|
||||
foreach ( $forms as $form ) {
|
||||
$form_choices[] = array( 'label' => $form['title'], 'value' => $form['id'] );
|
||||
|
||||
$delivery_settings = rgar($form, 'wiaas_delivery_process');
|
||||
|
||||
$code = $form['id'];
|
||||
|
||||
if (! empty($delivery_settings['delivery_action_code'])) {
|
||||
|
||||
$code = $delivery_settings['delivery_action_code'];
|
||||
}
|
||||
|
||||
$form_choices[] = array( 'label' => $form['title'], 'value' => $code );
|
||||
}
|
||||
|
||||
$settings = array(
|
||||
@@ -77,15 +69,47 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
return $settings;
|
||||
}
|
||||
|
||||
public function start() {
|
||||
|
||||
$complete = parent::start();
|
||||
|
||||
if ($complete) {
|
||||
|
||||
$this->update_step_status('complete');
|
||||
} else {
|
||||
|
||||
$this->update_step_status('pending');
|
||||
}
|
||||
|
||||
return $complete;
|
||||
}
|
||||
|
||||
public function evaluate_status() {
|
||||
|
||||
return 'pending';
|
||||
}
|
||||
|
||||
public function get_status_label($status) {
|
||||
|
||||
$label = parent::get_status_label($status);
|
||||
|
||||
if (empty($label)) {
|
||||
|
||||
$label = __('Not started', 'wiaas');
|
||||
}
|
||||
|
||||
return $label;
|
||||
}
|
||||
|
||||
public function update_step_status($status = false) {
|
||||
|
||||
if (isset( $_POST['_gravityflow_admin_action'] ) ) {
|
||||
if ($status === 'cancelled' && $admin_action = rgpost( 'gravityflow_admin_action' )) {
|
||||
|
||||
$admin_action = rgpost( 'gravityflow_admin_action' );
|
||||
list( $base_admin_action, $step_id ) = rgexplode( '|', $admin_action, 2 );
|
||||
|
||||
list( $base_admin_action, $action_id ) = rgexplode( '|', $admin_action, 2 );
|
||||
|
||||
if ($base_admin_action === 'send_to_step' && $this->get_status() === 'pending') {
|
||||
$next_step = gravity_flow()->get_next_step($this, $this->get_entry(), $this->get_form());
|
||||
// going to next step
|
||||
if ($base_admin_action === 'send_to_step' && $next_step && $next_step->get_id() == $step_id) {
|
||||
|
||||
$status = 'complete';
|
||||
}
|
||||
@@ -157,18 +181,6 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates current step status based on target form entry status
|
||||
*
|
||||
* If target form entry has associated workflow current step will complete its status
|
||||
* only when target form entry workflow is completed
|
||||
* @return string
|
||||
*/
|
||||
public function status_evaluation() {
|
||||
|
||||
// return 'pending';
|
||||
}
|
||||
|
||||
public function workflow_detail_box($form, $args) {
|
||||
parent::workflow_detail_box($form, $args);
|
||||
|
||||
@@ -225,27 +237,6 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
return $action_forms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves delivery action type that is executed with this step
|
||||
* @return string
|
||||
*/
|
||||
public function get_delivery_action_type() {
|
||||
$target_form = GFAPI::get_form( $this->target_form_id );
|
||||
return self::$delivery_action_types[$target_form['title']];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves target form entry created when step was started
|
||||
* @return array|null
|
||||
*/
|
||||
public function get_target_form_entry() {
|
||||
$entry = GFAPI::get_entry($this->get_target_form_entry_id());
|
||||
if(is_wp_error($entry)) {
|
||||
return null;
|
||||
}
|
||||
return $entry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves target form entry id created when step was started
|
||||
|
||||
@@ -27,6 +27,10 @@ class Wiaas_Field_Order_Bundle_Document extends GF_Field_FileUpload {
|
||||
);
|
||||
}
|
||||
|
||||
public function get_input_type() {
|
||||
return 'fileupload';
|
||||
}
|
||||
|
||||
public function get_form_editor_field_title() {
|
||||
return esc_attr__( 'Bundle Document', 'wiaas' );
|
||||
}
|
||||
|
||||
@@ -8,6 +8,11 @@ class Wiaas_Field_Order_Supplier_Select extends GF_Field_Select {
|
||||
|
||||
public $type = 'wiaas_order_supplier';
|
||||
|
||||
public function get_input_type() {
|
||||
// set this input type so delivery workflow step can be assigned to supplier in this field
|
||||
return 'workflow_assignee_select';
|
||||
}
|
||||
|
||||
public function get_form_editor_field_title() {
|
||||
return esc_attr__( 'Supplier Select', 'wiaas' );
|
||||
}
|
||||
@@ -41,9 +46,9 @@ class Wiaas_Field_Order_Supplier_Select extends GF_Field_Select {
|
||||
|
||||
private function _get_selected_supplier_display_name($value) {
|
||||
|
||||
list ($order_id, $supplier_id) = explode('|', $value);
|
||||
list ($order_key, $supplier_id) = explode('|', $value);
|
||||
|
||||
if (! empty($order_id) && ! empty($supplier_id) && $order = wc_get_order($order_id)) {
|
||||
if (! empty($supplier_id)) {
|
||||
|
||||
return wiaas_get_organization_name($supplier_id);
|
||||
}
|
||||
@@ -65,7 +70,7 @@ class Wiaas_Field_Order_Supplier_Select extends GF_Field_Select {
|
||||
foreach ($suppliers as $supplier_id => $supplier_name) {
|
||||
|
||||
$choices[] = array(
|
||||
'value' => $order_id . '|' . $supplier_id,
|
||||
'value' => 'wiaas_organization_order_' . $order_id . '|' . $supplier_id,
|
||||
'text' => $supplier_name
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,8 +71,6 @@ class Wiaas_Order_Fields {
|
||||
return false;
|
||||
}
|
||||
|
||||
error_log(json_encode('here'));
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$bundle_item = $order->get_item($bundle_item_id);
|
||||
@@ -129,6 +127,15 @@ class Wiaas_Order_Fields {
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_supplier':
|
||||
$suppliers = wiaas_get_order_suppliers($order);
|
||||
|
||||
$supplier_ids = array_keys($suppliers);
|
||||
|
||||
$supplier_id = $supplier_ids[0];
|
||||
|
||||
$entry[(string) $field->id] = 'wiaas_organization_order_' . $order_id . '|' . $supplier_id;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user