You are here

function nodeorder_handle_node_lists_decrease in Node Order 7

Reorder list in which the node is dropped and where the borders became out of range.

2 calls to nodeorder_handle_node_lists_decrease()
nodeorder_node_delete in ./nodeorder.module
Implements hook_node_delete().
nodeorder_node_update in ./nodeorder.module
Implements hook_node_update().

File

./nodeorder.module, line 876
Nodeorder module.

Code

function nodeorder_handle_node_lists_decrease($tid) {
  $taxonomy_nids = taxonomy_select_nodes($tid, FALSE, FALSE, array(
    't.weight' => 'ASC',
  ));
  if (!count($taxonomy_nids)) {
    return;
  }
  $weights = nodeorder_get_term_min_max($tid, TRUE);
  $range_border = ceil(count($taxonomy_nids) / 2);

  // Out of range when one of both new list's border weights is corresponding range border.
  $border_out_of_range = $weights['min'] < -$range_border || $weights['max'] > $range_border;
  if ($border_out_of_range) {
    $weight = -$range_border;
    foreach ($taxonomy_nids as $nid) {
      $query = db_update('taxonomy_index')
        ->fields(array(
        'weight' => $weight,
      ))
        ->condition('nid', $nid)
        ->condition('tid', $tid)
        ->execute();
      $weight++;
    }

    // Make sure the weight cache is invalidated.
    nodeorder_get_term_min_max($tid, TRUE);
  }
}