50 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace BusinessLogic\Attachments;
2017-03-17 22:05:51 -04:00
use BusinessLogic\Exceptions\ValidationException;
use BusinessLogic\ValidationModel;
2017-03-17 22:05:51 -04:00
class AttachmentHandler {
2017-03-17 22:05:51 -04:00
/**
* @param $createAttachmentModel CreateAttachmentForTicketModel
*/
function createAttachmentForTicket($createAttachmentModel) {
2017-03-17 22:05:51 -04:00
$this->validate($createAttachmentModel);
}
2017-03-17 22:05:51 -04:00
/**
* @param $createAttachmentModel CreateAttachmentForTicketModel
* @throws ValidationException
*/
private function validate($createAttachmentModel) {
2017-03-17 22:05:51 -04:00
$errorKeys = array();
if ($createAttachmentModel->attachmentContents === null ||
trim($createAttachmentModel->attachmentContents) === '') {
$errorKeys[] = 'CONTENTS_EMPTY';
}
if (base64_decode($createAttachmentModel->attachmentContents, true) === false) {
$errorKeys[] = 'CONTENTS_NOT_BASE_64';
}
if ($createAttachmentModel->displayName === null ||
trim($createAttachmentModel->displayName === '')) {
$errorKeys[] = 'DISPLAY_NAME_EMPTY';
}
if ($createAttachmentModel->ticketId === null ||
$createAttachmentModel->ticketId < 1) {
$errorKeys[] = 'TICKET_ID_MISSING';
}
if (count($errorKeys) > 0) {
$validationModel = new ValidationModel();
$validationModel->errorKeys = $errorKeys;
$validationModel->valid = false;
throw new ValidationException($validationModel);
}
}
}