sculpin / proxy-source-collection-contrib

[READ-ONLY] Subtree split of Sculpin\Contrib\ProxySourceCollection.
MIT License
0 stars 1 forks source link

Natural Order #1

Closed rachelwhitton closed 9 years ago

rachelwhitton commented 9 years ago

Feature Request

Implement natural order within the MetaSorter.php script.

Currently standard sorting seems to be used for this script, is there a way to modify the class on a local build to use natural order or is this something that could be considered for a future patch/release?

Thanks!

simensen commented 9 years ago

@rachelwhitton It is currently implemented using strnatcmp. Is this not what you want? What would you propose instead?

rachelwhitton commented 9 years ago

Thanks for showing me strnatcmp @simensen - I overlooked that. I'm using sculpin and calling this class to sort article titles, but it seems to be case sensitive.

Example: PHP Slow Log is sorted before Pantheon Architecture

Any tips on how to fix that? Thank you for your time!

rachelwhitton commented 9 years ago

Proposing strnatcasecmp

This function implements a comparison algorithm that orders alphanumeric strings in the way a human being would. The behaviour of this function is similar to strnatcmp(), except that the comparison is not case sensitive.

simensen commented 9 years ago

I need to document how to change that. I know it is possible to change sorting it just isn't super intuitive. You would put something like this in app/config/sculpin_services.yml:

services:
    sculpin_content_types.types.projects.collection.sorter:
        class: Sculpin\Contrib\ProxySourceCollection\Sorter\MetaSorter
        arguments:
            - title

In this case, .projects. represents the name of the content type. So if you are working with the default posts content type, it is .posts.. You can create your own implementation of the sorter using the case-insensitive natural sort and use that.

rachelwhitton commented 9 years ago

Thanks @simensen - really appreciate the guidance!

simensen commented 9 years ago

@rachelwhitton Sure thing! Did it work? :)

rachelwhitton commented 9 years ago

Haven't gotten it working just yet - still trying to figure out how to use a custom class in sculpin_services.yml

I joined the #sculpin IRC channel to see if I can get some more guidance.