You are here

function _quiz_delete_question in Quiz 8.5

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. 6.4 question_types/quiz_question/quiz_question.module \_quiz_delete_question()
  4. 7.6 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

stdClass $node: The question node.

bool $only_this_version: Whether to delete only the specific revision of the question.

1 call to _quiz_delete_question()
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 168
Quiz Question module.

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 ($quiz_to_update = $res
    ->fetchField()) {
    $quizzes_to_update[] = $quiz_to_update;
  }
  quiz_update_max_score_properties($quizzes_to_update);
}