mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-08 01:14:34 +02:00
Added very basic controller to merge info provider data into the part
This commit is contained in:
parent
01784a9d1f
commit
87626589a3
3 changed files with 31 additions and 12 deletions
|
@ -63,6 +63,8 @@ trait EntityMergerHelperTrait
|
|||
|
||||
//Set the value
|
||||
$this->property_accessor->setValue($target, $field, $value);
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,7 +77,7 @@ trait EntityMergerHelperTrait
|
|||
*/
|
||||
protected function useOtherValueIfNotNull(object $target, object $other, string $field): object
|
||||
{
|
||||
$this->useCallback(
|
||||
return $this->useCallback(
|
||||
function ($target_value, $other_value) {
|
||||
return $target_value ?? $other_value;
|
||||
},
|
||||
|
@ -84,7 +86,6 @@ trait EntityMergerHelperTrait
|
|||
$field
|
||||
);
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,7 +98,7 @@ trait EntityMergerHelperTrait
|
|||
*/
|
||||
protected function useOtherValueIfNotEmtpy(object $target, object $other, string $field): object
|
||||
{
|
||||
$this->useCallback(
|
||||
return $this->useCallback(
|
||||
function ($target_value, $other_value) {
|
||||
return empty($target_value) ? $other_value : $target_value;
|
||||
},
|
||||
|
@ -105,8 +106,6 @@ trait EntityMergerHelperTrait
|
|||
$other,
|
||||
$field
|
||||
);
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,7 +118,7 @@ trait EntityMergerHelperTrait
|
|||
*/
|
||||
protected function useLargerValue(object $target, object $other, string $field): object
|
||||
{
|
||||
$this->useCallback(
|
||||
return $this->useCallback(
|
||||
function ($target_value, $other_value) {
|
||||
return max($target_value, $other_value);
|
||||
},
|
||||
|
@ -127,8 +126,6 @@ trait EntityMergerHelperTrait
|
|||
$other,
|
||||
$field
|
||||
);
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,7 +138,7 @@ trait EntityMergerHelperTrait
|
|||
*/
|
||||
protected function useSmallerValue(object $target, object $other, string $field): object
|
||||
{
|
||||
$this->useCallback(
|
||||
return $this->useCallback(
|
||||
function ($target_value, $other_value) {
|
||||
return min($target_value, $other_value);
|
||||
},
|
||||
|
@ -149,8 +146,6 @@ trait EntityMergerHelperTrait
|
|||
$other,
|
||||
$field
|
||||
);
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,14 +37,19 @@ class PartMerger implements EntityMergerInterface
|
|||
return $target instanceof Part && $other instanceof Part;
|
||||
}
|
||||
|
||||
public function merge(object $target, object $other, array $context = []): object
|
||||
public function merge(object $target, object $other, array $context = []): Part
|
||||
{
|
||||
if (!$target instanceof Part || !$other instanceof Part) {
|
||||
throw new \InvalidArgumentException('The target and the other entity must be instances of Part');
|
||||
}
|
||||
|
||||
//Merge the fields
|
||||
$this->useOtherValueIfNotNull($target, $other, 'manufacturer');
|
||||
|
||||
$this->mergeCollections($target, $other, 'partLots');
|
||||
$this->mergeCollections($target, $other, 'attachments');
|
||||
$this->mergeCollections($target, $other, 'orderdetails');
|
||||
$this->mergeCollections($target, $other, 'parameters');
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue