pdoTools AND OR

I've got 3 TV's per resource and each TV is multi-select.

In pdoTools tvFilters I want to say

if (TV1 = a or b) AND (TV2 = red or blue) AND (TV3 = 5 or 6 or 7)

but it seems I can not say AND before OR. I have to say OR first?
Mark
27 января 2014, 13:46
modx.pro
1 318
0

Комментарии: 3

Василий Наумкин
27 января 2014, 17:56
0
No need to use &tvFilters, it is not getResources:
[[!pdoResources?
	&parents=`0`
	&select=`id,pagetitle`
	&includeTVs=`tv1,tv2,tv3`
	&where=`["((tv1 IN ('a','b')) AND (tv2 IN ('red','blue')) AND (tv3 IN ('5','6','7')))"]`
	&showLog=`1`
]]

You will get this:
... WHERE  ( ((`TVtv1`.`value` IN ('a','b')) AND (`TVtv2`.`value` IN ('red','blue')) AND (`TVtv3`.`value` IN ('5','6','7'))) AND `modResource`.`published` = 1 AND `modResource`.`deleted` = 0 ) ...
    Mark
    27 января 2014, 18:51
    0
    Great. Thanks for your help.

    But my TV's are multi-select so the data stored is a||b so

    ((`TVtv1`. `Value` IN ('a', 'b'))
    doesn't work.

    I could do

    ('a' IN (`TVtv1`. `Value`)) OR ('b' IN (`TVtv1`. `Value`))
    or is there a shorter way to write this?
      Mark
      27 января 2014, 21:09
      0
      This is now working with like. I know my code is not elegant but

      $thisFilter = array();
      $getFilters = array('rabenefit','racollateral','ralanguage','ralob','rasector'); 
          foreach( $getFilters as $filterkey=>$filtervalue) {
          if(isset($_GET[$filtervalue])) {
              $getParam = $_GET[$filtervalue];
              $getParam2 = '';
              foreach( $getParam as $key=>$value) {
                  $thisValue = $modx->sanitizeString($value);
                  $getParam2 .= "(`TV$filtervalue`.`value` LIKE '%$value%')";
                  if ($key <> count($getParam)-1) $getParam2 .= " OR ";
              }
              $thisFilter[] = "($getParam2)";
          }
      }
    Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
    3