| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user, $wpscfunction; |
| 7 |
|
| 8 |
$response = array( |
| 9 |
'ticket_id' => $ticket_id |
| 10 |
); |
| 11 |
|
| 12 |
$ticket = $wpscfunction->get_ticket($ticket_id); |
| 13 |
$response = array_merge($response,$ticket); |
| 14 |
|
| 15 |
// Remove id element as slug for ticket id is ticket_id |
| 16 |
unset($response['id']); |
| 17 |
|
| 18 |
// Assigned agents |
| 19 |
$assigned_agents = $wpscfunction->get_assigned_agents($ticket_id); |
| 20 |
$temp_data = array(); |
| 21 |
foreach ($assigned_agents as $val) { |
| 22 |
$temp_data[] = array( |
| 23 |
'val' => $val, |
| 24 |
); |
| 25 |
} |
| 26 |
$response['assigned_agents'] = $temp_data; |
| 27 |
|
| 28 |
$custom_fields = get_terms([ |
| 29 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 30 |
'hide_empty' => false, |
| 31 |
'orderby' => 'meta_value_num', |
| 32 |
'meta_key' => 'wpsc_tf_load_order', |
| 33 |
'order' => 'ASC', |
| 34 |
'meta_query' => array( |
| 35 |
'relation' => 'AND', |
| 36 |
array( |
| 37 |
'key' => 'agentonly', |
| 38 |
'value' => array(0,1), |
| 39 |
'compare' => 'IN' |
| 40 |
), |
| 41 |
array( |
| 42 |
'key' => 'wpsc_tf_type', |
| 43 |
'value' => '0', |
| 44 |
'compare' => '>' |
| 45 |
), |
| 46 |
), |
| 47 |
]); |
| 48 |
|
| 49 |
foreach ( $custom_fields as $custom_field ) { |
| 50 |
|
| 51 |
$tf_type = get_term_meta($custom_field->term_id,'wpsc_tf_type',true); |
| 52 |
|
| 53 |
switch ($tf_type) { |
| 54 |
case '1': |
| 55 |
case '2': |
| 56 |
case '4': |
| 57 |
case '5': |
| 58 |
case '6': |
| 59 |
case '7': |
| 60 |
case '8': |
| 61 |
case '9': |
| 62 |
case '18': |
| 63 |
case '21': |
| 64 |
$response[$custom_field->slug] = $wpscfunction->get_ticket_meta($ticket_id,$custom_field->slug,true); |
| 65 |
break; |
| 66 |
case '3': |
| 67 |
case '10': |
| 68 |
$arrVal = $wpscfunction->get_ticket_meta($ticket_id,$custom_field->slug); |
| 69 |
$temp_data = array(); |
| 70 |
foreach ($arrVal as $val) { |
| 71 |
$temp_data[] = array( |
| 72 |
'val' => $val, |
| 73 |
); |
| 74 |
} |
| 75 |
$response[$custom_field->slug] = $temp_data; |
| 76 |
break; |
| 77 |
|
| 78 |
default: |
| 79 |
$response = apply_filters('wpsc_api_v1_custom_field_val',$response, $ticket_id, $custom_field, $tf_type); |
| 80 |
break; |
| 81 |
} |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
$ticket_description = $wpscfunction->get_ticket_description($ticket_id); |
| 86 |
$ticket_description['description'] = str_replace('$','\$', $ticket_description['description']); |
| 87 |
|
| 88 |
$response['ticket_description'] = $ticket_description['description']; |
| 89 |
|