You are here

function nodeorder_get_term_min_max in Node Order 7

Same name and namespace in other branches
  1. 6 nodeorder.module \nodeorder_get_term_min_max()

Get the minimum and maximum weights available for ordering nodes on a term.

Parameters

int $tid: The tid of the term from which to check values.

bool $reset: (optional) Select from or reset the cache.

Return value

array An associative array with elements 'min' and 'max'.

3 calls to nodeorder_get_term_min_max()
nodeorder_add_links in ./nodeorder.module
Adds links to move node up or down in term.
nodeorder_add_node_to_list in ./nodeorder.module
Push new or newly orderable node to top of ordered list.
nodeorder_handle_node_lists_decrease in ./nodeorder.module
Reorder list in which the node is dropped and where the borders became out of range.

File

./nodeorder.module, line 350
Nodeorder module.

Code

function nodeorder_get_term_min_max($tid, $reset = FALSE) {
  static $min_weights = array();
  static $max_weights = array();
  if ($reset) {
    $min_weights = array();
    $max_weights = array();
  }
  if (!isset($min_weights[$tid]) || !isset($max_weights[$tid])) {
    $query = db_select('taxonomy_index', 'i')
      ->fields('i', array(
      'tid',
    ))
      ->condition('tid', $tid)
      ->groupBy('tid');
    $query
      ->addExpression('MAX(weight)', 'max_weight');
    $query
      ->addExpression('MIN(weight)', 'min_weight');
    $record = $query
      ->execute()
      ->fetch();
    $min_weights[$tid] = $record->min_weight;
    $max_weights[$tid] = $record->max_weight;
  }
  $weights['min'] = $min_weights[$tid];
  $weights['max'] = $max_weights[$tid];
  return $weights;
}