Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New REST API to get SLA info

  • Loading branch information...
commit 44afb28f9348c33964ee4e25fd94557e1d90302b 1 parent 2e47268
@davidecassenti authored
Showing with 80 additions and 16 deletions.
  1. +46 −0 api/rest/sla.php
  2. +18 −14 api/util.php
  3. +16 −2 plugin.xml
View
46 api/rest/sla.php
@@ -0,0 +1,46 @@
+<?php
+class ChRest_Sla extends Extension_RestController implements IExtensionRestController {
+ function __construct($manifest) {
+ parent::__construct($manifest);
+ }
+
+ function getAction($stack) {
+ @$action = array_shift($stack);
+
+ // Looking up a single ID?
+ if(is_numeric($action)) {
+ $this->success(PiSlaUtils::getTicketSLAInfo(intval($action)));
+
+ } else { // actions
+ switch($action) {
+ default:
+ $this->error(self::ERRNO_NOT_IMPLEMENTED);
+ break;
+ }
+ }
+ }
+
+ function putAction($stack) {
+ $this->error(self::ERRNO_NOT_IMPLEMENTED);
+ }
+
+ function postAction($stack) {
+ $this->error(self::ERRNO_NOT_IMPLEMENTED);
+ }
+
+ function deleteAction($stack) {
+ $this->error(self::ERRNO_NOT_IMPLEMENTED);
+ }
+
+ function translateToken($token, $type='dao') {
+ return null;
+ }
+
+ function getContext($id) {
+ return null;
+ }
+
+ function search($filters=array(), $sortToken='email_id', $sortAsc=1, $page=1, $limit=10) {
+ return null;
+ }
+};
View
32 api/util.php
@@ -87,6 +87,11 @@ function getTicketSLAInfo($ticket_id) {
$ticket_sla_info['days_passed'] = self::calculateDays ($ticket->created_date, time());
$ticket_sla_info['business_days_passed'] = self::calculateWorkingDays ($ticket->created_date, time());
+ // calculate how many days ago the last reply was sent
+ if ($ticket_sla_info['last_response_time'] > 0) {
+ $ticket_sla_info['last_response_business_days_ago'] = PiSlaUtils::calculateWorkingDays ($ticket_sla_info['last_response_time'], time());
+ $ticket_sla_info['last_response_days_ago'] = PiSlaUtils::calculateDays ($ticket_sla_info['last_response_time'], time());
+ }
// find out if we missed the SLA
$customer_type_field_id = $properties['customer_type_field_id'];
@@ -128,25 +133,24 @@ function getTicketSLAInfo($ticket_id) {
}
// check if we missed SLA
- if ($ticket_sla_info['sla_days'] == 0) {
- $ticket_sla_info['sla_status'] = "green"; // everything is ok, no SLA here
- } else if ($first_response_time_to_use > $ticket_sla_info['sla_days']) {
- $ticket_sla_info['sla_status'] = "red"; // oops, we missed it
- } else if ($ticket_sla_info['first_response_time'] == -1) {
- $ticket_sla_info['sla_status'] = "yellow"; // we're still in time...
+ if ($ticket_sla_info['sla_type'] == "b") {
+ if ($ticket_sla_info['response_business_days'] == -1 && $ticket_sla_info['business_days_passed'] <= $ticket_sla_info['sla_days'])
+ $ticket_sla_info['sla_status'] = "yellow";
+ else if ($ticket_sla_info['response_business_days'] == -1 || $ticket_sla_info['response_business_days'] > $ticket_sla_info['sla_days'])
+ $ticket_sla_info['sla_status'] = "red";
+ else
+ $ticket_sla_info['sla_status'] = "green";
} else {
- $ticket_sla_info['sla_status'] = "green"; // great job!
+ if ($ticket_sla_info['response_days'] == -1 && $ticket_sla_info['days_passed'] <= $ticket_sla_info['sla_days'])
+ $ticket_sla_info['sla_status'] = "yellow";
+ else if ($ticket_sla_info['response_days'] == -1 || $ticket_sla_info['response_days'] > $ticket_sla_info['sla_days'])
+ $ticket_sla_info['sla_status'] = "red";
+ else
+ $ticket_sla_info['sla_status'] = "green";
}
}
}
-
- // calculate how many days ago the last reply was sent
- if ($ticket_sla_info['last_response_time'] > 0) {
- $ticket_sla_info['last_response_business_days_ago'] = PiSlaUtils::calculateWorkingDays ($ticket_sla_info['last_response_time'], time());
- $ticket_sla_info['last_response_days_ago'] = PiSlaUtils::calculateDays ($ticket_sla_info['last_response_time'], time());
- }
-
return $ticket_sla_info;
}
View
18 plugin.xml
@@ -2,9 +2,9 @@
<plugin>
<id>net.pixelinstrument.sla</id>
<name>[PI] Tickets SLA Management</name>
- <description>Manage calculation of SLA dates for tickets Version 1.0.0</description>
+ <description>Manage calculation of SLA dates for tickets Version 1.1.0</description>
<author>Davide Cassenti</author>
- <revision>1.0.0</revision>
+ <revision>1.1.0</revision>
<link>http://www.pixelinstrument.net</link>
<image>plugin.png</image>
@@ -49,5 +49,19 @@
<params>
</params>
</extension>
+
+ <!-- REST Controllers -->
+
+ <extension point="cerberusweb.rest.controller">
+ <id>net.pixelinstrument.sla.rest.controller</id>
+ <name>SLA</name>
+ <class>
+ <file>api/rest/sla.php</file>
+ <name>ChRest_Sla</name>
+ </class>
+ <params>
+ <param key="uri" value="sla" />
+ </params>
+ </extension>
</extensions>
</plugin>
Please sign in to comment.
Something went wrong with that request. Please try again.