You are here

function nodequeue_load_subqueues_by_reference in Nodequeue 5.2

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

Load a set of subqueues by reference.

This can be used to load a set of subqueues by reference; it will primarily be used by plugins that are managing subqueues.

Parameters

$references: A keyed array of references to load. The key is the $qid and each value is another array of references.

3 calls to nodequeue_load_subqueues_by_reference()
nodequeue_get_subqueues_by_node in ./nodequeue.module
Get a list of valid subqueues for a node, along with the position of the node.
smartqueue_author_nodequeue_subqueues in ./authorqueue.module
Implementation of hook_nodequeue_subqueues()
smartqueue_taxonomy_nodequeue_subqueues in ./smartqueue.module
Implementation of hook_nodequeue_subqueues()

File

./nodequeue.module, line 1726

Code

function nodequeue_load_subqueues_by_reference($references) {
  static $cache = array();
  $subqueues = array();

  // build strings for the query based upon the qids and references.
  $keys = $values = array();
  foreach ($references as $qid => $qid_references) {
    $keys[$qid] = array();
    $qid_values = array();
    foreach ($qid_references as $reference) {

      // If we already have this qid/reference combo cached, don't add it to
      // our little list.
      if (isset($cache[$qid][$reference])) {
        $subqueues[$cache[$qid][$reference]->sqid] = $cache[$qid][$reference];
      }
      else {
        $keys[$qid][] = "'%s'";
        $qid_values[] = $reference;
      }
    }
    if (!empty($keys[$qid])) {
      $values = array_merge($values, array(
        $qid,
      ), $qid_values);
    }
    else {
      unset($keys[$qid]);
    }
  }
  if (!empty($keys)) {
    $where = '';
    foreach ($keys as $key_list) {
      if ($where) {
        $where .= ' OR ';
      }
      $where .= 's.qid = %d AND s.reference IN (' . implode(', ', $key_list) . ')';
    }
    $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 {$where} GROUP BY s.sqid", $values);
    while ($subqueue = db_fetch_object($result)) {
      $cache[$subqueue->qid][$subqueue->reference] = $subqueues[$subqueue->sqid] = $subqueue;
    }
  }
  return $subqueues;
}