We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12110
    • 122 Posts
    Hello,

    I’m using about 100 documents in a folder to let Ditto retrieve randomized quotes out of them into a client’s home page by &randomized=`1` in the Ditto call.

    Now the client wants to have the quotes randomized, but by week. I’m not sure if I can get this via Ditto? Can somebody recommend a hack to do this?

    Or should I write my own SQL query into a snippet to extract the contents directly via MySQL from the modx_site_content table?

    Thanks for your thoughts.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      In this case, especially if there is only one parent for these, it would be best to use a custom snippet. You will need a custom snippet in any case to determine when to change the "random" resource to grab; there’s no point in doing a whole $modx->runSnippet() bit if you’re comfortable enough writing your own SQL to grab the document’s content.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 4172
        • 5,888 Posts
        perhaps you can save your actual random-ressource-ID of the week in a chunk ’weeklydoc’.
        Store the timestamp for this week perhaps in description-field of this chunk.
        Change these value per plugin every week.

        Then you can use Ditto with &documents=`{{weeklydoc}}`

        geht das?
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 12110
          • 122 Posts
          Hi Bruno,

          thanks for your post - staying in English here. I’ve not yet tried the solution.

          I thought about something like that:
          - create a table quote_timing with last_timestamp, actual_timestamp and quote_id
          - Get a quote_id by MySQL query, where quote_timing.actual_timestamp < 1 week (time difference)
          - Retrieve that id from the ditto folder of quotes
          - If there’s no result for quote_id: Get a quote_id where last_timestamp > (back at least 25... weeks)
          - Retrieve that id from the ditto folder of quotes
          - Set a new timestamp on this quote into the actual_timestamp column

          Im not a super pro in MySQL time formats so I didn’t try yet. What do you think of that way?

          Thanks again!
            • 3749
            • 24,544 Posts
            It looks reasonable to me. It might be a little faster and easier to just save the expiration date and do something like:

            if (now() > exp_date) ) {
               exp_date = now() + '1 week';
              /* save exp date  and update pointer */
            } else {
               /* do the regular grab */
            }


            I usually just grab a random quote from the whole pile to avoid messing with date arithmetic. 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
              you can try thisone: http://modxcms.com/forums/index.php/topic,47881.msg283536.html#msg283536

              of course you can store an exp_date to a tv on the new grabbed resource.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!