You are here

function nodequeue_save in Nodequeue 7.2

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

Save a nodequeue. This does not save subqueues; those must be added separately.

4 calls to nodequeue_save()
NodequeueAPICRUDUnitTest::testNodequeueModify in tests/nodequeue.test
NodequeueWebTestCase::createNodequeue in tests/nodequeue.test
@internal param int $rid The role ID allowed to manipulate this queue.
nodequeue_edit_queue_form_submit in includes/nodequeue.admin.inc
Submit function for the nodequeue_queue form.
nodequeue_form_node_type_form_submit in ./nodequeue.module
Submit handler for the node type form.

File

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

Code

function nodequeue_save(&$queue) {
  $nodequeue_queue_fields = array(
    'name' => $queue->name,
    'title' => $queue->title,
    'subqueue_title' => $queue->subqueue_title,
    'size' => $queue->size,
    'link' => $queue->link,
    'link_remove' => $queue->link_remove,
    'owner' => $queue->owner,
    'show_in_links' => $queue->show_in_links ? 1 : 0,
    'show_in_tab' => $queue->show_in_tab,
    'show_in_ui' => $queue->show_in_ui,
    'i18n' => $queue->i18n,
    'reverse' => $queue->reverse,
    'unique_entries' => $queue->unique_entries ? 1 : 0,
    'insert_at_front' => $queue->insert_at_front,
    'reference' => $queue->reference,
  );
  if (!isset($queue->qid)) {
    $queue->qid = db_insert('nodequeue_queue')
      ->fields($nodequeue_queue_fields)
      ->execute();
    if (module_exists('views')) {
      views_invalidate_cache();
    }
  }
  else {
    db_update('nodequeue_queue')
      ->fields($nodequeue_queue_fields)
      ->condition('qid', $queue->qid)
      ->execute();
    db_delete('nodequeue_roles')
      ->condition('qid', $queue->qid)
      ->execute();
    db_delete('nodequeue_types')
      ->condition('qid', $queue->qid)
      ->execute();
  }
  if (is_array($queue->roles)) {
    foreach ($queue->roles as $rid) {
      db_insert('nodequeue_roles')
        ->fields(array(
        'qid' => $queue->qid,
        'rid' => $rid,
      ))
        ->execute();
    }
  }
  if (is_array($queue->types)) {
    foreach ($queue->types as $type) {
      db_insert('nodequeue_types')
        ->fields(array(
        'qid' => $queue->qid,
        'type' => $type,
      ))
        ->execute();
    }
  }

  // Set global that tells us if we need to activate nodequeue_node_links().
  if (db_query("SELECT COUNT(*) FROM {nodequeue_queue} WHERE link <> ''")
    ->fetchField()) {
    variable_set('nodequeue_links', TRUE);
  }
  else {
    variable_set('nodequeue_links', FALSE);
  }
  if (isset($queue->add_subqueue) && is_array($queue->add_subqueue)) {
    foreach ($queue->add_subqueue as $reference => $title) {

      // If reference is unset it should be set to the qid; this is generally
      // used for a single subqueue; setting the reference to the qid makes
      // it easy to find that one subqueue.
      if ($reference == 0) {
        $reference = $queue->qid;
      }
      nodequeue_add_subqueue($queue, $title, $reference);
    }
  }
  return $queue->qid;
}