Permalink
Browse files

New field saved in audit log

  • Loading branch information...
1 parent 10ff9e1 commit fca1e61c47e01bdd35a9eae9029d66bbe1e2d44f @davidecassenti committed Apr 4, 2011
Showing with 57 additions and 13 deletions.
  1. +57 −13 api/util.php
View
70 api/util.php
@@ -33,7 +33,8 @@ function getTicketSLAInfo($ticket_id) {
'last_response_time' => -1,
'sla_status' => 'green',
'sla_end_date' => -1,
- 'sla_type' => 'b'
+ 'sla_type' => 'b',
+ 'sla_customer_type' => '-'
);
$ticket = DAO_Ticket::get ($ticket_id);
@@ -76,33 +77,51 @@ function getTicketSLAInfo($ticket_id) {
// get or calculate SLA end date and type
// if the ticket is not new, get the SLA date from the audit log
- $sla_date = DAO_TicketAuditLog::search(
+
+ // sla_date contains the milestone: ticket should get a reply before that date
+ $audit_sla_date = DAO_TicketAuditLog::search(
array(
new DevblocksSearchCriteria(SearchFields_TicketAuditLog::TICKET_ID, DevblocksSearchCriteria::OPER_EQ, $ticket_id),
new DevblocksSearchCriteria(SearchFields_TicketAuditLog::CHANGE_FIELD, DevblocksSearchCriteria::OPER_EQ, 'sla_date')
),
1);
- list ($key, $sla_date) = each($sla_date);
- list ($key, $sla_date) = each($sla_date);
-
+ list ($key, $audit_sla_date) = each($audit_sla_date);
+ list ($key, $audit_sla_date) = each($audit_sla_date);
- $sla_type = DAO_TicketAuditLog::search(
+ // sla_type contains the kind of SLA: it might be business days, standard days etc.
+ $audit_sla_type = DAO_TicketAuditLog::search(
array(
new DevblocksSearchCriteria(SearchFields_TicketAuditLog::TICKET_ID, DevblocksSearchCriteria::OPER_EQ, $ticket_id),
new DevblocksSearchCriteria(SearchFields_TicketAuditLog::CHANGE_FIELD, DevblocksSearchCriteria::OPER_EQ, 'sla_type')
),
1);
- list ($key, $sla_type) = each($sla_type);
- list ($key, $sla_type) = each($sla_type);
+ list ($key, $audit_sla_type) = each($audit_sla_type);
+ list ($key, $audit_sla_type) = each($audit_sla_type);
+
+ // sla_customer_type contains the type of customer; useful for reporting
+ $audit_sla_customer_type = DAO_TicketAuditLog::search(
+ array(
+ new DevblocksSearchCriteria(SearchFields_TicketAuditLog::TICKET_ID, DevblocksSearchCriteria::OPER_EQ, $ticket_id),
+ new DevblocksSearchCriteria(SearchFields_TicketAuditLog::CHANGE_FIELD, DevblocksSearchCriteria::OPER_EQ, 'sla_customer_type')
+ ),
+ 1);
+ list ($key, $audit_sla_customer_type) = each($audit_sla_customer_type);
+ list ($key, $audit_sla_customer_type) = each($audit_sla_customer_type);
- if (isset($sla_date[SearchFields_TicketAuditLog::CHANGE_VALUE]) && isset($sla_type[SearchFields_TicketAuditLog::CHANGE_VALUE])) {
- $log_sla_date = intval ($sla_date[SearchFields_TicketAuditLog::CHANGE_VALUE]);
+ // if all values are set, get the info from the audit_log
+ if (isset($audit_sla_date[SearchFields_TicketAuditLog::CHANGE_VALUE]) &&
+ isset($audit_sla_type[SearchFields_TicketAuditLog::CHANGE_VALUE]) &&
+ isset($audit_sla_customer_type[SearchFields_TicketAuditLog::CHANGE_VALUE]))
+ {
+ $log_sla_date = intval ($audit_sla_date[SearchFields_TicketAuditLog::CHANGE_VALUE]);
$ticket_sla_info['sla_end_date'] = ($log_sla_date > 0) ? $log_sla_date : -1;
- $ticket_sla_info['sla_type'] = $sla_type[SearchFields_TicketAuditLog::CHANGE_VALUE];
+ $ticket_sla_info['sla_type'] = $audit_sla_type[SearchFields_TicketAuditLog::CHANGE_VALUE];
+ $ticket_sla_info['sla_customer_type'] = $audit_sla_customer_type[SearchFields_TicketAuditLog::CHANGE_VALUE];
} else {
$sla = -1;
$sla_type = -1;
+ $sla_customer_type = '-';
// get custom values for the customer, if any
$customer_type_field_id = $properties['customer_type_field_id'];
@@ -119,9 +138,12 @@ function getTicketSLAInfo($ticket_id) {
$sla_type = isset ($properties['sla_type'][$customer_type]) ? ($properties['sla_type'][$customer_type]) : "b";
}
}
-
+
+ echo $sla;
if ($sla <= 0)
$sla_type = '-';
+ else
+ $ticket_sla_info['sla_customer_type'] = $customer_type;
$ticket_sla_info['sla_type'] = $sla_type;
@@ -145,6 +167,18 @@ function getTicketSLAInfo($ticket_id) {
? $active_worker->id
: 0;
+
+ // remove old SLA info, if any
+ if (isset($audit_sla_date[SearchFields_TicketAuditLog::ID]))
+ DAO_TicketAuditLog::delete($audit_sla_date[SearchFields_TicketAuditLog::ID]);
+
+ if (isset($audit_sla_type[SearchFields_TicketAuditLog::ID]))
+ DAO_TicketAuditLog::delete($audit_sla_type[SearchFields_TicketAuditLog::ID]);
+
+ if (isset($audit_sla_customer_type[SearchFields_TicketAuditLog::ID]))
+ DAO_TicketAuditLog::delete($audit_sla_customer_type[SearchFields_TicketAuditLog::ID]);
+
+
// sla date
$fields = array(
DAO_TicketAuditLog::TICKET_ID => $ticket_id,
@@ -153,7 +187,7 @@ function getTicketSLAInfo($ticket_id) {
DAO_TicketAuditLog::CHANGE_FIELD => 'sla_date',
DAO_TicketAuditLog::CHANGE_VALUE => substr($ticket_sla_info['sla_end_date'],0,128),
);
- $log_id = DAO_TicketAuditLog::create($fields);
+ $log_id = DAO_TicketAuditLog::create($fields);
// sla type
$fields = array(
@@ -163,6 +197,16 @@ function getTicketSLAInfo($ticket_id) {
DAO_TicketAuditLog::CHANGE_FIELD => 'sla_type',
DAO_TicketAuditLog::CHANGE_VALUE => substr($ticket_sla_info['sla_type'],0,128),
);
+ $log_id = DAO_TicketAuditLog::create($fields);
+
+ // sla customer type
+ $fields = array(
+ DAO_TicketAuditLog::TICKET_ID => $ticket_id,
+ DAO_TicketAuditLog::WORKER_ID => $worker_id,
+ DAO_TicketAuditLog::CHANGE_DATE => $ticket->created_date,
+ DAO_TicketAuditLog::CHANGE_FIELD => 'sla_customer_type',
+ DAO_TicketAuditLog::CHANGE_VALUE => substr($ticket_sla_info['sla_customer_type'],0,128),
+ );
$log_id = DAO_TicketAuditLog::create($fields);
}

0 comments on commit fca1e61

Please sign in to comment.