/**
  * Processes a status update for a specified assignee of the current step of the specified entry.
  *
  * @param $entry_id
  * @param string $assignee_key
  */
 function post_entries_assignees($entry_id, $assignee_key = null)
 {
     global $HTTP_RAW_POST_DATA;
     $capability = apply_filters('gravityflow_web_api_capability_post_entries_assignees', 'gravityflow_create_steps');
     $this->authorize($capability);
     if (empty($assignee_key)) {
         $this->end(400, 'Bad request');
     }
     $entry = GFAPI::get_entry($entry_id);
     if (empty($entry)) {
         $this->end(404, 'Entry not found');
     }
     $form_id = absint($entry['form_id']);
     $api = new Gravity_Flow_API($form_id);
     $step = $api->get_current_step($entry);
     $assignee = new Gravity_Flow_Assignee($assignee_key, $step);
     if (!isset($HTTP_RAW_POST_DATA)) {
         $HTTP_RAW_POST_DATA = file_get_contents('php://input');
     }
     $data = json_decode($HTTP_RAW_POST_DATA, true);
     $new_status = $data['status'];
     $form = GFAPI::get_form($form_id);
     $step->process_assignee_status($assignee, $new_status, $form);
     $api->process_workflow($entry_id);
     $response = 'Status updated successfully';
     $this->end(200, $response);
 }
 /**
  * Get the value of the Workflow Step based on the `workflow_step` entry meta int value
  *
  * @uses Gravity_Flow_API::get_current_step
  *
  * @param string $output HTML value output
  * @param array  $entry The GF entry array
  * @param  array $field_settings Settings for the particular GV field
  * @param array $field Current field being displayed
  *
  * @since 1.17
  *
  * @return string If Gravity Flow not found, or entry not processed yet, returns initial value. Otherwise, returns name of workflow step.
  */
 function modify_entry_value_workflow_step($output, $entry, $field_settings, $field)
 {
     // If not set, the entry hasn't started a workflow
     $has_workflow_step = isset($entry['workflow_step']);
     if ($has_workflow_step) {
         $GFlow = new Gravity_Flow_API($entry['form_id']);
         if ($current_step = $GFlow->get_current_step($entry)) {
             $output = esc_html($current_step->get_name());
         } else {
             $output = esc_html__('Workflow Complete', 'gravityview');
         }
         unset($GFlow);
     }
     return $output;
 }
