make id public, organigram impl. media password/encryption, settings bug fix, Money->FloatInt change, ...

This commit is contained in:
Dennis Eichhorn 2023-05-06 11:42:05 +00:00
parent 9ff4b47113
commit 1d69691538
5 changed files with 33 additions and 11 deletions

View File

@ -290,7 +290,7 @@ final class ApiController extends Controller
$this->createModelRelation( $this->createModelRelation(
$request->header->account, $request->header->account,
(int) $request->getData('type'), (int) $request->getData('type'),
$attrValue->getId(), $attrValue->id,
AttributeTypeMapper::class, 'defaults', '', $request->getOrigin() AttributeTypeMapper::class, 'defaults', '', $request->getOrigin()
); );
} }

View File

@ -30,7 +30,7 @@ class Attribute implements \JsonSerializable
* @var int * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
protected int $id = 0; public int $id = 0;
/** /**
* this attribute belongs to * this attribute belongs to
@ -67,6 +67,14 @@ class Attribute implements \JsonSerializable
$this->value = new NullAttributeValue(); $this->value = new NullAttributeValue();
} }
public function deepClone() : self
{
$clone = clone $this;
$clone->value = clone $this->value;
return $clone;
}
/** /**
* Get id * Get id
* *

View File

@ -84,11 +84,11 @@ trait AttributeHolderTrait
* *
* @param string $attrName Attribute name * @param string $attrName Attribute name
* *
* @return null|Attribute * @return Attribute
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getAttribute(string $attrName) : ?Attribute public function getAttribute(string $attrName) : Attribute
{ {
foreach ($this->attributes as $attribute) { foreach ($this->attributes as $attribute) {
if ($attribute->type->name === $attrName) { if ($attribute->type->name === $attrName) {
@ -96,6 +96,6 @@ trait AttributeHolderTrait
} }
} }
return null; return new NullAttribute();
} }
} }

View File

@ -33,7 +33,7 @@ class AttributeType implements \JsonSerializable
* @var int * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
protected int $id = 0; public int $id = 0;
/** /**
* Name/string identifier by which it can be found/categorized * Name/string identifier by which it can be found/categorized
@ -49,7 +49,7 @@ class AttributeType implements \JsonSerializable
* @var int * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
protected int $fields = 0; public int $fields = 0;
/** /**
* Is a custom value allowed (e.g. custom string) * Is a custom value allowed (e.g. custom string)
@ -76,14 +76,14 @@ class AttributeType implements \JsonSerializable
* *
* @var BaseStringL11n * @var BaseStringL11n
*/ */
private string | BaseStringL11n $l11n = ''; public string | BaseStringL11n $l11n = '';
/** /**
* Possible default attribute values * Possible default attribute values
* *
* @var array * @var array
*/ */
private array $defaults = []; public array $defaults = [];
/** /**
* Default attribute value * Default attribute value
@ -128,6 +128,20 @@ class AttributeType implements \JsonSerializable
*/ */
public function getDefaultByValue(mixed $value) : AttributeValue public function getDefaultByValue(mixed $value) : AttributeValue
{ {
$value = null;
if ($this->datatype === AttributeValueType::_STRING) {
$value = (string) $value;
} elseif ($this->datatype === AttributeValueType::_INT
|| $this->datatype === AttributeValueType::_FLOAT_INT
|| $this->datatype === AttributeValueType::_BOOL
) {
$value = (int) $value;
} elseif ($this->datatype === AttributeValueType::_FLOAT) {
$value = (float) $value;
} elseif ($this->datatype === AttributeValueType::_DATETIME) {
$value = new \DateTime((string) $value);
}
foreach ($this->defaults as $default) { foreach ($this->defaults as $default) {
if ($default->getValue() === $value) { if ($default->getValue() === $value) {
return $default; return $default;

View File

@ -35,7 +35,7 @@ class AttributeValue implements \JsonSerializable
* @var int * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
protected int $id = 0; public int $id = 0;
/** /**
* Depending attribute type * Depending attribute type
@ -106,7 +106,7 @@ class AttributeValue implements \JsonSerializable
* *
* @var null|BaseStringL11n * @var null|BaseStringL11n
*/ */
private ?BaseStringL11n $l11n = null; public ?BaseStringL11n $l11n = null;
/** /**
* Get id * Get id