taxonomy_weight.module 5.x-1.x head
<?php
// $Id: taxonomy_weight.module,v 1.0 2008/01/24 0829 Exp $
/**
* Implementation of hook_form_alter().
*/
function taxonomy_weight_form_alter($form_id, &$form) {
switch ($form_id) {
case 'taxonomy_form_vocabulary':
$form['term_weight'] = array(
'#type' => 'textfield',
'#title' => t('Term weight range'),
'#default_value' => _taxonomy_weight_get($form['vid']['#value']),
'#description' => t('Input number of weights to have selectable. For example, it is 10, the weight selection box would display numbers from -10 to 10.'),
'#size' => 6,
);
// Move submit buttons to bottom
$form['submit']['#weight'] = 1;
$form['delete']['#weight'] = 1;
break;
case 'taxonomy_form_term':
$form['weight']['#delta'] = _taxonomy_weight_get($form['vid']['#value']);
break;
}
}
/**
* Implementation of hook_taxonomy().
*/
function taxonomy_weight_taxonomy($op, $type, $object = NULL) {
if ($type == 'vocabulary') {
$table = '{taxonomy_weight}';
$vid = $object['vid'];
$weight = $object['term_weight'];
if ($op == 'delete') {
db_query("DELETE FROM $table WHERE vid = %d", $vid);
}
elseif ($op == 'update' && _taxonomy_weight_set($vid)) {
db_query("UPDATE $table SET weight = %d WHERE vid = %d", $weight, $vid);
}
elseif ($op == 'update' || $op == 'insert') {
db_query("INSERT INTO $table (vid, weight) VALUES (%d, %d)", $vid, $weight);
}
}
}
function _taxonomy_weight_set($vid) {
$result = db_fetch_array(db_query("SELECT weight FROM {taxonomy_weight} WHERE vid = %d", $vid));
return $result;
}
function _taxonomy_weight_get($vid) {
$weight = 10;
if ($row = _taxonomy_weight_set($vid)) {
$weight = $row['weight'];
}
return $weight;
}
// $Id: taxonomy_weight.module,v 1.0 2008/01/24 0829 Exp $
/**
* Implementation of hook_form_alter().
*/
function taxonomy_weight_form_alter($form_id, &$form) {
switch ($form_id) {
case 'taxonomy_form_vocabulary':
$form['term_weight'] = array(
'#type' => 'textfield',
'#title' => t('Term weight range'),
'#default_value' => _taxonomy_weight_get($form['vid']['#value']),
'#description' => t('Input number of weights to have selectable. For example, it is 10, the weight selection box would display numbers from -10 to 10.'),
'#size' => 6,
);
// Move submit buttons to bottom
$form['submit']['#weight'] = 1;
$form['delete']['#weight'] = 1;
break;
case 'taxonomy_form_term':
$form['weight']['#delta'] = _taxonomy_weight_get($form['vid']['#value']);
break;
}
}
/**
* Implementation of hook_taxonomy().
*/
function taxonomy_weight_taxonomy($op, $type, $object = NULL) {
if ($type == 'vocabulary') {
$table = '{taxonomy_weight}';
$vid = $object['vid'];
$weight = $object['term_weight'];
if ($op == 'delete') {
db_query("DELETE FROM $table WHERE vid = %d", $vid);
}
elseif ($op == 'update' && _taxonomy_weight_set($vid)) {
db_query("UPDATE $table SET weight = %d WHERE vid = %d", $weight, $vid);
}
elseif ($op == 'update' || $op == 'insert') {
db_query("INSERT INTO $table (vid, weight) VALUES (%d, %d)", $vid, $weight);
}
}
}
function _taxonomy_weight_set($vid) {
$result = db_fetch_array(db_query("SELECT weight FROM {taxonomy_weight} WHERE vid = %d", $vid));
return $result;
}
function _taxonomy_weight_get($vid) {
$weight = 10;
if ($row = _taxonomy_weight_set($vid)) {
$weight = $row['weight'];
}
return $weight;
}

