From fd41a589fe23c3637fab3544ab5195bca18cef2d Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Fri, 28 Apr 2017 13:03:25 -0400 Subject: [PATCH] Add a status controller to retrieve statuses --- api/ApplicationContext.php | 4 ++++ api/BusinessLogic/Statuses/Status.php | 4 ++-- .../Statuses/StatusRetriever.php | 20 +++++++++++++++++ api/Controllers/Statuses/StatusController.php | 17 ++++++++++++++ api/DataAccess/Statuses/StatusGateway.php | 22 +++++++++++++++++++ api/index.php | 2 ++ 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 api/BusinessLogic/Statuses/StatusRetriever.php create mode 100644 api/Controllers/Statuses/StatusController.php diff --git a/api/ApplicationContext.php b/api/ApplicationContext.php index e8e66b2c..1de7ca80 100644 --- a/api/ApplicationContext.php +++ b/api/ApplicationContext.php @@ -13,6 +13,7 @@ use BusinessLogic\Security\BanRetriever; use BusinessLogic\Security\UserContextBuilder; use BusinessLogic\Security\UserToTicketChecker; use BusinessLogic\Settings\ApiChecker; +use BusinessLogic\Statuses\StatusRetriever; use BusinessLogic\Tickets\Autoassigner; use BusinessLogic\Tickets\TicketDeleter; use BusinessLogic\Tickets\TicketEditor; @@ -120,5 +121,8 @@ class ApplicationContext { $this->get[AttachmentHandler::class]); $this->get[TicketEditor::class] = new TicketEditor($this->get[TicketGateway::class], $this->get[UserToTicketChecker::class]); + + // Statuses + $this->get[StatusRetriever::class] = new StatusRetriever($this->get[StatusGateway::class]); } } \ No newline at end of file diff --git a/api/BusinessLogic/Statuses/Status.php b/api/BusinessLogic/Statuses/Status.php index 37561bd7..a726334f 100644 --- a/api/BusinessLogic/Statuses/Status.php +++ b/api/BusinessLogic/Statuses/Status.php @@ -6,7 +6,7 @@ namespace BusinessLogic\Statuses; class Status { static function fromDatabase($row, $languageRs) { $status = new Status(); - $status->id = $row['ID']; + $status->id = intval($row['ID']); $status->textColor = $row['TextColor']; $status->defaultActions = array(); @@ -21,7 +21,7 @@ class Status { $localizedLanguages[$languageRow['language']] = new StatusLanguage($languageRow['language'], $languageRow['text']); } $status->localizedNames = $localizedLanguages; - $status->sort = $row['sort']; + $status->sort = intval($row['sort']); return $status; } diff --git a/api/BusinessLogic/Statuses/StatusRetriever.php b/api/BusinessLogic/Statuses/StatusRetriever.php new file mode 100644 index 00000000..0bcfe844 --- /dev/null +++ b/api/BusinessLogic/Statuses/StatusRetriever.php @@ -0,0 +1,20 @@ +statusGateway = $statusGateway; + } + + function getAllStatuses($heskSettings) { + return $this->statusGateway->getStatuses($heskSettings); + } +} \ No newline at end of file diff --git a/api/Controllers/Statuses/StatusController.php b/api/Controllers/Statuses/StatusController.php new file mode 100644 index 00000000..f9e2f087 --- /dev/null +++ b/api/Controllers/Statuses/StatusController.php @@ -0,0 +1,17 @@ +get[StatusRetriever::class]; + + output($statusRetriever->getAllStatuses($hesk_settings)); + } +} \ No newline at end of file diff --git a/api/DataAccess/Statuses/StatusGateway.php b/api/DataAccess/Statuses/StatusGateway.php index 636852b1..c18e9b19 100644 --- a/api/DataAccess/Statuses/StatusGateway.php +++ b/api/DataAccess/Statuses/StatusGateway.php @@ -31,4 +31,26 @@ class StatusGateway extends CommonDao { return $status; } + + /** + * @param $heskSettings array + * @return Status[] + */ + function getStatuses($heskSettings) { + $this->init(); + + $metaRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "statuses`"); + + $statuses = array(); + while ($row = hesk_dbFetchAssoc($metaRs)) { + $languageRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "text_to_status_xref` + WHERE `status_id` = " . intval($row['ID'])); + + $statuses[] = Status::fromDatabase($row, $languageRs); + } + + $this->close(); + + return $statuses; + } } \ No newline at end of file diff --git a/api/index.php b/api/index.php index c8d333bf..a4d69986 100644 --- a/api/index.php +++ b/api/index.php @@ -157,6 +157,8 @@ Link::all(array( // Attachments '/v1/staff/tickets/{i}/attachments' => \Controllers\Attachments\StaffTicketAttachmentsController::class, '/v1/staff/tickets/{i}/attachments/{i}' => \Controllers\Attachments\StaffTicketAttachmentsController::class, + // Statuses + '/v1/statuses' => \Controllers\Statuses\StatusController::class, // Any URL that doesn't match goes to the 404 handler '404' => 'handle404'