From bfe13d806a7b0cc0b7900ebb6719b7cfd1924dd4 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 26 Jan 2023 21:54:13 +0100 Subject: [PATCH] org -> unit change, some new functionality --- Controller/BackendController.php | 2 +- Models/AttributeValueType.php | 4 + Models/NullTaskAttributeTypeL11n.php | 47 ------- Models/TaskAttributeTypeL11n.php | 135 --------------------- Models/TaskAttributeTypeL11nMapper.php | 13 +- Models/TaskAttributeTypeMapper.php | 2 +- Models/TaskAttributeValue.php | 73 ++++++----- Models/TaskAttributeValueL11n.php | 135 --------------------- Models/TaskAttributeValueL11nMapper.php | 12 +- Models/TaskAttributeValueMapper.php | 2 +- tests/Controller/ApiControllerTest.php | 2 +- tests/Controller/BackendControllerTest.php | 2 +- 12 files changed, 65 insertions(+), 364 deletions(-) delete mode 100755 Models/NullTaskAttributeTypeL11n.php delete mode 100755 Models/TaskAttributeTypeL11n.php delete mode 100755 Models/TaskAttributeValueL11n.php diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 68a96d4..c2fa515 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -204,7 +204,7 @@ final class BackendController extends Controller implements DashboardElementInte || $task->isCCAccount($accountId) || $task->isToAccount($accountId)) && !$this->app->accountManager->get($accountId)->hasPermission( - PermissionType::READ, $this->app->orgId, $this->app->appName, self::NAME, PermissionCategory::TASK, $task->getId()) + PermissionType::READ, $this->app->unitId, $this->app->appName, self::NAME, PermissionCategory::TASK, $task->getId()) ) { $view->setTemplate('/Web/Backend/Error/403_inline'); $response->header->status = RequestStatusCode::R_403; diff --git a/Models/AttributeValueType.php b/Models/AttributeValueType.php index ba5eaa9..9329de8 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/NullTaskAttributeTypeL11n.php b/Models/NullTaskAttributeTypeL11n.php deleted file mode 100755 index e00e168..0000000 --- a/Models/NullTaskAttributeTypeL11n.php +++ /dev/null @@ -1,47 +0,0 @@ -id = $id; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/TaskAttributeTypeL11n.php b/Models/TaskAttributeTypeL11n.php deleted file mode 100755 index 7040cc9..0000000 --- a/Models/TaskAttributeTypeL11n.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/TaskAttributeTypeL11nMapper.php b/Models/TaskAttributeTypeL11nMapper.php index 9778bc1..41a7612 100755 --- a/Models/TaskAttributeTypeL11nMapper.php +++ b/Models/TaskAttributeTypeL11nMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\Tasks\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\Localization\BaseStringL11n; /** * Task mapper class. @@ -34,8 +35,8 @@ final class TaskAttributeTypeL11nMapper extends DataMapperFactory */ public const COLUMNS = [ 'task_attr_type_l11n_id' => ['name' => 'task_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'task_attr_type_l11n_title' => ['name' => 'task_attr_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], - 'task_attr_type_l11n_type' => ['name' => 'task_attr_type_l11n_type', 'type' => 'int', 'internal' => 'type'], + 'task_attr_type_l11n_title' => ['name' => 'task_attr_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], + 'task_attr_type_l11n_type' => ['name' => 'task_attr_type_l11n_type', 'type' => 'int', 'internal' => 'ref'], 'task_attr_type_l11n_lang' => ['name' => 'task_attr_type_l11n_lang', 'type' => 'string', 'internal' => 'language'], ]; @@ -54,4 +55,12 @@ final class TaskAttributeTypeL11nMapper extends DataMapperFactory * @since 1.0.0 */ public const PRIMARYFIELD ='task_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/TaskAttributeTypeMapper.php b/Models/TaskAttributeTypeMapper.php index 26be77d..a539cd0 100755 --- a/Models/TaskAttributeTypeMapper.php +++ b/Models/TaskAttributeTypeMapper.php @@ -52,7 +52,7 @@ final class TaskAttributeTypeMapper extends DataMapperFactory 'mapper' => TaskAttributeTypeL11nMapper::class, 'table' => 'task_attr_type_l11n', 'self' => 'task_attr_type_l11n_type', - 'column' => 'title', + 'column' => 'content', 'external' => null, ], 'defaults' => [ diff --git a/Models/TaskAttributeValue.php b/Models/TaskAttributeValue.php index b3d4386..b3a5ed5 100755 --- a/Models/TaskAttributeValue.php +++ b/Models/TaskAttributeValue.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Tasks\Models; +use phpOMS\Localization\BaseStringL11n; use phpOMS\Localization\ISO639x1Enum; /** @@ -37,12 +38,20 @@ class TaskAttributeValue implements \JsonSerializable protected int $id = 0; /** - * Datatype 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 @@ -95,24 +104,9 @@ class TaskAttributeValue implements \JsonSerializable /** * Localization * - * @var null|TaskAttributeValueL11n + * @var null|BaseStringL11n */ - private ?TaskAttributeValueL11n $l11n = null; - - /** - * Constructor. - * - * @param int $type Type - * @param mixed $value Value - * - * @since 1.0.0 - */ - public function __construct(int $type = 0, mixed $value = '') - { - $this->type = $type; - - $this->setValue($value); - } + private ?BaseStringL11n $l11n = null; /** * Get id @@ -129,22 +123,23 @@ class TaskAttributeValue implements \JsonSerializable /** * Set l11n * - * @param string|TaskAttributeValueL11n $l11n Tag article l11n + * @param string|BaseStringL11n $l11n Tag article l11n * @param string $lang Language * * @return void * * @since 1.0.0 */ - public function setL11n(string | TaskAttributeValueL11n $l11n, string $lang = ISO639x1Enum::_EN) : void + public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void { - if ($l11n instanceof TaskAttributeValueL11n) { + if ($l11n instanceof BaseStringL11n) { $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof TaskAttributeValueL11n) { - $this->l11n->title = $l11n; + } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { + $this->l11n->content = $l11n; } else { - $this->l11n = new TaskAttributeValueL11n(); - $this->l11n->title = $l11n; + $this->l11n = new BaseStringL11n(); + $this->l11n->content = $l11n; + $this->l11n->ref = $this->id; $this->l11n->setLanguage($lang); } } @@ -158,7 +153,7 @@ class TaskAttributeValue implements \JsonSerializable */ public function getL11n() : ?string { - return $this->l11n instanceof TaskAttributeValueL11n ? $this->l11n->title : $this->l11n; + return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; } /** @@ -170,16 +165,19 @@ class TaskAttributeValue implements \JsonSerializable * * @since 1.0.0 */ - public function setValue(mixed $value) : void + public function setValue(mixed $value, int $datatype) : void { - if (\is_string($value)) { - $this->valueStr = $value; - } elseif (\is_int($value)) { - $this->valueInt = $value; - } elseif (\is_float($value)) { - $this->valueDec = $value; - } elseif ($value instanceof \DateTimeInterface) { - $this->valueDat = $value; + if ($datatype === AttributeValueType::_STRING) { + $this->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($value); } } @@ -212,7 +210,6 @@ class TaskAttributeValue implements \JsonSerializable { return [ 'id' => $this->id, - 'type' => $this->type, 'valueInt' => $this->valueInt, 'valueStr' => $this->valueStr, 'valueDec' => $this->valueDec, diff --git a/Models/TaskAttributeValueL11n.php b/Models/TaskAttributeValueL11n.php deleted file mode 100755 index b9180cd..0000000 --- a/Models/TaskAttributeValueL11n.php +++ /dev/null @@ -1,135 +0,0 @@ -value = $value; - $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, - 'value' => $this->value, - 'language' => $this->language, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/TaskAttributeValueL11nMapper.php b/Models/TaskAttributeValueL11nMapper.php index 50e3f71..1827ab1 100755 --- a/Models/TaskAttributeValueL11nMapper.php +++ b/Models/TaskAttributeValueL11nMapper.php @@ -34,8 +34,8 @@ final class TaskAttributeValueL11nMapper extends DataMapperFactory */ public const COLUMNS = [ 'task_attr_value_l11n_id' => ['name' => 'task_attr_value_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'task_attr_value_l11n_title' => ['name' => 'task_attr_value_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], - 'task_attr_value_l11n_value' => ['name' => 'task_attr_value_l11n_value', 'type' => 'int', 'internal' => 'value'], + 'task_attr_value_l11n_title' => ['name' => 'task_attr_value_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], + 'task_attr_value_l11n_value' => ['name' => 'task_attr_value_l11n_value', 'type' => 'int', 'internal' => 'ref'], 'task_attr_value_l11n_lang' => ['name' => 'task_attr_value_l11n_lang', 'type' => 'string', 'internal' => 'language'], ]; @@ -54,4 +54,12 @@ final class TaskAttributeValueL11nMapper extends DataMapperFactory * @since 1.0.0 */ public const PRIMARYFIELD ='task_attr_value_l11n_id'; + + /** + * Model to use by the mapper. + * + * @var string + * @since 1.0.0 + */ + public const MODEL = BaseStringL11n::class; } diff --git a/Models/TaskAttributeValueMapper.php b/Models/TaskAttributeValueMapper.php index e759185..e149ff1 100755 --- a/Models/TaskAttributeValueMapper.php +++ b/Models/TaskAttributeValueMapper.php @@ -35,7 +35,6 @@ final class TaskAttributeValueMapper extends DataMapperFactory public const COLUMNS = [ 'task_attr_value_id' => ['name' => 'task_attr_value_id', 'type' => 'int', 'internal' => 'id'], 'task_attr_value_default' => ['name' => 'task_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'], - 'task_attr_value_valuetype' => ['name' => 'task_attr_value_valuetype', 'type' => 'int', 'internal' => 'type'], 'task_attr_value_valueStr' => ['name' => 'task_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'], 'task_attr_value_valueInt' => ['name' => 'task_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'], 'task_attr_value_valueDec' => ['name' => 'task_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'], @@ -54,6 +53,7 @@ final class TaskAttributeValueMapper extends DataMapperFactory 'mapper' => TaskAttributeValueL11nMapper::class, 'table' => 'task_attr_value_l11n', 'self' => 'task_attr_value_l11n_value', + 'column' => 'content', 'external' => null, ], ]; diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 6b6893a..bb05deb 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -52,7 +52,7 @@ final class ControllerTest 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/'); diff --git a/tests/Controller/BackendControllerTest.php b/tests/Controller/BackendControllerTest.php index d78c557..66d5e8d 100755 --- a/tests/Controller/BackendControllerTest.php +++ b/tests/Controller/BackendControllerTest.php @@ -46,7 +46,7 @@ final class BackendControllerTest 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/');