location_taxonomize.inc in Location Taxonomize 7
Some useful functions for Location taxonomize
File
location_taxonomize.inc
View source
<?php
define('LOCATION_TAXONOMIZE_MODULE_ID', 'location_taxonomize');
define('LOCATION_TAXONOMIZE_MODULE_NAME', 'Location taxonomize');
define('LOCATION_TAXONOMIZE_VOCAB_NAME', 'location_taxonomize');
function _location_taxonomize_reset() {
location_taxonomize_empty_vocab();
_location_taxonomize_set_defaults();
drupal_set_message(t('Module reset'));
}
function _location_taxonomize_variables() {
$fields = _get_location_fields();
foreach ($fields as $key => $value) {
if ($key != 'country' && $key != 'province' && $key != 'city') {
$fields[$key] = 0;
}
}
return array(
'location_taxonomize_vid' => NULL,
'location_taxonomize_vocab' => array(
'method' => 'existing',
'possible_vid' => NULL,
'fields' => $fields,
),
'location_taxonomize_settings' => array(
'enable' => 1,
'naming' => array(
'country' => 'name',
'province' => 'name',
'usa' => 1,
),
'na_text' => 'Unknown',
'longname_enable' => 0,
'longname' => array(
'fields' => NULL,
'separator' => ',',
'country_naming' => 'code',
'province_naming' => 'code',
'usa' => 1,
),
),
);
}
function location_taxonomize_empty_vocab() {
$terms = taxonomy_get_tree(variable_get('location_taxonomize_vid'));
foreach ($terms as $term) {
taxonomy_term_delete($term->tid);
}
$termsnow = taxonomy_get_tree(variable_get('location_taxonomize_vid'));
if (!$termsnow) {
return t('Location vocabulary emptied.');
}
return t('There was a problem emptying the Location Vocabulary.');
}
function _get_location_fields($assoc = TRUE) {
$fields = drupal_schema_fields_sql('location');
$return = array();
foreach ($fields as $field) {
if ($field != 'lid' && $field != 'additional' && $field != 'latitude' && $field != 'longitude' && $field != 'source' && $field != 'is_primary' && $field != 'postal_code') {
if ($assoc) {
$return[$field] = $field;
}
else {
$return[] = $field;
}
}
}
return array_reverse($return);
}
function _location_taxonomize_get_hierarchy($assoc = FALSE) {
$vocab = variable_get('location_taxonomize_vocab');
$fields = $vocab['fields'];
$hierarchy = array();
foreach ($fields as $key => $value) {
if ($value) {
if ($assoc) {
$hierarchy[$key] = $key;
}
else {
$hierarchy[] = $key;
}
}
}
return $hierarchy;
}
function location_taxonomize_disassociate($form, $form_state) {
variable_del('location_taxonomize_vid');
drupal_set_message(t('Location Taxonomy successfully disassociated'));
}
function _location_taxonomize_set_defaults() {
$defaults = _location_taxonomize_variables();
foreach ($defaults as $key => $value) {
if ($value) {
variable_set($key, $value);
}
else {
variable_del($key);
}
}
}
function _location_taxonomize_del_variables() {
$vars = _location_taxonomize_variables();
foreach ($vars as $key => $value) {
variable_del($key);
}
return t('All variables deleted');
}