diff --git a/src/34959721-415b-4b5e-8002-3d1fc84b3b2b/README.md b/src/34959721-415b-4b5e-8002-3d1fc84b3b2b/README.md index 83e23eb..c94f699 100644 --- a/src/34959721-415b-4b5e-8002-3d1fc84b3b2b/README.md +++ b/src/34959721-415b-4b5e-8002-3d1fc84b3b2b/README.md @@ -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 diff --git a/src/34959721-415b-4b5e-8002-3d1fc84b3b2b/code.php b/src/34959721-415b-4b5e-8002-3d1fc84b3b2b/code.php index f80eea6..5e1da6d 100644 --- a/src/34959721-415b-4b5e-8002-3d1fc84b3b2b/code.php +++ b/src/34959721-415b-4b5e-8002-3d1fc84b3b2b/code.php @@ -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 diff --git a/src/34959721-415b-4b5e-8002-3d1fc84b3b2b/code.power b/src/34959721-415b-4b5e-8002-3d1fc84b3b2b/code.power index 7d53f29..269ad00 100644 --- a/src/34959721-415b-4b5e-8002-3d1fc84b3b2b/code.power +++ b/src/34959721-415b-4b5e-8002-3d1fc84b3b2b/code.power @@ -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 diff --git a/src/7832a726-87b6-4e95-887e-7b725d3fab8f/code.php b/src/7832a726-87b6-4e95-887e-7b725d3fab8f/code.php index 10f93aa..e57858f 100644 --- a/src/7832a726-87b6-4e95-887e-7b725d3fab8f/code.php +++ b/src/7832a726-87b6-4e95-887e-7b725d3fab8f/code.php @@ -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 { diff --git a/src/7832a726-87b6-4e95-887e-7b725d3fab8f/code.power b/src/7832a726-87b6-4e95-887e-7b725d3fab8f/code.power index be0f50a..39927d7 100644 --- a/src/7832a726-87b6-4e95-887e-7b725d3fab8f/code.power +++ b/src/7832a726-87b6-4e95-887e-7b725d3fab8f/code.power @@ -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 { diff --git a/src/85785701-07b2-4f81-bc1e-0f423700c254/README.md b/src/85785701-07b2-4f81-bc1e-0f423700c254/README.md index 957af58..3520491 100644 --- a/src/85785701-07b2-4f81-bc1e-0f423700c254/README.md +++ b/src/85785701-07b2-4f81-bc1e-0f423700c254/README.md @@ -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 ``` diff --git a/src/85785701-07b2-4f81-bc1e-0f423700c254/code.php b/src/85785701-07b2-4f81-bc1e-0f423700c254/code.php index 7025b0b..c15bed7 100644 --- a/src/85785701-07b2-4f81-bc1e-0f423700c254/code.php +++ b/src/85785701-07b2-4f81-bc1e-0f423700c254/code.php @@ -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; } } diff --git a/src/85785701-07b2-4f81-bc1e-0f423700c254/code.power b/src/85785701-07b2-4f81-bc1e-0f423700c254/code.power index dfdfdcc..931d321 100644 --- a/src/85785701-07b2-4f81-bc1e-0f423700c254/code.power +++ b/src/85785701-07b2-4f81-bc1e-0f423700c254/code.power @@ -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; } \ No newline at end of file diff --git a/src/d46c4667-378b-49e8-9782-ffb28d92415a/README.md b/src/d46c4667-378b-49e8-9782-ffb28d92415a/README.md index a6c7fe7..ce974e7 100644 --- a/src/d46c4667-378b-49e8-9782-ffb28d92415a/README.md +++ b/src/d46c4667-378b-49e8-9782-ffb28d92415a/README.md @@ -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 diff --git a/src/d46c4667-378b-49e8-9782-ffb28d92415a/code.php b/src/d46c4667-378b-49e8-9782-ffb28d92415a/code.php index b108e68..766d61b 100644 --- a/src/d46c4667-378b-49e8-9782-ffb28d92415a/code.php +++ b/src/d46c4667-378b-49e8-9782-ffb28d92415a/code.php @@ -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 * diff --git a/src/d46c4667-378b-49e8-9782-ffb28d92415a/code.power b/src/d46c4667-378b-49e8-9782-ffb28d92415a/code.power index 825f963..324b55f 100644 --- a/src/d46c4667-378b-49e8-9782-ffb28d92415a/code.power +++ b/src/d46c4667-378b-49e8-9782-ffb28d92415a/code.power @@ -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 * diff --git a/src/d46c4667-378b-49e8-9782-ffb28d92415a/settings.json b/src/d46c4667-378b-49e8-9782-ffb28d92415a/settings.json index 3f0777c..cfa1b3b 100644 --- a/src/d46c4667-378b-49e8-9782-ffb28d92415a/settings.json +++ b/src/d46c4667-378b-49e8-9782-ffb28d92415a/settings.json @@ -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" }