Update 2024-09-15 17:57:10

This commit is contained in:
Robot 2024-09-15 17:57:10 +02:00
parent 599c54d774
commit c67a23df10
Signed by untrusted user: Robot
GPG Key ID: 14DECD44E7E1BB95
12 changed files with 174 additions and 21 deletions

View File

@ -36,6 +36,7 @@ note right of SubformInterface::get
string $linkKey
string $field
array $get
bool $multi = true
end note
note right of SubformInterface::set

View File

@ -36,11 +36,12 @@ interface SubformInterface
* @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 $get The array SET of the keys of each row in the subform.
* @param bool $multi The switch to return a multiple set.
*
* @return array|null The subform
* @since 3.2.2
*/
public function get(string $linkValue, string $linkKey, string $field, array $get): ?array;
public function get(string $linkValue, string $linkKey, string $field, array $get, bool $multi = true): ?array;
/**
* Set a subform items

View File

@ -15,11 +15,12 @@
* @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 $get The array SET of the keys of each row in the subform.
* @param bool $multi The switch to return a multiple set.
*
* @return array|null The subform
* @since 3.2.2
*/
public function get(string $linkValue, string $linkKey, string $field, array $get): ?array;
public function get(string $linkValue, string $linkKey, string $field, array $get, bool $multi = true): ?array;
/**
* Set a subform items

View File

@ -432,7 +432,20 @@ abstract class UserHelper
*/
private static function handlePostRegistration(int $userId, int $autologin, array $credentials): int
{
if ($autologin && isset($credentials['password']))
// make sure user is it the correct groups
if ($userId > 0 && !empty($credentials['groups']))
{
try
{
JoomlaUserHelper::setUserGroups($userId, $credentials['groups']);
}
catch (\Exception $e)
{
// we might need say something
}
}
if ($autologin && !empty($credentials['password']))
{
try
{

View File

@ -398,7 +398,20 @@
*/
private static function handlePostRegistration(int $userId, int $autologin, array $credentials): int
{
if ($autologin && isset($credentials['password']))
// make sure user is it the correct groups
if ($userId > 0 && !empty($credentials['groups']))
{
try
{
JoomlaUserHelper::setUserGroups($userId, $credentials['groups']);
}
catch (\Exception $e)
{
// we might need say something
}
}
if ($autologin && !empty($credentials['password']))
{
try
{

View File

@ -22,6 +22,7 @@ class Subform << (F,LightGreen) >> #RoyalBlue {
- purge(array $items, string $indexKey, ...) : void
- converter(array $items, array $keySet, ...) : array
- process(mixed $items, string $indexKey, ...) : array
- isMultipleSets(array $array) : bool
}
note right of Subform::__construct
@ -48,6 +49,7 @@ note right of Subform::get
string $linkKey
string $field
array $get
bool $multi = true
end note
note left of Subform::set
@ -94,6 +96,7 @@ and sets them by association with a specified key and an incrementing integer.
array $items
array $keySet
string $field
bool $multi
end note
note left of Subform::process
@ -108,6 +111,13 @@ note left of Subform::process
string $linkKey
string $linkValue
end note
note right of Subform::isMultipleSets
Function to determine if the array consists of multiple data sets (arrays of arrays).
since: 5.0.2
return: bool
end note
@enduml
```

View File

@ -86,16 +86,17 @@ final class Subform implements GuidInterface, 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 $get The array get: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.
* @param bool $multi The switch to return a multiple set.
*
* @return array|null The subform
* @since 3.2.2
*/
public function get(string $linkValue, string $linkKey, string $field, array $get): ?array
public function get(string $linkValue, string $linkKey, string $field, array $get, bool $multi = true): ?array
{
if (($items = $this->items->table($this->getTable())->get([$linkValue], $linkKey)) !== null)
{
return $this->converter($items, $get, $field);
return $this->converter($items, $get, $field, $multi);
}
return null;
}
@ -188,11 +189,12 @@ final class Subform implements GuidInterface, SubformInterface
* @param array $items Array of objects or arrays to be filtered.
* @param array $keySet Array of keys to retain in each item.
* @param string $field The field prefix for the resulting associative array.
* @param bool $multi The switch to return a multiple set.
*
* @return array Array of filtered arrays set by association.
* @since 3.2.2
*/
private function converter(array $items, array $keySet, string $field): array
private function converter(array $items, array $keySet, string $field, bool $multi): array
{
/**
* Filters keys for a single item and converts it to an array.
@ -218,6 +220,10 @@ final class Subform implements GuidInterface, SubformInterface
$result = [];
foreach ($items as $index => $item)
{
if (!$multi)
{
return $filterKeys($item, $keySet);
}
$filteredArray = $filterKeys($item, $keySet);
$result[$field . $index] = $filteredArray;
}
@ -239,6 +245,11 @@ final class Subform implements GuidInterface, SubformInterface
private function process($items, string $indexKey, string $linkKey, string $linkValue): array
{
$items = is_array($items) ? $items : [];
if ($items !== [] && !$this->isMultipleSets($items))
{
$items = [$items];
}
foreach ($items as &$item)
{
$value = $item[$indexKey] ?? '';
@ -265,6 +276,29 @@ final class Subform implements GuidInterface, SubformInterface
}
return array_values($items);
}
/**
* Function to determine if the array consists of multiple data sets (arrays of arrays).
*
* @param array $array The input array to be checked.
*
* @return bool True if the array contains only arrays (multiple data sets), false otherwise.
* @since 5.0.2
*/
private function isMultipleSets(array $array): bool
{
foreach ($array as $element)
{
// As soon as we find a non-array element, return false
if (!is_array($element))
{
return false;
}
}
// If all elements are arrays, return true
return true;
}
}

View File

@ -59,16 +59,17 @@
* @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 $get The array get: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.
* @param bool $multi The switch to return a multiple set.
*
* @return array|null The subform
* @since 3.2.2
*/
public function get(string $linkValue, string $linkKey, string $field, array $get): ?array
public function get(string $linkValue, string $linkKey, string $field, array $get, bool $multi = true): ?array
{
if (($items = $this->items->table($this->getTable())->get([$linkValue], $linkKey)) !== null)
{
return $this->converter($items, $get, $field);
return $this->converter($items, $get, $field, $multi);
}
return null;
}
@ -161,11 +162,12 @@
* @param array $items Array of objects or arrays to be filtered.
* @param array $keySet Array of keys to retain in each item.
* @param string $field The field prefix for the resulting associative array.
* @param bool $multi The switch to return a multiple set.
*
* @return array Array of filtered arrays set by association.
* @since 3.2.2
*/
private function converter(array $items, array $keySet, string $field): array
private function converter(array $items, array $keySet, string $field, bool $multi): array
{
/**
* Filters keys for a single item and converts it to an array.
@ -191,6 +193,10 @@
$result = [];
foreach ($items as $index => $item)
{
if (!$multi)
{
return $filterKeys($item, $keySet);
}
$filteredArray = $filterKeys($item, $keySet);
$result[$field . $index] = $filteredArray;
}
@ -212,6 +218,11 @@
private function process($items, string $indexKey, string $linkKey, string $linkValue): array
{
$items = is_array($items) ? $items : [];
if ($items !== [] && !$this->isMultipleSets($items))
{
$items = [$items];
}
foreach ($items as &$item)
{
$value = $item[$indexKey] ?? '';
@ -238,4 +249,27 @@
}
return array_values($items);
}
/**
* Function to determine if the array consists of multiple data sets (arrays of arrays).
*
* @param array $array The input array to be checked.
*
* @return bool True if the array contains only arrays (multiple data sets), false otherwise.
* @since 5.0.2
*/
private function isMultipleSets(array $array): bool
{
foreach ($array as $element)
{
// As soon as we find a non-array element, return false
if (!is_array($element))
{
return false;
}
}
// If all elements are arrays, return true
return true;
}

View File

@ -18,6 +18,7 @@ class Display << (F,LightGreen) >> #RoyalBlue {
# array $fileTypeTasks
+ __construct(Item $item, Items $items)
+ get(string $entity, string $target) : ?array
# setFileTypeName(object $file) : void
# setFileTypeTask(object $file) : void
# setFileDownloadLink(object $file) : void
# getFileTypeTask(object $data) : string
@ -37,8 +38,15 @@ note right of Display::get
return: ?array
end note
note right of Display::setFileTypeName
Add the file type name to this file
since: 5.0.2
return: void
end note
note right of Display::setFileTypeTask
Add the file type details to this file
Add the file type task to this file
since: 5.0.2
return: void

View File

@ -91,9 +91,8 @@ final class Display
unset($files[$n]);
continue;
}
// set the file type task
$this->setFileTypeTask($file);
// set the file download link
$this->setFileTypeName($file);
$this->setFileDownloadLink($file);
}
@ -105,7 +104,27 @@ final class Display
}
/**
* Add the file type details to this file
* Add the file type name to this file
*
* @param object $file The file being updated
*
* @return void
* @since 5.0.2
*/
protected function setFileTypeName(object &$file): void
{
if (($fileType = $this->getFileType($file->file_type ?? null)) !== null)
{
$file->type_name = $fileType->name;
}
else
{
$file->type_name = 'error';
}
}
/**
* Add the file type task to this file
*
* @param object $file The file being updated
*

View File

@ -64,9 +64,8 @@
unset($files[$n]);
continue;
}
// set the file type task
$this->setFileTypeTask($file);
// set the file download link
$this->setFileTypeName($file);
$this->setFileDownloadLink($file);
}
@ -78,7 +77,27 @@
}
/**
* Add the file type details to this file
* Add the file type name to this file
*
* @param object $file The file being updated
*
* @return void
* @since 5.0.2
*/
protected function setFileTypeName(object &$file): void
{
if (($fileType = $this->getFileType($file->file_type ?? null)) !== null)
{
$file->type_name = $fileType->name;
}
else
{
$file->type_name = 'error';
}
}
/**
* Add the file type task to this file
*
* @param object $file The file being updated
*

View File

@ -10,11 +10,11 @@
"system_name": "Joomla.File.Display",
"type": "final class",
"use_selection": {
"use_selection1": {
"use_selection0": {
"use": "05744dd3-4030-4cf8-8dda-a93ab809b473",
"as": "Item"
},
"use_selection0": {
"use_selection1": {
"use": "7212e4db-371f-4cfd-8122-32e9bb100d83",
"as": "Items"
}