You are here

function _quiz_delete_question in Quiz 7.6

Same name and namespace in other branches
  1. 8.6 question_types/quiz_question/quiz_question.module \_quiz_delete_question()
  2. 8.4 question_types/quiz_question/quiz_question.module \_quiz_delete_question()
  3. 8.5 question_types/quiz_question/quiz_question.module \_quiz_delete_question()
  4. 6.4 question_types/quiz_question/quiz_question.module \_quiz_delete_question()
  5. 7 question_types/quiz_question/quiz_question.module \_quiz_delete_question()
  6. 7.4 question_types/quiz_question/quiz_question.module \_quiz_delete_question()
  7. 7.5 question_types/quiz_question/quiz_question.module \_quiz_delete_question()

Delete the question node from the db, and mark its identifiers in the quiz linking table as "NEVER". This is safer than deleting them and allows for same tracing of what's happened if a question was deleted unintentionally.

Parameters

$node the question node:

$only_this_version whether to delete only the specific revision of the question:

2 calls to _quiz_delete_question()
quiz_question_delete in question_types/quiz_question/quiz_question.module
Implements hook_delete().
quiz_question_node_revision_delete in question_types/quiz_question/quiz_question.module
Implements hook_node_revision_delete().

File

question_types/quiz_question/quiz_question.module, line 505
Quiz Question module. This module provides the basic facilities for adding quiz question types to a quiz.

Code

function _quiz_delete_question($node, $only_this_version) {

  // let each question class delete its own stuff
  _quiz_question_get_instance($node, TRUE)
    ->delete($only_this_version);

  // FIXME QuizQuestion class makes these relationships, so it should handle their 'deletion' too
  // FIXME alternately, move the relationship handling out of QuizQuestion class
  // @todo reconsider this QUESTION_NEVER status, since the node is actually gone
  // then remove it from {quiz_node_relationship} linking table

  //$base_sql = "UPDATE {quiz_node_relationship} SET question_status = " . QUESTION_NEVER;
  $select_sql = 'SELECT parent_vid FROM {quiz_node_relationship}';
  if ($only_this_version) {
    $select_sql .= ' WHERE child_nid = :child_nid AND child_vid = :child_vid';
    $filter_arg = array(
      ':child_nid' => $node->nid,
      ':child_vid' => $node->vid,
    );
  }
  else {
    $select_sql .= ' WHERE child_nid = :child_nid';
    $filter_arg = array(
      ':child_nid' => $node->nid,
    );
  }

  //$res = db_query($select_sql . $filter_sql, $node->nid, $node->vid);
  $res = db_query($select_sql, $filter_arg);

  //db_query($base_sql . $filter_sql, $node->nid, $node->vid);
  $update = db_update('quiz_node_relationship')
    ->fields(array(
    'question_status' => QUIZ_QUESTION_NEVER,
  ))
    ->condition('child_nid', $node->nid);
  if ($only_this_version) {
    $update = $update
      ->condition('child_vid', $node->vid);
  }
  $update
    ->execute();
  $quizzes_to_update = array();
  while ($quizzes_to_update[] = $res
    ->fetchField()) {
  }
  quiz_update_max_score_properties($quizzes_to_update);
}