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

Unable to perform case-insensitive ordering of a collection when the order is based on a custom header field. #1169

Closed
parcand opened this issue Nov 11, 2016 · 3 comments

Comments

@parcand
Copy link

parcand commented Nov 11, 2016

The $sort_flags parameter is always set to SORT_REGULAR when ordering a collection based on a custom header field.

This is quite problematic since there are many situations where data is expected to be sorted case-insensitively.

Adding an optional sort_flags parameter to the order method of the Grav\Common\Page\Collection class could help solve that issue.

flaviocopes added a commit that referenced this issue Nov 15, 2016
…ring.

 If the `intl` PHP extension is loaded, only these flags are available:
https://secure.php.net/manual/en/collator.asort.php. Otherwise, you can
use the PHP standard sorting flags
(https://secure.php.net/manual/en/array.constants.php)
[#1169](#1169)
@flaviocopes
Copy link
Contributor

Ok I've done a bit of research into this, and came up with this PR #1173

The thing to note is this: If the intl PHP extension is loaded, only these flags are available:
https://secure.php.net/manual/en/collator.asort.php as we use PHP's Collator class to sort.

Otherwise, if intl is not loaded, you can use the PHP standard sorting flags (https://secure.php.net/manual/en/array.constants.php) and add

content:
    ....
    order:
        by: header.title
        sort_flags:
            - SORT_NATURAL
            - SORT_FLAG_CASE

to order case insensitive.

@parcand
Copy link
Author

parcand commented Nov 15, 2016

Wow, that was fast, and your solution is great. Thanks a lot!

rhukster pushed a commit that referenced this issue Nov 19, 2016
…ring. (#1173)

If the `intl` PHP extension is loaded, only these flags are available:
https://secure.php.net/manual/en/collator.asort.php. Otherwise, you can
use the PHP standard sorting flags
(https://secure.php.net/manual/en/array.constants.php)
[#1169](#1169)
@rhukster
Copy link
Member

Also we are going to improve collections in Grav 2.0

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

No branches or pull requests

3 participants