We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    Where can we report bugs and feature requests for getResources? I’d love to see a unified front for the MODx repo and the rtfm "official" docs so all the accepted 3rd party addons got their own little subproject in the bugs.modx.com Redmine bugtracker... nerd drool...

    I just spotted an area that could be optimized in get resources...

    Actually, it relates to the Auto-Tag template variable class... the tags are separated by ’||’, e.g.
    mysql> select * from modx_site_tmplvar_contentvalues where contentid=37;
    +-----+-----------+-----------+----------------------------------------------------------+
    | id  | tmplvarid | contentid | value                                                    |
    +-----+-----------+-----------+----------------------------------------------------------+
    | 117 |        57 |        37 | 12||11                                                   |
    +-----+-----------+-----------+----------------------------------------------------------+
    


    It’d be much better for searching if the values were stored as "||12||11||" -- in other words ALWAYS pad the numbers with the separator. Know what I mean? The MySQL LIKE statements would be much simpler.
      • 22019
      • 390 Posts
      My auto-tag contents are stored as comma delimited, not double pipe. It’s user-controllable.

      You can raise issues on Github for getResources = https://github.com/opengeek/getResources/issues

      I hate the Redmine interface, personally, but never mind.
        Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
        • 4172
        • 5,888 Posts
        you can allways surround your tagfields with ’||’ by using ’CONCAT’ for searching.
        This isn’t a big matter.
        $c->where("CONCAT('||'," . $modx->escape($classname) . '.' . $modx->escape($tagfield) . ",'||') LIKE '%||".$tag."||%'", xPDOQuery::SQL_AND);
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 22303 MODX Staff
          • 10,725 Posts
          I would create a custom Snippet for this purpose rather than trying to make getResources handle every feature people want.
            • 9207 ☆ A M B ☆
            • 2,475 Posts
            No, my question here is more like "how the heck is the getResourcesTag Snippet working AT ALL?" If you store a list of values with a delimiter, e.g. "12,123,456", then searching to see if a TV contains "12" is hard -- LIKE ’12%’ produces false positives. The Auto-Tag TVs should insert the delimiter before and after all values in a list so you can write LIKE statements that actually work, e.g. LIKE ’%,12,%’.

            Does that make sense? I’m kinda stuck on a variation of the getResourcesTag Snippet and the only database query I have that returns appropriate results is fugly because it has to accommodate 4 possible cases:

            WHERE 
            (
            my_tv_val = '12'    // TV contains only 1 tag in the list
            OR
            my_tv_val  LIKE '12,%'  // The tag we're looking for is at the start of the list
            OR
            my_tv_val  LIKE '%,12,%' // The tag we're looking for is somewhere in the middle of the list
            OR
            my_tv_val  LIKE '%,12' // The tag we're looking for is at the end of the list
            )


            Does that make sense? If the Auto-Tag stored ",1,2,3," instead of "1,2,3", custom queries would be MUCH easier. The getResources Snippet can’t help me here because it allows only 2 TV filters in its tvFilters parameter. Major bummer.

            odeclas -- what do you prefer better than Redmine? I’ve tested at least 20 of these project management software packages and taken some pretty in-depth notes and Redmine is one of only a few that didn’t really suck. I’d be curious to know if there’s something better out there.
              • 11055 ☆ A M B ☆
              • 3,112 Posts
              Try to use MATCH()... AGAINST() rather than LIKE.
              Simple case: if you have ’revolution’ and ’evolution’ tags, you’ll have problem when trying to get the ’evolution’, because ’revolution’ is "LIKE ’%evolution%’".

              http://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html
              http://modxcms.com/forums/index.php/topic,61256.0.html

              Keep in mind that this Full-Text Search Function needs less than 50% results of the whole rows, or it’ll return empty (for this situation, I used to use the ’LIKE’ fallback if it does).
                Rico
                Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                MODx is great, but knowing how to use it well makes it perfect!

                www.virtudraft.com

                Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                Maintainter/contributor of Babel

                Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                • 9207 ☆ A M B ☆
                • 2,475 Posts
                Thanks for the tip!

                My work-around for this was to adapt the checkbox TV’s @SELECT binding so it concatenated values:

                @SELECT pagetitle, CONCAT('xx',id,'xx') as id FROM modx_site_content WHERE parent=3


                Then I can reference those same values (i.e. ’xx’) in my call to getResources:

                [[!getResources?  &tpl=`mytpl` &parents=`35` &includeTV=`1` &tvFilters=`my_checkbox==%xx[[*id]]xx%`]]


                That way I can display any pages that are have a particular value checked. In this example, the checkbox values are page IDs, but the principle applies even if the checkboxes were listing categories or other values: so long as all tags are padded on both sides with the delimiter, you can easily search for resources that have been tagged.