diff --git a/Admin/Installer.php b/Admin/Installer.php index b7a96fc..8e84fde 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -47,6 +47,13 @@ final class Installer extends InstallerAbstract self::createItemAttributeValues($attrTypes); } + /** + * Install default attribute types + * + * @return ItemAttributeType[] + * + * @since 1.0.0 + */ private static function createItemAttributeTypes() : array { $itemAttrType = []; @@ -59,6 +66,15 @@ final class Installer extends InstallerAbstract return $itemAttrType; } + /** + * Create default attribute values for types + * + * @param ItemAttributeType[] $itemAttrType Attribute types + * + * @return array + * + * @since 1.0.0 + */ private static function createItemAttributeValues(array $itemAttrType) : array { $itemAttrValue = []; @@ -110,6 +126,6 @@ final class Installer extends InstallerAbstract $itemAttrValue['color'][] = new ItemAttributeValue($id, 'Grau', ISO639x1Enum::_DE); ItemAttributeValueMapper::create($itemAttrValue['color'][21]); - return $itemAttrType; + return $itemAttrValue; } } diff --git a/Models/Item.php b/Models/Item.php index 8afbb71..66b6c83 100644 --- a/Models/Item.php +++ b/Models/Item.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\ItemManagement\Models; use Modules\Media\Models\NullMedia; +use Modules\Media\Models\Media; /** * Account class. @@ -34,25 +35,41 @@ class Item */ protected int $id = 0; - private $number = ''; - - private $articleGroup = 0; - - private $salesGroup = 0; - - private $productGroup = 0; - - private $segment = 0; + /** + * Item number/id + * + * @var string + * @since 1.0.0 + */ + private string $number = ''; private $successor = 0; private int $type = 0; - private $files = []; + /** + * Files. + * + * @var int[]|Media[] + * @since 1.0.0 + */ + private array $files = []; - private $l11n = []; + /** + * Localizations. + * + * @var int[]|ItemL11n[] + * @since 1.0.0 + */ + private array $l11n = []; - private $attributes = []; + /** + * Attributes. + * + * @var int[]|ItemAttribute[] + * @since 1.0.0 + */ + private array $attributes = []; private $partslist = null; @@ -60,7 +77,13 @@ class Item private $disposal = null; - private $createdAt = null; + /** + * Created at. + * + * @var \DateTimeImmutable + * @since 1.0.0 + */ + private \DateTimeImmutable $createdAt; private $info = ''; @@ -182,12 +205,30 @@ class Item return new NullItemL11n(); } + /** + * Add media to item + * + * @param int|Media $media Media + * + * @return void + * + * @since 1.0.0 + */ public function addFile($media) : void { $this->files[] = $media; } - public function getFileByType(string $type) + /** + * Get media file by type + * + * @param string $type Media type + * + * @return Media + * + * @since 1.0.0 + */ + public function getFileByType(string $type) : Media { foreach ($this->files as $file) { if ($file->getType() === $type) { @@ -198,6 +239,15 @@ class Item return new NullMedia(); } + /** + * Get all media files by type + * + * @param string $type Media type + * + * @return Media[] + * + * @since 1.0.0 + */ public function getFilesByType(string $type) : array { $files = []; diff --git a/Models/ItemAttribute.php b/Models/ItemAttribute.php index be899e4..ebbe2f3 100644 --- a/Models/ItemAttribute.php +++ b/Models/ItemAttribute.php @@ -26,12 +26,36 @@ use phpOMS\Contract\ArrayableInterface; */ class ItemAttribute implements \JsonSerializable, ArrayableInterface { + /** + * Id. + * + * @var int + * @since 1.0.0 + */ protected int $id = 0; - protected $item = 0; + /** + * Item this attribute belongs to + * + * @var int + * @since 1.0.0 + */ + protected int $item = 0; + /** + * Attribute type the attribute belongs to + * + * @var int|ItemAttributeType + * @since 1.0.0 + */ protected $type = 0; + /** + * Attribute value the attribute belongs to + * + * @var int|ItemAttributeValue + * @since 1.0.0 + */ protected $value = 0; /** diff --git a/Models/ItemAttributeMapper.php b/Models/ItemAttributeMapper.php index 1e042f5..53e677c 100644 --- a/Models/ItemAttributeMapper.php +++ b/Models/ItemAttributeMapper.php @@ -44,7 +44,7 @@ final class ItemAttributeMapper extends DataMapperAbstract /** * Has one relation. * - * @var array + * @var array * @since 1.0.0 */ protected static array $ownsOne = [ diff --git a/Models/ItemAttributeType.php b/Models/ItemAttributeType.php index 4a7a6de..5d54faa 100644 --- a/Models/ItemAttributeType.php +++ b/Models/ItemAttributeType.php @@ -17,7 +17,7 @@ namespace Modules\ItemManagement\Models; use phpOMS\Contract\ArrayableInterface; /** - * Item class. + * Item Attribute Type class. * * @package Modules\ItemManagement\Models * @license OMS License 1.0 @@ -26,16 +26,52 @@ use phpOMS\Contract\ArrayableInterface; */ class ItemAttributeType implements \JsonSerializable, ArrayableInterface { + /** + * 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 + */ protected string $name = ''; - protected $fields = 0; + /** + * Which field data type is required (string, int, ...) in the value + * + * @var int + * @since 1.0.0 + */ + protected int $fields = 0; + /** + * Is a custom value allowed (e.g. custom string) + * + * @var bool + * @since 1.0.0 + */ protected bool $custom = false; + /** + * Localization + * + * @var int|int[]|ItemAttributeTypeL11n|ItemAttributeTypeL11n[] + */ protected $l11n = 0; + /** + * Constructor. + * + * @param string $name Name/identifier of the attribute type + * + * @since 1.0.0 + */ public function __construct(string $name = '') { $this->name = $name; diff --git a/Models/ItemAttributeTypeL11n.php b/Models/ItemAttributeTypeL11n.php index f0951bc..00b0884 100644 --- a/Models/ItemAttributeTypeL11n.php +++ b/Models/ItemAttributeTypeL11n.php @@ -28,7 +28,7 @@ use phpOMS\Localization\ISO639x1Enum; class ItemAttributeTypeL11n implements \JsonSerializable, ArrayableInterface { /** - * Article ID. + * ID. * * @var int * @since 1.0.0 @@ -62,15 +62,17 @@ class ItemAttributeTypeL11n implements \JsonSerializable, ArrayableInterface /** * Constructor. * - * @param string $description Title + * @param int|ItemL11nType $type Attribute type + * @param string $title Localized title + * @param string $language Language * * @since 1.0.0 */ public function __construct($type = 0, string $title = '', string $language = ISO639x1Enum::_EN) { - $this->type = $type; - $this->title = $title; - $this->language = $language; + $this->type = $type; + $this->title = $title; + $this->language = $language; } /** @@ -85,6 +87,44 @@ class ItemAttributeTypeL11n implements \JsonSerializable, ArrayableInterface return $this->id; } + /** + * Get attribute type + * + * @return int|ItemL11nType + * + * @since 1.0.0 + */ + public function getType() + { + return $this->type; + } + + /** + * Get attribute title + * + * @return string + * + * @since 1.0.0 + */ + public function getTitle() : string + { + return $this->title; + } + + /** + * Set title + * + * @param string $title Title + * + * @return void + * + * @since 1.0.0 + */ + public function setTitle(string $title) : void + { + $this->title = $title; + } + /** * {@inheritdoc} */ diff --git a/Models/ItemAttributeTypeL11nMapper.php b/Models/ItemAttributeTypeL11nMapper.php index bc5a6fb..e6b9533 100644 --- a/Models/ItemAttributeTypeL11nMapper.php +++ b/Models/ItemAttributeTypeL11nMapper.php @@ -45,7 +45,7 @@ final class ItemAttributeTypeL11nMapper extends DataMapperAbstract /** * Has one relation. * - * @var array + * @var array * @since 1.0.0 */ protected static array $ownsOne = [ diff --git a/Models/ItemAttributeTypeMapper.php b/Models/ItemAttributeTypeMapper.php index b99a41e..212a826 100644 --- a/Models/ItemAttributeTypeMapper.php +++ b/Models/ItemAttributeTypeMapper.php @@ -23,8 +23,6 @@ use phpOMS\DataStorage\Database\DataMapperAbstract; * @license OMS License 1.0 * @link https://orange-management.org * @since 1.0.0 - * - * @todo Do I really want to create a relation to the language mapper? It's not really needed right? */ final class ItemAttributeTypeMapper extends DataMapperAbstract { diff --git a/Models/ItemAttributeValue.php b/Models/ItemAttributeValue.php index f8cb819..306456c 100644 --- a/Models/ItemAttributeValue.php +++ b/Models/ItemAttributeValue.php @@ -19,7 +19,7 @@ use phpOMS\Localization\ISO3166TwoEnum; use phpOMS\Localization\ISO639x1Enum; /** - * Item class. + * Item attribute value class. * * @package Modules\ItemManagement\Models * @license OMS License 1.0 @@ -28,34 +28,90 @@ use phpOMS\Localization\ISO639x1Enum; */ class ItemAttributeValue implements \JsonSerializable, ArrayableInterface { + /** + * Id + * + * @var int + * @since 1.0.0 + */ protected int $id = 0; - protected $type = 0; + /** + * Type of the attribute + * + * @var int + * @since 1.0.0 + */ + protected int $type = 0; + /** + * Int value + * + * @var null|int + * @since 1.0.0 + */ protected ?int $valueInt = null; + /** + * String value + * + * @var null|string + * @since 1.0.0 + */ protected ?string $valueStr = null; + /** + * Decimal value + * + * @var null|float + * @since 1.0.0 + */ protected ?float $valueDec = null; - protected ?\DateTime $valueDat = null; + /** + * DateTime value + * + * @var null|\DateTimeInterface + * @since 1.0.0 + */ + protected ?\DateTimeInterface $valueDat = null; + /** + * Is a default value which can be selected + * + * @var bool + * @since 1.0.0 + */ protected bool $isDefault = false; + /** + * Language + * + * @var string + * @since 1.0.0 + */ protected string $language = ISO639x1Enum::_EN; + /** + * Country + * + * @var string + * @since 1.0.0 + */ protected string $country = ISO3166TwoEnum::_USA; /** * Constructor. * - * @param string $description Title + * @param int $type Type + * @param mixed $value Value + * @param string $language Language * * @since 1.0.0 */ - public function __construct($type = 0, $value = '', string $language = ISO639x1Enum::_EN) + public function __construct(int $type = 0, $value = '', string $language = ISO639x1Enum::_EN) { - $this->type = $type; + $this->type = $type; if (\is_string($value)) { $this->valueStr = $value; @@ -67,7 +123,7 @@ class ItemAttributeValue implements \JsonSerializable, ArrayableInterface $this->valueDat = $value; } - $this->language = $language; + $this->language = $language; } /** diff --git a/Models/ItemAttributeValueMapper.php b/Models/ItemAttributeValueMapper.php index 9be67d3..aefb9e3 100644 --- a/Models/ItemAttributeValueMapper.php +++ b/Models/ItemAttributeValueMapper.php @@ -8,7 +8,7 @@ * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link https://orange-management.org + * @link https: //orange-management.org */ declare(strict_types=1); @@ -23,7 +23,7 @@ use phpOMS\Localization\Defaults\LanguageMapper; * * @package Modules\ItemManagement\Models * @license OMS License 1.0 - * @link https://orange-management.org + * @link https: //orange-management.org * @since 1.0.0 * * @todo Do I really want to create a relation to the language mapper? It's not really needed right? @@ -37,37 +37,37 @@ final class ItemAttributeValueMapper extends DataMapperAbstract * @since 1.0.0 */ protected static array $columns = [ - 'itemmgmt_attr_value_id' => ['name' => 'itemmgmt_attr_value_id', 'type' => 'int', 'internal' => 'id'], - 'itemmgmt_attr_value_default' => ['name' => 'itemmgmt_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'], - 'itemmgmt_attr_value_type' => ['name' => 'itemmgmt_attr_value_type', 'type' => 'int', 'internal' => 'type'], - 'itemmgmt_attr_value_valueStr' => ['name' => 'itemmgmt_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'], - 'itemmgmt_attr_value_valueInt' => ['name' => 'itemmgmt_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'], - 'itemmgmt_attr_value_valueDec' => ['name' => 'itemmgmt_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'], - 'itemmgmt_attr_value_valueDat' => ['name' => 'itemmgmt_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'], - 'itemmgmt_attr_value_lang' => ['name' => 'itemmgmt_attr_value_lang', 'type' => 'string', 'internal' => 'language'], - 'itemmgmt_attr_value_country' => ['name' => 'itemmgmt_attr_value_country', 'type' => 'string', 'internal' => 'country'], + 'itemmgmt_attr_value_id' => ['name' => 'itemmgmt_attr_value_id', 'type' => 'int', 'internal' => 'id'], + 'itemmgmt_attr_value_default' => ['name' => 'itemmgmt_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'], + 'itemmgmt_attr_value_type' => ['name' => 'itemmgmt_attr_value_type', 'type' => 'int', 'internal' => 'type'], + 'itemmgmt_attr_value_valueStr' => ['name' => 'itemmgmt_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'], + 'itemmgmt_attr_value_valueInt' => ['name' => 'itemmgmt_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'], + 'itemmgmt_attr_value_valueDec' => ['name' => 'itemmgmt_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'], + 'itemmgmt_attr_value_valueDat' => ['name' => 'itemmgmt_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'], + 'itemmgmt_attr_value_lang' => ['name' => 'itemmgmt_attr_value_lang', 'type' => 'string', 'internal' => 'language'], + 'itemmgmt_attr_value_country' => ['name' => 'itemmgmt_attr_value_country', 'type' => 'string', 'internal' => 'country'], ]; /** * Has one relation. * - * @var array + * @var array * @since 1.0.0 */ protected static array $ownsOne = [ 'language' => [ - 'mapper' => LanguageMapper::class, - 'external' => 'itemmgmt_attr_value_lang', - 'by' => 'code2', - 'column' => 'code2', - 'conditional' => true, + 'mapper' => LanguageMapper::class, + 'external' => 'itemmgmt_attr_value_lang', + 'by' => 'code2', + 'column' => 'code2', + 'conditional' => true, ], 'country' => [ - 'mapper' => CountryMapper::class, - 'external' => 'itemmgmt_attr_value_country', - 'by' => 'code2', - 'column' => 'code2', - 'conditional' => true, + 'mapper' => CountryMapper::class, + 'external' => 'itemmgmt_attr_value_country', + 'by' => 'code2', + 'column' => 'code2', + 'conditional' => true, ], ]; diff --git a/Models/ItemL11n.php b/Models/ItemL11n.php index 9e07836..956f881 100644 --- a/Models/ItemL11n.php +++ b/Models/ItemL11n.php @@ -18,7 +18,7 @@ use phpOMS\Contract\ArrayableInterface; use phpOMS\Localization\ISO639x1Enum; /** - * Item class. + * Localization of the item class. * * @package Modules\ItemManagement\Models * @license OMS License 1.0 @@ -70,7 +70,9 @@ class ItemL11n implements \JsonSerializable, ArrayableInterface /** * Constructor. * - * @param string $description Title + * @param int|ItemL11nType $type Item localization type + * @param string $description Description/content + * @param string $language Language * * @since 1.0.0 */ @@ -136,7 +138,7 @@ class ItemL11n implements \JsonSerializable, ArrayableInterface /** * Get type * - * @return int + * @return int|ItemL11nType * * @since 1.0.0 */ diff --git a/Models/ItemL11nMapper.php b/Models/ItemL11nMapper.php index f29e95b..2e8fa27 100644 --- a/Models/ItemL11nMapper.php +++ b/Models/ItemL11nMapper.php @@ -36,30 +36,30 @@ final class ItemL11nMapper extends DataMapperAbstract * @since 1.0.0 */ protected static array $columns = [ - 'itemmgmt_item_l11n_id' => ['name' => 'itemmgmt_item_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'itemmgmt_item_l11n_description' => ['name' => 'itemmgmt_item_l11n_description', 'type' => 'string', 'internal' => 'description', 'autocomplete' => true], - 'itemmgmt_item_l11n_item' => ['name' => 'itemmgmt_item_l11n_item', 'type' => 'int', 'internal' => 'item'], - 'itemmgmt_item_l11n_lang' => ['name' => 'itemmgmt_item_l11n_lang', 'type' => 'string', 'internal' => 'language'], - 'itemmgmt_item_l11n_typeref' => ['name' => 'itemmgmt_item_l11n_typeref', 'type' => 'int', 'internal' => 'type'], + 'itemmgmt_item_l11n_id' => ['name' => 'itemmgmt_item_l11n_id', 'type' => 'int', 'internal' => 'id'], + 'itemmgmt_item_l11n_description' => ['name' => 'itemmgmt_item_l11n_description', 'type' => 'string', 'internal' => 'description', 'autocomplete' => true], + 'itemmgmt_item_l11n_item' => ['name' => 'itemmgmt_item_l11n_item', 'type' => 'int', 'internal' => 'item'], + 'itemmgmt_item_l11n_lang' => ['name' => 'itemmgmt_item_l11n_lang', 'type' => 'string', 'internal' => 'language'], + 'itemmgmt_item_l11n_typeref' => ['name' => 'itemmgmt_item_l11n_typeref', 'type' => 'int', 'internal' => 'type'], ]; /** * Has one relation. * - * @var array + * @var array * @since 1.0.0 */ protected static array $ownsOne = [ 'language' => [ - 'mapper' => LanguageMapper::class, - 'external' => 'itemmgmt_item_l11n_lang', - 'by' => 'code2', - 'column' => 'code2', - 'conditional' => true, + 'mapper' => LanguageMapper::class, + 'external' => 'itemmgmt_item_l11n_lang', + 'by' => 'code2', + 'column' => 'code2', + 'conditional' => true, ], 'type' => [ - 'mapper' => ItemL11nTypeMapper::class, - 'external' => 'itemmgmt_item_l11n_typeref', + 'mapper' => ItemL11nTypeMapper::class, + 'external' => 'itemmgmt_item_l11n_typeref', ], ]; diff --git a/Models/ItemL11nType.php b/Models/ItemL11nType.php index 0697079..d29a4c8 100644 --- a/Models/ItemL11nType.php +++ b/Models/ItemL11nType.php @@ -35,9 +35,9 @@ class ItemL11nType implements \JsonSerializable, ArrayableInterface protected int $id = 0; /** - * Item type. + * Item title. * - * @var int + * @var string * @since 1.0.0 */ protected string $title = ''; @@ -45,7 +45,7 @@ class ItemL11nType implements \JsonSerializable, ArrayableInterface /** * Constructor. * - * @param string $description Title + * @param string $title Title * * @since 1.0.0 */ diff --git a/Models/ItemMapper.php b/Models/ItemMapper.php index 4700815..e31d379 100644 --- a/Models/ItemMapper.php +++ b/Models/ItemMapper.php @@ -34,9 +34,9 @@ final class ItemMapper extends DataMapperAbstract * @since 1.0.0 */ protected static array $columns = [ - 'itemmgmt_item_id' => ['name' => 'itemmgmt_item_id', 'type' => 'int', 'internal' => 'id'], - 'itemmgmt_item_no' => ['name' => 'itemmgmt_item_no', 'type' => 'string', 'internal' => 'number', 'autocomplete' => true], - 'itemmgmt_item_info' => ['name' => 'itemmgmt_item_info', 'type' => 'string', 'internal' => 'info'], + 'itemmgmt_item_id' => ['name' => 'itemmgmt_item_id', 'type' => 'int', 'internal' => 'id'], + 'itemmgmt_item_no' => ['name' => 'itemmgmt_item_no', 'type' => 'string', 'internal' => 'number', 'autocomplete' => true], + 'itemmgmt_item_info' => ['name' => 'itemmgmt_item_info', 'type' => 'string', 'internal' => 'info'], ]; protected static array $conditionals = [ @@ -67,24 +67,24 @@ final class ItemMapper extends DataMapperAbstract */ protected static array $hasMany = [ 'files' => [ - 'mapper' => MediaMapper::class, /* mapper of the related object */ - 'table' => 'itemmgmt_item_media', /* table of the related object, null if no relation table is used (many->1) */ + 'mapper' => MediaMapper::class, /* mapper of the related object */ + 'table' => 'itemmgmt_item_media', /* table of the related object, null if no relation table is used (many->1) */ 'external' => 'itemmgmt_item_media_media', 'self' => 'itemmgmt_item_media_item', ], 'l11n' => [ - 'mapper' => ItemL11nMapper::class, - 'table' => 'itemmgmt_item_l11n', - 'self' => 'itemmgmt_item_l11n_item', - 'conditional' => true, - 'external' => null, + 'mapper' => ItemL11nMapper::class, + 'table' => 'itemmgmt_item_l11n', + 'self' => 'itemmgmt_item_l11n_item', + 'conditional' => true, + 'external' => null, ], 'attributes' => [ - 'mapper' => ItemAttributeMapper::class, - 'table' => 'itemmgmt_item_attr', - 'self' => 'itemmgmt_item_attr_item', - 'conditional' => true, - 'external' => null, + 'mapper' => ItemAttributeMapper::class, + 'table' => 'itemmgmt_item_attr', + 'self' => 'itemmgmt_item_attr_item', + 'conditional' => true, + 'external' => null, ], ]; } diff --git a/Models/ItemMedia.php b/Models/ItemMedia.php deleted file mode 100644 index e69de29..0000000