You are here

function _keyword_table in Glossify 6

Same name and namespace in other branches
  1. 6.3 glossify.module \_keyword_table()

Helper function that performs operations on the Glossify keyword-table and returns the new, old or removed values, depending on the operation.

3 calls to _keyword_table()
glossify_nodeapi in ./glossify.module
Implementation of hook_nodeapi().
_backwards_compatibility in ./glossify.module
Helper function that cleans up old variables and inserts old cck values into the keyword table.
_fetch_affected_keywords in ./glossify.module
Helper function that fetches and returns an array of all new and old keywords of a node, depending on the method.

File

./glossify.module, line 427

Code

function _keyword_table($operation, $nid, $method, $language = '', $term = '', $alternate = '') {
  switch ($operation) {
    case 'insert':
      $gnid = db_result(db_query("SELECT nid FROM {glossify} WHERE term = '%s' AND language = '%s'", $term, $language));
      $new_terms = array();
      if (!$gnid) {
        db_query("INSERT INTO {glossify} (nid, term, language, method, alternate) VALUES (%d, '%s', '%s', '%s', '%s')", $nid, $term, $language, $method, $alternate);
        $new_terms[$term] = $term;
      }
      else {
        $node = node_load($gnid);
        drupal_set_message(t("Keyword: '%term' already exists for <a href=\"/node/{$node->nid}\">%title</a>", array(
          '%term' => $term,
          '%title' => $node->title,
        )), 'warning');
      }
      return $new_terms;
      break;
    case 'update':
      $old_term = db_result(db_query("SELECT term FROM {glossify} WHERE nid = %d AND method = '%s'", $nid, 'title'));
      db_query("UPDATE {glossify} SET term = '%s', language = '%s', method = '%s' WHERE nid = %d AND method = '%s'", $term, $language, $method, $nid, 'title');
      return array(
        $old_term => $old_term,
      );
      break;
    case 'delete':
      $old_terms = array();
      if (!empty($term)) {
        $old_terms[$term] = $term;
        db_query("DELETE FROM {glossify} WHERE nid = %d AND method = '%s' AND language = '%s' AND term = '%s'", $nid, $method, $language, $term);
      }
      else {
        $q = db_query("SELECT term FROM {glossify} WHERE nid = %d AND method = '%s' ORDER BY term", $nid, $method);
        while ($r = db_fetch_array($q)) {
          $old_terms[$r['term']] = $r['term'];
        }
        db_query("DELETE FROM {glossify} WHERE nid = %d AND method = '%s'", $nid, $method);
      }
      return $old_terms;
      break;
  }
  return TRUE;
}