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.
-
☆ 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.
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?
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!
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.
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.