From fa5cb8adf3a9c185cbfb594f7b560fac30c0e465 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Wed, 22 Mar 2023 10:05:39 +0000 Subject: [PATCH] Refactor getBulkLinks Signed-off-by: Kamil Tekiela --- libraries/classes/Display/Results.php | 29 ++++++++++++++------------- psalm-baseline.xml | 4 ++++ templates/display/results/table.twig | 6 +++--- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index 34258881fef5..cf235e046906 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -3553,7 +3553,7 @@ public function getTable( $this->properties['display_params'] = null; // 4. ----- Prepares the link for multi-fields edit and delete - $bulkLinks = $this->getBulkLinks($dtResult, $statementInfo, $displayParts->deleteLink); + $isClauseUnique = $this->isClauseUnique($dtResult, $statementInfo, $displayParts->deleteLink); // 5. ----- Prepare "Query results operations" $operations = []; @@ -3568,7 +3568,9 @@ public function getTable( 'navigation' => $navigation, 'headers' => $headers, 'body' => $body, - 'bulk_links' => $bulkLinks, + 'has_bulk_links' => $displayParts->deleteLink === DisplayParts::DELETE_ROW, + 'has_export_button' => $this->hasExportButton($statementInfo, $displayParts->deleteLink), + 'clause_is_unique' => $isClauseUnique, 'operations' => $operations, 'db' => $this->properties['db'], 'table' => $this->properties['table'], @@ -3873,19 +3875,16 @@ private function setParamForLinkForeignKeyRelatedTables(array $map): array * * @see getTable() * - * @param ResultInterface $dtResult the link id associated to the query which - * results have to be displayed + * @param ResultInterface $dtResult the link id associated to the query which results have to be displayed * @psalm-param DisplayParts::NO_DELETE|DisplayParts::DELETE_ROW|DisplayParts::KILL_PROCESS $deleteLink - * - * @psalm-return array{has_export_button:bool, clause_is_unique:mixed}|array */ - private function getBulkLinks( + private function isClauseUnique( ResultInterface $dtResult, StatementInfo $statementInfo, int $deleteLink, - ): array { + ): bool { if ($deleteLink !== DisplayParts::DELETE_ROW) { - return []; + return false; } // fetch last row of the result set @@ -3894,7 +3893,7 @@ private function getBulkLinks( $expressions = []; - if (isset($statementInfo->statement) && $statementInfo->statement instanceof SelectStatement) { + if ($statementInfo->statement instanceof SelectStatement) { $expressions = $statementInfo->statement->expr; } @@ -3914,10 +3913,12 @@ private function getBulkLinks( // reset to first row for the loop in getTableBody() $dtResult->seek(0); - return [ - 'has_export_button' => $statementInfo->queryType === 'SELECT', - 'clause_is_unique' => $clauseIsUnique, - ]; + return $clauseIsUnique; + } + + private function hasExportButton(StatementInfo $statementInfo, int $deleteLink): bool + { + return $deleteLink === DisplayParts::DELETE_ROW && $statementInfo->queryType === 'SELECT'; } /** diff --git a/psalm-baseline.xml b/psalm-baseline.xml index dc1a8320b505..f8409231aeb0 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -6576,6 +6576,7 @@ Message + bool new $className() @@ -6602,6 +6603,9 @@ statement->from[0]->table]]> statement->limit->offset]]> + + $clauseIsUnique + $map -{% if bulk_links is not empty %} +{% if has_bulk_links %}
{% trans 'With selected:' %} @@ -317,14 +317,14 @@ {{ get_icon('b_drop', 'Delete'|trans) }} - {% if bulk_links.has_export_button %} + {% if has_export_button %} {% endif %}
- + {% endif %}