You are here

public function MatchingQuestion::delete in Quiz 8.4

Implementation of delete

Overrides QuizQuestion::delete

See also

QuizQuestion#delete($only_this_version)

File

question_types/matching/lib/Drupal/matching/MatchingQuestion.php, line 122
The main classes for the matching question type.

Class

MatchingQuestion
Extension of QuizQuestion.

Namespace

Drupal\matching

Code

public function delete($only_this_version = FALSE) {
  parent::delete($only_this_version);
  if ($only_this_version) {
    $match_id = db_query('SELECT match_id FROM {quiz_matching_node} WHERE nid = :nid AND vid = :vid', array(
      ':nid' => $this->node
        ->id(),
      ':vid' => $this->node
        ->getRevisionId(),
    ))
      ->fetchCol();
    db_delete('quiz_matching_user_answers')
      ->condition('match_id', is_array($match_id) ? $match_id : array(
      0,
    ), 'IN')
      ->execute();
    db_delete('quiz_matching_node')
      ->condition('nid', $this->node
      ->id())
      ->condition('vid', $this->node
      ->getRevisionId())
      ->execute();
  }
  else {
    $match_id = db_query('SELECT match_id FROM {quiz_matching_node} WHERE nid = :nid', array(
      ':nid' => $this->node
        ->id(),
    ))
      ->fetchCol();
    db_delete('quiz_matching_user_answers')
      ->condition('match_id', is_array($match_id) ? $match_id : array(
      0,
    ), 'IN')
      ->execute();
    db_delete('quiz_matching_node')
      ->condition('nid', $this->node
      ->id())
      ->execute();
  }
}