What would it take to get node queue to generate a daily random node from the queue? In other words, rather than the node_fetch_random function generating a new random node every time the page updates, the module checks the date and displays the same random node throughout that day. When the day changes, so does the node.

CommentFileSizeAuthor
#7 shuffle.patch928 bytescolan

Comments

merlinofchaos’s picture

You need to write a little bit of code that checks the time and the last time nodequeue_fetch_random was called; if now - time > 24 hours, or no result is stored call nodequeue_fetch_random and store the result; otherwise, fetch the result. Return the result.

This won't be a feature of node queue itself, but the code to do it is pretty short, and would make a good PHP snippet in the handbook.

droopy’s picture

Thanks. That's beyond me though, so if any can help out, I'd appreciate it.

merlinofchaos’s picture

  $queue = QID; // Put your nodequeue qid here.

  if (variable_get("snippet_nodequeue_last_random_$queue", 0) + (60 * 60 * 24) < time()) {
    $output = nodequeue_fetch_random($queue);
    variable_set("snippet_nodequeue_last_random_$queue", time());
    variable_set("snippet_nodequeue_random_$queue", $output);
  }
  else {
    $output =  variable_get("snippet_nodequeue_random_$queue", 'Error');
  }

  return $output
merlinofchaos’s picture

BTW if this is useful to someone, reposting this in the snippets section and closing this issue would be awesomely helpful!

discursives’s picture

I tried this out and I get an error, where I had been using the simple random function with the same queue and that was working.

Every 3rd or fourth try there would be no content for the random one. This gets an error every time though.

I think I am just going to use the random function for views, though. I would like it to be sequential from a view, and daily, in all truth. I know that most sites won't have those requirements, but hey, at least i know what I need!

discursives’s picture

Did anyone else get this to work by any chance?

colan’s picture

Version: 4.7.x-1.1 » 5.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new928 bytes

I came up with a similar but different solution because I needed to use views. If would be great if this could make it into the module; clearly I'm not the only one that needs this.

I wrote a little patch that provides the function nodequeue_queue_shuffle() that shuffles a queue. The idea is that this can be called from cron whenever it's necessary. For example, I call it once a day:

function example_cron() {
  if (variable_get('cron_last', 0) < (time() - (1 * 60 * 60 * 24))) {
    if (module_exists('nodequeue')) {
      nodequeue_queue_shuffle(<whichever queue you'd like to shuffle>);
    }
  }
}
merlinofchaos’s picture

Status: Needs review » Fixed

I did this and went one better, putting it in the UI and providing some javascript to do the same thing from the UI. Both methods work.

Note that the patch as given does not apply to the 2.x branch because it was referring to queues, and 2.x needed subqueues.

This'll go out in Nodequeue 2.x-rc

Anonymous’s picture

Status: Fixed » Closed (fixed)