Bootswatch, Summernote, and Captcheck mods for Mods for HESK (mods-for-hesk.com). In use at support.netsyms.com.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AttachmentRetriever.php 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace BusinessLogic\Attachments;
  3. use BusinessLogic\Exceptions\AccessViolationException;
  4. use BusinessLogic\Exceptions\ApiFriendlyException;
  5. use BusinessLogic\Security\UserToTicketChecker;
  6. use DataAccess\Attachments\AttachmentGateway;
  7. use DataAccess\Files\FileReader;
  8. use DataAccess\Tickets\TicketGateway;
  9. class AttachmentRetriever {
  10. /* @var $attachmentGateway AttachmentGateway */
  11. private $attachmentGateway;
  12. /* @var $fileReader FileReader */
  13. private $fileReader;
  14. /* @var $ticketGateway TicketGateway */
  15. private $ticketGateway;
  16. /* @var $userToTicketChecker UserToTicketChecker */
  17. private $userToTicketChecker;
  18. function __construct($attachmentGateway, $fileReader, $ticketGateway, $userToTicketChecker) {
  19. $this->attachmentGateway = $attachmentGateway;
  20. $this->fileReader = $fileReader;
  21. $this->ticketGateway = $ticketGateway;
  22. $this->userToTicketChecker = $userToTicketChecker;
  23. }
  24. //-- TODO Test
  25. function getAttachmentContentsForTrackingId($trackingId, $attachmentId, $userContext, $heskSettings) {
  26. $ticket = $this->ticketGateway->getTicketByTrackingId($trackingId, $heskSettings);
  27. if ($ticket === null) {
  28. throw new ApiFriendlyException("Ticket {$trackingId} not found!", "Ticket Not Found", 404);
  29. }
  30. $attachment = $this->attachmentGateway->getAttachmentById($attachmentId, $heskSettings);
  31. return array('meta' => $attachment,
  32. 'contents' => $this->fileReader->readFromFile($attachment->savedName, $heskSettings['attach_dir']));
  33. }
  34. function getAttachmentContentsForTicket($ticketId, $attachmentId, $userContext, $heskSettings) {
  35. $ticket = $this->ticketGateway->getTicketById($ticketId, $heskSettings);
  36. if ($ticket === null) {
  37. throw new ApiFriendlyException("Ticket {$ticketId} not found!", "Ticket Not Found", 404);
  38. }
  39. if (!$this->userToTicketChecker->isTicketAccessibleToUser($userContext, $ticket, $heskSettings)) {
  40. throw new AccessViolationException("User does not have access to attachment {$attachmentId}!");
  41. }
  42. $attachment = $this->attachmentGateway->getAttachmentById($attachmentId, $heskSettings);
  43. $contents = base64_encode($this->fileReader->readFromFile(
  44. $attachment->savedName, $heskSettings['attach_dir']));
  45. return $contents;
  46. }
  47. }