Skip to content
Snippets Groups Projects
Commit 1cf96e04 authored by Brandon Bergren's avatar Brandon Bergren
Browse files

Work on gmap_taxonomy.

It's pretty obviously flawed, but everything is up and running except association.

It doesn't really make much sense under D7 anyway, taxonomy doesn't associate with nodes the way it did before,
it's all field based now.
parent 43852fc0
No related branches found
No related tags found
No related merge requests found
......@@ -280,7 +280,7 @@ function gmap_location_node_page($nid = NULL) {
if (module_exists('gmap_taxonomy')) {
$query
->fields('m', array('marker'))
->leftjoin('gmap_taxonomy_node', 'm', 'n.vid = m.vid');
->leftjoin('gmap_taxonomy_node', 'm', 'n.nid = m.nid');
}
$query->addTag('node_access');
$result = $query->execute();
......@@ -705,7 +705,7 @@ function _gmap_location_block_view($nid) {
$count++;
$markername = isset($markertypes[$node->type]) ? $markertypes[$node->type] : 'drupal';
if (module_exists('gmap_taxonomy')) {
$t = db_query('SELECT marker FROM {gmap_taxonomy_node} WHERE vid = :vid', array(':vid' => $node->vid))
$t = db_query('SELECT marker FROM {gmap_taxonomy_node} WHERE nid = :nid', array(':nid' => $node->nid))
->fetchField();
if (!empty($t)) {
$markername = $t;
......
......@@ -2,6 +2,7 @@
name = GMap Taxonomy Markers
description = Taxonomy based markers
package = Location
core = 6.x
core = 7.x
dependencies[] = taxonomy
dependencies[] = gmap
files[] = gmap_taxonomy.module
\ No newline at end of file
......@@ -6,6 +6,23 @@
* gmap_taxonomy install routines.
*/
/**
* Implement hook_requirements().
*/
function gmap_taxonomy_requirements($phase) {
if (!variable_get('taxonomy_maintain_index_table', TRUE)) {
return array(
'gmap_taxonomy_able_to_index' => array(
'title' => t('GMap Taxonomy Markers'),
'value' => '',
'description' => t('The variable <em>taxonomy_maintain_index_table</em> is set to FALSE. gmap_taxonomy.module will not work properly.'),
'severity' => REQUIREMENT_ERROR,
),
);
}
}
/**
* Implementation of hook_schema().
*/
......@@ -21,7 +38,7 @@ function gmap_taxonomy_schema() {
$schema['gmap_taxonomy_node'] = array(
'fields' => array(
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
// 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'marker' => array('type' => 'varchar', 'length' => 32),
),
......
......@@ -29,13 +29,15 @@ function gmap_taxonomy_form_alter(&$form, &$form_state, $form_id) {
'#default_value' => $temp[$vid],
);
}
if ($form_id == 'taxonomy_form_term') {
$vid = $form['vid']['#value'];
// @@@ Why does this get called up on delete?
if ($form_id == 'taxonomy_form_term' && empty($form['confirm']['#value'])) {
$vid = $form['#vocabulary']->vid;
$term = (object)$form['#term'];
$vocs = variable_get('gmap_taxonomy_vocabs', array());
if (isset($vocs[$vid]) && $vocs[$vid]) {
$temp = '';
if (isset($form['tid'])) {
if ($t = db_query('SELECT marker FROM {gmap_taxonomy_term} WHERE tid = :tid', array(':tid' => $form['tid']['#value']))->fetchField()) {
if (!empty($term->tid)) {
if ($t = db_query('SELECT marker FROM {gmap_taxonomy_term} WHERE tid = :tid', array(':tid' => $term->tid))->fetchField()) {
$temp = $t;
}
}
......@@ -50,6 +52,7 @@ function gmap_taxonomy_form_alter(&$form, &$form_state, $form_id) {
}
// Move the Save and Delete buttons down below our additions.
/*
if ($form_id == 'taxonomy_form_vocabulary' || $form_id == 'taxonomy_form_term') {
if (isset($form['submit']['#weight'])) {
$form['submit']['#weight']++;
......@@ -66,70 +69,83 @@ function gmap_taxonomy_form_alter(&$form, &$form_state, $form_id) {
}
}
}
*/
}
/**
* Implementation of hook_taxonomy().
* Implement hook_taxonomy_vocabulary_insert().
*/
function gmap_taxonomy_taxonomy($op, $type, $array = NULL) {
if ($type == 'vocabulary') {
switch ($op) {
case 'insert':
case 'update':
// This can get called in other places than vocabulary form submission.
// @@@ TODO move this to the form itself..
if (isset($array['gmap_taxonomy_enable'])) {
$status = variable_get('gmap_taxonomy_vocabs', array());
$status[$array['vid']] = $array['gmap_taxonomy_enable'];
variable_set('gmap_taxonomy_vocabs', $status);
}
break;
case 'delete':
$status = variable_get('gmap_taxonomy_vocabs', array());
unset($status[$array['vid']]);
variable_set('gmap_taxonomy_vocabs', $status);
}
function gmap_taxonomy_taxonomy_vocabulary_insert($vocabulary) {
return gmap_taxonomy_taxonomy_vocabulary_update($vocabulary);
}
/**
* Implement hook_taxonomy_vocabulary_update().
*/
function gmap_taxonomy_taxonomy_vocabulary_update($vocabulary) {
if (isset($vocabulary->gmap_taxonomy_enable)) {
$status = variable_get('gmap_taxonomy_vocabs', array());
$status[$vocabulary->vid] = $vocabulary->gmap_taxonomy_enable;
variable_set('gmap_taxonomy_vocabs', $status);
}
else {
switch ($op) {
case 'insert':
case 'update':
$vocabs = variable_get('gmap_taxonomy_vocabs', array());
if (isset($vocabs[$array['vid']]) && $vocabs[$array['vid']]) {
db_delete('gmap_taxonomy_term')
->condition('tid', $array['tid'])
->execute();
// Do we have an assigned marker?
if (!empty($array['gmap_taxonomy_marker'])) {
db_insert('gmap_taxonomy_term')
->fields(array(
'tid' => $array['tid'],
'marker' => $array['gmap_taxonomy_marker'],
))
->execute();
// Update name changes in the gmap_taxonomy_node table.
db_update('gmap_taxonomy_node')
->fields(array(
'marker' => $array['gmap_taxonomy_marker'],
))
->condition('tid', $array['tid'])
->execute();
}
}
gmap_taxonomy_reassign_marker($array['tid']);
}
break;
case 'delete':
// Delete and reassign even if the term isn't currently gmap_taxonomy enabled.
db_delete('gmap_taxonomy_term')
->condition('tid', $array['tid'])
->execute();
// Use gmap_taxonomy_node for search because term_node rows are already gone.
gmap_taxonomy_reassign_marker($array['tid'], 'gmap_taxonomy_node');
/**
* Implement hook_taxonomy_vocabulary_delete().
*/
function gmap_taxonomy_taxonomy_vocabulary_delete($vocabulary) {
$status = variable_get('gmap_taxonomy_vocabs', array());
unset($status[$vocabulary->vid]);
variable_set('gmap_taxonomy_vocabs', $status);
}
/**
* Implement hook_taxonomy_term_insert().
*/
function gmap_taxonomy_taxonomy_term_insert($term) {
return gmap_taxonomy_taxonomy_term_update($term);
}
/**
* Implement hook_taxonomy_term_update().
*/
function gmap_taxonomy_taxonomy_term_update($term) {
$vocabs = variable_get('gmap_taxonomy_vocabs', array());
if (isset($vocabs[$term->vid]) && $vocabs[$term->vid]) {
db_delete('gmap_taxonomy_term')
->condition('tid', $term->tid)
->execute();
// Do we have an assigned marker?
if (!empty($term->gmap_taxonomy_marker)) {
db_insert('gmap_taxonomy_term')
->fields(array(
'tid' => $term->tid,
'marker' => $term->gmap_taxonomy_marker,
))
->execute();
// Update name changes in the gmap_taxonomy_node table.
db_update('gmap_taxonomy_node')
->fields(array(
'marker' => $term->gmap_taxonomy_marker,
))
->condition('tid', $term->tid)
->execute();
}
gmap_taxonomy_reassign_marker($term->tid);
}
}
/**
* Implement hook_taxonomy_term_delete().
*/
function gmap_taxonomy_taxonomy_term_delete($term) {
db_delete('gmap_taxonomy_term')
->condition('tid', $term->tid)
->execute();
// Use gmap_taxonomy_node for search because term_node rows are already gone.
gmap_taxonomy_reassign_marker($term->tid, TRUE);
}
/**
* Implement hook_node_insert().
*/
......@@ -144,11 +160,12 @@ function gmap_taxonomy_node_update($node) {
// Remove the marker association if present. We'll readd it later if it's
// still applicable.
db_delete('gmap_taxonomy_node')
->condition('vid', $node->vid)
->condition('nid', $node->nid)
->execute();
$status = variable_get('gmap_taxonomy_vocabs', array());
$marker = '';
// @@@ PROBLEM -- $node->taxonomy doesn't exist anymore!
if (isset($node->taxonomy) && is_array($node->taxonomy)) {
foreach ($node->taxonomy as $voc => $terms) {
if (isset($status[$voc]) && $status[$voc]) {
......@@ -169,7 +186,6 @@ function gmap_taxonomy_node_update($node) {
db_insert('gmap_taxonomy_node')
->fields(array(
'nid' => $node->nid,
'vid' => $node->vid,
'tid' => $markertid,
'marker' => $marker,
))
......@@ -190,33 +206,47 @@ function gmap_taxonomy_node_delete($node) {
/**
* Implement hook_node_revision_delete().
*/
/*
function gmap_taxonomy_node_revision_delete($node) {
db_delete('gmap_taxonomy_node')
->condition('vid', $node->vid)
->execute();
}
*/
/**
* Reassign markers associated with a term that's going away.
*/
function gmap_taxonomy_reassign_marker($tid, $table = 'taxonomy_term_node') {
$result = db_query('SELECT vid FROM {:table} WHERE tid = :tid', array(':table' => db_escape_table($table), ':tid' => $tid));
while ($node = db_fetch_object($result)) {
$markers = db_query('SELECT t.tid, gt.marker FROM {taxonomy_term_node} r INNER JOIN {gmap_taxonomy_term} gt ON r.tid = gt.tid INNER JOIN {taxonomy_term_data} t ON r.tid = t.tid INNER JOIN {taxonomy_vocabulary} v ON t.vid = v.vid WHERE r.vid = :vid ORDER BY v.weight DESC, t.weight DESC, t.name DESC', array(':vid' => $node->vid));
if ($marker = db_fetch_object($markers)) {
function gmap_taxonomy_reassign_marker($tid, $deletion = FALSE) {
$nids = array();
if ($deletion) {
$result = db_query('SELECT nid FROM {gmap_taxonomy_node} WHERE tid = :tid', array(':tid' => $tid));
foreach ($result as $node) {
$nids[] = $node->nid;
}
}
else {
$result = db_query('SELECT nid FROM {taxonomy_index} WHERE tid = :tid', array(':tid' => $tid));
foreach ($result as $node) {
$nids[] = $node->nid;
}
}
foreach ($nids as $nid) {
$markers = db_query('SELECT t.tid, gt.marker FROM {taxonomy_index} r INNER JOIN {gmap_taxonomy_term} gt ON r.tid = gt.tid INNER JOIN {taxonomy_term_data} t ON r.tid = t.tid INNER JOIN {taxonomy_vocabulary} v ON t.vid = v.vid WHERE r.nid = :nid ORDER BY v.weight DESC, t.weight DESC, t.name DESC', array(':nid' => $nid));
if ($marker = $markers->fetchObject()) {
// Fallback found.
db_update('gmap_taxonomy_node')
->fields(array(
'tid' => $marker->tid,
'marker' => $marker->marker,
))
->condition('vid', $node->vid)
->condition('nid', $nid)
->execute();
}
else {
// No replacement marker, delete the row.
db_delete('gmap_taxonomy_node')
->condition('vid', $marker->vid)
->condition('nid', $nid)
->execute();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment