Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Waigie
Copy link

@Waigie Waigie commented Jan 11, 2024

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).

Copy link

codecov bot commented Jan 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.64%. Comparing base (2d9d36c) to head (45f5af4).
Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@Waigie
Copy link
Author

Waigie commented Jan 24, 2024

Merged the upstream changes, problems should be fixed

Copy link

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.

@Waigie
Copy link
Author

Waigie commented Sep 14, 2024

Rebase done.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated
@@ -50,6 +50,9 @@ a release.
- Make doctrine/annotations an optional dependency.
- Remove `@internal` annotation from `Gedmo\Mapping\Driver\AttributeReader`.

## Changed
Copy link
Collaborator

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?

Copy link
Author

@Waigie Waigie Jan 18, 2025

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
Copy link
Collaborator

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'.

Copy link
Author

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

Copy link
Collaborator

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?

Comment on lines +24 to +26
### Changed
- Allow `string[]` as `$sortByField` and `$direction` parameter in `\Gedmo\Tree\Entity\Repository\NestedTreeRepository::reorder()` and `\Gedmo\Tree\Entity\Repository\NestedTreeRepository::reorderAll()`

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 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()`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants