mirror of
https://github.com/Karaka-Management/oms-Attribute.git
synced 2026-02-15 00:48:41 +00:00
bug fixes and item management improvements
This commit is contained in:
parent
953df0d2b2
commit
38bacc3bc5
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
||||||
namespace Modules\Attribute\Models;
|
namespace Modules\Attribute\Models;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class.
|
* Attribute class.
|
||||||
*
|
*
|
||||||
* @package Modules\Attribute\Models
|
* @package Modules\Attribute\Models
|
||||||
* @license OMS License 2.0
|
* @license OMS License 2.0
|
||||||
|
|
|
||||||
121
Models/Attribute.php.out
Normal file
121
Models/Attribute.php.out
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Karaka
|
||||||
|
*
|
||||||
|
* PHP Version 8.1
|
||||||
|
*
|
||||||
|
* @package Modules\Attribute\Models
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Attribute\Models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute class.
|
||||||
|
*
|
||||||
|
* @package Modules\Attribute\Models
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class Attribute implements \JsonSerializable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Id.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public int $id = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this attribute belongs to
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public int $ref = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute type the attribute belongs to.
|
||||||
|
*
|
||||||
|
* @var AttributeType
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public AttributeType $type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute value the attribute belongs to.
|
||||||
|
*
|
||||||
|
* @var AttributeValue
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public AttributeValue $value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->type = new NullAttributeType();
|
||||||
|
$this->value = new NullAttributeValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a deep clone of the object.
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function deepClone() : self
|
||||||
|
{
|
||||||
|
$clone = clone $this;
|
||||||
|
$clone->value = clone $this->value;
|
||||||
|
|
||||||
|
return $clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the id of the attribute.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getId() : int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the attribute to an array.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function toArray() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'ref' => $this->ref,
|
||||||
|
'type' => $this->type,
|
||||||
|
'value' => $this->value,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function jsonSerialize() : mixed
|
||||||
|
{
|
||||||
|
return $this->toArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -128,22 +128,22 @@ class AttributeType implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public function getDefaultByValue(mixed $value) : AttributeValue
|
public function getDefaultByValue(mixed $value) : AttributeValue
|
||||||
{
|
{
|
||||||
$value = null;
|
$mValue = null;
|
||||||
if ($this->datatype === AttributeValueType::_STRING) {
|
if ($this->datatype === AttributeValueType::_STRING) {
|
||||||
$value = (string) $value;
|
$mValue = (string) $value;
|
||||||
} elseif ($this->datatype === AttributeValueType::_INT
|
} elseif ($this->datatype === AttributeValueType::_INT
|
||||||
|| $this->datatype === AttributeValueType::_FLOAT_INT
|
|| $this->datatype === AttributeValueType::_FLOAT_INT
|
||||||
|| $this->datatype === AttributeValueType::_BOOL
|
|| $this->datatype === AttributeValueType::_BOOL
|
||||||
) {
|
) {
|
||||||
$value = (int) $value;
|
$mValue = (int) $value;
|
||||||
} elseif ($this->datatype === AttributeValueType::_FLOAT) {
|
} elseif ($this->datatype === AttributeValueType::_FLOAT) {
|
||||||
$value = (float) $value;
|
$mValue = (float) $value;
|
||||||
} elseif ($this->datatype === AttributeValueType::_DATETIME) {
|
} elseif ($this->datatype === AttributeValueType::_DATETIME) {
|
||||||
$value = new \DateTime((string) $value);
|
$mValue = new \DateTime((string) $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->defaults as $default) {
|
foreach ($this->defaults as $default) {
|
||||||
if ($default->getValue() === $value) {
|
if ($default->getValue() === $mValue) {
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -192,13 +192,13 @@ class AttributeValue implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public function getValue() : mixed
|
public function getValue() : mixed
|
||||||
{
|
{
|
||||||
if (!empty($this->valueStr)) {
|
if ($this->valueStr !== null) {
|
||||||
return $this->valueStr;
|
return $this->valueStr;
|
||||||
} elseif (!empty($this->valueInt)) {
|
} elseif ($this->valueInt !== null) {
|
||||||
return $this->valueInt;
|
return $this->valueInt;
|
||||||
} elseif (!empty($this->valueDec)) {
|
} elseif ($this->valueDec !== null) {
|
||||||
return $this->valueDec;
|
return $this->valueDec;
|
||||||
} elseif ($this->valueDat instanceof \DateTimeInterface) {
|
} elseif ($this->valueDat !== null) {
|
||||||
return $this->valueDat;
|
return $this->valueDat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,14 @@
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
return ['Attribute' => [
|
return ['Attribute' => [
|
||||||
'Accounts/Groups' => 'Accounts/Groups',
|
'AttributeTypes' => 'Attribute Types',
|
||||||
|
'Attribute' => 'Attribute',
|
||||||
|
'Name' => 'Name',
|
||||||
|
'Title' => 'Title',
|
||||||
|
'Datatype' => 'Datatype',
|
||||||
|
'Status' => 'Status',
|
||||||
|
'DefaultValues' => 'Default Values',
|
||||||
|
'Pattern' => 'Pattern',
|
||||||
|
'IsRequired' => 'Is required?',
|
||||||
|
'CustomValue' => 'Custom values allowed?',
|
||||||
]];
|
]];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user