You are here

function _nodequeue_ajax_add in Nodequeue 5.2

1 call to _nodequeue_ajax_add()
nodequeue_ajax_add in ./nodequeue.module
Page callback to ajaxily add a node.

File

./nodequeue.module, line 1295

Code

function _nodequeue_ajax_add($sqid, $position, $string) {
  if (!$string) {
    return array(
      'error' => t('Invalid input'),
    );
  }
  if (!$sqid || !is_numeric($sqid)) {
    return array(
      'error' => t('Invalid sqid'),
    );
  }
  $subqueue = nodequeue_load_subqueue($sqid);
  if (!$subqueue) {
    return array(
      'error' => t('Invalid sqid'),
    );
  }
  if (!nodequeue_api_subqueue_access($subqueue)) {
    return array(
      'error' => t('Access denied'),
    );
  }
  $queue = nodequeue_load($subqueue->qid);
  if (!$queue) {
    return array(
      'error' => t('Invalid sqid'),
    );
  }
  $nodes = nodequeue_api_autocomplete($queue, $subqueue, $string);
  if (empty($nodes) || !is_array($nodes)) {
    return array(
      'error' => t('Invalid node'),
    );
  }
  if (count($nodes) > 1) {
    return array(
      'error' => t('That matches too many nodes'),
    );
  }
  $keys = array_keys($nodes);
  $node = node_load(array_pop($keys));
  if (!node_access('view', $node)) {
    return array(
      'error' => t('Invalid node'),
    );
  }
  $node->position = $position;
  $nids_visible = nodequeue_nids_visible($subqueue->sqid);
  return array(
    'status' => 1,
    'extra' => $node->nid,
    'max' => $queue->size,
    'data' => nodequeue_arrange_subqueue_entry($queue, $subqueue, $node, $nids_visible),
  );
}