We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I’m running out of gas on this one.

    I’m running getResources from inside a snippet to do an A to Z links glossary page.

    It works perfectly if I create my own $where scriptProperty like this ($v is the letter I’m looking for as the first letter of the pagetitle):

    <?php
    $local_where = array(
            'pagetitle' . ':LIKE' => $v . '%',
        );
    $scriptProperties['where'] = $modx->toJSON($local_where);
    $resources = $modx->runSnippet('getResources',$scriptProperties);
    


    The problem is that I’d like to merge that in as an AND condition with any JSON-encoded getResources criteria sent in the snippet’s &where property. I’ve spent the day trying various versions of creating an array from the &where scriptProperty with fromJSON(), merging the two arrays, and running toJSON() on the new array, but getResources always returns all resources on every call. I assume that means getResources couldn’t make sense of the $where I sent.

    I also tried some PHP code I found using array_values on one of the arrays, but couldn’t make that work either. I’m stumped. huh

    A related problem: I’d like to let users send the &resources property to include extra resources, but of course getResources then includes them on every call regardless of the letter restriction (though it works fine to exclude resources). I suspect that’s insoluble, but figured it couldn’t hurt to ask. tongue
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      That sounds tricky. Presumably, you tried converting the JSON strings to PHP arrays, then using array_merge() before converting them back to JSON?
        • 3749
        • 24,544 Posts
        Yup. No luck with that at all.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 3749
          • 24,544 Posts
          Still hoping for help here. tongue
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 4172
            • 5,888 Posts
            Hi Bob,
            Some times ago I made a A-Z Glossary-listing together with getResources.
            I created the letter-anchors with a little snippet, which I putted into the getResources-tpl.
            Need to have a research to put together what I did, if you are interested.

            Can you explain what you want todo all in all?
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 3749
              • 24,544 Posts
              Quote from: Bruno17 at Jan 25, 2011, 01:46 AM

              Hi Bob,
              Some times ago I made a A-Z Glossary-listing together with getResources.
              I created the letter-anchors with a little snippet, which I putted into the getResources-tpl.
              Need to have a research to put together what I did, if you are interested.

              Can you explain what you want todo all in all?

              Hi Bruno,

              I have the snippet working perfectly. The only thing I haven’t been able to do is let the user send the &where parameter in the snippet call, which is a JSON string. I have to use my own JSON string in the $where property to tell getResources which letter to get and I haven’t been able to successfully merge the two.

              Bob

              BTW, did that other front-end bug with TinyMCE looking for modx-panel-resource ever get fixed?
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 22303 MODX Staff
                • 10,725 Posts
                Why don’t you just call where() twice, once with the calculated where, and then a second time with the user-provided JSON conditions?
                  • 3749
                  • 24,544 Posts
                  Quote from: OpenGeek at Jan 25, 2011, 11:28 AM

                  Why don’t you just call where() twice, once with the calculated where, and then a second time with the user-provided JSON conditions?

                  Because I have no query. I have to pass a JSON string to getResources so I just have an array and the toJSON() version of that array. And the $where property from the snippet tag comes in as a JSON string as well.

                  Is there a way to convert the JSON string from the snippet tag into a query object, then back to a JSON string to be sent to getResources?
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Quote from: BobRay at Jan 25, 2011, 11:42 AM

                    Quote from: OpenGeek at Jan 25, 2011, 11:28 AM

                    Why don’t you just call where() twice, once with the calculated where, and then a second time with the user-provided JSON conditions?

                    Because I have no query. I have to pass a JSON string to getResources so I just have an array and the toJSON() version of that array. And the $where property from the snippet tag comes in as a JSON string as well.

                    Is there a way to convert the JSON string from the snippet tag into a query object, then back to a JSON string to be sent to getResources?
                    Just convert it to an array, merge it, and convert it back to JSON?
                      • 3749
                      • 24,544 Posts
                      First thing I tried. I never got it to work. Looking at the debug values, it looks like fromJSON()->toJSON() doesn’t always give you what you started with.

                      Are the JSON examples here correct? http://rtfm.modx.com/display/ADDON/getResources#getResources-Examples. That’s what I was using for the &where property.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting