diff --git a/api/BusinessLogic/Attachments/AttachmentRetriever.php b/api/BusinessLogic/Attachments/AttachmentRetriever.php new file mode 100644 index 00000000..bf905018 --- /dev/null +++ b/api/BusinessLogic/Attachments/AttachmentRetriever.php @@ -0,0 +1,24 @@ +attachmentGateway = $attachmentGateway; + $this->fileReader = $fileReader; + } + + function getAttachmentContentsForTicket($id, $heskSettings) { + + } +} \ No newline at end of file diff --git a/api/Controllers/Attachments/StaffTicketAttachmentsController.php b/api/Controllers/Attachments/StaffTicketAttachmentsController.php index 9c054e79..47f265ed 100644 --- a/api/Controllers/Attachments/StaffTicketAttachmentsController.php +++ b/api/Controllers/Attachments/StaffTicketAttachmentsController.php @@ -10,12 +10,22 @@ use BusinessLogic\Helpers; use Controllers\JsonRetriever; class StaffTicketAttachmentsController { - function post($ticketId) { + function get($attachmentId) { global $hesk_settings, $applicationContext; - if (!$hesk_settings['attachments']['use']) { + $this->verifyAttachmentsAreEnabled($hesk_settings); + } + + private function verifyAttachmentsAreEnabled($heskSettings) { + if (!$heskSettings['attachments']['use']) { throw new ApiFriendlyException('Attachments are disabled on this server', 'Attachments Disabled', 404); } + } + + function post($ticketId) { + global $hesk_settings, $applicationContext; + + $this->verifyAttachmentsAreEnabled($hesk_settings); /* @var $attachmentHandler AttachmentHandler */ $attachmentHandler = $applicationContext->get[AttachmentHandler::class]; diff --git a/api/DataAccess/Attachments/AttachmentGateway.php b/api/DataAccess/Attachments/AttachmentGateway.php index 70931e3e..ac7403fe 100644 --- a/api/DataAccess/Attachments/AttachmentGateway.php +++ b/api/DataAccess/Attachments/AttachmentGateway.php @@ -3,6 +3,7 @@ namespace DataAccess\Attachments; +use BusinessLogic\Attachments\Attachment; use BusinessLogic\Attachments\TicketAttachment; use DataAccess\CommonDao; @@ -27,4 +28,29 @@ class AttachmentGateway extends CommonDao { return $attachmentId; } + + function getAttachmentById($id, $heskSettings) { + $this->init(); + + $rs = hesk_dbQuery("SELECT * + FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "attachments` + WHERE `att_id` = " . intval($id)); + + if (hesk_dbNumRows($rs) === 0) { + return null; + } + + $row = hesk_dbFetchAssoc($rs); + + $attachment = new Attachment(); + $attachment->id = $row['att_id']; + $attachment->savedName = $row['saved_name']; + $attachment->displayName = $row['real_name']; + $attachment->downloadCount = $row['download_count']; + $attachment->fileSize = $row['size']; + + $this->close(); + + return $attachment; + } } \ No newline at end of file diff --git a/api/DataAccess/Files/FileReader.php b/api/DataAccess/Files/FileReader.php new file mode 100644 index 00000000..e30f810c --- /dev/null +++ b/api/DataAccess/Files/FileReader.php @@ -0,0 +1,25 @@ +attachmentGateway = $this->createMock(AttachmentGateway::class); + $this->fileReader = $this->createMock(FileReader::class); + + $this->attachmentRetriever = new AttachmentRetriever($this->attachmentGateway, $this->fileReader); + } + + function testItGetsTheAttachmentFromTheFilesystem() { + + } +} diff --git a/api/index.php b/api/index.php index 1dea517d..b4c1ef29 100644 --- a/api/index.php +++ b/api/index.php @@ -155,6 +155,7 @@ Link::all(array( // Attachments '/v1/staff/tickets/{i}/attachments' => \Controllers\Attachments\StaffTicketAttachmentsController::class, + '/v1/staff/attachments/{i}' => \Controllers\Attachments\StaffTicketAttachmentsController::class, // Any URL that doesn't match goes to the 404 handler '404' => 'handle404'