You are here

function lingotek_lingonode in Lingotek Translation 6

Same name and namespace in other branches
  1. 7.2 lingotek.util.inc \lingotek_lingonode()
  2. 7.3 lingotek.util.inc \lingotek_lingonode()
  3. 7.4 lingotek.util.inc \lingotek_lingonode()
12 calls to lingotek_lingonode()
lingotek_dequeue in ./lingotek.mt.inc
lingotek_dev_form in ./lingotek.dev.inc
lingotek_dev_submit in ./lingotek.dev.inc
lingotek_download_document in ./lingotek.api.inc
lingotek_event_complete in ./lingotek.util.inc

... See full list

File

./lingotek.util.inc, line 20
Utilities

Code

function lingotek_lingonode($nid, $key = "", $value = "") {
  if ($nid == 'all') {
    $lingo_node = array();
    $result = db_query('SELECT n.nid, n.lingokey, n.lingovalue FROM {lingotek} n');
    while ($row = db_fetch_object($result)) {
      $lingo_node[$row->nid][$row->lingokey] = check_plain($row->lingovalue);
    }
    return $lingo_node;
  }
  elseif (is_numeric($nid) && $nid) {

    //Return an array with all of the keys and values.
    if ($key == "") {
      $lingo_node = array();
      $result = db_query('SELECT n.lingokey, n.lingovalue FROM {lingotek} n WHERE n.nid = %d', $nid);
      while ($row = db_fetch_object($result)) {
        $lingo_node[$row->lingokey] = check_plain($row->lingovalue);
      }
      return $lingo_node;
    }
    elseif ($value == "") {
      $result = db_query("SELECT n.lingovalue FROM {lingotek} n WHERE n.nid = %d AND n.lingokey = '%s'", $nid, $key);
      $row = db_fetch_object($result);
      if ($row) {
        return check_plain($row->lingovalue);
      }
      else {
        return FALSE;
      }
    }
    else {

      //insert or update

      // Insert
      if (lingotek_lingonode($nid, $key) === FALSE) {
        db_query("INSERT INTO {lingotek} VALUES(%d, '%s', '%s')", $nid, $key, $value);
      }
      else {
        db_query("UPDATE {lingotek} SET lingovalue = '%s' WHERE nid = %d AND lingokey = '%s'", $value, $nid, $key);
      }
    }
  }
}