mirror of
https://github.com/Karaka-Management/oms-Attribute.git
synced 2026-02-14 16:38:41 +00:00
update
This commit is contained in:
parent
2d4b96cf9f
commit
5fed6a6a0e
|
|
@ -17,13 +17,20 @@ namespace Modules\Attribute\Controller;
|
||||||
use Modules\Attribute\Models\Attribute;
|
use Modules\Attribute\Models\Attribute;
|
||||||
use Modules\Attribute\Models\AttributeType;
|
use Modules\Attribute\Models\AttributeType;
|
||||||
use Modules\Attribute\Models\AttributeValue;
|
use Modules\Attribute\Models\AttributeValue;
|
||||||
use Modules\Attribute\Models\NullAttribute;
|
|
||||||
use Modules\Attribute\Models\NullAttributeType;
|
use Modules\Attribute\Models\NullAttributeType;
|
||||||
use Modules\Attribute\Models\NullAttributeValue;
|
use Modules\Attribute\Models\NullAttributeValue;
|
||||||
use phpOMS\Localization\BaseStringL11n;
|
use phpOMS\Localization\BaseStringL11n;
|
||||||
use phpOMS\Localization\ISO639x1Enum;
|
use phpOMS\Localization\ISO639x1Enum;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General attribute api functionality.
|
||||||
|
*
|
||||||
|
* @package Modules\Attribute
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
trait ApiAttributeTraitController
|
trait ApiAttributeTraitController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -174,6 +181,7 @@ trait ApiAttributeTraitController
|
||||||
{
|
{
|
||||||
$attrValue = new AttributeValue();
|
$attrValue = new AttributeValue();
|
||||||
$attrValue->isDefault = $request->getDataBool('default') ?? false;
|
$attrValue->isDefault = $request->getDataBool('default') ?? false;
|
||||||
|
$attrValue->unit = $request->getDataString('unit') ?? '';
|
||||||
$attrValue->setValue($request->getDataString('value'), $type->datatype);
|
$attrValue->setValue($request->getDataString('value'), $type->datatype);
|
||||||
|
|
||||||
if ($request->hasData('title')) {
|
if ($request->hasData('title')) {
|
||||||
|
|
@ -258,8 +266,14 @@ trait ApiAttributeTraitController
|
||||||
*/
|
*/
|
||||||
public function updateAttributeFromRequest(RequestAbstract $request, Attribute $new) : Attribute
|
public function updateAttributeFromRequest(RequestAbstract $request, Attribute $new) : Attribute
|
||||||
{
|
{
|
||||||
if ($request->hasData('value')) {
|
if ($new->type->custom) {
|
||||||
$new->value = $request->hasData('value') ? new NullAttributeValue((int) $request->getData('value')) : $new->value;
|
if ($request->hasData('value')) {
|
||||||
|
$new->value = new NullAttributeValue((int) $request->getData('value'));
|
||||||
|
} else {
|
||||||
|
// @todo: consider to check if custom value already exist and just reference the id? Problematic if content of id gets changed.
|
||||||
|
$new->value = new AttributeValue();
|
||||||
|
$new->value->setValue($request->getData('custom'), $new->type->datatype);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// @todo: fix by only accepting the value id to be used
|
// @todo: fix by only accepting the value id to be used
|
||||||
// this is a workaround for now because the front end doesn't allow to dynamically show default values.
|
// this is a workaround for now because the front end doesn't allow to dynamically show default values.
|
||||||
|
|
@ -267,7 +281,7 @@ trait ApiAttributeTraitController
|
||||||
|
|
||||||
// Couldn't find matching default value
|
// Couldn't find matching default value
|
||||||
if ($value->id === 0) {
|
if ($value->id === 0) {
|
||||||
return new NullAttribute();
|
return $new;
|
||||||
}
|
}
|
||||||
|
|
||||||
$new->value = $value;
|
$new->value = $value;
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,14 @@ use phpOMS\Localization\BaseStringL11nType;
|
||||||
use phpOMS\Localization\NullBaseStringL11nType;
|
use phpOMS\Localization\NullBaseStringL11nType;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General localization api functionality.
|
||||||
|
*
|
||||||
|
* @package Modules\Attribute
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
trait ApiLocalizationTraitController
|
trait ApiLocalizationTraitController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user