The task is simple, there is a resource with id 198, it has MIGX TV field_news with a event field, you need to filter records by the WHERE clause, where event (type text) = new or old. All this is needed for the AJAX filter.
Here is the logic of the snippet. Simplified as much as possible for clarity.
In $ _GET [‘event’], the parameter is passed from the form. But in the example I directly prescribed it rigidly.
The problem is that the syntax of the where clause for getImageList is complicated, and I can’t understand how to write it.
If you bypass the $ filter array and write the condition $ where = ‘{“event: =”: “new”}’ directly in WHERE; then everything works. But you need to do this through an array, since there can be a lot of filtering parameters, and for AJAX you need the JSON format, in snippets this place is $ where = $ modx-> toJSON (array ($ filter));
Greetings! Thank you for responding! Happy New Year! It’s not really about getImageList, it’s about the WHERE clause, the syntax, I want to configure the filter with the conditions simply. I already have a working code, AJAX filter, but it works with pdoResources with resources. Now I want to redo this code to work with MIGX fields instead of resources. And for this I use getImageList instead of pdoResources.
Here is the working code for working with resources and snippets pdoResources.
Now I want this code to make work for MIGX TV, a simplified code example in my question above.
And I can’t get him to work with MIGX TV, I think the point is in the syntax WHERE here: 'where' => $ where
// ‘where’ => ‘{“date”: $ where}’
and in the format of the JSON here $ where = $ modx-> toJSON (array ($ filter));
I want to make a selection in getImageList with several conditions via the API, this is necessary for the AJAX filter by MIGX fields on the site. I think the problem is the syntax of the WHERE parameter
In most cases, and I do think this is true for getImageList, the syntax of a &where property is a JSON-encoded array of key => value syntax, with optional conditions defined in the keys.
The examples there show the array example; you’d need to encode them to JSON to pass them along in a snippet property.
For example if it gives the following PHP array:
$query->where(array(
'width' => 15,
));
Then you’d encode the array to JSON and pass it like this:
[[getImageList?
&where=`{"width":"15"}`
]]
(Or as you’re generating it with PHP before using runSnippet: 'where' => json_encode($filter) )
If that doesn’t work with getImageList, that makes it a MIGX-specific question which I’m afraid I don’t know too much about anymore. Its documentation unfortunately doesn’t mention limits to the where syntax but I can imagine it is a bit more restrictive than the full xPDOQuery syntax.