You are here

function _lineage_weights in Taxonomy Lineage 6

Same name and namespace in other branches
  1. 7 lineage.module \_lineage_weights()

Determine how many digits to use in weights.

Parameters

vid the vocabulary.:

Return value

array of min weight, max weight, offset to use, and # digits.

1 call to _lineage_weights()
lineage_string in ./lineage.module

File

./lineage.module, line 295

Code

function _lineage_weights($vid) {

  // Keep static array with weight info to prevent unneeded queries.
  static $weights = array();
  if (!isset($weights[$vid])) {
    $min_r = db_query("SELECT MIN(weight) FROM {term_data} WHERE vid = %d", $vid);
    $weights[$vid]['min'] = db_result($min_r);
    $weights[$vid]['offset'] = $weights[$vid]['min'] < 0 ? abs($weights[$vid]['min']) : 0;
    $max_r = db_query("SELECT MAX(weight) FROM {term_data} WHERE vid = %d", $vid);
    $weights[$vid]['max'] = db_result($max_r);
    $weights[$vid]['digits'] = floor(log($weights[$vid]['max'] + $weights[$vid]['offset'] + 1));
    if ($weights[$vid]['digits'] == 0) {
      $weights[$vid]['digits']++;
    }
  }
  return $weights[$vid];
}