Add a status controller to retrieve statuses

remotes/upstream/api-rewrite
Mike Koch 7 years ago
parent 167d6c76ac
commit fd41a589fe

@ -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]);
}
}

@ -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;
}

@ -0,0 +1,20 @@
<?php
namespace BusinessLogic\Statuses;
use DataAccess\Statuses\StatusGateway;
// TODO Test!
class StatusRetriever {
/* @var $statusGateway StatusGateway */
private $statusGateway;
function __construct($statusGateway) {
$this->statusGateway = $statusGateway;
}
function getAllStatuses($heskSettings) {
return $this->statusGateway->getStatuses($heskSettings);
}
}

@ -0,0 +1,17 @@
<?php
namespace Controllers\Statuses;
use BusinessLogic\Statuses\StatusRetriever;
class StatusController {
function get() {
global $applicationContext, $hesk_settings;
/* @var $statusRetriever StatusRetriever */
$statusRetriever = $applicationContext->get[StatusRetriever::class];
output($statusRetriever->getAllStatuses($hesk_settings));
}
}

@ -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;
}
}

@ -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'

Loading…
Cancel
Save