You are here

function gmap_taxonomy_nodeapi in GMap Module 5

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

Implementation of hook_nodeapi().

File

./gmap_taxonomy.module, line 107
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 nid = %d', $node->nid);
      $status = variable_get('gmap_taxonomy_vocabs', array());
      $marker = '';
      if (isset($node->taxonomy) && is_array($node->taxonomy)) {
        foreach ($node->taxonomy as $voc => $terms) {
          if (isset($status[$voc]) && $status[$voc]) {
            $t = $terms;
            if (!is_array($t)) {
              $t = array(
                $t,
              );
            }
            foreach ($t as $term) {
              $result = db_query('SELECT marker, tid FROM {gmap_taxonomy_term} WHERE tid = %d', $term);
              if ($m = db_fetch_object($result)) {
                $marker = $m->marker;
                $markertid = $m->tid;
              }
            }
          }
        }
        if (!empty($marker)) {

          // There's an applicable taxonomy marker. Stash the association in the db.
          db_query("INSERT INTO {gmap_taxonomy_node} (nid, tid, marker) VALUES (%d, %d, '%s')", $node->nid, $markertid, $marker);
        }
      }
      break;
    case 'delete':
      db_query('DELETE FROM {gmap_taxonomy_node} WHERE nid = %d', $node->nid);
      break;
  }
}