Converted everything to camelCase se and some other improvements

This commit is contained in:
Mike Koch 2015-11-29 15:39:38 -05:00
parent b94ea93991
commit 641348d757
12 changed files with 246 additions and 46 deletions

View File

@ -27,7 +27,7 @@ $request_method = $_SERVER['REQUEST_METHOD'];
* @apiSuccess {Number} id ID of the canned response
* @apiSuccess {String} title The title of the canned response.
* @apiSuccess {String} message The contents of the canned response, including HTML markup.
* @apiSuccess {Integer} reply_order The position of the canned response in the list of canned responses (in multiples of 10).
* @apiSuccess {Integer} replyOrder The position of the canned response in the list of canned responses (in multiples of 10).
*
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
@ -35,7 +35,7 @@ $request_method = $_SERVER['REQUEST_METHOD'];
* "id": 2,
* "title": "html",
* "message": "<p><strong>My<em> canned response&nbsp;</em></strong></p>\r\n<p>%%HESK_ID%%</p>",
* "reply_order": 10
* "replyOrder": 10
* }
*
* @apiError (noTokenProvided) 400 No `X-Auth-Token` was provided where it is required

View File

@ -15,6 +15,32 @@ hesk_dbConnect();
// Routing
$request_method = $_SERVER['REQUEST_METHOD'];
/**
* @api {get} /admin/ticket-template Retrieve a ticket templates
* @apiVersion 0.0.0
* @apiName GetTicketTemplate
* @apiGroup Ticket Template
* @apiPermission protected
*
* @apiParam {Number} [id] The ID of the ticket template. Omit for all templates.
*
* @apiSuccess {Number} id ID of the template
* @apiSuccess {String} title The title of the template.
* @apiSuccess {String} message The contents of the template, including HTML markup.
* @apiSuccess {Integer} displayOrder The position of the template in the list of templates (in multiples of 10).
*
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "id": 2,
* "title": "html",
* "message": "<p><strong>My<em> ticket template&nbsp;</em></strong></p>",
* "displayOrder": 10
* }
*
* @apiError (noTokenProvided) 400 No `X-Auth-Token` was provided where it is required
* @apiError (invalidXAuthToken) 401 The `X-Auth-Token` provided was invalid
*/
if ($request_method == 'GET') {
$token = get_header('X-Auth-Token');

View File

@ -25,57 +25,57 @@ $request_method = $_SERVER['REQUEST_METHOD'];
* @apiParam {Number} [id] The ID of the ticket. Omit for all tickets.
*
* @apiSuccess {Number} id ID of the ticket
* @apiSuccess {String} trackid The tracking id of the ticket
* @apiSuccess {String} trackingId The tracking id of the ticket
* @apiSuccess {String} name The name of the contact
* @apiSuccess {String} email The email address of the ticket (empty string if no email)
* @apiSuccess {Integer} category The ID of the category the ticket is in
* @apiSuccess {Integer} priority The ID of the priority the ticket is in
* @apiSuccess {String} subject The subject of the ticket
* @apiSuccess {String} message The original message of the ticket
* @apiSuccess {String} dt The date and time the ticket was submitted, in `YYYY-MM-DD hh:mm:ss`
* @apiSuccess {String} dateCreated The date and time the ticket was submitted, in `YYYY-MM-DD hh:mm:ss`
* @apiSuccess {Integer} articles The knowledgebase article IDs suggested when the user created the ticket
* @apiSuccess {String} ip The IP address of the submitter
* @apiSuccess {String} language The language the ticket was submitted in
* @apiSuccess {Integer} status The ID of the status the ticket is set to
* @apiSuccess {Integer} owner The user ID of the ticket owner
* @apiSuccess {String} time_worked The total time worked on the ticket, in `hh:mm:ss`
* @apiSuccess {String} timeWorked The total time worked on the ticket, in `hh:mm:ss`
* @apiSuccess {Boolean} archive `true` if the ticket is tagged<br>`false` otherwise
* @apiSuccess {Boolean} locked `true` if the ticket is locked<br>`false` otherwise
* @apiSuccess {Binary[]} attachments Array of attachments, in base-64 encoded binary
* @apiSuccess {Integer[]} merged Array of merged ticket IDs
* @apiSuccess {String} history HTML markup of the entire "Audit Trail" section
* @apiSuccess {String} legacyAuditTrail HTML markup of the entire "Audit Trail" section
* @apiSuccess {String} custom1-20 Custom fields 1-20's values.
* @apiSuccess {Integer} parent The ID of the ticket linked to this ticket
* @apiSuccess {Integer} linkedTo The ID of the ticket linked to this ticket
* @apiSuccess {String} latitude The latitudinal coordinate of the user's location, or one of the corresponding error codes.
* @apiSuccess {String} longitude The longitudinal coordinate of the user's location, or one of the corresponding error codes.
* @apiSuccess {Boolean} html `true` if the ticket was created with HTML encoding<br>`false` otherwise
* @apiSuccess {String} user_agent The user agent of the user who submitted the ticket
* @apiSuccess {Integer} screen_resolution_width The width of the screen resolution of the user who submitted the ticket
* @apiSuccess {Integer} screen_resolution_height The height of the screen resolution of the user who submitted the ticket
* @apiSuccess {String} userAgent The user agent of the user who submitted the ticket
* @apiSuccess {Integer} screenResolutionWidth The width of the screen resolution of the user who submitted the ticket
* @apiSuccess {Integer} screenResolutionHeight The height of the screen resolution of the user who submitted the ticket
*
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "id": 22,
* "trackid": "EVL-RRL-DUBG",
* "trackingId": "EVL-RRL-DUBG",
* "name": "Test",
* "email": "",
* "category": 1,
* "priority": 3,
* "subject": "test",
* "message": "test",
* "dt": "2014-12-28 00:57:26",
* "dateCreated": "2014-12-28 00:57:26",
* "articles": null,
* "ip": "127.0.0.1",
* "language": null,
* "status": 3,
* "owner": 1,
* "time_worked": "00:05:07",
* "timeWorked": "00:05:07",
* "archive": true,
* "locked": true,
* "attachments": "",
* "merged": "",
* "history": "<li class=\"smaller\">2014-12-28 06:57:28 | ticket created by Your name (mkoch)</li><li class=\"smaller\">2014-12-31 21:00:59 | closed by Your name (mkoch)</li><li class=\"smaller\">2014-12-31 21:01:05 | status changed to Waiting reply by Your name (mkoch)</li><li class=\"smaller\">2014-12-31 21:01:58 | closed by Your name (mkoch)</li><li class=\"smaller\">2015-01-17 16:21:18 | closed by Your name (mkoch)</li><li class=\"smaller\">2015-01-17 16:21:31 | closed by Your name (mkoch)</li><li class=\"smaller\">2015-01-17 16:22:05 | closed by Your name (mkoch)</li><li class=\"smaller\">2015-01-17 16:24:06 | status changed to by Your name (mkoch)</li><li class=\"smaller\">2015-01-17 16:25:40 | status changed to On Hold by Your name (mkoch)</li><li class=\"smaller\">2015-01-17 16:25:53 | status changed to In Progress by Your name (mkoch)</li><li class=\"smaller\">2015-01-17 21:39:11 | locked by Your name (mkoch)</li>",
* "legacyAuditTrail": "<li class=\"smaller\">2014-12-28 06:57:28 | ticket created by Your name (username)</li><li class=\"smaller\">2014-12-31 21:00:59 | closed by Your name (username)</li><li class=\"smaller\">2014-12-31 21:01:05 | status changed to Waiting reply by Your name (username)</li><li class=\"smaller\">2014-12-31 21:01:58 | closed by Your name (username)</li><li class=\"smaller\">2015-01-17 16:21:18 | closed by Your name (username)</li>",
* "custom1": "1420671600",
* "custom2": "",
* "custom3": "",
@ -100,9 +100,9 @@ $request_method = $_SERVER['REQUEST_METHOD'];
* "latitude": "E-0",
* "longitude": "E-0",
* "html": false,
* "user_agent": null,
* "screen_resolution_width": null,
* "screen_resolution_height": null
* "userAgent": null,
* "screenResolutionWidth": null,
* "screenResolutionHeight": null
* }
*
* @apiError (noTokenProvided) 400 No `X-Auth-Token` was provided where it is required

