197 lines
4.8 KiB
PHP
197 lines
4.8 KiB
PHP
<?php
|
|
|
|
class Wiaas_Admin_Delivery_Process {
|
|
|
|
public static function init() {
|
|
|
|
add_action( 'gravityflow_entry_detail', array( __CLASS__, 'display_process_steps_details' ), 10, 3 );
|
|
|
|
add_action( 'gravityflow_title_entry_detail', array( __CLASS__, 'process_title' ), 10, 3 );
|
|
}
|
|
|
|
|
|
public static function display_process_steps_details($form, $entry, $current_step) {
|
|
|
|
$delivery_settings = rgar($form, 'wiaas_delivery_process');
|
|
|
|
if ($delivery_settings['delivery_form_type'] === 'action') {
|
|
return;
|
|
}
|
|
|
|
// get process order ID
|
|
$order_id = absint($entry['wiaas_delivery_order_id']);
|
|
|
|
if (empty($order_id)) {
|
|
|
|
$order_field = GFCommon::get_fields_by_type($form, array( 'wiaas_order') )[0];
|
|
|
|
if ( ! empty($order_field)) {
|
|
|
|
$order_id = $entry[$order_field->id];
|
|
}
|
|
}
|
|
|
|
// display process steps
|
|
|
|
$workflow_api = new Gravity_Flow_API($form['id']);
|
|
|
|
$steps = $workflow_api->get_steps();
|
|
|
|
foreach ($steps as $index => $step) {
|
|
|
|
if (! $step->is_active()) {
|
|
continue;
|
|
}
|
|
|
|
$is_step_running = $step->get_status() === 'pending';
|
|
$is_step_completed = $step->get_status() === 'complete';
|
|
$is_current_step = $step->get_id() === $current_step->get_id();
|
|
|
|
//$disabled_style = $is_step_running ? '' : 'opacity: 0.5';
|
|
$completed_style = $is_step_completed ? 'border-left: 4px solid #46b450;' : '';
|
|
|
|
?>
|
|
|
|
<div class="postbox" style="<?php esc_attr_e($completed_style, 'wiaas') ?>">
|
|
|
|
<h3>
|
|
<span><?php esc_html_e($step->get_name(), 'wiaas') ?></span>
|
|
</h3>
|
|
|
|
<?php
|
|
if ($is_current_step) {
|
|
Gravity_Flow_Entry_Detail::maybe_show_instructions(true, true, $current_step, $form, $entry);
|
|
|
|
$action_form = GFAPI::get_form( $step->target_form_id );
|
|
|
|
if (empty($action_form)) {
|
|
|
|
echo '</div>';
|
|
|
|
continue;
|
|
}
|
|
|
|
$action_delivery_settings = rgar($action_form, 'wiaas_delivery_process');
|
|
|
|
?>
|
|
|
|
<div class="submitbox" style="padding: 10px;">
|
|
|
|
<table>
|
|
<tbody>
|
|
<?php
|
|
|
|
if (! $action_delivery_settings['automatic_action_entries_enabled']) {
|
|
|
|
$form_url = admin_url( 'admin-ajax.php' ) .
|
|
'?action=wiaas_delivery_get_form&order_id=' . $order_id .
|
|
'&form_id=' . $action_form['id'] .
|
|
'&wiaas_delivery_process_id=' . $entry['id'];
|
|
$form_url .= '&is_admin=1';
|
|
|
|
$form_link = sprintf(
|
|
'<a href="%s&TB_iframe=true&width=600&height=550" class="button button-primary thickbox">' .
|
|
'<i class="fa fa-plus"></i> ' . $action_form['title'] . '</a>',
|
|
$form_url );
|
|
|
|
echo $form_link;
|
|
}
|
|
|
|
echo '<br><br><br>';
|
|
|
|
$page_size = 20;
|
|
$search_criteria = array(
|
|
'status' => 'active',
|
|
'field_filters' => array(
|
|
array( 'key' => 'wiaas_delivery_process_id',
|
|
'value' => $entry['id']
|
|
),
|
|
),
|
|
);
|
|
$sorting = array( 'key' => 'date_created', 'direction' => 'DESC' );
|
|
$paging = array( 'offset' => 0, 'page_size' => $page_size );
|
|
|
|
$entries = GFAPI::get_entries( $action_form, $search_criteria, $sorting, $paging );
|
|
|
|
foreach ($entries as $action_entry) {
|
|
self::_display_step_action_entry($action_form, $action_entry);
|
|
}
|
|
|
|
?>
|
|
</tbody>
|
|
</table>
|
|
|
|
</div>
|
|
|
|
<?php
|
|
}
|
|
?>
|
|
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
add_thickbox();
|
|
}
|
|
|
|
|
|
|
|
private static function _display_step_action_entry($action_form, $action_entry) {
|
|
$workflow_api = new Gravity_Flow_API($action_entry['form_id']);
|
|
|
|
$current_action_step = $workflow_api->get_current_step($action_entry);
|
|
|
|
|
|
?>
|
|
<table>
|
|
|
|
<?php
|
|
foreach ($action_form['fields'] as $field) {
|
|
|
|
if ($field->type === 'wiaas_order') {
|
|
continue;
|
|
}
|
|
|
|
if ($field->type === 'workflow_discussion') {
|
|
|
|
echo '<tr style="padding: 20px;"><td colspan="2">' . $field->format_discussion_value($action_entry[$field->id]) . '</td></tr>';
|
|
|
|
continue;
|
|
}
|
|
|
|
$value = $field->get_value_entry_detail($action_entry[$field->id]);
|
|
$label = $field->get_field_label(false, $action_entry[$field->id]);
|
|
|
|
echo '<tr>' .
|
|
'<td><h5>' . $label . ' : </h5></td>' .
|
|
'<td>' . $value . '</td>' .
|
|
'</tr>';
|
|
}
|
|
|
|
if (! empty($current_action_step)) {
|
|
|
|
?>
|
|
|
|
<tfoot>
|
|
<tr>
|
|
<td colspan="2">
|
|
<a style="text-transform: uppercase; font-size: 11px; letter-spacing: 0.4px; margin:10px;" href="<?php echo $current_action_step->get_entry_url() ?>">
|
|
<?php echo $current_action_step->get_name() . ' ' . $current_action_step->get_status_label($current_action_step->get_status()) ?>
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
</tfoot>
|
|
|
|
<?php
|
|
|
|
}
|
|
?>
|
|
</table>
|
|
|
|
<hr />
|
|
<?php
|
|
}
|
|
}
|
|
|
|
Wiaas_Admin_Delivery_Process::init();
|