Is there a possibility to sort pdoressources by a selfdefined list of TV content?
Example: TV-content of “animals” is dog, cat, pig.
I can sort it by TV asc or desc.
But I want my own sorting structure by TV content:
1=pig, 2 = cat, 3 = dog
From what I can see in pdoResources, I don’t think you can. I’m not sure how much you are or want to get into PHP, but any Extra that is in Github is very easy to search and explore:
The pdoResources snippet sets up a few things and then passes over to pdoFetch. In the pdoFetch file you can see the sequence of events in the “run” function:
It looks like line 469 is where it’s doing the sorting and checks the type to determine the sorting statement.
I think what you would need is the ability to pass in a sorting function which would add a fair amount of complexity to that Extra.
There’s only two options I can think of:
Return the raw data, sorting the array results by your custom sorting function, and then further processing to render the templates with that new data set.
Maybe someone can think of a better solution here. There is a &returnIds property you could pass that would return the list of resource Ids instead of any parsed content. You could pass that set of Ids to your own snippet, get them as a collection, sort them based on your logic and then return the Ids back into another pdoResources call with the templates.
Javascript based sorting applied on the client side.
Maybe you can use the extra Tagger instead of a TV.
Create a group “animals” in Tagger with the field type “Combo box” and add dog, cat and pig as tags to this group.
Then you should be able to use the tables from Tagger as joins in the pdoResources query and sort the result by the field rank of the tag.
It doesnt throw any error but the statement doesnt work. Of course there are much more possible contenct entries in “Kursart” but after my knowledge it should start sorting by this.
What Im doing wrong?
The problem could be, that all the values of “Kursart” that are not in the FIELD()-list get a value of 0 and are therefore put at the top when sorting by ASC. One Solution could be to sort by DESC and reverse the order of your FIELD()-list.
If that doesn’t work, add the property &showLog=`1` to your pdoResources-call and check in the SQL-query it outputs, that the ORDER BY-clause is correct.
“showlog” shows simply "ORDER BY modResource.publishedon ASC LIMIT 500 " with the new FIELD statement
I digged into “Kursart” and found the TV with the following config: @EVAL return $modx->runSnippet('listMyResources',array('parent' => 47));
The data fetching in listmyressources is done pdofetch. I dont think that should influence my new sorting but anyhow, this seems not to be the solution.
Before anyone puts more time into the solution I have to say this is done for me because no one will reward the effort which will be put into this further. This special sorting would be a nice addon but not really important. Everyone has to stay on their main tasks.
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.