You are here

function gmap_taxonomy_nodeapi in GMap Module 6.2

Same name and namespace in other branches
  1. 5 gmap_taxonomy.module \gmap_taxonomy_nodeapi()
  2. 6 gmap_taxonomy.module \gmap_taxonomy_nodeapi()

Implementation of hook_nodeapi().

File

./gmap_taxonomy.module, line 121
GMap Taxonomy Markers

Code

function gmap_taxonomy_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'insert':
    case 'update':

      // Remove the marker association if present. We'll readd it later if it's
      // still applicable.
      db_query('DELETE FROM {gmap_taxonomy_node} WHERE vid = %d', $node->vid);
      $status = variable_get('gmap_taxonomy_vocabs', array());
      $marker = '';
      if (isset($node->taxonomy) && is_array($node->taxonomy)) {
        foreach ($node->taxonomy as $tid => $term) {
          if (isset($status[$term->vid]) && $status[$term->vid]) {
            $result = db_query('SELECT marker, tid FROM {gmap_taxonomy_term} WHERE tid = %d', $tid);
            if ($m = db_fetch_object($result)) {
              $marker = $m->marker;
              $markertid = $tid;
              if (!empty($marker)) {
                db_query("INSERT INTO {gmap_taxonomy_node} (nid, vid, tid, marker) VALUES (%d, %d, %d, '%s')", $node->nid, $node->vid, $markertid, $marker);
              }
            }
          }
        }
      }
      break;
    case 'delete':
      db_query('DELETE FROM {gmap_taxonomy_node} WHERE nid = %d', $node->nid);
      break;
    case 'delete revision':
      db_query('DELETE FROM {gmap_taxonomy_node} WHERE vid = %d', $node->vid);
      break;
  }
}