You are here

function nodequeue_load_queues in Nodequeue 6.2

Same name and namespace in other branches
  1. 5.2 nodequeue.module \nodequeue_load_queues()
  2. 7.3 nodequeue.module \nodequeue_load_queues()
  3. 7.2 nodequeue.module \nodequeue_load_queues()

Load an array of $qids.

This exists to provide a way of loading a bunch of queues with the fewest queries. Loading 5 queues results in only 4 queries, not 20. This also caches queues so that they don't get loaded repeatedly.

Parameters

$qids: An array of queue IDs to load.

$bypass_cache: Boolean value indicating whether to bypass the cache or not.

18 calls to nodequeue_load_queues()
NodequeueAPICRUDUnitTest::testNodequeueModify in tests/nodequeue.test
nodequeue_add_action in ./nodequeue.module
Action to add a node to a queue.
nodequeue_add_action_form in ./nodequeue.module
Configuration form for Add to Nodequeues action.
nodequeue_apachesolr_update_index in ./nodequeue.module
Implementation of hook_apachesolr_update_index().
nodequeue_generate_form in ./nodequeue_generate.module

... See full list

File

./nodequeue.module, line 673
Maintains queues of nodes in arbitrary order.

Code

function nodequeue_load_queues($qids = array(), $bypass_cache = FALSE) {
  static $cache = array();
  $to_load = $loaded = array();
  foreach ($qids as $qid) {
    if ($bypass_cache || !isset($cache[$qid])) {
      $to_load[] = $qid;
    }
  }
  if (!empty($to_load)) {
    $placeholders = db_placeholders($to_load, 'int');
    $result = db_query("SELECT q.*, (SELECT count(*) FROM {nodequeue_subqueue} s WHERE q.qid = s.qid) AS subqueues FROM {nodequeue_queue} q WHERE q.qid IN ({$placeholders})", $to_load);
    while ($queue = db_fetch_object($result)) {
      $loaded[$queue->qid] = $queue;

      // ensure valid defaults:
      $loaded[$queue->qid]->types = array();
      $loaded[$queue->qid]->roles = array();
      $loaded[$queue->qid]->count = 0;
    }
    $result = db_query("SELECT qid, rid FROM {nodequeue_roles} WHERE qid IN ({$placeholders})", $to_load);
    while ($obj = db_fetch_object($result)) {
      $loaded[$obj->qid]->roles[] = $obj->rid;
    }
    $result = db_query("SELECT qid, type FROM {nodequeue_types} WHERE qid IN ({$placeholders})", $to_load);
    while ($obj = db_fetch_object($result)) {
      $loaded[$obj->qid]->types[] = $obj->type;
    }
    drupal_alter('nodequeue', $loaded, 'load_queues');
  }
  if ($bypass_cache) {
    return $loaded;
  }
  else {
    if (!empty($loaded)) {
      $cache += $loaded;
    }
    $queues = array();
    foreach ($qids as $qid) {
      if (isset($cache[$qid])) {
        $queues[$qid] = $cache[$qid];
      }
    }
    return $queues;
  }
}