function get_forms_steps($form_id) { $capability = apply_filters('gravityflow_web_api_capability_get_forms_steps', 'gravityflow_create_steps'); $this->authorize($capability); $api = new Gravity_Flow_API($form_id); $steps = $api->get_steps(); $response = array(); foreach ($steps as $step) { $response[] = array('id' => $step->get_id(), 'type' => $step->get_type(), 'label' => $step->get_label(), 'name' => $step->get_name(), 'is_active' => $step->is_active(), 'entry_count' => $step->entry_count(), 'supports_expiration' => $step->supports_expiration(), 'assignees' => $this->get_assignees_array($step), 'settings' => $step->get_feed_meta()); } $this->end(200, $response); }
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); }
public function action_gform_post_add_entry($entry, $form) { $this->log_debug(__METHOD__ . '(): starting'); $api = new Gravity_Flow_API($form['id']); $steps = $api->get_steps(); if ($steps) { $this->log_debug(__METHOD__ . '(): triggering workflow for entry ID: ' . $entry['id']); gravity_flow()->maybe_process_feed($entry, $form); $api->process_workflow($entry['id']); } }