Skip to content

Commit

Permalink
TASK: Reimplement _creationDateTime, _lastModificationDateTime and _l…
Browse files Browse the repository at this point in the history
…astPublicationDateTime support for `sort`
  • Loading branch information
mhsdesign committed Jul 3, 2024
1 parent 1be047a commit 9b2b607
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ public function canEvaluate($context)
}

/**
* {@inheritdoc}
*
* First argument is the node property to sort by. Works with internal arguments (_xyz) as well.
* First argument is the node property to sort by. To sort by time _creationDateTime, _lastModificationDateTime or _lastPublicationDateTime can be used.
* Second argument is the sort direction (ASC or DESC).
* Third optional argument are the sort options (see https://www.php.net/manual/en/function.sort):
* - 'SORT_REGULAR'
Expand Down Expand Up @@ -113,12 +111,12 @@ public function evaluate(FlowQuery $flowQuery, array $arguments)

// Determine the property value to sort by
foreach ($nodes as $node) {
$propertyValue = $node->getProperty($sortProperty);

// todo how to sort by creation date in Neos 9?? Something like node.timestamps.originalCreated
if ($propertyValue instanceof \DateTime) {
$propertyValue = $propertyValue->getTimestamp();
}
$propertyValue = match($sortProperty) {
'_creationDateTime' => $node->timestamps->created->getTimestamp(),
'_lastModificationDateTime' => $node->timestamps->lastModified?->getTimestamp(),
'_lastPublicationDateTime' => $node->timestamps->originalLastModified?->getTimestamp(),
default => $node->getProperty($sortProperty)
};

$sortSequence[$node->aggregateId->value] = $propertyValue;
$nodesByIdentifier[$node->aggregateId->value] = $node;
Expand Down
3 changes: 3 additions & 0 deletions Neos.Neos/Tests/Behavior/Features/Fusion/FlowQuery.feature
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ Feature: Tests for the "Neos.ContentRepository" Flow Query methods.
unsorted = ${q([a1a3, a1a4, a1a1, a1a2]).get()}
sortByTitleAsc = ${q([a1a3, a1a4, a1a1, a1a2]).sort("title", "ASC").get()}
sortByUriDesc = ${q([a1a3, a1a4, a1a1, a1a2]).sort("uriPathSegment", "DESC").get()}
# todo find out how to test time related logic
sortByDateAsc = ${q([a1a1]).sort("_creationDateTime", "ASC").get()}
@process.render = Neos.Neos:Test.RenderNodesDataStructure
}
"""
Expand All @@ -417,6 +419,7 @@ Feature: Tests for the "Neos.ContentRepository" Flow Query methods.
unsorted: a1a3,a1a4,a1a1,a1a2
sortByTitleAsc: a1a1,a1a2,a1a3,a1a4
sortByUriDesc: a1a4,a1a3,a1a2,a1a1
sortByDateAsc: a1a1
"""

Scenario: Node accessors (final Node access operations)
Expand Down

0 comments on commit 9b2b607

Please sign in to comment.