You are here

function nodequeue_load_subqueues in Nodequeue 6.2

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

Load a list of subqueues

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

$sqids: An array of subqueue IDs to load.

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

2 calls to nodequeue_load_subqueues()
nodequeue_load_subqueue in ./nodequeue.module
Load a single subqueue.
subqueue_load in ./nodequeue.module
This function exists so that %subqueue will work in hook_menu.

File

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

Code

function nodequeue_load_subqueues($sqids, $bypass_cache = FALSE) {
  static $cache = array();
  $to_load = array();
  foreach ($sqids as $sqid) {
    if ($bypass_cache || !isset($cache[$sqid])) {
      $to_load[] = $sqid;
    }
  }
  if (!empty($to_load)) {
    $placeholders = db_placeholders($to_load, 'int');
    $result = db_query("SELECT s.*, (SELECT count(*) FROM {nodequeue_nodes} n WHERE n.sqid = s.sqid) AS count FROM {nodequeue_subqueue} s WHERE s.sqid IN ({$placeholders})", $to_load);
    while ($obj = db_fetch_object($result)) {

      // Sometimes we want to get to subqueues by reference, sometimes by sqid.
      // sqid is always unique, but reference is sometimes more readily available.
      $cache[$obj->sqid] = $obj;
    }
  }
  foreach ($sqids as $sqid) {
    if (isset($cache[$sqid])) {
      $subqueues[$sqid] = $cache[$sqid];
    }
  }
  return $subqueues;
}