View File

@ -6,7 +6,7 @@ require_once(HESK_PATH . 'hesk_settings.inc.php');
require_once(HESK_PATH . 'inc/common.inc.php');
require_once(API_PATH . 'core/headers.php');
require_once(API_PATH . 'core/output.php');
require_once(API_PATH . 'dao/user_dao.php');
require_once(API_PATH . 'businesslogic/user_retriever.php');
require_once(API_PATH . 'businesslogic/security_retriever.php');
hesk_load_api_database_functions();
@ -15,6 +15,88 @@ hesk_dbConnect();
// Routing
$request_method = $_SERVER['REQUEST_METHOD'];
/**
* @api {get} /admin/user Retrieve a helpdesk user
* @apiVersion 0.0.0
* @apiName GetUser
* @apiGroup User
* @apiPermission protected
*
* @apiParam {Number} [id] The ID of the user. Omit for all users.
*
* @apiSuccess {Number} id ID of the user
* @apiSuccess {String} username The user's username
* @apiSuccess {Boolean} admin `true` if the user is under a permission template that is market as an administrative group<br>`false` otherwise
* @apiSuccess {String} name The user's name
* @apiSuccess {String} email The user's email address
* @apiSuccess {String} signature The user's signature, in plaintext
* @apiSuccess {Unknown} language ??? (Unknown)
* @apiSuccess {String[]} categories Ticket categories the user has access to. If the user is an admin, this list has one element: ""
* @apiSuccess {Integer} afterReply Action to perform after replying to a ticket:<br>
* `0` - Show the ticket I just replied to<br>
* `1` - Return to the main administration page<br>
* `2` - Open next ticket that needs my reply
* @apiSuccess {Boolean} autoStart Automatically start timer when the user opens a ticket
* @apiSuccess {Boolean} notifyCustomerNew Select notify customer option in the new ticket form
* @apiSuccess {Boolean} notifyCustomerReply Select notify customer option in the ticket reply form
* @apiSuccess {Boolean} showSuggested Show what knowledgebase articles were suggested to customers
* @apiSuccess {Boolean} notifyNewUnassigned Notify the user when a new ticket is submitted with owner: Unassigned
* @apiSuccess {Boolean} notifyNewMy Notify the user when a new ticket is submitted and is assigned to the user
* @apiSuccess {Boolean} notifyAssigned Notify the user when a ticket is assigned to the user
* @apiSuccess {Boolean} notifyReplyUnassigned Notify the user when the client responds to a ticket with owner: Unassigned
* @apiSuccess {Boolean} notifyReplyMy Notify the user when the client responds to a ticket assigned to the user
* @apiSuccess {Boolean} notifyPm Notify the user when a private message is sent to the user
* @apiSuccess {Boolean} notifyNoteUnassigned Notify the user when someone adds a note to a ticket not assigned to the user
* @apiSuccess {Unknown} defaultList ??? (Currently unknown)
* @apiSuccess {Boolean} autoassign Tickets are auto-assigned to this user
* @apiSuccess {String[]} heskPrivileges Helpdesk features the user has access to. If the user is an admin, this list has one element: ""
* @apiSuccess {Integer} ratingNeg Total number of negative feedback to "Was this reply helpful?" on replies by this user
* @apiSuccess {Integer} ratingPos Total number of positive feedback to "Was this reply helpful?" on replies by this user
* @apiSuccess {String} rating The overall rating of the user, as a floating point decimal
* @apiSuccess {Integer} autorefresh The ticket table autorefresh time for the user, in milliseconds
* @apiSuccess {Boolean} active `true` if the user is active<br>`false` otherwise
*
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "id": 1,
* "username": "mkoch",
* "admin": true,
* "name": "Your name",
* "email": "mkoch227@gmail.com",
* "signature": "Sincerely,\r\n\r\nYour name\r\nYour website\r\nhttp://www.yourwebsite.com\r\n& < > ^ &",
* "language": null,
* "categories": [
* ""
* ],
* "afterReply": 0,
* "autoStart": true,
* "notifyCustomerNew": true,
* "notifyCustomerReply": true,
* "showSuggested": true,
* "notifyNewUnassigned": true,
* "notifyNewMy": true,
* "notifyReplyUnassigned": true,
* "notifyReplyMy": true,
* "notifyAssigned": true,
* "notifyPm": false,
* "notifyNote": true,
* "notifyNoteUnassigned": false,
* "defaultList": "",
* "autoassign": true,
* "heskPrivileges": [
* ""
* ],
* "ratingNeg": 0,
* "ratingPos": 0,
* "rating": "0",
* "autorefresh": 0,
* "active": true
* }
*
* @apiError (noTokenProvided) 400 No `X-Auth-Token` was provided where it is required
* @apiError (invalidXAuthToken) 401 The `X-Auth-Token` provided was invalid
*/
if ($request_method == 'GET') {
$token = get_header('X-Auth-Token');
@ -25,9 +107,9 @@ if ($request_method == 'GET') {
}
if (isset($_GET['id'])) {
$results = get_user($hesk_settings, $_GET['id']);
$results = retrieve_user($hesk_settings, $_GET['id']);
} else {
$results = get_user($hesk_settings);
$results = retrieve_user($hesk_settings);
}
if ($results == NULL) {

View File

@ -5,24 +5,16 @@ function get_ticket_for_staff($hesk_settings, $id = NULL) {
$tickets = get_ticket_for_id($hesk_settings, $id);
if ($id === NULL) {
foreach ($tickets as $ticket) {
$original_tickets = $tickets;
$tickets = [];
foreach ($original_tickets as $ticket) {
$ticket = remove_common_properties($ticket);
$ticket['suggestedArticles'] = $ticket['articles'];
unset($ticket['articles']);
$ticket['legacyAuditTrail'] = $ticket['history'];
unset($ticket['history']);
$ticket['linkedTo'] = $ticket['parent'];
unset($ticket['parent']);
$ticket = convert_to_camel_case($ticket);
$tickets[] = $ticket;
}
} else {
$tickets = remove_common_properties($tickets);
$tickets['suggestedArticles'] = $tickets['articles'];
unset($tickets['articles']);
$tickets['legacyAuditTrail'] = $tickets['history'];
unset($tickets['history']);
$tickets['linkedTo'] = $tickets['parent'];
unset($tickets['parent']);
$tickets = convert_to_camel_case($tickets);
}
@ -44,10 +36,36 @@ function remove_common_properties($ticket) {
return $ticket;
}
function convert_to_camel_case($ticket) {
if (isset($ticket['articles'])) {
$ticket['suggestedArticles'] = $ticket['articles'];
unset($ticket['articles']);
$ticket['legacyAuditTrail'] = $ticket['history'];
unset($ticket['history']);
$ticket['linkedTo'] = $ticket['parent'];
unset($ticket['parent']);
$ticket['timeWorked'] = $ticket['time_worked'];
unset($ticket['time_worked']);
$ticket['userAgent'] = $ticket['user_agent'];
unset($ticket['user_agent']);
$ticket['screenResolutionWidth'] = $ticket['screen_resolution_width'];
unset($ticket['screen_resolution_width']);
$ticket['screenResolutionHeight'] = $ticket['screen_resolution_height'];
unset($ticket['screen_resolution_height']);
}
$ticket['trackingId'] = $ticket['trackid'];
unset($ticket['trackid']);
$ticket['dateCreated'] = $ticket['dt'];
unset($ticket['dt']);
return $ticket;
}
function get_ticket($hesk_settings, $id) {
$ticket = get_ticket_for_id($hesk_settings, $id);
$ticket = remove_common_properties($ticket);
$ticket = remove_staff_specific_properties($ticket);
$ticket = convert_to_camel_case($ticket);
return $ticket;
}

View File

@ -0,0 +1,73 @@
<?php
require_once(API_PATH . 'dao/user_dao.php');
function retrieve_user($hesk_settings, $id = NULL) {
$users = get_user($hesk_settings, $id);
if ($id === NULL) {
$original_users = $users;
$users = [];
foreach ($original_users as $user) {
$user = remove_unneeded_properties($user);
$user = convert_to_camel_case($user);
$users[] = $user;
}
} else {
$users = remove_unneeded_properties($users);
$users = convert_to_camel_case($users);
}
return $users;
}
function remove_unneeded_properties($user) {
unset($user['pass']);
unset($user['permission_template']);
unset($user['language']);
unset($user['replies']);
return $user;
}
function convert_to_camel_case($user) {
$user['username'] = $user['user'];
unset($user['user']);
$user['admin'] = $user['isadmin'];
unset($user['isadmin']);
$user['afterReply'] = $user['afterreply'];
unset($user['afterreply']);
$user['autoStart'] = $user['autostart'];
unset($user['autostart']);
$user['notifyCustomerNew'] = $user['notify_customer_new'];
unset($user['notify_customer_new']);
$user['notifyCustomerReply'] = $user['notify_customer_reply'];
unset($user['notify_customer_reply']);
$user['showSuggested'] = $user['show_suggested'];
unset($user['show_suggested']);
$user['notifyNewUnassigned'] = $user['notify_new_unassigned'];
unset($user['notify_new_unassigned']);
$user['notifyNewMy'] = $user['notify_new_my'];
unset($user['notify_new_my']);
$user['notifyReplyUnassigned'] = $user['notify_reply_unassigned'];
unset($user['notify_reply_unassigned']);
$user['notifyReplyMy'] = $user['notify_reply_my'];
unset($user['notify_reply_my']);
$user['notifyAssigned'] = $user['notify_assigned'];
unset($user['notify_assigned']);
$user['notifyPm'] = $user['notify_pm'];
unset($user['notify_pm']);
$user['notifyNote'] = $user['notify_note'];
unset($user['notify_note']);
$user['notifyNoteUnassigned'] = $user['notify_note_unassigned'];
unset($user['notify_note_unassigned']);
$user['defaultList'] = $user['default_list'];
unset($user['default_list']);
$user['ratingNeg'] = $user['ratingneg'];
unset($user['ratingneg']);
$user['ratingPos'] = $user['ratingpos'];
unset($user['ratingpos']);
$user['heskPrivileges'] = $user['heskprivileges'];
unset($user['heskprivileges']);
return $user;
}

View File

@ -24,7 +24,7 @@ $request_method = $_SERVER['REQUEST_METHOD'];
*
* @apiSuccess {Number} id ID of the category
* @apiSuccess {String} name The name of the category
* @apiSuccess {Integer} cat_order The order of the category (in multiples of 10)
* @apiSuccess {Integer} displayOrder The order of the category (in multiples of 10)
* @apiSuccess {Boolean} autoassign `true` if tickets set to this category are automatically assigned.<br>`false` otherwise
* @apiSuccess {Integer} type `0` - Public<br>`1` - Private
* @apiSuccess {Integer} priority Default priority of tickets created in this category
@ -35,11 +35,11 @@ $request_method = $_SERVER['REQUEST_METHOD'];
* {
* "id": 1,
* "name": "General",
* "cat_order": 10,
* "displayOrder": 10,
* "autoassign": true,
* "type": 0,
* "priority": 2,
* "manager": 0
* "manager": null
* }
*/
if ($request_method == 'GET') {

View File

@ -15,7 +15,10 @@ function get_canned_response($hesk_settings, $id = NULL) {
$results = [];
while ($row = hesk_dbFetchAssoc($response)) {
$row['id'] = intval($row['id']);
$row['reply_order'] = intval($row['reply_order']);
$row['replyOrder'] = intval($row['reply_order']);
unset($row['reply_order']);
$row['title'] = hesk_html_entity_decode($row['title']);
$row['message'] = hesk_html_entity_decode($row['message']);
$results[] = $row;

View File

@ -15,7 +15,8 @@ function get_category($hesk_settings, $id = NULL) {
$results = [];
while ($row = hesk_dbFetchAssoc($response)) {
$row['id'] = intval($row['id']);
$row['cat_order'] = intval($row['cat_order']);
$row['displayOrder'] = intval($row['cat_order']);
unset($row['cat_order']);
$row['autoassign'] = $row['autoassign'] == 1;
$row['type'] = intval($row['type']);
$row['priority'] = intval($row['priority']);

View File

@ -15,7 +15,8 @@ function get_ticket_template($hesk_settings, $id = NULL) {
$results = [];
while ($row = hesk_dbFetchAssoc($response)) {
$row['id'] = intval($row['id']);
$row['tpl_order'] = intval($row['tpl_order']);
$row['displayOrder'] = intval($row['tpl_order']);
unset($row['tpl_order']);
$row['title'] = hesk_html_entity_decode($row['title']);
$row['message'] = hesk_html_entity_decode($row['message']);
$results[] = $row;

View File

@ -15,10 +15,6 @@ function get_user($hesk_settings, $id = NULL) {
$results = [];
while ($row = hesk_dbFetchAssoc($response)) {
// Never send back a user's password, even if it is hashed.
unset($row['pass']);
unset($row['permission_template']);
$row['id'] = intval($row['id']);
$row['isadmin'] = get_boolean($row['isadmin']);
$row['signature'] = hesk_html_entity_decode($row['signature']);

View File

@ -45,14 +45,14 @@ $request_method = $_SERVER['REQUEST_METHOD'];
* HTTP/1.1 200 OK
* {
* "id": 22,
* "trackid": "EVL-RRL-DUBG",
* "trackingId": "EVL-RRL-DUBG",
* "name": "Test",
* "email": "",
* "category": 1,
* "priority": 3,
* "subject": "test",
* "message": "test",
* "dt": "2014-12-28 00:57:26",
* "dateCreated": "2014-12-28 00:57:26",
* "status": 3,
* "archive": true,
* "locked": true,