diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 3310c55..73c970c 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -88,207 +88,5 @@ "foreignKey": "support_ticket_id" } } - }, - "support_attr_type": { - "name": "support_attr_type", - "fields": { - "support_attr_type_id": { - "name": "support_attr_type_id", - "type": "INT", - "null": false, - "primary": true, - "autoincrement": true - }, - "support_attr_type_name": { - "name": "support_attr_type_name", - "type": "VARCHAR(255)", - "null": false - }, - "support_attr_type_fields": { - "name": "support_attr_type_fields", - "type": "INT(11)", - "null": false - }, - "support_attr_type_custom": { - "name": "support_attr_type_custom", - "type": "TINYINT(1)", - "null": false - }, - "support_attr_type_required": { - "description": "Every ticket must have this attribute type if set to true.", - "name": "support_attr_type_required", - "type": "TINYINT(1)", - "null": false - }, - "support_attr_type_pattern": { - "description": "This is a regex validation pattern.", - "name": "support_attr_type_pattern", - "type": "VARCHAR(255)", - "null": false - } - } - }, - "support_attr_type_l11n": { - "name": "support_attr_type_l11n", - "fields": { - "support_attr_type_l11n_id": { - "name": "support_attr_type_l11n_id", - "type": "INT", - "null": false, - "primary": true, - "autoincrement": true - }, - "support_attr_type_l11n_title": { - "name": "support_attr_type_l11n_title", - "type": "VARCHAR(255)", - "null": false - }, - "support_attr_type_l11n_type": { - "name": "support_attr_type_l11n_type", - "type": "INT(11)", - "null": false, - "foreignTable": "support_attr_type", - "foreignKey": "support_attr_type_id" - }, - "support_attr_type_l11n_lang": { - "name": "support_attr_type_l11n_lang", - "type": "VARCHAR(2)", - "null": false, - "foreignTable": "language", - "foreignKey": "language_639_1" - } - } - }, - "support_attr_value": { - "name": "support_attr_value", - "fields": { - "support_attr_value_id": { - "name": "support_attr_value_id", - "type": "INT", - "null": false, - "primary": true, - "autoincrement": true - }, - "support_attr_value_default": { - "name": "support_attr_value_default", - "type": "TINYINT(1)", - "null": false - }, - "support_attr_value_valueStr": { - "name": "support_attr_value_valueStr", - "type": "VARCHAR(255)", - "null": true, - "default": null - }, - "support_attr_value_valueInt": { - "name": "support_attr_value_valueInt", - "type": "INT(11)", - "null": true, - "default": null - }, - "support_attr_value_valueDec": { - "name": "support_attr_value_valueDec", - "type": "DECIMAL(19,5)", - "null": true, - "default": null - }, - "support_attr_value_valueDat": { - "name": "support_attr_value_valueDat", - "type": "DATETIME", - "null": true, - "default": null - } - } - }, - "support_attr_value_l11n": { - "name": "support_attr_value_l11n", - "fields": { - "support_attr_value_l11n_id": { - "name": "support_attr_value_l11n_id", - "type": "INT", - "null": false, - "primary": true, - "autoincrement": true - }, - "support_attr_value_l11n_title": { - "name": "support_attr_value_l11n_title", - "type": "VARCHAR(255)", - "null": false - }, - "support_attr_value_l11n_value": { - "name": "support_attr_value_l11n_value", - "type": "INT(11)", - "null": false, - "foreignTable": "support_attr_value", - "foreignKey": "support_attr_value_id" - }, - "support_attr_value_l11n_lang": { - "name": "support_attr_value_l11n_lang", - "type": "VARCHAR(2)", - "null": false, - "foreignTable": "language", - "foreignKey": "language_639_1" - } - } - }, - "support_ticket_attr_default": { - "name": "support_ticket_attr_default", - "fields": { - "support_ticket_attr_default_id": { - "name": "support_ticket_attr_default_id", - "type": "INT", - "null": false, - "primary": true, - "autoincrement": true - }, - "support_ticket_attr_default_type": { - "name": "support_ticket_attr_default_type", - "type": "INT(11)", - "null": false, - "foreignTable": "support_attr_type", - "foreignKey": "support_attr_type_id" - }, - "support_ticket_attr_default_value": { - "name": "support_ticket_attr_default_value", - "type": "INT(11)", - "null": false, - "foreignTable": "support_attr_value", - "foreignKey": "support_attr_value_id" - } - } - }, - "support_ticket_attr": { - "name": "support_ticket_attr", - "fields": { - "support_ticket_attr_id": { - "name": "support_ticket_attr_id", - "type": "INT", - "null": false, - "primary": true, - "autoincrement": true - }, - "support_ticket_attr_ticket": { - "name": "support_ticket_attr_ticket", - "type": "INT(11)", - "null": false, - "foreignTable": "support_ticket", - "foreignKey": "support_ticket_id" - }, - "support_ticket_attr_type": { - "name": "support_ticket_attr_type", - "type": "INT(11)", - "null": false, - "foreignTable": "support_attr_type", - "foreignKey": "support_attr_type_id" - }, - "support_ticket_attr_value": { - "name": "support_ticket_attr_value", - "type": "INT(11)", - "null": true, - "default": null, - "foreignTable": "support_attr_value", - "foreignKey": "support_attr_value_id" - } - } } } \ No newline at end of file diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 64c0284..ea639eb 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -16,27 +16,15 @@ namespace Modules\Support\Controller; use Modules\Admin\Models\NullAccount; use Modules\Support\Models\NullSupportApp; -use Modules\Support\Models\NullTicketAttributeType; -use Modules\Support\Models\NullTicketAttributeValue; use Modules\Support\Models\SupportApp; use Modules\Support\Models\SupportAppMapper; use Modules\Support\Models\Ticket; -use Modules\Support\Models\TicketAttribute; -use Modules\Support\Models\TicketAttributeMapper; -use Modules\Support\Models\TicketAttributeType; -use Modules\Support\Models\TicketAttributeTypeL11nMapper; -use Modules\Support\Models\TicketAttributeTypeMapper; -use Modules\Support\Models\TicketAttributeValue; -use Modules\Support\Models\TicketAttributeValueL11nMapper; -use Modules\Support\Models\TicketAttributeValueMapper; use Modules\Support\Models\TicketElement; use Modules\Support\Models\TicketElementMapper; use Modules\Support\Models\TicketMapper; use Modules\Tasks\Models\TaskMapper; use Modules\Tasks\Models\TaskStatus; use Modules\Tasks\Models\TaskType; -use phpOMS\Localization\BaseStringL11n; -use phpOMS\Localization\ISO639x1Enum; use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; @@ -386,370 +374,4 @@ final class ApiController extends Controller return []; } - - /** - * Api method to create ticket attribute - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiTicketAttributeCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void - { - if (!empty($val = $this->validateTicketAttributeCreate($request))) { - $response->header->status = RequestStatusCode::R_400; - $this->createInvalidCreateResponse($request, $response, $val); - - return; - } - - /* - @todo: If value data is in attribute create, create attribute value - - if () { - $attrValue = $this->createTicketAttributeValueFromRequest($request); - $this->createModel($request->header->account, $attrValue, TicketAttributeValueMapper::class, 'attr_value', $request->getOrigin()); - } - */ - - $attribute = $this->createTicketAttributeFromRequest($request); - $this->createModel($request->header->account, $attribute, TicketAttributeMapper::class, 'attribute', $request->getOrigin()); - $this->createStandardCreateResponse($request, $response, $attribute); - } - - /** - * Method to create ticket attribute from request. - * - * @param RequestAbstract $request Request - * - * @return TicketAttribute - * - * @since 1.0.0 - */ - private function createTicketAttributeFromRequest(RequestAbstract $request) : TicketAttribute - { - $attribute = new TicketAttribute(); - $attribute->ticket = (int) $request->getData('ticket'); - $attribute->type = new NullTicketAttributeType((int) $request->getData('type')); - $attribute->value = new NullTicketAttributeValue((int) $request->getData('value')); - - return $attribute; - } - - /** - * Validate ticket attribute create request - * - * @param RequestAbstract $request Request - * - * @return array - * - * @since 1.0.0 - */ - private function validateTicketAttributeCreate(RequestAbstract $request) : array - { - $val = []; - if (($val['type'] = !$request->hasData('type')) - || ($val['value'] = !$request->hasData('value')) - || ($val['ticket'] = !$request->hasData('ticket')) - ) { - return $val; - } - - return []; - } - - /** - * Api method to create ticket attribute l11n - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiTicketAttributeTypeL11nCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void - { - if (!empty($val = $this->validateTicketAttributeTypeL11nCreate($request))) { - $response->header->status = RequestStatusCode::R_400; - $this->createInvalidCreateResponse($request, $response, $val); - - return; - } - - $attrL11n = $this->createTicketAttributeTypeL11nFromRequest($request); - $this->createModel($request->header->account, $attrL11n, TicketAttributeTypeL11nMapper::class, 'attr_type_l11n', $request->getOrigin()); - $this->createStandardCreateResponse($request, $response, $attrL11n); - } - - /** - * Method to create ticket attribute l11n from request. - * - * @param RequestAbstract $request Request - * - * @return BaseStringL11n - * - * @since 1.0.0 - */ - private function createTicketAttributeTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n - { - $attrL11n = new BaseStringL11n(); - $attrL11n->ref = $request->getDataInt('type') ?? 0; - $attrL11n->setLanguage( - $request->getDataString('language') ?? $request->header->l11n->language - ); - $attrL11n->content = $request->getDataString('title') ?? ''; - - return $attrL11n; - } - - /** - * Validate ticket attribute l11n create request - * - * @param RequestAbstract $request Request - * - * @return array - * - * @since 1.0.0 - */ - private function validateTicketAttributeTypeL11nCreate(RequestAbstract $request) : array - { - $val = []; - if (($val['title'] = !$request->hasData('title')) - || ($val['type'] = !$request->hasData('type')) - ) { - return $val; - } - - return []; - } - - /** - * Api method to create ticket attribute type - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiTicketAttributeTypeCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void - { - if (!empty($val = $this->validateTicketAttributeTypeCreate($request))) { - $response->header->status = RequestStatusCode::R_400; - $this->createInvalidCreateResponse($request, $response, $val); - - return; - } - - $attrType = $this->createTicketAttributeTypeFromRequest($request); - $this->createModel($request->header->account, $attrType, TicketAttributeTypeMapper::class, 'attr_type', $request->getOrigin()); - $this->createStandardCreateResponse($request, $response, $attrType); - } - - /** - * Method to create ticket attribute from request. - * - * @param RequestAbstract $request Request - * - * @return TicketAttributeType - * - * @since 1.0.0 - */ - private function createTicketAttributeTypeFromRequest(RequestAbstract $request) : TicketAttributeType - { - $attrType = new TicketAttributeType(); - $attrType->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN); - $attrType->fields = $request->getDataInt('fields') ?? 0; - $attrType->custom = $request->getDataBool('custom') ?? false; - - return $attrType; - } - - /** - * Validate ticket attribute create request - * - * @param RequestAbstract $request Request - * - * @return array - * - * @since 1.0.0 - */ - private function validateTicketAttributeTypeCreate(RequestAbstract $request) : array - { - $val = []; - if (($val['title'] = !$request->hasData('title')) - ) { - return $val; - } - - return []; - } - - /** - * Api method to create ticket attribute value - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiTicketAttributeValueCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void - { - if (!empty($val = $this->validateTicketAttributeValueCreate($request))) { - $response->header->status = RequestStatusCode::R_400; - $this->createInvalidCreateResponse($request, $response, $val); - - return; - } - - $attrValue = $this->createTicketAttributeValueFromRequest($request); - $this->createModel($request->header->account, $attrValue, TicketAttributeValueMapper::class, 'attr_value', $request->getOrigin()); - - if ($attrValue->isDefault) { - $this->createModelRelation( - $request->header->account, - (int) $request->getData('type'), - $attrValue->id, - TicketAttributeTypeMapper::class, 'defaults', '', $request->getOrigin() - ); - } - - $this->createStandardCreateResponse($request, $response, $attrValue); - } - - /** - * Method to create ticket attribute value from request. - * - * @param RequestAbstract $request Request - * - * @return TicketAttributeValue - * - * @since 1.0.0 - */ - private function createTicketAttributeValueFromRequest(RequestAbstract $request) : TicketAttributeValue - { - /** @var TicketAttributeType $type */ - $type = TicketAttributeTypeMapper::get() - ->where('id', $request->getDataInt('type') ?? 0) - ->execute(); - - $attrValue = new TicketAttributeValue(); - $attrValue->isDefault = $request->getDataBool('default') ?? false; - $attrValue->setValue($request->getDataString('value'), $type->datatype); - - if ($request->hasData('title')) { - $attrValue->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN); - } - - return $attrValue; - } - - /** - * Validate ticket attribute value create request - * - * @param RequestAbstract $request Request - * - * @return array - * - * @since 1.0.0 - */ - private function validateTicketAttributeValueCreate(RequestAbstract $request) : array - { - $val = []; - if (($val['type'] = !$request->hasData('type')) - || ($val['value'] = !$request->hasData('value')) - ) { - return $val; - } - - return []; - } - - /** - * Api method to create ticket attribute l11n - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiTicketAttributeValueL11nCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void - { - if (!empty($val = $this->validateTicketAttributeValueL11nCreate($request))) { - $response->header->status = RequestStatusCode::R_400; - $this->createInvalidCreateResponse($request, $response, $val); - - return; - } - - $attrL11n = $this->createTicketAttributeValueL11nFromRequest($request); - $this->createModel($request->header->account, $attrL11n, TicketAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin()); - $this->createStandardCreateResponse($request, $response, $attrL11n); - } - - /** - * Method to create ticket attribute l11n from request. - * - * @param RequestAbstract $request Request - * - * @return BaseStringL11n - * - * @since 1.0.0 - */ - private function createTicketAttributeValueL11nFromRequest(RequestAbstract $request) : BaseStringL11n - { - $attrL11n = new BaseStringL11n(); - $attrL11n->ref = $request->getDataInt('value') ?? 0; - $attrL11n->setLanguage( - $request->getDataString('language') ?? $request->header->l11n->language - ); - $attrL11n->content = $request->getDataString('title') ?? ''; - - return $attrL11n; - } - - /** - * Validate ticket attribute l11n create request - * - * @param RequestAbstract $request Request - * - * @return array - * - * @since 1.0.0 - */ - private function validateTicketAttributeValueL11nCreate(RequestAbstract $request) : array - { - $val = []; - if (($val['title'] = !$request->hasData('title')) - || ($val['value'] = !$request->hasData('value')) - ) { - return $val; - } - - return []; - } } diff --git a/Models/AttributeValueType.php b/Models/AttributeValueType.php deleted file mode 100755 index a4cb2bd..0000000 --- a/Models/AttributeValueType.php +++ /dev/null @@ -1,40 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/NullTicketAttributeType.php b/Models/NullTicketAttributeType.php deleted file mode 100755 index 76d79a5..0000000 --- a/Models/NullTicketAttributeType.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/NullTicketAttributeValue.php b/Models/NullTicketAttributeValue.php deleted file mode 100755 index 3d91b89..0000000 --- a/Models/NullTicketAttributeValue.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/Ticket.php b/Models/Ticket.php index d0079ac..5266bf8 100755 --- a/Models/Ticket.php +++ b/Models/Ticket.php @@ -71,14 +71,6 @@ class Ticket */ public ?Account $for = null; - /** - * Attributes. - * - * @var int[]|TicketAttribute[] - * @since 1.0.0 - */ - private array $attributes = []; - /** * Constructor. * @@ -183,32 +175,6 @@ class Ticket return $this->ticketElements[$id] ?? new NullTicketElement(); } - /** - * Add attribute to item - * - * @param TicketAttribute $attribute Note - * - * @return void - * - * @since 1.0.0 - */ - public function addAttribute(TicketAttribute $attribute) : void - { - $this->attributes[] = $attribute; - } - - /** - * Get attributes - * - * @return int[]|TicketAttribute[] - * - * @since 1.0.0 - */ - public function getAttributes() : array - { - return $this->attributes; - } - /** * {@inheritdoc} */ @@ -220,7 +186,6 @@ class Ticket 'app' => $this->app, 'for' => $this->for, 'ticketElements' => $this->ticketElements, - 'attributes' => $this->attributes, ]; } diff --git a/Models/TicketAttribute.php b/Models/TicketAttribute.php deleted file mode 100755 index 525ddbe..0000000 --- a/Models/TicketAttribute.php +++ /dev/null @@ -1,90 +0,0 @@ -type = new TicketAttributeType(); - $this->value = new TicketAttributeValue(); - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'ticket' => $this->ticket, - 'type' => $this->type, - 'value' => $this->value, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/TicketAttributeMapper.php b/Models/TicketAttributeMapper.php deleted file mode 100755 index 26d4058..0000000 --- a/Models/TicketAttributeMapper.php +++ /dev/null @@ -1,77 +0,0 @@ - - */ -final class TicketAttributeMapper extends DataMapperFactory -{ - /** - * Columns. - * - * @var array - * @since 1.0.0 - */ - public const COLUMNS = [ - 'support_ticket_attr_id' => ['name' => 'support_ticket_attr_id', 'type' => 'int', 'internal' => 'id'], - 'support_ticket_attr_ticket' => ['name' => 'support_ticket_attr_ticket', 'type' => 'int', 'internal' => 'ticket'], - 'support_ticket_attr_type' => ['name' => 'support_ticket_attr_type', 'type' => 'int', 'internal' => 'type'], - 'support_ticket_attr_value' => ['name' => 'support_ticket_attr_value', 'type' => 'int', 'internal' => 'value'], - ]; - - /** - * Has one relation. - * - * @var array - * @since 1.0.0 - */ - public const OWNS_ONE = [ - 'type' => [ - 'mapper' => TicketAttributeTypeMapper::class, - 'external' => 'support_ticket_attr_type', - ], - 'value' => [ - 'mapper' => TicketAttributeValueMapper::class, - 'external' => 'support_ticket_attr_value', - ], - ]; - - /** - * Primary table. - * - * @var string - * @since 1.0.0 - */ - public const TABLE = 'support_ticket_attr'; - - /** - * Primary field name. - * - * @var string - * @since 1.0.0 - */ - public const PRIMARYFIELD = 'support_ticket_attr_id'; -} diff --git a/Models/TicketAttributeType.php b/Models/TicketAttributeType.php deleted file mode 100755 index be63a99..0000000 --- a/Models/TicketAttributeType.php +++ /dev/null @@ -1,160 +0,0 @@ -setL11n($name); - } - - /** - * Set l11n - * - * @param string|BaseStringL11n $l11n Tag article l11n - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void - { - if ($l11n instanceof BaseStringL11n) { - $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getL11n() : string - { - if (!isset($this->l11n)) { - return ''; - } - - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'fields' => $this->fields, - 'custom' => $this->custom, - 'validationPattern' => $this->validationPattern, - 'isRequired' => $this->isRequired, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/TicketAttributeTypeL11nMapper.php b/Models/TicketAttributeTypeL11nMapper.php deleted file mode 100755 index d3dad40..0000000 --- a/Models/TicketAttributeTypeL11nMapper.php +++ /dev/null @@ -1,69 +0,0 @@ - - */ -final class TicketAttributeTypeL11nMapper extends DataMapperFactory -{ - /** - * Columns. - * - * @var array - * @since 1.0.0 - */ - public const COLUMNS = [ - 'support_attr_type_l11n_id' => ['name' => 'support_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'support_attr_type_l11n_title' => ['name' => 'support_attr_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], - 'support_attr_type_l11n_type' => ['name' => 'support_attr_type_l11n_type', 'type' => 'int', 'internal' => 'ref'], - 'support_attr_type_l11n_lang' => ['name' => 'support_attr_type_l11n_lang', 'type' => 'string', 'internal' => 'language'], - ]; - - /** - * Primary table. - * - * @var string - * @since 1.0.0 - */ - public const TABLE = 'support_attr_type_l11n'; - - /** - * Primary field name. - * - * @var string - * @since 1.0.0 - */ - public const PRIMARYFIELD = 'support_attr_type_l11n_id'; - - /** - * Model to use by the mapper. - * - * @var class-string - * @since 1.0.0 - */ - public const MODEL = BaseStringL11n::class; -} diff --git a/Models/TicketAttributeTypeMapper.php b/Models/TicketAttributeTypeMapper.php deleted file mode 100755 index 68d52aa..0000000 --- a/Models/TicketAttributeTypeMapper.php +++ /dev/null @@ -1,84 +0,0 @@ - - */ -final class TicketAttributeTypeMapper extends DataMapperFactory -{ - /** - * Columns. - * - * @var array - * @since 1.0.0 - */ - public const COLUMNS = [ - 'support_attr_type_id' => ['name' => 'support_attr_type_id', 'type' => 'int', 'internal' => 'id'], - 'support_attr_type_name' => ['name' => 'support_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], - 'support_attr_type_fields' => ['name' => 'support_attr_type_fields', 'type' => 'int', 'internal' => 'fields'], - 'support_attr_type_custom' => ['name' => 'support_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'], - 'support_attr_type_pattern' => ['name' => 'support_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'], - 'support_attr_type_required' => ['name' => 'support_attr_type_required', 'type' => 'bool', 'internal' => 'isRequired'], - ]; - - /** - * Has many relation. - * - * @var array - * @since 1.0.0 - */ - public const HAS_MANY = [ - 'l11n' => [ - 'mapper' => TicketAttributeTypeL11nMapper::class, - 'table' => 'support_attr_type_l11n', - 'self' => 'support_attr_type_l11n_type', - 'column' => 'content', - 'external' => null, - ], - 'defaults' => [ - 'mapper' => TicketAttributeValueMapper::class, - 'table' => 'support_ticket_attr_default', - 'self' => 'support_ticket_attr_default_type', - 'external' => 'support_ticket_attr_default_value', - ], - ]; - - /** - * Primary table. - * - * @var string - * @since 1.0.0 - */ - public const TABLE = 'support_attr_type'; - - /** - * Primary field name. - * - * @var string - * @since 1.0.0 - */ - public const PRIMARYFIELD = 'support_attr_type_id'; -} diff --git a/Models/TicketAttributeValue.php b/Models/TicketAttributeValue.php deleted file mode 100755 index c25865e..0000000 --- a/Models/TicketAttributeValue.php +++ /dev/null @@ -1,218 +0,0 @@ -valueStr = (string) $value; - } elseif ($datatype === AttributeValueType::_INT - || $datatype === AttributeValueType::_FLOAT_INT - || $datatype === AttributeValueType::_BOOL - ) { - $this->valueInt = (int) $value; - } elseif ($datatype === AttributeValueType::_FLOAT) { - $this->valueDec = (float) $value; - } elseif ($datatype === AttributeValueType::_DATETIME) { - $this->valueDat = new \DateTime((string) $value); - } - } - - /** - * Get value - * - * @return null|int|string|float|\DateTimeInterface - * - * @since 1.0.0 - */ - public function getValue() : mixed - { - if (!empty($this->valueStr)) { - return $this->valueStr; - } elseif (!empty($this->valueInt)) { - return $this->valueInt; - } elseif (!empty($this->valueDec)) { - return $this->valueDec; - } elseif ($this->valueDat instanceof \DateTimeInterface) { - return $this->valueDat; - } - - return null; - } - - /** - * Set l11n - * - * @param string|BaseStringL11n $l11n Tag article l11n - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void - { - if ($l11n instanceof BaseStringL11n) { - $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->content = $l11n; - $this->l11n->ref = $this->id; - $this->l11n->setLanguage($lang); - } - } - - /** - * Get localization - * - * @return null|string - * - * @since 1.0.0 - */ - public function getL11n() : ?string - { - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'valueInt' => $this->valueInt, - 'valueStr' => $this->valueStr, - 'valueDec' => $this->valueDec, - 'valueDat' => $this->valueDat, - 'isDefault' => $this->isDefault, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/TicketAttributeValueL11nMapper.php b/Models/TicketAttributeValueL11nMapper.php deleted file mode 100755 index 91cfcfa..0000000 --- a/Models/TicketAttributeValueL11nMapper.php +++ /dev/null @@ -1,69 +0,0 @@ - - */ -final class TicketAttributeValueL11nMapper extends DataMapperFactory -{ - /** - * Columns. - * - * @var array - * @since 1.0.0 - */ - public const COLUMNS = [ - 'support_attr_value_l11n_id' => ['name' => 'support_attr_value_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'support_attr_value_l11n_title' => ['name' => 'support_attr_value_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], - 'support_attr_value_l11n_value' => ['name' => 'support_attr_value_l11n_value', 'type' => 'int', 'internal' => 'ref'], - 'support_attr_value_l11n_lang' => ['name' => 'support_attr_value_l11n_lang', 'type' => 'string', 'internal' => 'language'], - ]; - - /** - * Primary table. - * - * @var string - * @since 1.0.0 - */ - public const TABLE = 'support_attr_value_l11n'; - - /** - * Primary field name. - * - * @var string - * @since 1.0.0 - */ - public const PRIMARYFIELD = 'support_attr_value_l11n_id'; - - /** - * Model to use by the mapper. - * - * @var class-string - * @since 1.0.0 - */ - public const MODEL = BaseStringL11n::class; -} diff --git a/Models/TicketAttributeValueMapper.php b/Models/TicketAttributeValueMapper.php deleted file mode 100755 index 73115e4..0000000 --- a/Models/TicketAttributeValueMapper.php +++ /dev/null @@ -1,80 +0,0 @@ - - */ -final class TicketAttributeValueMapper extends DataMapperFactory -{ - /** - * Columns. - * - * @var array - * @since 1.0.0 - */ - public const COLUMNS = [ - 'support_attr_value_id' => ['name' => 'support_attr_value_id', 'type' => 'int', 'internal' => 'id'], - 'support_attr_value_default' => ['name' => 'support_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'], - 'support_attr_value_valueStr' => ['name' => 'support_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'], - 'support_attr_value_valueInt' => ['name' => 'support_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'], - 'support_attr_value_valueDec' => ['name' => 'support_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'], - 'support_attr_value_valueDat' => ['name' => 'support_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'], - ]; - - /** - * Has many relation. - * - * @var array - * @since 1.0.0 - */ - /* - public const HAS_MANY = [ - 'l11n' => [ - 'mapper' => EventAttributeValueL11nMapper::class, - 'table' => 'task_attr_value_l11n', - 'self' => 'task_attr_value_l11n_value', - 'column' => 'content', - 'external' => null, - ], - ]; - */ - - /** - * Primary table. - * - * @var string - * @since 1.0.0 - */ - public const TABLE = 'support_attr_value'; - - /** - * Primary field name. - * - * @var string - * @since 1.0.0 - */ - public const PRIMARYFIELD = 'support_attr_value_id'; -} diff --git a/Models/TicketMapper.php b/Models/TicketMapper.php index 04e0e3c..268bd91 100755 --- a/Models/TicketMapper.php +++ b/Models/TicketMapper.php @@ -70,13 +70,6 @@ final class TicketMapper extends DataMapperFactory 'self' => 'support_ticket_element_ticket', 'external' => null, ], - 'attributes' => [ - 'mapper' => TicketAttributeMapper::class, - 'table' => 'support_ticket_attr', - 'self' => 'support_ticket_attr_ticket', - 'conditional' => true, - 'external' => null, - ], ]; /** diff --git a/tests/Controller/Api/ApiControllerAttributeTrait.php b/tests/Controller/Api/ApiControllerAttributeTrait.php deleted file mode 100755 index 8a84e1b..0000000 --- a/tests/Controller/Api/ApiControllerAttributeTrait.php +++ /dev/null @@ -1,219 +0,0 @@ -header->account = 1; - $request->setData('title', 'EN:1'); - $request->setData('language', ISO639x1Enum::_EN); - - $this->module->apiTicketAttributeTypeCreate($request, $response); - self::assertGreaterThan(0, $response->get('')['response']->id); - } - - /** - * @covers Modules\Support\Controller\ApiController - * @group module - */ - public function testApiTicketAttributeTypeL11nCreate() : void - { - $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); - - $request->header->account = 1; - $request->setData('title', 'DE:2'); - $request->setData('type', '1'); - $request->setData('language', ISO639x1Enum::_DE); - - $this->module->apiTicketAttributeTypeL11nCreate($request, $response); - self::assertGreaterThan(0, $response->get('')['response']->id); - } - - /** - * @covers Modules\Support\Controller\ApiController - * @group module - */ - public function testApiTicketAttributeValueIntCreate() : void - { - $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); - - $request->header->account = 1; - $request->setData('default', '1'); - $request->setData('type', '1'); - $request->setData('value', '1'); - $request->setData('language', ISO639x1Enum::_DE); - $request->setData('country', ISO3166TwoEnum::_DEU); - - $this->module->apiTicketAttributeValueCreate($request, $response); - self::assertGreaterThan(0, $response->get('')['response']->id); - } - - /** - * @covers Modules\Support\Controller\ApiController - * @group module - */ - public function testApiTicketAttributeValueStrCreate() : void - { - $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); - - $request->header->account = 1; - $request->setData('type', '1'); - $request->setData('value', '1'); - $request->setData('language', ISO639x1Enum::_DE); - $request->setData('country', ISO3166TwoEnum::_DEU); - - $this->module->apiTicketAttributeValueCreate($request, $response); - self::assertGreaterThan(0, $response->get('')['response']->id); - } - - /** - * @covers Modules\Support\Controller\ApiController - * @group module - */ - public function testApiTicketAttributeValueFloatCreate() : void - { - $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); - - $request->header->account = 1; - $request->setData('type', '1'); - $request->setData('value', '1.1'); - $request->setData('language', ISO639x1Enum::_DE); - $request->setData('country', ISO3166TwoEnum::_DEU); - - $this->module->apiTicketAttributeValueCreate($request, $response); - self::assertGreaterThan(0, $response->get('')['response']->id); - } - - /** - * @covers Modules\Support\Controller\ApiController - * @group module - */ - public function testApiTicketAttributeValueDatCreate() : void - { - $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); - - $request->header->account = 1; - $request->setData('type', '1'); - $request->setData('value', '2020-08-02'); - $request->setData('language', ISO639x1Enum::_DE); - $request->setData('country', ISO3166TwoEnum::_DEU); - - $this->module->apiTicketAttributeValueCreate($request, $response); - self::assertGreaterThan(0, $response->get('')['response']->id); - } - - /** - * @covers Modules\Support\Controller\ApiController - * @group module - */ - public function testApiTicketAttributeCreate() : void - { - $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); - - $request->header->account = 1; - $request->setData('ticket', '1'); - $request->setData('value', '1'); - $request->setData('type', '1'); - - $this->module->apiTicketAttributeCreate($request, $response); - self::assertGreaterThan(0, $response->get('')['response']->id); - } - - /** - * @covers Modules\Support\Controller\ApiController - * @group module - */ - public function testApiTicketAttributeValueCreateInvalidData() : void - { - $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); - - $request->header->account = 1; - $request->setData('invalid', '1'); - - $this->module->apiTicketAttributeValueCreate($request, $response); - self::assertEquals(RequestStatusCode::R_400, $response->header->status); - } - - /** - * @covers Modules\Support\Controller\ApiController - * @group module - */ - public function testApiTicketAttributeTypeCreateInvalidData() : void - { - $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); - - $request->header->account = 1; - $request->setData('invalid', '1'); - - $this->module->apiTicketAttributeTypeCreate($request, $response); - self::assertEquals(RequestStatusCode::R_400, $response->header->status); - } - - /** - * @covers Modules\Support\Controller\ApiController - * @group module - */ - public function testApiTicketAttributeTypeL11nCreateInvalidData() : void - { - $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); - - $request->header->account = 1; - $request->setData('invalid', '1'); - - $this->module->apiTicketAttributeTypeL11nCreate($request, $response); - self::assertEquals(RequestStatusCode::R_400, $response->header->status); - } - - /** - * @covers Modules\Support\Controller\ApiController - * @group module - */ - public function testApiTicketAttributeCreateInvalidData() : void - { - $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); - - $request->header->account = 1; - $request->setData('invalid', '1'); - - $this->module->apiTicketAttributeCreate($request, $response); - self::assertEquals(RequestStatusCode::R_400, $response->header->status); - } -} diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 18400a5..225aa81 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -16,7 +16,6 @@ namespace Modules\Support\tests\Controller; use Model\CoreSettings; use Modules\Admin\Models\AccountPermission; -use Modules\Support\tests\Controller\Api\ApiControllerAttributeTrait; use Modules\Support\tests\Controller\Api\ApiControllerTicketTrait; use phpOMS\Account\Account; use phpOMS\Account\AccountManager; @@ -91,5 +90,4 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase } use ApiControllerTicketTrait; - use ApiControllerAttributeTrait; } diff --git a/tests/Models/NullTicketAttributeTest.php b/tests/Models/NullTicketAttributeTest.php deleted file mode 100755 index c456275..0000000 --- a/tests/Models/NullTicketAttributeTest.php +++ /dev/null @@ -1,42 +0,0 @@ -id); - } -} diff --git a/tests/Models/NullTicketAttributeTypeTest.php b/tests/Models/NullTicketAttributeTypeTest.php deleted file mode 100755 index b3e7d77..0000000 --- a/tests/Models/NullTicketAttributeTypeTest.php +++ /dev/null @@ -1,42 +0,0 @@ -id); - } -} diff --git a/tests/Models/NullTicketAttributeValueTest.php b/tests/Models/NullTicketAttributeValueTest.php deleted file mode 100755 index 66589a0..0000000 --- a/tests/Models/NullTicketAttributeValueTest.php +++ /dev/null @@ -1,42 +0,0 @@ -id); - } -} diff --git a/tests/Models/TicketAttributeTest.php b/tests/Models/TicketAttributeTest.php deleted file mode 100755 index 16b18a0..0000000 --- a/tests/Models/TicketAttributeTest.php +++ /dev/null @@ -1,63 +0,0 @@ -attribute = new TicketAttribute(); - } - - /** - * @covers Modules\Support\Models\TicketAttribute - * @group module - */ - public function testDefault() : void - { - self::assertEquals(0, $this->attribute->id); - self::assertInstanceOf('\Modules\Support\Models\TicketAttributeType', $this->attribute->type); - self::assertInstanceOf('\Modules\Support\Models\TicketAttributeValue', $this->attribute->value); - } - - /** - * @covers Modules\Support\Models\TicketAttribute - * @group module - */ - public function testSerialize() : void - { - $serialized = $this->attribute->jsonSerialize(); - - self::assertEquals( - [ - 'id', - 'ticket', - 'type', - 'value', - ], - \array_keys($serialized) - ); - } -} diff --git a/tests/Models/TicketAttributeTypeTest.php b/tests/Models/TicketAttributeTypeTest.php deleted file mode 100755 index 98c1661..0000000 --- a/tests/Models/TicketAttributeTypeTest.php +++ /dev/null @@ -1,78 +0,0 @@ -type = new TicketAttributeType(); - } - - /** - * @covers Modules\Support\Models\TicketAttributeType - * @group module - */ - public function testDefault() : void - { - self::assertEquals(0, $this->type->id); - self::assertEquals('', $this->type->getL11n()); - } - - /** - * @covers Modules\Support\Models\TicketAttributeType - * @group module - */ - public function testL11nInputOutput() : void - { - $this->type->setL11n('Test'); - self::assertEquals('Test', $this->type->getL11n()); - } - - /** - * @covers Modules\Support\Models\TicketAttributeType - * @group module - */ - public function testSerialize() : void - { - $this->type->name = 'Title'; - $this->type->fields = 2; - $this->type->custom = true; - $this->type->validationPattern = '\d*'; - $this->type->isRequired = true; - - self::assertEquals( - [ - 'id' => 0, - 'name' => 'Title', - 'fields' => 2, - 'custom' => true, - 'validationPattern' => '\d*', - 'isRequired' => true, - ], - $this->type->jsonSerialize() - ); - } -} diff --git a/tests/Models/TicketAttributeValueTest.php b/tests/Models/TicketAttributeValueTest.php deleted file mode 100755 index 99343f0..0000000 --- a/tests/Models/TicketAttributeValueTest.php +++ /dev/null @@ -1,108 +0,0 @@ -value = new TicketAttributeValue(); - } - - /** - * @covers Modules\Support\Models\TicketAttributeValue - * @group module - */ - public function testDefault() : void - { - self::assertEquals(0, $this->value->id); - self::assertNull($this->value->getValue()); - self::assertFalse($this->value->isDefault); - } - - /** - * @covers Modules\Support\Models\TicketAttributeValue - * @group module - */ - public function testValueIntInputOutput() : void - { - $this->value->setValue(1, AttributeValueType::_INT); - self::assertEquals(1, $this->value->getValue()); - } - - /** - * @covers Modules\Support\Models\TicketAttributeValue - * @group module - */ - public function testValueFloatInputOutput() : void - { - $this->value->setValue(1.1, AttributeValueType::_FLOAT); - self::assertEquals(1.1, $this->value->getValue()); - } - - /** - * @covers Modules\Support\Models\TicketAttributeValue - * @group module - */ - public function testValueStringInputOutput() : void - { - $this->value->setValue('test', AttributeValueType::_STRING); - self::assertEquals('test', $this->value->getValue()); - } - - /** - * @covers Modules\Support\Models\TicketAttributeValue - * @group module - */ - public function testValueDateInputOutput() : void - { - $dat = new \DateTime('now'); - $this->value->setValue('now', AttributeValueType::_DATETIME); - self::assertEquals($dat->format('Y-m-d'), $this->value->getValue()->format('Y-m-d')); - } - - /** - * @covers Modules\Support\Models\TicketAttributeValue - * @group module - */ - public function testSerialize() : void - { - $this->value->setValue('test', AttributeValueType::_STRING); - $this->value->isDefault = true; - - self::assertEquals( - [ - 'id' => 0, - 'valueInt' => null, - 'valueStr' => 'test', - 'valueDec' => null, - 'valueDat' => null, - 'isDefault' => true, - ], - $this->value->jsonSerialize() - ); - } -} diff --git a/tests/Models/TicketTest.php b/tests/Models/TicketTest.php index 4c464ec..d1040b3 100755 --- a/tests/Models/TicketTest.php +++ b/tests/Models/TicketTest.php @@ -42,7 +42,6 @@ final class TicketTest extends \PHPUnit\Framework\TestCase self::assertEquals(0, $this->ticket->id); self::assertNull($this->ticket->for); self::assertEquals([], $this->ticket->getTicketElements()); - self::assertEquals([], $this->ticket->getAttributes()); self::assertInstanceOf('\Modules\Tasks\Models\Task', $this->ticket->task); self::assertInstanceOf('\Modules\Support\Models\TicketElement', $this->ticket->getTicketElement(999)); self::assertInstanceOf('\Modules\Support\Models\SupportApp', $this->ticket->app); @@ -54,11 +53,8 @@ final class TicketTest extends \PHPUnit\Framework\TestCase */ public function testElementInputOutput() : void { - $element1 = new TicketElement(); - $element1->description = '1'; - - $element2 = new TicketElement(); - $element2->description = '2'; + $element1 = new TicketElement(); + $element2 = new TicketElement(); self::assertEquals(0, $this->ticket->addElement($element1)); self::assertEquals(1, $this->ticket->addElement($element2)); @@ -73,8 +69,7 @@ final class TicketTest extends \PHPUnit\Framework\TestCase */ public function testElementRemove() : void { - $element1 = new TicketElement(); - $element1->description = '1'; + $element1 = new TicketElement(); $this->ticket->addElement($element1); self::assertCount(1, $this->ticket->getTicketElements()); @@ -83,18 +78,6 @@ final class TicketTest extends \PHPUnit\Framework\TestCase self::assertFalse($this->ticket->removeElement(0)); } - /** - * @covers Modules\Support\Models\Ticket - * @group module - */ - public function testAttributeInputOutput() : void - { - $attr = new TicketAttribute(); - $this->ticket->addAttribute($attr); - - self::assertCount(1, $this->ticket->getAttributes()); - } - /** * @covers Modules\Support\Models\Ticket * @group module @@ -107,10 +90,9 @@ final class TicketTest extends \PHPUnit\Framework\TestCase self::assertEquals( [ - 'id' => 0, - 'for' => null, - 'ticketElements' => [], - 'attributes' => [], + 'id' => 0, + 'for' => null, + 'ticketElements' => [], ], $serialized );