You are here

function nodequeue_add_subqueue in Nodequeue 6.2

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

Add a new subqueue to a queue.

Parameters

$queue: The queue object that is the parent of this subqueue.

$title: The title of the subqueue.

$reference: A reference that uniquely identifies this subqueue. If NULL it will be assigned the sqid.

3 calls to nodequeue_add_subqueue()
NodequeueAdministerTestCase::testNodequeueTableSort in tests/nodequeue.test
nodequeue_save in ./nodequeue.module
Save a nodequeue. This does not save subqueues; those must be added separately.
smartqueue_taxonomy_nodequeue_subqueues in ./smartqueue.module
Implementation of hook_nodequeue_subqueues()

File

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

Code

function nodequeue_add_subqueue(&$queue, $title, $reference = NULL) {
  if (empty($reference)) {
    $insert_reference = "";
  }
  else {
    $insert_reference = $reference;
  }
  $subqueue = new stdClass();
  $subqueue->reference = $reference;
  $subqueue->qid = $queue->qid;
  $subqueue->title = $title;
  db_query("INSERT INTO {nodequeue_subqueue} (qid, reference, title) VALUES (%d, '%s', '%s')", $queue->qid, $insert_reference, $title);
  $subqueue->sqid = db_last_insert_id('nodequeue_subqueue', 'sqid');

  // If somehow the $reference is null, here we set it to the sqid.
  // We have to do it here, because before the insert we don't know what the sqid will be.
  if (empty($reference)) {
    db_query("UPDATE {nodequeue_subqueue} SET reference = '%s' WHERE sqid = %d", $subqueue->sqid, $subqueue->sqid);
  }
  return $subqueue;
}