We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36516
    • 179 Posts
    I'm trying to use MIGX to display items filtered by the content of a checkbox field:

    Monday==Monday||Tuesday==Tuesday||Wednesday==Wednesday||Thursday==Thursday||Friday==Friday||Saturday==Saturday||Sunday==Sunday
    


    The output isn't being delimited, yet, because at first it didn't seem necessary. First I tried my own snippet filter, but even upon reducing it to:

    return;


    ...it wouldn't stop outputting everything anyway. Never solved that one, except to switch to 'contains' after reading about it in the changelog (neither are in the full documentation yet) which appeared to work remarkably, saving me the bother of writing the script to look for the day string in the concatenated bunch.

    &where=`{"days:contains":"Sunday"}


    Seemed perfect till I start noticing that certain days were squeezing through the filter inexplicably. I haven't managed to figure it out yet, hence this post. I've got an example written to the page where the filter is somehow finding 'Sunday' in the following string:

    MondayTuesdayWednesdayThursdayFridaySaturday


    Other day names are successfully filtered out. I've seen another example of an unwanted day being found where it doesn't appear.

    I'll continue experimenting, but for now I'm at a loss as to why my filter snippet had absolutely no effect at all, and why this strikingly useful 'contains' filter seems not to work very well.

    I'd like to see proper documentation. I have no idea how either really work, and it would be nice to know how flexible 'contains' really is. I presume it'll look for strings within strings, as I've been using it, because I observe it to be working. Maybe that's a fluke and it's not really working at all. I worked from the snippet example here, with no luck:

    http://forums.modx.com/forums/thread/80164/filter-with-where-parameter#dis-post-441721

    Here's hoping Bruno17 will chime in, I know he'll have the answers.
      • 4172
      • 5,888 Posts
      did you try 'find_in_pipesdelimited_set' or 'find_pd' ?

      &where=`{"days:find_pd":"Sunday"}


      https://github.com/Bruno17/MIGX/blob/master/core/components/migx/model/migx/migx.class.php#L1592
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 36516
        • 179 Posts
        I did not, but surely that would only apply if the output was in fact the pipe delimited string that I've put *in* to the TV. The output is stripped of all delimiters, a conjoined list of the enabled checkbox values.

        In case I've misunderstood I'll certainly give it a shot. Thanks for the github link - I see the list of possibilities. I also see that 'contains' is essentially using strpos to look for the input string. Unless I've wrong, it looks like the following code isn't actually producing the expected result:

        case 'contains':
          $output = strpos($subject, $operand) !== false ? $then : (isset($else) ? $else : '');
          break;
        


        Where $subject = 'MondayTuesdayWednesdayThursdayFridaySaturday'
        $operand = 'Sunday'
        $then = 1
        $else = false

        Why might that return 1? my concern about find_pd is that the subject isn't pipe delimited. Are you suggest that I arrange for the output of that TV to be delimited? Or perhaps is there a way I have yet to discover to pipe delimit the output of my compound checkbox TV content using a standard output filter?
          • 4172
          • 5,888 Posts
          checkbox - values are stored doublepipe-delimited in the db and in the MIGX-json,
          if I'm not wrong.

          But let me see your unprocessed output of your MIGX-TV.
          You can get it by putting the TV-tag of your MIGX-TV into the content:

          [[*yourMIGXtv]]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 36516
            • 179 Posts
            Ok it's becoming clearer now:

            {"MIGX_id":"5","title":"Early bird menu","status":"Enabled","days":["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]}

            I was only seeing the flattened output after modx had essentially squirted the array onto the screen. So it's not pipe delimited - it's actually an array it seems [Edit: unless migx is just rendering it like this even though it's really pipe delimited. But in either case, neither 'find_pd' nor 'in' have worked].

            But I tried using 'in' instead of 'contains' or 'find_pd' and it didn't find what I was looking for. [ed. note: davidsmith last edited this post 10 years, 1 month ago.]
              • 4172
              • 5,888 Posts
              this seems to work:

              snippet 'filter_inarray':

              $operand = $modx->getOption('operand',$scriptProperties,'');
              $subject = $modx->getOption('subject',$scriptProperties,'');
              
              if (is_array($subject)){
                  return  in_array($operand,$subject) ? '1' : '';
              }
              
              return $operand == $subject ? '1' : '';
              


              [[!getImageList? 
              &tvname=`images` 
              &where=`{"days:snippet:filter_inarray":"Freitag"}`]]
              


              the result:

              http://www.revo222.webcmsolutions.de/75/days.html



              [ed. note: Bruno17 last edited this post 10 years, 1 month ago.]
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 36516
                • 179 Posts
                Sorry about the slow response. Turns out that code does indeed work perfectly. I'll perhaps need to reassess at some stage, but off the top of my head I can't see why your original 'find_pd' plan didn't work. Seems like it should be the same.

                Anyway, thanks indeed for your help, and the timely fashion in which it was given.

                PS: The migx documentation is rather out of date, or at least inexhaustive. None of the filter stuff is documented from what I can see.
                • I am also having the same problem. I am running migxLoopCollection via runSnippet and I am trying to see if a value exists in a pipe delimited string:
                  'where'=>'{"kategorien:IN":"'.$category.'"}'
                  or
                  'where'=>'{"kategorien:find_pd":"'.$category.'"}'

                  and am having no luck.

                  The database column is called "kategorien" and I am via a GET request getting the category value.

                  What is the proper syntax here to look through a pipe delimited string?
                  [ed. note: sonicpunk last edited this post 8 years, 6 months ago.]
                    Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
                  • I found a way to solve it:
                    'where'=>'[{"kategorien":"'.$category.'"},{"OR:kategorien:LIKE":"%||'.$category.'||%"},{"OR:kategorien:LIKE":"%'.$category.'||%"},{"OR:kategorien:LIKE":"%||'.$category.'%"}]'
                      Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
                      • 4172
                      • 5,888 Posts
                      Yeah, each "OR:kategorien:LIKE" has to be in a seperate array-object.
                      Otherwise you would have duplicate array-keys, where only one would make it into the array.

                      Another way would be, to make sure the values start and ends allways with a double-pipe in the db.
                      Also adding the doublepipes with the query would be possible.
                      I'm sure, I had posted examples for both solutions at the forums.
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!