This commit is contained in:
Oh
2024-08-20 14:25:24 +02:00
parent 2024bef575
commit 96cb33e792
93 changed files with 859 additions and 299 deletions

View File

@@ -46,7 +46,7 @@ final class MultiSubform implements MultiSubformInterface
/**
* Get a subform items
*
* @param array $getMap The the map to get the subfrom data
* @param array $getMap The map to get the subfrom data
*
* Example:
* $getMap = [
@@ -94,8 +94,8 @@ final class MultiSubform implements MultiSubformInterface
/**
* Set a subform items
*
* @param array $items The list of items from the subform to set
* @param array $setMap The the map to set the subfrom data
* @param mixed $items The list of items from the subform to set
* @param array $setMap The map to set the subfrom data
*
* Example:
* $items,
@@ -117,7 +117,7 @@ final class MultiSubform implements MultiSubformInterface
* @return bool
* @since 3.2.2
*/
public function set(array $items, array $setMap): bool
public function set(mixed $items, array $setMap): bool
{
// Validate the core map presence and structure
if (!isset($setMap['_core']) || !is_array($setMap['_core']) || !$this->validSetMap($setMap['_core']))
@@ -125,6 +125,12 @@ final class MultiSubform implements MultiSubformInterface
return false;
}
// catch an empty set
if (!is_array($items))
{
$items = []; // will delete all existing linked items :( not ideal, but real
}
// Save the core data
if (!$this->setSubformData($items, $setMap['_core']))
{
@@ -167,7 +173,7 @@ final class MultiSubform implements MultiSubformInterface
* Set data based on provided map configuration.
*
* @param array $items The list of items from the subform to set
* @param array $map The the map to set the subfrom data
* @param array $map The map to set the subfrom data
* @param array|null $coreData The core data to be appended with subform data
*
* @return bool

View File

@@ -94,7 +94,7 @@ final class Subform implements SubformInterface
/**
* Set a subform items
*
* @param array $items The list of items from the subform to set
* @param mixed $items The list of items from the subform to set
* @param string $indexKey The index key on which the items should be observed as it relates to insert/update/delete.
* @param string $linkKey The link key on which the items where linked in the child table.
* @param string $linkValue The value of the link key in child table.
@@ -102,12 +102,17 @@ final class Subform implements SubformInterface
* @return bool
* @since 3.2.2
*/
public function set(array $items, string $indexKey, string $linkKey, string $linkValue): bool
public function set(mixed $items, string $indexKey, string $linkKey, string $linkValue): bool
{
$items = $this->process($items, $indexKey, $linkKey, $linkValue);
$this->purge($items, $indexKey, $linkKey, $linkValue);
if (empty($items))
{
return true; // nothing to set (already purged)
}
return $this->items->table($this->getTable())->set(
$items, $indexKey
);
@@ -142,10 +147,19 @@ final class Subform implements SubformInterface
if ($currentIndexValues !== null)
{
// Extract the index values from the items array
$activeIndexValues = array_values(array_map(function($item) use ($indexKey) {
return $item[$indexKey] ?? null;
}, $items));
// Check if the items array is empty
if (empty($items))
{
// Set activeIndexValues to an empty array if items is empty
$activeIndexValues = [];
}
else
{
// Extract the index values from the items array
$activeIndexValues = array_values(array_map(function($item) use ($indexKey) {
return $item[$indexKey] ?? null;
}, $items));
}
// Find the index values that are no longer in the items array
$inactiveIndexValues = array_diff($currentIndexValues, $activeIndexValues);
@@ -205,7 +219,7 @@ final class Subform implements SubformInterface
/**
* Processes an array of arrays based on the specified key.
*
* @param array $items Array of arrays to be processed.
* @param mixed $items Array of arrays to be processed.
* @param string $indexKey The index key on which the items should be observed as it relates to insert/update/delete
* @param string $linkKey The link key on which the items where linked in the child table.
* @param string $linkValue The value of the link key in child table.
@@ -213,8 +227,9 @@ final class Subform implements SubformInterface
* @return array The processed array of arrays.
* @since 3.2.2
*/
private function process(array $items, string $indexKey, string $linkKey, string $linkValue): array
private function process($items, string $indexKey, string $linkKey, string $linkValue): array
{
$items = is_array($items) ? $items : [];
foreach ($items as &$item)
{
$value = $item[$indexKey] ?? '';

View File

@@ -49,7 +49,7 @@ interface MultiSubformInterface
/**
* Set a subform items
*
* @param array $items The list of items from the subform to set
* @param mixed $items The list of items from the subform to set
* @param array $setMap The the map to set the subfrom data
*
* Example:
@@ -72,6 +72,6 @@ interface MultiSubformInterface
* @return bool
* @since 3.2.2
*/
public function set(array $items, array $setMap): bool;
public function set(mixed $items, array $setMap): bool;
}

View File

@@ -35,17 +35,17 @@ interface SubformInterface
* @param string $linkValue The value of the link key in child table.
* @param string $linkKey The link key on which the items where linked in the child table.
* @param string $field The parent field name of the subform in the parent view.
* @param array $set The array SET of the keys of each row in the subform.
* @param array $get The array SET of the keys of each row in the subform.
*
* @return array|null The subform
* @since 3.2.2
*/
public function get(string $linkValue, string $linkKey, string $field, array $set): ?array;
public function get(string $linkValue, string $linkKey, string $field, array $get): ?array;
/**
* Set a subform items
*
* @param array $items The list of items from the subform to set
* @param mixed $items The list of items from the subform to set
* @param string $indexKey The index key on which the items should be observed as it relates to insert/update/delete.
* @param string $linkKey The link key on which the items where linked in the child table.
* @param string $linkValue The value of the link key in child table.
@@ -53,7 +53,7 @@ interface SubformInterface
* @return bool
* @since 3.2.2
*/
public function set(array $items, string $indexKey, string $linkKey, string $linkValue): bool;
public function set(mixed $items, string $indexKey, string $linkKey, string $linkValue): bool;
/**
* Get the current active table

View File

@@ -159,17 +159,17 @@ final class Table extends BaseTable implements Tableinterface
],
],
'currency' => [
'name' => [
'name' => 'name',
'label' => 'COM_SUBFORMPOWER_CURRENCY_NAME_LABEL',
'type' => 'text',
'ext_number' => [
'name' => 'ext_number',
'label' => 'COM_SUBFORMPOWER_CURRENCY_EXT_NUMBER_LABEL',
'type' => 'number',
'title' => true,
'list' => 'currencies',
'store' => NULL,
'tab_name' => 'Details',
'db' => [
'type' => 'VARCHAR(255)',
'default' => '',
'type' => 'INT(10)',
'default' => '0',
'null_switch' => 'NOT NULL',
'unique_key' => false,
'key' => true,