function nodequeue_save_subqueue_order in Nodequeue 7.3
Same name and namespace in other branches
- 6.2 includes/nodequeue.admin.inc \nodequeue_save_subqueue_order()
- 7.2 includes/nodequeue.admin.inc \nodequeue_save_subqueue_order()
Validates new subqueue order information and if it passes validation, deletes the old subqueue data from the database and saves the new data.
Parameters
$nodes:: an array of nodes, keyed on the subqueue position.
$name: the queue id
unknown_type $sqid: the subqueue id
Return value
An array where the first element is a numeric status code (0 means successfully saved) and the second element is a status message.
1 call to nodequeue_save_subqueue_order()
- nodequeue_arrange_subqueue_form_submit in includes/
nodequeue.admin.inc - Submit handler for nodequeue drag'n'drop form. Updates node positions in {nodequeue_nodes}.
File
- includes/
nodequeue.admin.inc, line 951 - Admin page callbacks for the nodequeue module.
Code
function nodequeue_save_subqueue_order($nodes, $name, $sqid) {
$positions = array();
$now = REQUEST_TIME;
$queue = nodequeue_load($name);
$subqueue = nodequeue_load_subqueue($sqid);
// cleanup the node array
$clean = array();
$count = 1;
ksort($nodes);
drupal_alter('nodequeue_sort', $nodes, $sqid);
foreach ($nodes as $pos => $node) {
if (!is_numeric($node['nid']) || $node['nid'] < 1) {
return array(
NODEQUEUE_INVALID_NID,
'Invalid nid value. New subqueue order not saved.',
);
}
if (is_numeric($pos)) {
$clean[$count] = $node;
$count++;
}
elseif ($pos == 'r') {
// Remove the node from this subqueue.
nodequeue_subqueue_remove_node($sqid, $node['nid']);
}
else {
return array(
NODEQUEUE_INVALID_POSITION,
'Invalid position value. New subqueue order not saved.',
);
}
}
$nodes = $clean;
array_walk($clean, '_nodequeue_serialize');
if (count(array_unique($clean)) < count($nodes)) {
return array(
NODEQUEUE_DUPLICATE_POSITION,
'Duplicate position values are not allowed. New subqueue order not saved.',
);
}
// Allow other modules to alter the order of nodes.
foreach (module_implements('nodequeue_save_subqueue_order_alter') as $module) {
$function = $module . '_nodequeue_save_subqueue_order_alter';
$function($sqid, $nodes);
}
// clear the queue and save the new positions
db_delete('nodequeue_nodes')
->condition('sqid', $sqid)
->execute();
foreach ($nodes as $pos => $node) {
$args = array();
if ($pos != 'r') {
$query = db_insert('nodequeue_nodes')
->fields(array(
'sqid' => $sqid,
'name' => $name,
'nid' => $node['nid'],
'position' => $pos,
'timestamp' => $now,
))
->execute();
}
}
if ($queue->size) {
// only necessary if the subqueue is of finite length
nodequeue_check_subqueue_size($queue, $subqueue);
}
return array(
NODEQUEUE_OK,
'The queue has been updated.',
);
}