Building the 'where' json for the GetExtUsers snippet

Hey all,

I have a tricky situation that I need some assistance. I am building a job search website and I’m using ClassExtender to add fields for the users (i.e candidates) that can be used to search for potential candidates. I have build a search form (using FormIt) to have the search filters that the employers will be using to find their potential candidate. These filters include multiple select checkboxes with fields such as: location, qualification, job type, job status, etc.

My issue is that now that I have captured what the array of fields + options for the employers, how can I convert it into a where JSON object that will be used with the GetExtUsers snippet that truly represents the search combinations?

For example, if the selected search filter are like…let’s say Miami, New York, Artist, Secretary, Fulltime, Parttime, I would assume the query should be like

(Miami or New York) AND (Artist or Secretary) AND (Fulltime or Parttime)???

meaning the JSON object should look like

[{"location:=":"Miami","OR:location:=":"New York","job_type:=":"Artist","OR:job_type:=":"Secretary","job_status:=":"Fulltime","OR:job_status:=":"Parttime"}]???

I hope that my question is clear enough and I’m not sure if my approach is correct

Sometimes it’s easier to create a PHP array as you would for a MODX query’s where() statement (see this), then use $modx->toJSON on it to make the JSON you want, though your approach looks correct to me.

It may be easier to duplicate and adjust the GetExtUsers snippet, than to create a JSON object.

With multiple calls to the xPDOQuery.where function, it can be easier to get complicated combinations of AND/OR conditions right.

Also read the documentation about the xPDOQuery.where function:
https://docs.modx.com/current/en/extending-modx/xpdo/class-reference/xpdoquery/xpdoquery.where


In the snippet code, it can also be helpful to use the toSQL function to check if the generated SQL query is correct.

$c->prepare();
return $c->toSQL();