65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
|
|
class Wiass_REST_Delivery_Process_API {
|
|
/**
|
|
* Endpoint namespace.
|
|
*
|
|
* @var string
|
|
*/
|
|
private static $namespace = 'wiaas';
|
|
|
|
|
|
public static function register_routes() {
|
|
register_rest_route( self::$namespace, 'next-delivery-steps', array(
|
|
'methods' => 'GET',
|
|
'callback' => array(__CLASS__, 'get_next_actions_for_user'),
|
|
) );
|
|
}
|
|
|
|
|
|
public static function get_next_actions_for_user() {
|
|
$current_user = wp_get_current_user();
|
|
|
|
$field_filters = array();
|
|
$field_filters[] = array(
|
|
'key' => 'workflow_user_id_' . $current_user->ID,
|
|
'value' => 'pending',
|
|
);
|
|
|
|
$user_roles = gravity_flow()->get_user_roles();
|
|
foreach ( $user_roles as $user_role ) {
|
|
$field_filters[] = array(
|
|
'key' => 'workflow_role_' . $user_role,
|
|
'value' => 'pending',
|
|
);
|
|
}
|
|
|
|
$field_filters['mode'] = 'any';
|
|
|
|
$search_criteria = array();
|
|
$search_criteria['field_filters'] = $field_filters;
|
|
$search_criteria['status'] = 'active';
|
|
|
|
$form_ids = gravity_flow()->get_workflow_form_ids();
|
|
|
|
$total_count = 7;
|
|
|
|
|
|
$entries = GFAPI::get_entries( $form_ids, $search_criteria, null, null, $total_count );
|
|
|
|
$data = array();
|
|
foreach ($entries as $entry) {
|
|
$step = gravity_flow()->get_step( $entry['workflow_step'] );
|
|
$data[] = array(
|
|
'order_id' => $entry['wiaas_delivery_order_id'],
|
|
'order_number' => $entry['wiaas_delivery_order_id'],
|
|
'status' => $entry['workflow_final_status'],
|
|
'step_action' => $step->get_name(),
|
|
);
|
|
}
|
|
|
|
$response = new WP_REST_Response( $data );
|
|
|
|
return $response;
|
|
}
|
|
} |