Howdy.

I'd like to provide next/previous links when displaying a node. I think that all I need is the nid, since I'm just constructing links, so calling nodequeue_load_nodes and then walking the array seems kind of heavy weight.

Is there an easy, or canonical way to do this? If anyone else would be interested in having utility functions for this, I'd consider writing them.

I realize this is similar to #464310: nodequeue pager (pager through nodes in a queue) - code provided but more minimal. It seems to me that use cases for both a pager, and a simple get_next or get_previous function exist.

Comments

firebus’s picture

Category: feature » support
Status: Needs review » Active

well, if anyone is interested, here's my take on this. any and all feedback welcome.

/**
 * Get the next nid for a node in each subqueue it belongs to
 * If node is the last node in subqueue, return first node
 *
 * @param object $node a fully loaded node object
 *
 * @return array of arrays, one for each subqueue the node belongs to
 * If a node belongs to. if the node belongs to multiple subqueues, it is up to the caller to determine
 * which one to use
 *
 */
function nodequeue_get_next_nids($node) {
  $qids = nodequeue_get_all_qids(0);
  $queues = nodequeue_load_queues($qids);
  $subqueues = nodequeue_get_subqueues_by_node($queues, $node);
  if (! empty($subqueues)) {
    $nextNodes = array();
    foreach ($subqueues as $key => $subqueue) { 
      $nextNodes[] = _nodequeue_get_next_nid_by_subqueue($node, $subqueue);
    }
    return $nextNodes;
  }
}

function _nodequeue_get_next_nid_by_subqueue($node, $subqueue) {
  $position = nodequeue_subqueue_position($subqueue->sqid, $node->nid);
  $next_node = array_shift(nodequeue_load_nodes($subqueue->sqid, FALSE, $position, 1));
  if (empty($next_node)) { //we are at the last node in the subqueue
    $next_node = nodequeue_load_front($subqueue->sqid);
  }

  return array(
    'sqid' => $subqueue->sqid,
    'nid' => $next_node->nid,
  );
}
firebus’s picture

Category: support » feature
Status: Active » Needs review

Status: Active » Needs review