Update 2024-06-25 2:09:12

This commit is contained in:
Robot 2024-06-25 14:09:34 +02:00
parent eea2fa1f13
commit 780d952014
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
19 changed files with 1403 additions and 55 deletions

View File

@ -42,6 +42,7 @@ This repository contains an index (see below) of all the approved powers within
- **abstract class Factory** | [Details](src/9d76b8dc-3883-4755-b11c-131d19ca8a53) | [Code](src/9d76b8dc-3883-4755-b11c-131d19ca8a53/code.php) | [Settings](src/9d76b8dc-3883-4755-b11c-131d19ca8a53/settings.json) | Super__9d76b8dc_3883_4755_b11c_131d19ca8a53__Power
- **final class Item** | [Details](src/9206082e-a3f7-472e-98b2-de90d06cbdcd) | [Code](src/9206082e-a3f7-472e-98b2-de90d06cbdcd/code.php) | [Settings](src/9206082e-a3f7-472e-98b2-de90d06cbdcd/settings.json) | Super__9206082e_a3f7_472e_98b2_de90d06cbdcd__Power
- **final class Items** | [Details](src/21bca8a4-5b28-41c4-843e-8097f0ba7cca) | [Code](src/21bca8a4-5b28-41c4-843e-8097f0ba7cca/code.php) | [Settings](src/21bca8a4-5b28-41c4-843e-8097f0ba7cca/settings.json) | Super__21bca8a4_5b28_41c4_843e_8097f0ba7cca__Power
- **final class MultiSubform** | [Details](src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9) | [Code](src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/code.php) | [Settings](src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/settings.json) | Super__e0198c3f_777a_4a0b_87b7_e6a198afc8f9__Power
- **final class Subform** | [Details](src/85785701-07b2-4f81-bc1e-0f423700c254) | [Code](src/85785701-07b2-4f81-bc1e-0f423700c254/code.php) | [Settings](src/85785701-07b2-4f81-bc1e-0f423700c254/settings.json) | Super__85785701_07b2_4f81_bc1e_0f423700c254__Power
- **class Remote** | [Details](src/728ee726-3f0f-4762-899d-f8c9430cee58) | [Code](src/728ee726-3f0f-4762-899d-f8c9430cee58/code.php) | [Settings](src/728ee726-3f0f-4762-899d-f8c9430cee58/settings.json) | Super__728ee726_3f0f_4762_899d_f8c9430cee58__Power
- **Namespace**: [VDM\Joomla\Database](#vdm-joomla-database)

View File

@ -12,19 +12,19 @@
```uml
@startuml
interface Registryinterface #Lavender {
+ set(string $path, mixed $value) : static
+ add(string $path, mixed $value, ...) : static
+ set(string $path, mixed $value) : self
+ add(string $path, mixed $value, ...) : self
+ get(string $path, mixed $default = null) : mixed
+ remove(string $path) : static
+ remove(string $path) : self
+ exists(string $path) : bool
+ setSeparator(?string $value) : static
+ setSeparator(?string $value) : self
}
note right of Registryinterface::set
Sets a value into the registry using multiple keys.
since: 3.2.0
return: static
return: self
end note
note right of Registryinterface::add
@ -34,7 +34,7 @@ Default is $addAsArray = false (if null) in base class.
Override in child class allowed set class property $addAsArray = true.
since: 3.2.0
return: static
return: self
arguments:
string $path
@ -53,7 +53,7 @@ note right of Registryinterface::remove
Removes a value (or sub-array) from the registry using multiple keys.
since: 3.2.0
return: static
return: self
end note
note right of Registryinterface::exists
@ -67,7 +67,7 @@ note right of Registryinterface::setSeparator
Sets a separator value
since: 3.2.0
return: static
return: self
end note
@enduml

View File

@ -29,10 +29,10 @@ interface Registryinterface extends Activeregistryinterface
* @param mixed $value Value of entry
*
* @throws \InvalidArgumentException If any of the path values are not a number or string.
* @return $this
* @return self
* @since 3.2.0
*/
public function set(string $path, $value): static;
public function set(string $path, $value): self;
/**
* Adds content into the registry. If a key exists,
@ -45,10 +45,10 @@ interface Registryinterface extends Activeregistryinterface
* Override in child class allowed set class property $addAsArray = true.
*
* @throws \InvalidArgumentException If any of the path values are not a number or string.
* @return $this
* @return self
* @since 3.2.0
*/
public function add(string $path, $value, ?bool $asArray = null): static;
public function add(string $path, $value, ?bool $asArray = null): self;
/**
* Retrieves a value (or sub-array) from the registry using multiple keys.
@ -68,10 +68,10 @@ interface Registryinterface extends Activeregistryinterface
* @param string $path Registry path (e.g. vdm.content.builder)
*
* @throws \InvalidArgumentException If any of the path values are not a number or string.
* @return $this
* @return self
* @since 3.2.0
*/
public function remove(string $path): static;
public function remove(string $path): self;
/**
* Checks the existence of a particular location in the registry using multiple keys.
@ -89,9 +89,9 @@ interface Registryinterface extends Activeregistryinterface
*
* @param string|null $value The value to set.
*
* @return $this
* @return self
* @since 3.2.0
*/
public function setSeparator(?string $value): static;
public function setSeparator(?string $value): self;
}

View File

@ -5,10 +5,10 @@
* @param mixed $value Value of entry
*
* @throws \InvalidArgumentException If any of the path values are not a number or string.
* @return $this
* @return self
* @since 3.2.0
*/
public function set(string $path, $value): static;
public function set(string $path, $value): self;
/**
* Adds content into the registry. If a key exists,
@ -21,10 +21,10 @@
* Override in child class allowed set class property $addAsArray = true.
*
* @throws \InvalidArgumentException If any of the path values are not a number or string.
* @return $this
* @return self
* @since 3.2.0
*/
public function add(string $path, $value, ?bool $asArray = null): static;
public function add(string $path, $value, ?bool $asArray = null): self;
/**
* Retrieves a value (or sub-array) from the registry using multiple keys.
@ -44,10 +44,10 @@
* @param string $path Registry path (e.g. vdm.content.builder)
*
* @throws \InvalidArgumentException If any of the path values are not a number or string.
* @return $this
* @return self
* @since 3.2.0
*/
public function remove(string $path): static;
public function remove(string $path): self;
/**
* Checks the existence of a particular location in the registry using multiple keys.
@ -65,7 +65,7 @@
*
* @param string|null $value The value to set.
*
* @return $this
* @return self
* @since 3.2.0
*/
public function setSeparator(?string $value): static;
public function setSeparator(?string $value): self;

View File

@ -13,12 +13,12 @@
@startuml
abstract Registry #Orange {
# ?string $separator
+ set(string $path, mixed $value) : static
+ add(string $path, mixed $value, ...) : static
+ set(string $path, mixed $value) : self
+ add(string $path, mixed $value, ...) : self
+ get(string $path, mixed $default = null) : mixed
+ remove(string $path) : static
+ remove(string $path) : self
+ exists(string $path) : bool
+ setSeparator(?string $value) : static
+ setSeparator(?string $value) : self
# getActiveKeys(string $path) : ?array
}
@ -26,7 +26,7 @@ note right of Registry::set
Sets a value into the registry using multiple keys.
since: 3.2.0
return: static
return: self
end note
note right of Registry::add
@ -36,7 +36,7 @@ Default is $addAsArray = false (if null) in base class.
Override in child class allowed set class property $addAsArray = true.
since: 3.2.0
return: static
return: self
arguments:
string $path
@ -55,7 +55,7 @@ note right of Registry::remove
Removes a value (or sub-array) from the registry using multiple keys.
since: 3.2.0
return: static
return: self
end note
note right of Registry::exists
@ -69,7 +69,7 @@ note right of Registry::setSeparator
Sets a separator value
since: 3.2.0
return: static
return: self
end note
note right of Registry::getActiveKeys

View File

@ -40,10 +40,10 @@ abstract class Registry extends ActiveRegistry implements Registryinterface
* @param mixed $value Value of entry
*
* @throws \InvalidArgumentException If any of the path values are not a number or string.
* @return $this
* @return self
* @since 3.2.0
*/
public function set(string $path, $value): static
public function set(string $path, $value): self
{
if (($keys = $this->getActiveKeys($path)) === null)
{
@ -66,10 +66,10 @@ abstract class Registry extends ActiveRegistry implements Registryinterface
* Override in child class allowed set class property $addAsArray = true.
*
* @throws \InvalidArgumentException If any of the path values are not a number or string.
* @return $this
* @return self
* @since 3.2.0
*/
public function add(string $path, $value, ?bool $asArray = null): static
public function add(string $path, $value, ?bool $asArray = null): self
{
if (($keys = $this->getActiveKeys($path)) === null)
{
@ -107,10 +107,10 @@ abstract class Registry extends ActiveRegistry implements Registryinterface
* @param string $path Registry path (e.g. vdm.content.builder)
*
* @throws \InvalidArgumentException If any of the path values are not a number or string.
* @return $this
* @return self
* @since 3.2.0
*/
public function remove(string $path): static
public function remove(string $path): self
{
if (($keys = $this->getActiveKeys($path)) === null)
{
@ -146,10 +146,10 @@ abstract class Registry extends ActiveRegistry implements Registryinterface
*
* @param string|null $value The value to set.
*
* @return $this
* @return self
* @since 3.2.0
*/
public function setSeparator(?string $value): static
public function setSeparator(?string $value): self
{
$this->separator = $value;

View File

@ -13,10 +13,10 @@
* @param mixed $value Value of entry
*
* @throws \InvalidArgumentException If any of the path values are not a number or string.
* @return $this
* @return self
* @since 3.2.0
*/
public function set(string $path, $value): static
public function set(string $path, $value): self
{
if (($keys = $this->getActiveKeys($path)) === null)
{
@ -39,10 +39,10 @@
* Override in child class allowed set class property $addAsArray = true.
*
* @throws \InvalidArgumentException If any of the path values are not a number or string.
* @return $this
* @return self
* @since 3.2.0
*/
public function add(string $path, $value, ?bool $asArray = null): static
public function add(string $path, $value, ?bool $asArray = null): self
{
if (($keys = $this->getActiveKeys($path)) === null)
{
@ -80,10 +80,10 @@
* @param string $path Registry path (e.g. vdm.content.builder)
*
* @throws \InvalidArgumentException If any of the path values are not a number or string.
* @return $this
* @return self
* @since 3.2.0
*/
public function remove(string $path): static
public function remove(string $path): self
{
if (($keys = $this->getActiveKeys($path)) === null)
{
@ -119,10 +119,10 @@
*
* @param string|null $value The value to set.
*
* @return $this
* @return self
* @since 3.2.0
*/
public function setSeparator(?string $value): static
public function setSeparator(?string $value): self
{
$this->separator = $value;

View File

@ -48,7 +48,7 @@ note right of Subform::get
string $linkValue
string $linkKey
string $field
array $set
array $get
end note
note left of Subform::set

View File

@ -77,16 +77,16 @@ final class Subform implements 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 get: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
{
if (($items = $this->items->table($this->getTable())->get([$linkValue], $linkKey)) !== null)
{
return $this->converter($items, $set, $field);
return $this->converter($items, $get, $field);
}
return null;
}

View File

@ -52,16 +52,16 @@
* @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 get: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
{
if (($items = $this->items->table($this->getTable())->get([$linkValue], $linkKey)) !== null)
{
return $this->converter($items, $set, $field);
return $this->converter($items, $get, $field);
}
return null;
}

View File

@ -20,6 +20,7 @@ class Data #Gold {
+ getItem(Container $container) : Item
+ getItems(Container $container) : Items
+ getSubform(Container $container) : Subform
+ getMultiSubform(Container $container) : MultiSubform
}
note right of Data::register
@ -77,6 +78,13 @@ note left of Data::getSubform
since: 3.2.0
return: Subform
end note
note right of Data::getMultiSubform
Get The MultiSubform Class.
since: 3.2.0
return: MultiSubform
end note
@enduml
```

View File

@ -21,6 +21,7 @@ use VDM\Joomla\Data\Action\Delete;
use VDM\Joomla\Data\Item;
use VDM\Joomla\Data\Items;
use VDM\Joomla\Data\Subform;
use VDM\Joomla\Data\MultiSubform;
/**
@ -60,6 +61,9 @@ class Data implements ServiceProviderInterface
$container->alias(Subform::class, 'Data.Subform')
->share('Data.Subform', [$this, 'getSubform'], true);
$container->alias(MultiSubform::class, 'Data.MultiSubform')
->share('Data.MultiSubform', [$this, 'getMultiSubform'], true);
}
/**
@ -176,6 +180,21 @@ class Data implements ServiceProviderInterface
return new Subform(
$container->get('Data.Items')
);
}
/**
* Get The MultiSubform Class.
*
* @param Container $container The DI container.
*
* @return MultiSubform
* @since 3.2.0
*/
public function getMultiSubform(Container $container): MultiSubform
{
return new MultiSubform(
$container->get('Data.Subform')
);
}
}

