示例#1
0
 function test_send_to_step()
 {
     $step1_id = $this->_add_approval_step();
     $step2_id = $this->_add_approval_step();
     $steps = $this->api->get_steps();
     $count_steps = count($steps);
     $this->assertEquals(2, $count_steps);
     $this->_create_entries();
     $entries = GFAPI::get_entries($this->form_id);
     $entry = $entries[0];
     $entry_id = $entry['id'];
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Check status
     $status = $this->api->get_status($entry);
     $this->assertEquals('pending', $status);
     // Approve
     $step = $this->api->get_step($step1_id, $entry);
     $assignees = $step->get_assignees();
     $this->assertEquals(1, count($assignees));
     $assignees[0]->update_status('approved');
     $this->api->process_workflow($entry_id);
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     $current_step = $this->api->get_current_step($entry);
     $this->assertEquals($step2_id, $current_step->get_id());
     // Check status
     $status = $this->api->get_status($entry);
     $this->assertEquals('pending', $status);
     // Send back to first step
     $this->api->send_to_step($entry, $step1_id);
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Check status
     $status = $this->api->get_status($entry);
     $this->assertEquals('pending', $status);
     $current_step = $this->api->get_current_step($entry);
     $this->assertEquals($step1_id, $current_step->get_id());
 }
 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;
 }