fix static analysis

This commit is contained in:
Dennis Eichhorn 2023-04-09 06:03:39 +02:00
parent 57e12dabb7
commit d085322f68
13 changed files with 53 additions and 785 deletions

View File

@ -16,20 +16,18 @@ namespace Modules\SupplierManagement\Controller;
use Modules\Admin\Models\Account; use Modules\Admin\Models\Account;
use Modules\Admin\Models\Address; use Modules\Admin\Models\Address;
use Modules\Attribute\Models\Attribute;
use Modules\Attribute\Models\AttributeType;
use Modules\Attribute\Models\AttributeValue;
use Modules\Attribute\Models\NullAttributeType;
use Modules\Attribute\Models\NullAttributeValue;
use Modules\Media\Models\MediaMapper; use Modules\Media\Models\MediaMapper;
use Modules\Media\Models\PathSettings; use Modules\Media\Models\PathSettings;
use Modules\Profile\Models\ContactElementMapper;
use Modules\Profile\Models\Profile;
use Modules\SupplierManagement\Models\NullSupplierAttributeType;
use Modules\SupplierManagement\Models\NullSupplierAttributeValue;
use Modules\SupplierManagement\Models\NullSupplierL11nType; use Modules\SupplierManagement\Models\NullSupplierL11nType;
use Modules\SupplierManagement\Models\Supplier; use Modules\SupplierManagement\Models\Supplier;
use Modules\SupplierManagement\Models\SupplierAttribute;
use Modules\SupplierManagement\Models\SupplierAttributeMapper; use Modules\SupplierManagement\Models\SupplierAttributeMapper;
use Modules\SupplierManagement\Models\SupplierAttributeType;
use Modules\SupplierManagement\Models\SupplierAttributeTypeL11nMapper; use Modules\SupplierManagement\Models\SupplierAttributeTypeL11nMapper;
use Modules\SupplierManagement\Models\SupplierAttributeTypeMapper; use Modules\SupplierManagement\Models\SupplierAttributeTypeMapper;
use Modules\SupplierManagement\Models\SupplierAttributeValue;
use Modules\SupplierManagement\Models\SupplierAttributeValueL11nMapper; use Modules\SupplierManagement\Models\SupplierAttributeValueL11nMapper;
use Modules\SupplierManagement\Models\SupplierAttributeValueMapper; use Modules\SupplierManagement\Models\SupplierAttributeValueMapper;
use Modules\SupplierManagement\Models\SupplierL11n; use Modules\SupplierManagement\Models\SupplierL11n;
@ -302,16 +300,16 @@ final class ApiController extends Controller
* *
* @param RequestAbstract $request Request * @param RequestAbstract $request Request
* *
* @return SupplierAttribute * @return Attribute
* *
* @since 1.0.0 * @since 1.0.0
*/ */
private function createSupplierAttributeFromRequest(RequestAbstract $request) : SupplierAttribute private function createSupplierAttributeFromRequest(RequestAbstract $request) : Attribute
{ {
$attribute = new SupplierAttribute(); $attribute = new Attribute();
$attribute->supplier = (int) $request->getData('supplier'); $attribute->ref = (int) $request->getData('supplier');
$attribute->type = new NullSupplierAttributeType((int) $request->getData('type')); $attribute->type = new NullAttributeType((int) $request->getData('type'));
$attribute->value = new NullSupplierAttributeValue((int) $request->getData('value')); $attribute->value = new NullAttributeValue((int) $request->getData('value'));
return $attribute; return $attribute;
} }
@ -440,13 +438,13 @@ final class ApiController extends Controller
* *
* @param RequestAbstract $request Request * @param RequestAbstract $request Request
* *
* @return SupplierAttributeType * @return AttributeType
* *
* @since 1.0.0 * @since 1.0.0
*/ */
private function createSupplierAttributeTypeFromRequest(RequestAbstract $request) : SupplierAttributeType private function createSupplierAttributeTypeFromRequest(RequestAbstract $request) : AttributeType
{ {
$attrType = new SupplierAttributeType($request->getDataString('name') ?? ''); $attrType = new AttributeType($request->getDataString('name') ?? '');
$attrType->datatype = $request->getDataInt('datatype') ?? 0; $attrType->datatype = $request->getDataInt('datatype') ?? 0;
$attrType->custom = $request->getDataBool('custom') ?? false; $attrType->custom = $request->getDataBool('custom') ?? false;
$attrType->isRequired = (bool) ($request->getData('is_required') ?? false); $attrType->isRequired = (bool) ($request->getData('is_required') ?? false);
@ -520,18 +518,18 @@ final class ApiController extends Controller
* *
* @param RequestAbstract $request Request * @param RequestAbstract $request Request
* *
* @return SupplierAttributeValue * @return AttributeValue
* *
* @since 1.0.0 * @since 1.0.0
*/ */
private function createSupplierAttributeValueFromRequest(RequestAbstract $request) : SupplierAttributeValue private function createSupplierAttributeValueFromRequest(RequestAbstract $request) : AttributeValue
{ {
/** @var SupplierAttributeType $type */ /** @var AttributeType $type */
$type = SupplierAttributeTypeMapper::get() $type = SupplierAttributeTypeMapper::get()
->where('id', $request->getDataInt('type') ?? 0) ->where('id', $request->getDataInt('type') ?? 0)
->execute(); ->execute();
$attrValue = new SupplierAttributeValue(); $attrValue = new AttributeValue();
$attrValue->isDefault = $request->getDataBool('default') ?? false; $attrValue->isDefault = $request->getDataBool('default') ?? false;
$attrValue->setValue($request->getData('value'), $type->datatype); $attrValue->setValue($request->getData('value'), $type->datatype);

View File

@ -56,7 +56,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/SupplierManagement/Theme/Backend/attribute-type-list'); $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/attribute-type-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response));
/** @var \Modules\SupplierManagement\Models\SupplierAttributeType[] $attributes */ /** @var \Modules\Attribute\Models\AttributeType[] $attributes */
$attributes = SupplierAttributeTypeMapper::getAll() $attributes = SupplierAttributeTypeMapper::getAll()
->with('l11n') ->with('l11n')
->where('l11n/language', $response->getLanguage()) ->where('l11n/language', $response->getLanguage())
@ -85,7 +85,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/SupplierManagement/Theme/Backend/attribute-value-list'); $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/attribute-value-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response));
/** @var \Modules\SupplierManagement\Models\SupplierAttributeValue[] $attributes */ /** @var \Modules\Attribute\Models\AttributeValue[] $attributes */
$attributes = SupplierAttributeValueMapper::getAll() $attributes = SupplierAttributeValueMapper::getAll()
->with('l11n') ->with('l11n')
->where('l11n/language', $response->getLanguage()) ->where('l11n/language', $response->getLanguage())
@ -114,7 +114,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/SupplierManagement/Theme/Backend/attribute-type'); $view->setTemplate('/Modules/SupplierManagement/Theme/Backend/attribute-type');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response));
/** @var \Modules\SupplierManagement\Models\SupplierAttributeType $attribute */ /** @var \Modules\Attribute\Models\AttributeType $attribute */
$attribute = SupplierAttributeTypeMapper::get() $attribute = SupplierAttributeTypeMapper::get()
->with('l11n') ->with('l11n')
->where('id', (int) $request->getData('id')) ->where('id', (int) $request->getData('id'))

View File

@ -1,40 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\SupplierManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\SupplierManagement\Models;
use phpOMS\Stdlib\Base\Enum;
/**
* Attribute value type enum.
*
* @package Modules\SupplierManagement\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
abstract class AttributeValueType extends Enum
{
public const _INT = 1;
public const _STRING = 2;
public const _FLOAT = 3;
public const _DATETIME = 4;
public const _BOOL = 5;
public const _FLOAT_INT = 6;
}

View File

@ -1,47 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\SupplierManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\SupplierManagement\Models;
/**
* Null model
*
* @package Modules\SupplierManagement\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullSupplierAttribute extends SupplierAttribute
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
parent::__construct();
$this->id = $id;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return ['id' => $this->id];
}
}

View File

@ -1,46 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\SupplierManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\SupplierManagement\Models;
/**
* Null model
*
* @package Modules\SupplierManagement\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullSupplierAttributeType extends SupplierAttributeType
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return ['id' => $this->id];
}
}

View File

@ -1,46 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\SupplierManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\SupplierManagement\Models;
/**
* Null model
*
* @package Modules\SupplierManagement\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullSupplierAttributeValue extends SupplierAttributeValue
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return ['id' => $this->id];
}
}

View File

@ -20,10 +20,9 @@ use Modules\Admin\Models\NullAddress;
use Modules\Editor\Models\EditorDoc; use Modules\Editor\Models\EditorDoc;
use Modules\Media\Models\Media; use Modules\Media\Models\Media;
use Modules\Media\Models\NullMedia; use Modules\Media\Models\NullMedia;
use Modules\Payment\Models\Payment;
use Modules\Profile\Models\ContactElement; use Modules\Profile\Models\ContactElement;
use Modules\Profile\Models\NullContactElement; use Modules\Profile\Models\NullContactElement;
use Modules\Profile\Models\Profile;
use Modules\Payment\Models\Payment;
/** /**
* Supplier class. * Supplier class.
@ -60,7 +59,7 @@ class Supplier
/** /**
* Attributes. * Attributes.
* *
* @var SupplierAttribute[] * @var \Modules\Attribute\Models\Attribute[]
* @since 1.0.0 * @since 1.0.0
*/ */
private array $attributes = []; private array $attributes = [];
@ -293,43 +292,6 @@ class Supplier
return $this->partners; return $this->partners;
} }
/**
* Add attribute to supplier
*
* @param SupplierAttribute $attribute Attribute
*
* @return void
*
* @since 1.0.0
*/
public function addAttribute(SupplierAttribute $attribute) : void
{
$this->attributes[] = $attribute;
}
/**
* Get attributes
*
* @return SupplierAttribute[]
*
* @since 1.0.0
*/
public function getAttributes() : array
{
return $this->attributes;
}
public function getAttributeByTypeName(string $name) : SupplierAttribute
{
foreach ($this->attributes as $attribute) {
if ($attribute->type->name === $name) {
return $attribute;
}
}
return new NullSupplierAttribute();
}
/** /**
* Get contacts. * Get contacts.
* *
@ -467,4 +429,6 @@ class Supplier
{ {
return $this->toArray(); return $this->toArray();
} }
use \Modules\Attribute\Models\AttributeHolderTrait;
} }

View File

@ -1,102 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\SupplierManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\SupplierManagement\Models;
/**
* Supplier class.
*
* @package Modules\SupplierManagement\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
class SupplierAttribute implements \JsonSerializable
{
/**
* Id.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Supplier this attribute belongs to
*
* @var int
* @since 1.0.0
*/
public int $supplier = 0;
/**
* Attribute type the attribute belongs to
*
* @var SupplierAttributeType
* @since 1.0.0
*/
public SupplierAttributeType $type;
/**
* Attribute value the attribute belongs to
*
* @var SupplierAttributeValue
* @since 1.0.0
*/
public SupplierAttributeValue $value;
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct()
{
$this->type = new SupplierAttributeType();
$this->value = new SupplierAttributeValue();
}
/**
* Get id
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'supplier' => $this->supplier,
'type' => $this->type,
'value' => $this->value,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Modules\SupplierManagement\Models; namespace Modules\SupplierManagement\Models;
use Modules\Attribute\Models\Attribute;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
@ -34,7 +35,7 @@ final class SupplierAttributeMapper extends DataMapperFactory
*/ */
public const COLUMNS = [ public const COLUMNS = [
'suppliermgmt_supplier_attr_id' => ['name' => 'suppliermgmt_supplier_attr_id', 'type' => 'int', 'internal' => 'id'], 'suppliermgmt_supplier_attr_id' => ['name' => 'suppliermgmt_supplier_attr_id', 'type' => 'int', 'internal' => 'id'],
'suppliermgmt_supplier_attr_supplier' => ['name' => 'suppliermgmt_supplier_attr_supplier', 'type' => 'int', 'internal' => 'supplier'], 'suppliermgmt_supplier_attr_supplier' => ['name' => 'suppliermgmt_supplier_attr_supplier', 'type' => 'int', 'internal' => 'ref'],
'suppliermgmt_supplier_attr_type' => ['name' => 'suppliermgmt_supplier_attr_type', 'type' => 'int', 'internal' => 'type'], 'suppliermgmt_supplier_attr_type' => ['name' => 'suppliermgmt_supplier_attr_type', 'type' => 'int', 'internal' => 'type'],
'suppliermgmt_supplier_attr_value' => ['name' => 'suppliermgmt_supplier_attr_value', 'type' => 'int', 'internal' => 'value'], 'suppliermgmt_supplier_attr_value' => ['name' => 'suppliermgmt_supplier_attr_value', 'type' => 'int', 'internal' => 'value'],
]; ];
@ -56,6 +57,14 @@ final class SupplierAttributeMapper extends DataMapperFactory
], ],
]; ];
/**
* Model to use by the mapper.
*
* @var class-string
* @since 1.0.0
*/
public const MODEL = Attribute::class;
/** /**
* Primary table. * Primary table.
* *

View File

@ -1,209 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\SupplierManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\SupplierManagement\Models;
use phpOMS\Localization\BaseStringL11n;
use phpOMS\Localization\ISO639x1Enum;
/**
* Supplier Attribute Type class.
*
* @package Modules\SupplierManagement\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
class SupplierAttributeType implements \JsonSerializable
{
/**
* Id
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Name/string identifier by which it can be found/categorized
*
* @var string
* @since 1.0.0
*/
public string $name = ''; // @todo: currently not filled, should be used as identifier or if not required removed (at the moment it seems like it is useless?!)
/**
* Which field data type is required (string, int, ...) in the value
*
* @var int
* @since 1.0.0
*/
public int $fields = 0;
/**
* Is a custom value allowed (e.g. custom string)
*
* @var bool
* @since 1.0.0
*/
public bool $custom = false;
public string $validationPattern = '';
public bool $isRequired = false;
/**
* Datatype of the attribute
*
* @var int
* @since 1.0.0
*/
public int $datatype = AttributeValueType::_STRING;
/**
* Localization
*
* @var string | BaseStringL11n
*/
protected string | BaseStringL11n $l11n;
/**
* Possible default attribute values
*
* @var array
*/
protected array $defaults = [];
/**
* Constructor.
*
* @param string $name Name/identifier of the attribute type
*
* @since 1.0.0
*/
public function __construct(string $name = '')
{
$this->name = $name;
}
/**
* Get id
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
public function getDefaultByValue(mixed $value) : SupplierAttributeValue
{
foreach ($this->defaults as $default) {
if ($default->getValue() === $value) {
return $default;
}
}
return new NullSupplierAttributeValue();
}
/**
* 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;
}
/**
* Set fields
*
* @param int $fields Fields
*
* @return void
*
* @since 1.0.0
*/
public function setFields(int $fields) : void
{
$this->fields = $fields;
}
/**
* Get default values
*
* @return array
*
* @sicne 1.0.0
*/
public function getDefaults() : array
{
return $this->defaults;
}
/**
* {@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();
}
}

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Modules\SupplierManagement\Models; namespace Modules\SupplierManagement\Models;
use Modules\Attribute\Models\AttributeTypeMapper;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
@ -64,6 +65,14 @@ final class SupplierAttributeTypeMapper extends DataMapperFactory
], ],
]; ];
/**
* Model to use by the mapper.
*
* @var class-string
* @since 1.0.0
*/
public const MODEL = AttributeTypeMapper::class;
/** /**
* Primary table. * Primary table.
* *

View File

@ -1,231 +0,0 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\SupplierManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\SupplierManagement\Models;
use phpOMS\Localization\BaseStringL11n;
use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Localization\ISO639x1Enum;
/**
* Supplier attribute value class.
*
* The relation with the type/supplier is defined in the SupplierAttribute class.
*
* @package Modules\SupplierManagement\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
class SupplierAttributeValue implements \JsonSerializable
{
/**
* Id
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Depending attribute type
*
* @var null|int
* @since 1.0.0
*/
public ?int $dependingAttributeType = null;
/**
* Depending attribute value
*
* @var null|int
* @since 1.0.0
*/
public ?int $dependingAttributeValue = null;
/**
* Int value
*
* @var null|int
* @since 1.0.0
*/
public ?int $valueInt = null;
/**
* String value
*
* @var null|string
* @since 1.0.0
*/
public ?string $valueStr = null;
/**
* Decimal value
*
* @var null|float
* @since 1.0.0
*/
public ?float $valueDec = null;
/**
* DateTime value
*
* @var null|\DateTimeInterface
* @since 1.0.0
*/
public ?\DateTimeInterface $valueDat = null;
/**
* Is a default value which can be selected
*
* @var bool
* @since 1.0.0
*/
public bool $isDefault = false;
/**
* Unit of the value
*
* @var string
* @since 1.0.0
*/
public string $unit = '';
/**
* Localization
*
* @var null|BaseStringL11n
*/
private ?BaseStringL11n $l11n = null;
/**
* Get id
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
/**
* 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;
}
/**
* Set value
*
* @param int|string|float $value Value
* @param int $datatype Datatype
*
* @return void
*
* @since 1.0.0
*/
public function setValue(mixed $value, int $datatype) : void
{
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((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;
}
/**
* {@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();
}
}

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Modules\SupplierManagement\Models; namespace Modules\SupplierManagement\Models;
use Modules\Attribute\Models\AttributeValueType;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
@ -59,6 +60,14 @@ final class SupplierAttributeValueMapper extends DataMapperFactory
], ],
]; ];
/**
* Model to use by the mapper.
*
* @var class-string
* @since 1.0.0
*/
public const MODEL = AttributeValueType::class;
/** /**
* Primary table. * Primary table.
* *