View File

@ -28,6 +28,9 @@
$container->alias(Subform::class, 'Data.Subform')
->share('Data.Subform', [$this, 'getSubform'], true);
$container->alias(MultiSubform::class, 'Data.MultiSubform')
->share('Data.MultiSubform', [$this, 'getMultiSubform'], true);
}
/**
@ -144,4 +147,19 @@
return new Subform(
$container->get('Data.Items')
);
}
/**
* Get The MultiSubform Class.
*
* @param Container $container The DI container.
*
* @return MultiSubform
* @since 3.2.0
*/
public function getMultiSubform(Container $container): MultiSubform
{
return new MultiSubform(
$container->get('Data.Subform')
);
}

View File

@ -39,6 +39,10 @@
"use_selection6": {
"use": "85785701-07b2-4f81-bc1e-0f423700c254",
"as": "default"
},
"use_selection7": {
"use": "e0198c3f-777a-4a0b-87b7-e6a198afc8f9",
"as": "default"
}
},
"extendsinterfaces": null,

View File

@ -0,0 +1,269 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class MultiSubform (Details)
> namespace: **VDM\Joomla\Data**
> extends: ****
```uml
@startuml
class MultiSubform << (F,LightGreen) >> #RoyalBlue {
# Subform $subform
+ __construct(Items $subform)
+ get(array $getMap) : ?array
+ set(array $items, array $setMap) : bool
- getSubformData(array $map, ?array $coreData = null) : ?array
- setSubformData(array $items, array $map, ...) : bool
- setLinkValue(string $linkValue, ?array $data = null) : ?string
- getNestedSubforms(array $getMap, array $subformData, ...) : array
- setNestedSubforms(array $setMap, array $subformData, ...) : bool
- processGetSubform(array $getMap, array $subform, ...) : array
- processSetSubform(array $setMap, array $subform, ...) : bool
- processGetMap($subform, array $map, ...) : void
- processSetMap(array $subform, array $map, ...) : bool
- handleCoreGetMap($subform, array $map, ...) : void
- handleCoreSetMap(array $subform, array $map, ...) : bool
- handleRegularGetMap($subform, array $map, ...) : void
- handleRegularSetMap(array $subform, array $map, ...) : bool
- validGetMap(array $map) : bool
- validSetMap(array $map) : bool
}
note right of MultiSubform::__construct
Constructor.
since: 3.2.2
end note
note left of MultiSubform::get
Get a subform items
Example:
$getMap = [
'_core' => [
'table' =>'data',
'linkValue' => $item->guid ?? '',
'linkKey' => 'look',
'field' => 'data',
'get' => ['guid','email','image','mobile_phone','website','dateofbirth']
],
'countries' => [
'table' =>'data_country',
'linkValue' => 'data:guid', // coretable:fieldname
'linkKey' => 'data',
'get' => ['guid','country','currency']
]
];
since: 3.2.2
return: ?array
end note
note right of MultiSubform::set
Set a subform items
Example:
$items,
$setMap = [
'_core' => [
'table' =>'data',
'indexKey' => 'guid',
'linkKey' => 'look',
'linkValue' => $data['guid'] ?? ''
],
'countries' => [
'table' =>'data_country',
'indexKey' => 'guid',
'linkKey' => 'data',
'linkValue' => 'data:guid' // coretable:fieldname
]
];
since: 3.2.2
return: bool
end note
note left of MultiSubform::getSubformData
Fetch data based on provided map configuration.
since: 3.2.2
return: ?array
end note
note right of MultiSubform::setSubformData
Set data based on provided map configuration.
since: 3.2.2
return: bool
arguments:
array $items
array $map
?array $coreData = null
end note
note left of MultiSubform::setLinkValue
Set the linked value if needed, and posible.
since: 3.2.2
return: ?string
end note
note right of MultiSubform::getNestedSubforms
Recursively process additional subform data.
since: 3.2.2
return: array
arguments:
array $getMap
array $subformData
string $table
end note
note left of MultiSubform::setNestedSubforms
Recursively process additional subform data.
since: 3.2.2
return: bool
arguments:
array $setMap
array $subformData
string $table
end note
note right of MultiSubform::processGetSubform
Process each subform entry based on the map.
since: 3.2.2
return: array
arguments:
array $getMap
array $subform
string $table
end note
note left of MultiSubform::processSetSubform
Process each subform entry based on the map.
since: 3.2.2
return: bool
arguments:
array $setMap
array $subform
string $table
end note
note right of MultiSubform::processGetMap
Process a given map by either fetching nested subforms or handling them directly.
since: 3.2.2
return: void
arguments:
$subform
array $map
string $key
string $table
end note
note left of MultiSubform::processSetMap
Process a given map by either setting nested subforms or handling them directly.
since: 3.2.2
return: bool
arguments:
array $subform
array $map
string $key
string $table
end note
note right of MultiSubform::handleCoreGetMap
Handle the processing of '_core' maps in a subform.
since: 3.2.2
return: void
arguments:
$subform
array $map
string $key
string $table
end note
note left of MultiSubform::handleCoreSetMap
Handle the processing of '_core' maps in a subform.
since: 3.2.2
return: bool
arguments:
array $subform
array $map
string $key
string $table
end note
note right of MultiSubform::handleRegularGetMap
Handle the processing of regular maps in a subform.
since: 3.2.2
return: void
arguments:
$subform
array $map
string $key
string $table
end note
note left of MultiSubform::handleRegularSetMap
Handle the processing of regular maps in a subform.
since: 3.2.2
return: bool
arguments:
array $subform
array $map
string $key
string $table
end note
note right of MultiSubform::validGetMap
Validate the get map configuration for fetching subform data.
Ensures all required keys are present and have valid values.
since: 3.2.2
return: bool
end note
note left of MultiSubform::validSetMap
Validate the set map configuration for fetching subform data.
Ensures all required keys are present and have valid values.
since: 3.2.2
return: bool
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,510 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 3rd September, 2020
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Data;
use VDM\Joomla\Interfaces\Data\SubformInterface as Subform;
/**
* CRUD the data of multi subform to another views (tables)
*
* @since 3.2.2
*/
final class MultiSubform
{
/**
* The Subform Class.
*
* @var Subform
* @since 3.2.2
*/
protected Subform $subform;
/**
* Constructor.
*
* @param Subform $subform The Subform Class.
*
* @since 3.2.2
*/
public function __construct(Items $subform)
{
$this->subform = $subform;
}
/**
* Get a subform items
*
* @param array $getMap The the map to get the subfrom data
*
* Example:
* $getMap = [
* '_core' => [
* 'table' =>'data',
* 'linkValue' => $item->guid ?? '',
* 'linkKey' => 'look',
* 'field' => 'data',
* 'get' => ['guid','email','image','mobile_phone','website','dateofbirth']
* ],
* 'countries' => [
* 'table' =>'data_country',
* 'linkValue' => 'data:guid', // coretable:fieldname
* 'linkKey' => 'data',
* 'get' => ['guid','country','currency']
* ]
* ];
*
* @return array|null The subform
* @since 3.2.2
*/
public function get(array $getMap): ?array
{
// Validate the core map presence and structure
if (!isset($getMap['_core']) || !is_array($getMap['_core']) || !$this->validGetMap($getMap['_core']))
{
return null;
}
// Initialize the core data
$coreData = $this->getSubformData($getMap['_core']);
// Return null if fetching core data fails
if (null === $coreData)
{
return null;
}
$table = $getMap['_core']['table'];
unset($getMap['_core']);
// Recursively get data for all nested subforms
return $this->getNestedSubforms($getMap, $coreData, $table);
}
/**
* 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
*
* Example:
* $items,
* $setMap = [
* '_core' => [
* 'table' =>'data',
* 'indexKey' => 'guid',
* 'linkKey' => 'look',
* 'linkValue' => $data['guid'] ?? ''
* ],
* 'countries' => [
* 'table' =>'data_country',
* 'indexKey' => 'guid',
* 'linkKey' => 'data',
* 'linkValue' => 'data:guid' // coretable:fieldname
* ]
* ];
*
* @return bool
* @since 3.2.2
*/
public function set(array $items, array $setMap): bool
{
// Validate the core map presence and structure
if (!isset($setMap['_core']) || !is_array($getMap['_core']) || !$this->validSetMap($setMap['_core']))
{
return false;
}
// Save the core data
if (!$this->setSubformData($items, $setMap['_core']))
{
return false;
}
$table = $setMap['_core']['table'];
unset($setMap['_core']);
// Recursively set data for all nested subforms
return $this->setNestedSubforms($setMap, $items, $table);
}
/**
* Fetch data based on provided map configuration.
*
* @param array $map Map configuration
* @param array|null $coreData The core data to be appended with subform data
*
* @return array|null Fetched data or null on failure
* @since 3.2.2
*/
private function getSubformData(array $map, ?array $coreData = null): ?array
{
$map['linkValue'] = $this->setLinkValue($map['linkValue'], $coreData);
if (empty($map['linkValue']) || strpos($map['linkValue'], ':') !== false)
{
return null;
}
return $this->subform->table($map['table'])->get(
$map['linkValue'],
$map['linkKey'],
$map['field'],
$map['get']
);
}
/**
* 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|null $coreData The core data to be appended with subform data
*
* @return bool
* @since 3.2.2
*/
private function setSubformData(array $items, array $map, ?array $coreData = null): bool
{
$map['linkValue'] = $this->setLinkValue($map['linkValue'], $coreData);
if (empty($map['linkValue']) || strpos($map['linkValue'], ':') !== false)
{
return false;
}
return $this->subform->table($map['table'])->set(
$items,
$map['indexKey'],
$map['linkKey'],
$map['linkValue']
);
}
/**
* Set the linked value if needed, and posible.
*
* @param string $linkValue The current linkValue
* @param array|null $data The already found data as table => dataSet[field] => value
*
* @return string|null The actual linkValue
* @since 3.2.2
*/
private function setLinkValue(string $linkValue, ?array $data = null): ?string
{
if ($data !== null && strpos($linkValue, ':') !== false)
{
[$table, $field] = explode(':', $linkValue);
$linkValue = $data[$table][$field] ?? null;
}
return $linkValue;
}
/**
* Recursively process additional subform data.
*
* @param array $getMap The nested map of data to process
* @param array $subformData The core subform data
* @param string $table The core table
*
* @return array The core data with nested subforms included
* @since 3.2.2
*/
private function getNestedSubforms(array $getMap, array $subformData, string $table): array
{
foreach ($subformData as &$subform)
{
$subform = $this->processGetSubform($getMap, $subform, $table);
}
return $subformData;
}
/**
* Recursively process additional subform data.
*
* @param array $setMap The nested map of data to process
* @param array $subformData The core subform data
* @param string $table The core table
*
* @return bool
* @since 3.2.2
*/
private function setNestedSubforms(array $setMap, array $subformData, string $table): bool
{
$status = true;
foreach ($subformData as $subform)
{
if (!$this->processSetSubform($setMap, $subform, $table))
{
$status = false;
}
}
return $status;
}
/**
* Process each subform entry based on the map.
*
* @param array $getMap Mapping data for processing subforms
* @param array $subform A single subform entry
* @param string $table The table name used for linking values
*
* @return array Updated subform
* @since 3.2.2
*/
private function processGetSubform(array $getMap, array $subform, string $table): array
{
foreach ($getMap as $key => $map)
{
if (!is_array($map) || isset($subform[$key]))
{
continue;
}
$this->processGetMap($subform, $map, $key, $table);
}
return $subform;
}
/**
* Process each subform entry based on the map.
*
* @param array $setMap Mapping data for processing subforms
* @param array $subform A single subform entry
* @param string $table The table name used for linking values
*
* @return bool
* @since 3.2.2
*/
private function processSetSubform(array $setMap, array $subform, string $table): bool
{
$status = true;
foreach ($setMap as $key => $map)
{
if (!is_array($map) || !isset($subform[$key]))
{
continue;
}
if (!$this->processSetMap($subform, $map, $key, $table))
{
$status = false;
}
}
return $status;
}
/**
* Process a given map by either fetching nested subforms or handling them directly.
*
* @param array &$subform Reference to subform data
* @param array $map Map configuration for subform processing
* @param string $key Key associated with the map
* @param string $table Core table name for linking values
*
* @return void
* @since 3.2.2
*/
private function processGetMap(array &$subform, array $map, string $key, string $table): void
{
if (isset($map['_core']))
{
$this->handleCoreGetMap($subform, $map, $key, $table);
}
else
{
$this->handleRegularGetMap($subform, $map, $key, $table);
}
}
/**
* Process a given map by either setting nested subforms or handling them directly.
*
* @param array $subform Subform data
* @param array $map Map configuration for subform processing
* @param string $key Key associated with the map
* @param string $table Core table name for linking values
*
* @return bool
* @since 3.2.2
*/
private function processSetMap(array $subform, array $map, string $key, string $table): bool
{
if (isset($map['_core']))
{
return $this->handleCoreSetMap($subform, $map, $key, $table);
}
return $this->handleRegularSetMap($subform, $map, $key, $table);
}
/**
* Handle the processing of '_core' maps in a subform.
*
* @param array &$subform Reference to subform data
* @param array $map Map configuration for core subform processing
* @param string $key Key associated with the map
* @param string $table Core table name for linking values
*
* @return void
* @since 3.2.2
*/
private function handleCoreGetMap(array &$subform, array $map, string $key, string $table): void
{
if (is_array($map['_core']) && $this->validGetMap($map['_core']))
{
$map['_core']['linkValue'] = $this->setLinkValue($map['_core']['linkValue'], [$table => $subform]);
$subCoreData = $this->get($map);
if ($subCoreData !== null)
{
$subform[$key] = $subCoreData;
}
}
}
/**
* Handle the processing of '_core' maps in a subform.
*
* @param array $subform Subform data
* @param array $map Map configuration for core subform processing
* @param string $key Key associated with the map
* @param string $table Core table name for linking values
*
* @return bool
* @since 3.2.2
*/
private function handleCoreSetMap(array $subform, array $map, string $key, string $table): bool
{
if (is_array($map['_core']) && $this->validGetMap($map['_core']))
{
$map['_core']['linkValue'] = $this->setLinkValue($map['_core']['linkValue'], [$table => $subform]);
return $this->set($subform[$key], $map);
}
return false;
}
/**
* Handle the processing of regular maps in a subform.
*
* @param array &$subform Reference to subform data
* @param array $map Map configuration for regular subform processing
* @param string $key Key associated with the map
* @param string $table Core table name for linking values
*
* @return void
* @since 3.2.2
*/
private function handleRegularGetMap(array &$subform, array $map, string $key, string $table): void
{
$map['field'] = $key;
if ($this->validGetMap($map))
{
$subformData = $this->getSubformData($map, [$table => $subform]);
if ($subformData !== null)
{
$subform[$key] = $subformData;
}
}
}
/**
* Handle the processing of regular maps in a subform.
*
* @param array $subform Subform data
* @param array $map Map configuration for regular subform processing
* @param string $key Key associated with the map
* @param string $table Core table name for linking values
*
* @return bool
* @since 3.2.2
*/
private function handleRegularSetMap(array $subform, array $map, string $key, string $table): bool
{
if ($this->validSetMap($map))
{
return $this->setSubformData($subform[$key], $map, [$table => $subform]);
}
return false;
}
/**
* Validate the get map configuration for fetching subform data.
* Ensures all required keys are present and have valid values.
*
* @param array $map The map configuration to validate.
*
* @return bool Returns true if the map is valid, false otherwise.
* @since 3.2.2
*/
private function validGetMap(array $map): bool
{
// List of required keys with their expected types or validation functions
$requiredKeys = [
'table' => 'is_string',
'linkValue' => 'is_string',
'linkKey' => 'is_string',
'field' => 'is_string',
'get' => 'is_array'
];
// Iterate through each required key and validate
foreach ($requiredKeys as $key => $validator)
{
if (empty($map[$key]) || !$validator($map[$key]))
{
return false; // Key missing or validation failed
}
}
return true; // All checks passed
}
/**
* Validate the set map configuration for fetching subform data.
* Ensures all required keys are present and have valid values.
*
* @param array $map The map configuration to validate.
*
* @return bool Returns true if the map is valid, false otherwise.
* @since 3.2.2
*/
private function validSetMap(array $map): bool
{
// List of required keys with their expected types or validation functions
$requiredKeys = [
'table' => 'is_string',
'indexKey' => 'is_string',
'linkKey' => 'is_string',
'linkValue' => 'is_string'
];
// Iterate through each required key and validate
foreach ($requiredKeys as $key => $validator)
{
if (empty($map[$key]) || !$validator($map[$key]))
{
return false; // Key missing or validation failed
}
}
return true; // All checks passed
}
}

View File

@ -0,0 +1,484 @@
/**
* The Subform Class.
*
* @var Subform
* @since 3.2.2
*/
protected Subform $subform;
/**
* Constructor.
*
* @param Subform $subform The Subform Class.
*
* @since 3.2.2
*/
public function __construct(Items $subform)
{
$this->subform = $subform;
}
/**
* Get a subform items
*
* @param array $getMap The the map to get the subfrom data
*
* Example:
* $getMap = [
* '_core' => [
* 'table' =>'data',
* 'linkValue' => $item->guid ?? '',
* 'linkKey' => 'look',
* 'field' => 'data',
* 'get' => ['guid','email','image','mobile_phone','website','dateofbirth']
* ],
* 'countries' => [
* 'table' =>'data_country',
* 'linkValue' => 'data:guid', // coretable:fieldname
* 'linkKey' => 'data',
* 'get' => ['guid','country','currency']
* ]
* ];
*
* @return array|null The subform
* @since 3.2.2
*/
public function get(array $getMap): ?array
{
// Validate the core map presence and structure
if (!isset($getMap['_core']) || !is_array($getMap['_core']) || !$this->validGetMap($getMap['_core']))
{
return null;
}
// Initialize the core data
$coreData = $this->getSubformData($getMap['_core']);
// Return null if fetching core data fails
if (null === $coreData)
{
return null;
}
$table = $getMap['_core']['table'];
unset($getMap['_core']);
// Recursively get data for all nested subforms
return $this->getNestedSubforms($getMap, $coreData, $table);
}
/**
* 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
*
* Example:
* $items,
* $setMap = [
* '_core' => [
* 'table' =>'data',
* 'indexKey' => 'guid',
* 'linkKey' => 'look',
* 'linkValue' => $data['guid'] ?? ''
* ],
* 'countries' => [
* 'table' =>'data_country',
* 'indexKey' => 'guid',
* 'linkKey' => 'data',
* 'linkValue' => 'data:guid' // coretable:fieldname
* ]
* ];
*
* @return bool
* @since 3.2.2
*/
public function set(array $items, array $setMap): bool
{
// Validate the core map presence and structure
if (!isset($setMap['_core']) || !is_array($getMap['_core']) || !$this->validSetMap($setMap['_core']))
{
return false;
}
// Save the core data
if (!$this->setSubformData($items, $setMap['_core']))
{
return false;
}
$table = $setMap['_core']['table'];
unset($setMap['_core']);
// Recursively set data for all nested subforms
return $this->setNestedSubforms($setMap, $items, $table);
}
/**
* Fetch data based on provided map configuration.
*
* @param array $map Map configuration
* @param array|null $coreData The core data to be appended with subform data
*
* @return array|null Fetched data or null on failure
* @since 3.2.2
*/
private function getSubformData(array $map, ?array $coreData = null): ?array
{
$map['linkValue'] = $this->setLinkValue($map['linkValue'], $coreData);
if (empty($map['linkValue']) || strpos($map['linkValue'], ':') !== false)
{
return null;
}
return $this->subform->table($map['table'])->get(
$map['linkValue'],
$map['linkKey'],
$map['field'],
$map['get']
);
}
/**
* 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|null $coreData The core data to be appended with subform data
*
* @return bool
* @since 3.2.2
*/
private function setSubformData(array $items, array $map, ?array $coreData = null): bool
{
$map['linkValue'] = $this->setLinkValue($map['linkValue'], $coreData);
if (empty($map['linkValue']) || strpos($map['linkValue'], ':') !== false)
{
return false;
}
return $this->subform->table($map['table'])->set(
$items,
$map['indexKey'],
$map['linkKey'],
$map['linkValue']
);
}
/**
* Set the linked value if needed, and posible.
*
* @param string $linkValue The current linkValue
* @param array|null $data The already found data as table => dataSet[field] => value
*
* @return string|null The actual linkValue
* @since 3.2.2
*/
private function setLinkValue(string $linkValue, ?array $data = null): ?string
{
if ($data !== null && strpos($linkValue, ':') !== false)
{
[$table, $field] = explode(':', $linkValue);
$linkValue = $data[$table][$field] ?? null;
}
return $linkValue;
}
/**
* Recursively process additional subform data.
*
* @param array $getMap The nested map of data to process
* @param array $subformData The core subform data
* @param string $table The core table
*
* @return array The core data with nested subforms included
* @since 3.2.2
*/
private function getNestedSubforms(array $getMap, array $subformData, string $table): array
{
foreach ($subformData as &$subform)
{
$subform = $this->processGetSubform($getMap, $subform, $table);
}
return $subformData;
}
/**
* Recursively process additional subform data.
*
* @param array $setMap The nested map of data to process
* @param array $subformData The core subform data
* @param string $table The core table
*
* @return bool
* @since 3.2.2
*/
private function setNestedSubforms(array $setMap, array $subformData, string $table): bool
{
$status = true;
foreach ($subformData as $subform)
{
if (!$this->processSetSubform($setMap, $subform, $table))
{
$status = false;
}
}
return $status;
}
/**
* Process each subform entry based on the map.
*
* @param array $getMap Mapping data for processing subforms
* @param array $subform A single subform entry
* @param string $table The table name used for linking values
*
* @return array Updated subform
* @since 3.2.2
*/
private function processGetSubform(array $getMap, array $subform, string $table): array
{
foreach ($getMap as $key => $map)
{
if (!is_array($map) || isset($subform[$key]))
{
continue;
}
$this->processGetMap($subform, $map, $key, $table);
}
return $subform;
}
/**
* Process each subform entry based on the map.
*
* @param array $setMap Mapping data for processing subforms
* @param array $subform A single subform entry
* @param string $table The table name used for linking values
*
* @return bool
* @since 3.2.2
*/
private function processSetSubform(array $setMap, array $subform, string $table): bool
{
$status = true;
foreach ($setMap as $key => $map)
{
if (!is_array($map) || !isset($subform[$key]))
{
continue;
}
if (!$this->processSetMap($subform, $map, $key, $table))
{
$status = false;
}
}
return $status;
}
/**
* Process a given map by either fetching nested subforms or handling them directly.
*
* @param array &$subform Reference to subform data
* @param array $map Map configuration for subform processing
* @param string $key Key associated with the map
* @param string $table Core table name for linking values
*
* @return void
* @since 3.2.2
*/
private function processGetMap(array &$subform, array $map, string $key, string $table): void
{
if (isset($map['_core']))
{
$this->handleCoreGetMap($subform, $map, $key, $table);
}
else
{
$this->handleRegularGetMap($subform, $map, $key, $table);
}
}
/**
* Process a given map by either setting nested subforms or handling them directly.
*
* @param array $subform Subform data
* @param array $map Map configuration for subform processing
* @param string $key Key associated with the map
* @param string $table Core table name for linking values
*
* @return bool
* @since 3.2.2
*/
private function processSetMap(array $subform, array $map, string $key, string $table): bool
{
if (isset($map['_core']))
{
return $this->handleCoreSetMap($subform, $map, $key, $table);
}
return $this->handleRegularSetMap($subform, $map, $key, $table);
}
/**
* Handle the processing of '_core' maps in a subform.
*
* @param array &$subform Reference to subform data
* @param array $map Map configuration for core subform processing
* @param string $key Key associated with the map
* @param string $table Core table name for linking values
*
* @return void
* @since 3.2.2
*/
private function handleCoreGetMap(array &$subform, array $map, string $key, string $table): void
{
if (is_array($map['_core']) && $this->validGetMap($map['_core']))
{
$map['_core']['linkValue'] = $this->setLinkValue($map['_core']['linkValue'], [$table => $subform]);
$subCoreData = $this->get($map);
if ($subCoreData !== null)
{
$subform[$key] = $subCoreData;
}
}
}
/**
* Handle the processing of '_core' maps in a subform.
*
* @param array $subform Subform data
* @param array $map Map configuration for core subform processing
* @param string $key Key associated with the map
* @param string $table Core table name for linking values
*
* @return bool
* @since 3.2.2
*/
private function handleCoreSetMap(array $subform, array $map, string $key, string $table): bool
{
if (is_array($map['_core']) && $this->validGetMap($map['_core']))
{
$map['_core']['linkValue'] = $this->setLinkValue($map['_core']['linkValue'], [$table => $subform]);
return $this->set($subform[$key], $map);
}
return false;
}
/**
* Handle the processing of regular maps in a subform.
*
* @param array &$subform Reference to subform data
* @param array $map Map configuration for regular subform processing
* @param string $key Key associated with the map
* @param string $table Core table name for linking values
*
* @return void
* @since 3.2.2
*/
private function handleRegularGetMap(array &$subform, array $map, string $key, string $table): void
{
$map['field'] = $key;
if ($this->validGetMap($map))
{
$subformData = $this->getSubformData($map, [$table => $subform]);
if ($subformData !== null)
{
$subform[$key] = $subformData;
}
}
}
/**
* Handle the processing of regular maps in a subform.
*
* @param array $subform Subform data
* @param array $map Map configuration for regular subform processing
* @param string $key Key associated with the map
* @param string $table Core table name for linking values
*
* @return bool
* @since 3.2.2
*/
private function handleRegularSetMap(array $subform, array $map, string $key, string $table): bool
{
if ($this->validSetMap($map))
{
return $this->setSubformData($subform[$key], $map, [$table => $subform]);
}
return false;
}
/**
* Validate the get map configuration for fetching subform data.
* Ensures all required keys are present and have valid values.
*
* @param array $map The map configuration to validate.
*
* @return bool Returns true if the map is valid, false otherwise.
* @since 3.2.2
*/
private function validGetMap(array $map): bool
{
// List of required keys with their expected types or validation functions
$requiredKeys = [
'table' => 'is_string',
'linkValue' => 'is_string',
'linkKey' => 'is_string',
'field' => 'is_string',
'get' => 'is_array'
];
// Iterate through each required key and validate
foreach ($requiredKeys as $key => $validator)
{
if (empty($map[$key]) || !$validator($map[$key]))
{
return false; // Key missing or validation failed
}
}
return true; // All checks passed
}
/**
* Validate the set map configuration for fetching subform data.
* Ensures all required keys are present and have valid values.
*
* @param array $map The map configuration to validate.
*
* @return bool Returns true if the map is valid, false otherwise.
* @since 3.2.2
*/
private function validSetMap(array $map): bool
{
// List of required keys with their expected types or validation functions
$requiredKeys = [
'table' => 'is_string',
'indexKey' => 'is_string',
'linkKey' => 'is_string',
'linkValue' => 'is_string'
];
// Iterate through each required key and validate
foreach ($requiredKeys as $key => $validator)
{
if (empty($map[$key]) || !$validator($map[$key]))
{
return false; // Key missing or validation failed
}
}
return true; // All checks passed
}

View File

@ -0,0 +1,24 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "",
"guid": "e0198c3f-777a-4a0b-87b7-e6a198afc8f9",
"implements": null,
"load_selection": null,
"name": "MultiSubform",
"power_version": "1.0.0",
"system_name": "VDM.Data.MultiSubform",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "34959721-415b-4b5e-8002-3d1fc84b3b2b",
"as": "Subform"
}
},
"extendsinterfaces": null,
"namespace": "[[[NamespacePrefix]]]\\Joomla\\Data.MultiSubform",
"description": "CRUD the data of multi subform to another views (tables)\r\n\r\n@since 3.2.2",
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
"head": "",
"composer": ""
}

View File

@ -791,6 +791,17 @@
"spk": "Super__db87c339_5bb6_4291_a7ef_2c48ea1b06bc__Power",
"guid": "db87c339-5bb6-4291-a7ef-2c48ea1b06bc"
},
"e0198c3f-777a-4a0b-87b7-e6a198afc8f9": {
"name": "MultiSubform",
"type": "final class",
"namespace": "VDM\\Joomla\\Data",
"code": "src\/e0198c3f-777a-4a0b-87b7-e6a198afc8f9\/code.php",
"power": "src\/e0198c3f-777a-4a0b-87b7-e6a198afc8f9\/code.power",
"settings": "src\/e0198c3f-777a-4a0b-87b7-e6a198afc8f9\/settings.json",
"path": "src\/e0198c3f-777a-4a0b-87b7-e6a198afc8f9",
"spk": "Super__e0198c3f_777a_4a0b_87b7_e6a198afc8f9__Power",
"guid": "e0198c3f-777a-4a0b-87b7-e6a198afc8f9"
},
"e0f6ddbe-2a35-4537-942c-faff2ebd04f6": {
"name": "BaseTable",
"type": "abstract class",