My Snippet calls migxLoopCollection with $modx->runSnippet
.
To do this it builds a series of where
conditions as an array, these are based on frontend user selections (none, parent, family, date). An entry is added to the array for each user selection eg. $arr_where[] = '{"family":"' . $family . '"}';
.
The Snippet then generates a single $where
string by imploding the array ie. $where = implode(',', $arr_where);
.
The resulting value of $where
string becomes the JSON required for the migxLoopCollection call eg. {"family":"3"},{"published":"1"}
.
Unltimately the $where
variable is used, along with other relevant parameters, as
$modx->runSnippet('migxLoopCollection',array(
'where' => '[' . $where . ']',
The first strange part is this works as expected, depending on the user selection (2 of 4 combinations work).
Checking the value of the computed $where
variable for each combination shows each is correct.
{"published":"1"} - works
{"family":"3"},{"published":"1"} - fails
{"family":"2"},{"parent":"6"},{"published":"1"} - fails
{"date:>=":"2024-10-01"},{"date:<=":"2024-10-31"},{"published":"1"} - works
It becomes more strange if I manually set the $where
value in my Snippet to those noted above - in this case the migxLoopCollection call works every time eg. when I set
$where = '{"published":"1"}'; - works
$where = '{"family":"3"},{"published":"1"}'; - works
$where = '{"family":"2"},{"parent":"6"},{"published":"1"}'; - works
$where = '{"date:>=":"2024-10-01"},{"date:<=":"2024-10-31"},{"published":"1"}'; - works
But there is no difference in the $where
value set manually or computed by the snippet.
My first thought was this might somehow be caused by character encodiing but running mb_detect_encoding()
on the $where
value shows UTF-8
every time.
The actual Snippet is 500 lines so I’m not sure it should be posted in full.
Can anyone suggest what the issue might be?
I know it would be better to remove migxLoopCollection and use native xPDO instead, but my attempts to configure the joins for my schema and database tables failed hence migxLoopCollection looked like a reasonable option at the time.
Any help appreciated.
Thanks