-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Tree] Allow multiple order critieria in reorder and reorderAll #2744
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2744 +/- ##
=======================================
Coverage 78.64% 78.64%
=======================================
Files 171 171
Lines 8775 8775
=======================================
Hits 6901 6901
Misses 1874 1874 ☔ View full report in Codecov by Sentry. |
Merged the upstream changes, problems should be fixed |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Rebase done. |
CHANGELOG.md
Outdated
@@ -50,6 +50,9 @@ a release. | |||
- Make doctrine/annotations an optional dependency. | |||
- Remove `@internal` annotation from `Gedmo\Mapping\Driver\AttributeReader`. | |||
|
|||
## Changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to add this section in the released version 3.15.0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be there, but in the unreleased section, where i put it initialy. But I accidentialy moved it on one of the rebases. Moved it.
* @param bool $recursive true to also reorder further descendants, not just the direct children | ||
* @param object|null $node node from which to start reordering the tree; null will reorder everything | ||
* @param string|string[]|null $sortByField Field name or array of fields names to sort by | ||
* @param string|string[] $direction Sort order ('asc'|'desc'|'ASC'|'DESC'). If $sortByField is an array, this may also be an array with matching number of elements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change allowing the combination of string
and string[]
between these parameters? I mean by instance $sortByField = ['a', 'b'], $direction = 'ASC'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it does. The reorder functions does nothing with the $sortByField
and $direction
parameter directly but passes them to NestedTreeRepository::children(...)
where those parameters a passsed again (and again) till the function NestedTreeRepository::childrenQueryBuilder(...)
is reached. Where in line 283++ those cases are handled
if (!$sortByField) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the context.
Could you please add a test case for this scenario?
### Changed | ||
- Allow `string[]` as `$sortByField` and `$direction` parameter in `\Gedmo\Tree\Entity\Repository\NestedTreeRepository::reorder()` and `\Gedmo\Tree\Entity\Repository\NestedTreeRepository::reorderAll()` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Changed | |
- Allow `string[]` as `$sortByField` and `$direction` parameter in `\Gedmo\Tree\Entity\Repository\NestedTreeRepository::reorder()` and `\Gedmo\Tree\Entity\Repository\NestedTreeRepository::reorderAll()` | |
### Changed | |
- Allow `string[]` as `$sortByField` and `$direction` parameter in `\Gedmo\Tree\Entity\Repository\NestedTreeRepository::reorder()` and `\Gedmo\Tree\Entity\Repository\NestedTreeRepository::reorderAll()` |
The functions
\Gedmo\Tree\Entity\Repository\NestedTreeRepository::reorder
and\Gedmo\Tree\Entity\Repository\NestedTreeRepository::reorderAll
both take the parameters$sortByField
and$direction
with the type?string
. By allowing string arrays as well, the functions allow reordering with multiple order criteria (e.g. sort by category and date).