示例#3
0
 function test_complex_process()
 {
     $settings = array('destination_rejected' => 'next');
     $approval_step_1_id = $this->_add_approval_step($settings);
     $settings = array('destination_complete' => $approval_step_1_id);
     $input_step_1_id = $this->_add_user_input_step($settings);
     $settings = array('destination_rejected' => $input_step_1_id);
     $input_step_2_id = $this->_add_user_input_step($settings);
     $approval_step_1 = $this->api->get_step($approval_step_1_id);
     // Set destination approved to the input step 2 as we didn't have the ID before
     $approval_step_1->destination_approved = $input_step_2_id;
     gravity_flow()->update_feed_meta($approval_step_1_id, $approval_step_1->get_feed_meta());
     // Add final approval step
     $approval_step_2_id = $this->_add_approval_step();
     $steps = $this->api->get_steps();
     $count_steps = count($steps);
     $this->assertEquals(4, $count_steps);
     $this->_create_entries();
     $entries = GFAPI::get_entries($this->form_id);
     $entry = $entries[0];
     // Simulate submission to add our entry meta
     $form = GFAPI::get_form($this->form_id);
     gravity_flow()->maybe_process_feed($entry, $form);
     $entry_id = $entry['id'];
     // Start workflow
     $this->api->process_workflow($entry_id);
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Check status
     $status = $this->api->get_status($entry);
     $this->assertEquals('pending', $status);
     // Reject entry
     $approval_step_1 = $this->api->get_step($approval_step_1_id, $entry);
     $approval_step_1->update_user_status(1, 'rejected');
     $this->api->process_workflow($entry_id);
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Check workflow has moved to next step (input 1)
     $current_step = $this->api->get_current_step($entry);
     $this->assertEquals($input_step_1_id, $current_step->get_id());
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Complete input step 1
     $input_step_1 = $this->api->get_step($input_step_1_id, $entry);
     $input_step_1->update_user_status(1, 'complete');
     $this->api->process_workflow($entry_id);
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Check workflow has moved to next step (approval 1)
     $current_step = $this->api->get_current_step($entry);
     $this->assertEquals($approval_step_1_id, $current_step->get_id());
     // Reject entry again
     $approva_step_1 = $this->api->get_step($approval_step_1_id, $entry);
     $approva_step_1->update_user_status(1, 'rejected');
     $this->api->process_workflow($entry_id);
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Check workflow has moved to next step (input 1)
     $current_step = $this->api->get_current_step($entry);
     $this->assertEquals($input_step_1_id, $current_step->get_id());
     // Complete input step 1
     $input_step_1 = $this->api->get_step($input_step_1_id, $entry);
     $input_step_1->update_user_status(1, 'complete');
     $this->api->process_workflow($entry_id);
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Approve entry
     $approva_step_1 = $this->api->get_step($approval_step_1_id, $entry);
     $approva_step_1->update_user_status(1, 'approved');
     $this->api->process_workflow($entry_id);
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Check workflow has moved to next step (input 2)
     $current_step = $this->api->get_current_step($entry);
     $this->assertEquals($input_step_2_id, $current_step->get_id());
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Complete input step 2
     $input_step_2 = $this->api->get_step($input_step_2_id, $entry);
     $input_step_2->update_user_status(1, 'complete');
     $this->api->process_workflow($entry_id);
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Check workflow has moved to next step (approval 2)
     $current_step = $this->api->get_current_step($entry);
     $this->assertEquals($approval_step_2_id, $current_step->get_id());
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Approve entry
     $approva_step_2 = $this->api->get_step($approval_step_2_id, $entry);
     $approva_step_2->update_user_status(1, 'approved');
     $this->api->process_workflow($entry_id);
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Check workflow has finished
     $current_step = $this->api->get_current_step($entry);
     $this->assertEquals(false, $current_step);
     $final_status = $this->api->get_status($entry);
     $this->assertEquals('approved', $final_status);
 }
 function maybe_process_admin_action($form, $entry)
 {
     $feedback = false;
     if (isset($_POST['_gravityflow_admin_action']) && check_admin_referer('gravityflow_admin_action', '_gravityflow_admin_action_nonce') && GFAPI::current_user_can_any('gravityflow_workflow_detail_admin_actions')) {
         $admin_action = rgpost('gravityflow_admin_action');
         switch ($admin_action) {
             case 'cancel_workflow':
                 $api = new Gravity_Flow_API($form['id']);
                 $success = $api->cancel_workflow($entry);
                 if ($success) {
                     $this->log_debug(__METHOD__ . '() - workflow cancelled. entry id ' . $entry['id']);
                     $feedback = esc_html__('Workflow cancelled.', 'gravityflow');
                 } else {
                     $this->log_debug(__METHOD__ . '() - workflow cancel failed. entry id ' . $entry['id']);
                     $feedback = esc_html__('The entry does not currently have an active step.', 'gravityflow');
                 }
                 break;
             case 'restart_step':
                 $api = new Gravity_Flow_API($form['id']);
                 $success = $api->restart_step($entry);
                 if ($success) {
                     $this->log_debug(__METHOD__ . '() - step restarted. entry id ' . $entry['id']);
                     $feedback = esc_html__('Workflow Step restarted.', 'gravityflow');
                 } else {
                     $this->log_debug(__METHOD__ . '() - step restart failed. entry id ' . $entry['id']);
                     $feedback = esc_html__('The entry does not currently have an active step.', 'gravityflow');
                 }
                 break;
             case 'restart_workflow':
                 $api = new Gravity_Flow_API($form['id']);
                 $api->restart_workflow($entry);
                 $this->log_debug(__METHOD__ . '() - workflow restarted. entry id ' . $entry['id']);
                 $feedback = esc_html__('Workflow restarted.', 'gravityflow');
                 break;
         }
         list($admin_action, $action_id) = rgexplode('|', $admin_action, 2);
         if ($admin_action == 'send_to_step') {
             $step_id = $action_id;
             $api = new Gravity_Flow_API($form['id']);
             $api->send_to_step($entry, $step_id);
             $new_step = $api->get_current_step($entry);
             $feedback = sprintf(esc_html__('Sent to step: %s', 'gravityflow'), $new_step->get_name());
         }
     }
     return $feedback;
 }