Skip to content

Commit

Permalink
[FEATURE] Allow return only one element in CONTENT_JSON
Browse files Browse the repository at this point in the history
New option `returnSingleRow` is added to allow
advanced conditional query with option to fetch only one record
  • Loading branch information
twoldanski committed Jul 11, 2024
1 parent 44ffec9 commit 8ca0df7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Classes/ContentObject/JsonContentContentObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
* doNotGroupByColPos = 1
* }
*
* * ** sortByBackendLayout = 0(default)|1 **
* ** sortByBackendLayout = 0(default)|1 **
* This option allows to return sorted CE by colPos with order by used backendLayout
*
* lib.content = CONTENT_JSON
Expand All @@ -85,6 +85,18 @@
* }
* sortByBackendLayout = 1
* }
*
* ** returnSingleRow = 0(default)|1 **
* This option allows to return only one row instead of array with one element
*
* lib.content = CONTENT_JSON
* lib.content {
* table = tt_content
* select {
* orderBy = sorting
* }
* returnSingleRow = 1
* }
*/
class JsonContentContentObject extends ContentContentObject
{
Expand Down Expand Up @@ -174,6 +186,8 @@ protected function groupContentElementsByColPos(array $contentElements, array $c
}

$data = $sorted;
} elseif (!$groupingEnabled && $this->returnSingleRowEnabled($conf)) {
return $data[0] ?? [];
}

return $data;
Expand Down Expand Up @@ -289,4 +303,9 @@ private function isColPolsGroupingEnabled(array $conf): bool
{
return !isset($conf['doNotGroupByColPos']) || (int)$conf['doNotGroupByColPos'] === 0;
}

private function returnSingleRowEnabled(array $conf): bool
{
return isset($conf['returnSingleRow']) && (int)$conf['returnSingleRow'] === 1;
}
}

0 comments on commit 8ca0df7

Please sign in to comment.