You are here

function answers_nodeapi in Answers 5.2

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

File

./answers.module, line 186
Enables the creation of question nodes that can be answered by posting answer nodes.

Code

function answers_nodeapi(&$node, $op, $teaser, $page) {
  global $user;
  switch ($op) {
    case "insert":
      if (variable_get(ANSWERS_TYPE . $node->type, '0')) {
        if ($node->questid) {
          db_query("INSERT INTO {answers} (qid, nid, uid, Status, relationscore) VALUES ('%d', '{$node->nid}', '{$node->uid}', '%d', '%d')", $node->questid, 0, 0);
          $questnode = node_load($node->questid);
          if ($questnode->notifyme) {
            answers_notify($node->questid, $questnode->title);
          }
        }
      }
      break;
    case "update":
      if (variable_get(ANSWERS_TYPE . $node->type, '0')) {
        if ($node->questid) {
          db_query("UPDATE {answers} SET qid = '%d' WHERE nid = '%d' AND uid = '%d'", $node->questid, $node->nid, $user->uid);
        }
      }
      break;
    case "delete":
      if (variable_get(ANSWERS_TYPE . $node->type, '0')) {
        db_query('DELETE FROM {answers} WHERE nid = %d', $node->nid);
      }
      break;
  }
}