You are here

function nodequeue_subqueue_add in Nodequeue 7.3

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

Add a node to a queue.

Parameters

$queue: The parent queue of the subqueue. This is required so that we can pop nodes out if the queue breaks size limits.

$subqueue: The subqueue to add the node to.

$nid: The node ID. Defaults to NULL.

6 calls to nodequeue_subqueue_add()
action_nodequeue_add in includes/nodequeue.actions.inc
Old-style action to add a node to a queue.
nodequeue_add_action in includes/nodequeue.actions.inc
Action to add a node to a queue.
nodequeue_admin_add_node in includes/nodequeue.admin.inc
Page callback to add a node to a queue.
nodequeue_arrange_subqueue_form_add_submit in includes/nodequeue.admin.inc
nodequeue_nodequeue_generate in ./nodequeue_generate.module
Implements hook_nodequeue_generate() for owner 'nodequeue'.

... See full list

File

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

Code

function nodequeue_subqueue_add($queue, &$subqueue, $nid = NULL) {
  if (!empty($nid)) {
    $transaction = db_transaction();
    try {
      $position = db_query("SELECT MAX(position) + 1 FROM (SELECT * FROM {nodequeue_nodes} WHERE sqid = :sqid) as nn", array(
        ':sqid' => $subqueue->sqid,
      ))
        ->fetchField();
      $position = !empty($position) ? $position : 1;
      db_query("INSERT INTO {nodequeue_nodes} (sqid, name, nid, position, timestamp) VALUES (:sqid, :name, :nid, :position, :time)", array(
        ':sqid' => $subqueue->sqid,
        ':name' => $queue->name,
        ':nid' => $nid,
        ':position' => $position,
        ':time' => REQUEST_TIME,
      ));
    } catch (Exception $e) {
      $transaction
        ->rollback();
      watchdog_exception('nodequeue', $e);
      throw $e;
    }
    $subqueue->count = db_query("SELECT COUNT(nid) FROM {nodequeue_nodes} WHERE sqid = :sqid", array(
      ':sqid' => $subqueue->sqid,
    ))
      ->fetchField();

    // If adding this would make the queue too big, pop the front node
    // (or nodes) out.
    if (!empty($queue->size)) {

      // 0 means infinity so never do this if FALSE.
      nodequeue_check_subqueue_size($queue, $subqueue, $queue->size);
    }
    if (module_exists('apachesolr')) {
      apachesolr_mark_entity('node', $nid);
    }

    // Invoke the hook to notify other modules of the node addition.
    module_invoke_all('nodequeue_add', $subqueue->sqid, $nid);
  }
}