You are here

function nodequeue_load_subqueues in Nodequeue 5.2

Same name and namespace in other branches
  1. 6.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.

1 call to nodequeue_load_subqueues()
nodequeue_load_subqueue in ./nodequeue.module
Load a single subqueue.

File

./nodequeue.module, line 1633

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)) {
    $load_text = implode(', ', $to_load);
    $result = db_query("SELECT s.*, COUNT(n.position) AS count FROM {nodequeue_subqueue} s LEFT JOIN {nodequeue_nodes} n ON n.sqid = s.sqid WHERE s.sqid IN (%s) GROUP BY s.sqid", $load_text);
    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;
}