You are here

function nodequeue_nodeapi in Nodequeue 6.2

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

Implementation of hook_nodeapi().

File

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

Code

function nodequeue_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'delete':

      // If a node is being deleted, ensure it's also removed from any queues.
      $result = db_query("SELECT qid, sqid FROM {nodequeue_nodes} WHERE nid = %d", $node->nid);
      while ($obj = db_fetch_object($result)) {

        // If the queue is being tracked by translation set and the node is part
        // of a translation set, don't delete the queue record.
        // Instead, data will be updated in the 'translation_change' op, below.
        $queues = nodequeue_load_queues(array(
          $obj->qid,
        ));
        $queue = array_shift($queues);
        if (!$queue->i18n || isset($node->tnid) && empty($node->tnid)) {

          // This removes by nid, not position, because if we happen to have a
          // node in a queue twice, the 2nd position would be wrong.
          nodequeue_subqueue_remove_node($obj->sqid, $node->nid);
        }
      }
      break;
    case 'translation_change':
      if (isset($node->translation_change)) {

        // If there is only one node remaining, track by nid rather than tnid.
        // Otherwise, use the new tnid.
        $content_id = $node->translation_change['new_tnid'] == 0 ? $node->translation_change['remaining_nid'] : $node->translation_change['new_tnid'];
        db_query("UPDATE {nodequeue_nodes} SET nid = %d WHERE nid = %d", $content_id, $node->translation_change['old_tnid']);
      }
  }
}