You are here

function nodequeue_subqueue_remove in Nodequeue 7.2

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

Remove a node or node(s) from a nodequeue by position.

If you know the nid but but not the position, use

Parameters

$sqid: The subqueue to remove nodes from.

$start: The first position (starting from 1) to remove.

$end: The last position to remove. If NULL or equal to $start, only one node will be removed. Thus if $start is 1 and $end is 2, the first and second items will be removed from the queue.

See also

nodequeue_subqueue_remove_node() instead.

4 calls to nodequeue_subqueue_remove()
NodequeueAPISubqueueUnitTest::testNodequeueSubqueueRemove in tests/nodequeue.test
nodequeue_admin_remove in includes/nodequeue.admin.inc
Page callback to remove an item from a queue. This will be used only if javascript is disabled in the client, and is a fallback technique. This differs from nodequeue_admin_remove_node in that it removes a specific position, which is necessary in case…
nodequeue_check_subqueue_size in ./nodequeue.module
Guarantee that a subqueue has not gotten too big. It's important to call this after an operation that might have reduced a queue's maximum size. It stores the count to save a query if this is to be followed by an add operation.
nodequeue_subqueue_remove_node in ./nodequeue.module
Remove a node from the queue. If a node is in the queue more than once, only the first (closest to 0 position, or the front of the queue) will be removed.

File

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

Code

function nodequeue_subqueue_remove($sqid, $start, $end = NULL) {
  if (!isset($end)) {
    $end = $start;
  }

  // Retrieve the nodes that are being removed.
  $result = db_query("SELECT nid FROM {nodequeue_nodes} WHERE sqid = :sqid AND position >= :start AND position <= :end", array(
    ':sqid' => $sqid,
    ':start' => $start,
    ':end' => $end,
  ));
  $diff = $end - $start + 1;
  db_delete('nodequeue_nodes')
    ->condition('sqid', $sqid)
    ->condition('position', $start, '>=')
    ->condition('position', $end, '<=')
    ->execute();
  db_update('nodequeue_nodes')
    ->expression('position', 'position - ' . $diff)
    ->condition('sqid', $sqid)
    ->condition('position', $end, '>')
    ->execute();

  // Invoke the hook to let other modules know that the nodes were removed.
  foreach ($result as $node) {
    module_invoke_all('nodequeue_remove', $sqid, $node->nid);
  }
}