diff --git a/Admin/Install/Application/Shop/Application.php b/Admin/Install/Application/Shop/Application.php index c21e9c0..fd9d452 100755 --- a/Admin/Install/Application/Shop/Application.php +++ b/Admin/Install/Application/Shop/Application.php @@ -143,7 +143,7 @@ final class Application $this->app->eventManager = new EventManager($this->app->dispatcher); $this->app->accountManager = new AccountManager($this->app->sessionManager); $this->app->l11nServer = LocalizationMapper::get()->where('id', 1)->execute(); - $this->app->orgId = $this->getApplicationOrganization($request, $this->config['app']); + $this->app->unitId = $this->getApplicationOrganization($request, $this->config['app']); $aid = Auth::authenticate($this->app->sessionManager); $request->header->account = $aid; @@ -174,7 +174,7 @@ final class Application $pageView = new ShopView($this->app->l11nManager, $request, $response); $head = new Head(); - $pageView->setData('orgId', $this->app->orgId); + $pageView->setData('unitId', $this->app->unitId); $pageView->setData('head', $head); $response->set('Content', $pageView); @@ -213,7 +213,7 @@ final class Application $request->getData('CSRF'), $request->getRouteVerb(), $this->app->appName, - $this->app->orgId, + $this->app->unitId, $account, $request->getData() ), diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 0a978a0..555715b 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -19,8 +19,8 @@ "type": "INT", "default": null, "null": true, - "foreignTable": "organization_unit", - "foreignKey": "organization_unit_id" + "foreignTable": "unit", + "foreignKey": "unit_id" } } }, diff --git a/Models/AttributeValueType.php b/Models/AttributeValueType.php index a8722a6..a2ca382 100755 --- a/Models/AttributeValueType.php +++ b/Models/AttributeValueType.php @@ -33,4 +33,8 @@ abstract class AttributeValueType extends Enum public const _FLOAT = 3; public const _DATETIME = 4; + + public const _BOOL = 5; + + public const _FLOAT_INT = 6; } diff --git a/Models/NullTicketAttributeTypeL11n.php b/Models/NullTicketAttributeTypeL11n.php deleted file mode 100755 index cd4fd50..0000000 --- a/Models/NullTicketAttributeTypeL11n.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/TicketAttributeTypeL11n.php b/Models/TicketAttributeTypeL11n.php deleted file mode 100755 index 2201e8f..0000000 --- a/Models/TicketAttributeTypeL11n.php +++ /dev/null @@ -1,135 +0,0 @@ -type = $type; - $this->title = $title; - $this->language = $language; - } - - /** - * Get id - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - - /** - * Get language - * - * @return string - * - * @since 1.0.0 - */ - public function getLanguage() : string - { - return $this->language; - } - - /** - * Set language - * - * @param string $language Language - * - * @return void - * - * @since 1.0.0 - */ - public function setLanguage(string $language) : void - { - $this->language = $language; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'title' => $this->title, - 'type' => $this->type, - 'language' => $this->language, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/TicketAttributeTypeL11nMapper.php b/Models/TicketAttributeTypeL11nMapper.php index 37697d4..f40d07f 100755 --- a/Models/TicketAttributeTypeL11nMapper.php +++ b/Models/TicketAttributeTypeL11nMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\Support\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\Localization\BaseStringL11n; /** * Ticket mapper class. @@ -34,8 +35,8 @@ final class TicketAttributeTypeL11nMapper extends DataMapperFactory */ 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' => 'title', 'autocomplete' => true], - 'support_attr_type_l11n_type' => ['name' => 'support_attr_type_l11n_type', 'type' => 'int', 'internal' => 'type'], + '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'], ]; @@ -54,4 +55,12 @@ final class TicketAttributeTypeL11nMapper extends DataMapperFactory * @since 1.0.0 */ public const PRIMARYFIELD ='support_attr_type_l11n_id'; + + /** + * Model to use by the mapper. + * + * @var string + * @since 1.0.0 + */ + public const MODEL = BaseStringL11n::class; } diff --git a/Models/TicketAttributeTypeMapper.php b/Models/TicketAttributeTypeMapper.php index 2c2453d..5f0b427 100755 --- a/Models/TicketAttributeTypeMapper.php +++ b/Models/TicketAttributeTypeMapper.php @@ -52,7 +52,7 @@ final class TicketAttributeTypeMapper extends DataMapperFactory 'mapper' => TicketAttributeTypeL11nMapper::class, 'table' => 'support_attr_type_l11n', 'self' => 'support_attr_type_l11n_type', - 'column' => 'title', + 'column' => 'content', 'external' => null, ], 'defaults' => [ diff --git a/Models/TicketAttributeValue.php b/Models/TicketAttributeValue.php index 70e753b..6a513e1 100755 --- a/Models/TicketAttributeValue.php +++ b/Models/TicketAttributeValue.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Support\Models; +use phpOMS\Localization\BaseStringL11n; use phpOMS\Localization\ISO3166TwoEnum; use phpOMS\Localization\ISO639x1Enum; @@ -38,12 +39,20 @@ class TicketAttributeValue implements \JsonSerializable protected int $id = 0; /** - * Type of the attribute + * Depending attribute type * - * @var int + * @var null|int * @since 1.0.0 */ - public int $type = 0; + public ?int $dependingAttributeType = null; + + /** + * Depending attribute value + * + * @var null|int + * @since 1.0.0 + */ + public ?int $dependingAttributeValue = null; /** * Int value @@ -86,37 +95,19 @@ class TicketAttributeValue implements \JsonSerializable public bool $isDefault = false; /** - * Language + * Unit of the value * * @var string * @since 1.0.0 */ - protected string $language = ISO639x1Enum::_EN; + public string $unit = ''; /** - * Country + * Localization * - * @var string - * @since 1.0.0 + * @var null|BaseStringL11n */ - protected string $country = ISO3166TwoEnum::_USA; - - /** - * Constructor. - * - * @param int $type Type - * @param mixed $value Value - * @param string $language Language - * - * @since 1.0.0 - */ - public function __construct(int $type = 0, $value = '', string $language = ISO639x1Enum::_EN) - { - $this->type = $type; - $this->language = $language; - - $this->setValue($value); - } + private ?BaseStringL11n $l11n = null; /** * Get id @@ -175,55 +166,39 @@ class TicketAttributeValue implements \JsonSerializable } /** - * Set language + * Set l11n * - * @param string $language Language + * @param string|BaseStringL11n $l11n Tag article l11n + * @param string $lang Language * * @return void * * @since 1.0.0 */ - public function setLanguage(string $language) : void + public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void { - $this->language = $language; + if ($l11n instanceof BaseStringL11n) { + $this->l11n = $l11n; + } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { + $this->l11n->content = $l11n; + } else { + $this->l11n = new BaseStringL11n(); + $this->l11n->content = $l11n; + $this->l11n->ref = $this->id; + $this->l11n->setLanguage($lang); + } } /** - * Get language + * Get localization * - * @return string + * @return null|string * * @since 1.0.0 */ - public function getLanguage() : string + public function getL11n() : ?string { - return $this->language; - } - - /** - * Set country - * - * @param string $country Country - * - * @return void - * - * @since 1.0.0 - */ - public function setCountry(string $country) : void - { - $this->country = $country; - } - - /** - * Get country - * - * @return string - * - * @since 1.0.0 - */ - public function getCountry() : string - { - return $this->country; + return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; } /** @@ -233,14 +208,11 @@ class TicketAttributeValue implements \JsonSerializable { return [ 'id' => $this->id, - 'type' => $this->type, 'valueInt' => $this->valueInt, 'valueStr' => $this->valueStr, 'valueDec' => $this->valueDec, 'valueDat' => $this->valueDat, 'isDefault' => $this->isDefault, - 'language' => $this->language, - 'country' => $this->country, ]; } diff --git a/Models/TicketAttributeValueMapper.php b/Models/TicketAttributeValueMapper.php index 4f117ee..ba9c93f 100755 --- a/Models/TicketAttributeValueMapper.php +++ b/Models/TicketAttributeValueMapper.php @@ -35,15 +35,30 @@ final class TicketAttributeValueMapper extends DataMapperFactory 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_type' => ['name' => 'support_attr_value_type', 'type' => 'int', 'internal' => 'type'], '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'], - 'support_attr_value_lang' => ['name' => 'support_attr_value_lang', 'type' => 'string', 'internal' => 'language'], - 'support_attr_value_country' => ['name' => 'support_attr_value_country', 'type' => 'string', 'internal' => 'country'], ]; + /** + * 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. * diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 9bec941..a510176 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -55,7 +55,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase }; $this->app->dbPool = $GLOBALS['dbpool']; - $this->app->orgId = 1; + $this->app->unitId = 1; $this->app->accountManager = new AccountManager($GLOBALS['session']); $this->app->appSettings = new CoreSettings(); $this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/');