You are here

function nodequeue_get_qids in Nodequeue 7.2

Same name and namespace in other branches
  1. 5.2 nodequeue.module \nodequeue_get_qids()
  2. 6.2 nodequeue.module \nodequeue_get_qids()

Get an array of qids applicable to this node type.

Parameters

$type: The node type.

$account: The account to test against. Defaults to the currently logged in user.

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

Return value

$qids An array in the format: @code { array($qid => array('qid' => $qid, 'show_in_tab' ' => true/false, 'show_in_links' => true/false }

2 calls to nodequeue_get_qids()
nodequeue_load_queues_by_type in ./nodequeue.module
Fetch a list of available queues for a given location.
nodequeue_nodequeue_access in ./nodequeue.module
Return TRUE if $user can queue(s) for this node.

File

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

Code

function nodequeue_get_qids($type, $account = NULL, $bypass_cache = FALSE) {
  if (!isset($account)) {
    global $user;
    $account = $user;
  }
  $cache =& drupal_static(__FUNCTION__, array());
  if ($bypass_cache || !isset($cache[$type])) {
    $roles_join = $roles_where = '';
    $roles = array();

    // superuser always has access.
    if (!user_access('manipulate all queues', $account)) {
      $roles = array_keys((array) $account->roles) + array(
        DRUPAL_AUTHENTICATED_RID,
      );
      $roles_join = "INNER JOIN {nodequeue_roles} nr ON nr.qid = nq.qid ";
      $roles_where .= "AND nr.rid IN (:roles)";
    }
    $sql = 'SELECT nq.qid, nq.show_in_tab, nq.show_in_links, nq.show_in_ui, nq.i18n ' . 'FROM {nodequeue_queue} nq ' . 'INNER JOIN {nodequeue_types} nt ON nt.qid = nq.qid ' . $roles_join . "WHERE nt.type = :type " . $roles_where;
    $result = db_query($sql, array(
      ':type' => $type,
      ':roles' => $roles,
    ));
    $qids = array();
    foreach ($result as $qid) {
      $qids[$qid->qid] = $qid;
    }
    $cache[$type] = $qids;
  }
  return $cache[$type];
}