I have a bit complex filtering system that I try to replicate using Element API.
So far I have this which works to a degree:
Example url: training.json?reg=124&cat=99&prod=129&erp=
'criteria' => [
'section' => 'resources',
'search' => (craft()->request->getParam('q') ? craft()->request->getParam('q')."*" : ''),
'relatedTo' => [
'and',
craft()->request->getParam('reg'),
(craft()->request->getParam('cat') ? craft()->request->getParam('cat') : craft()->request->getParam('reg')),
(craft()->request->getParam('prod') ? craft()->request->getParam('prod') : craft()->request->getParam('reg')),
(craft()->request->getParam('erp') ? craft()->request->getParam('erp') : craft()->request->getParam('reg')),
],
...
First of all, I don't know how to deal with optional parameters, I've solved this by re-using the only required parameter - reg. It works, but it's not nice, any help here would be appreciated.
The real issue though is that I need the reg parameter to be an array with all the elements in the array having OR operator.
So basically:
Example url: training.json?reg[]=124®=[]=123&cat=99&prod=129&erp=
(reg[0] OR reg[1]) AND cat AND prod AND erp
Is there any way I can achieve this in element API? I've tried something in the lines of the following, but with no luck.
'relatedTo' => [
'and',
['targetRegions' => ['or', 124, 99]],
105,
231,
],