You are here

public function MatchingQuestion::saveNodeProperties in Quiz 8.4

Implementation of saveNodeProperties

Overrides QuizQuestion::saveNodeProperties

See also

QuizQuestion#saveNodeProperties($is_new)

File

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

Class

MatchingQuestion
Extension of QuizQuestion.

Namespace

Drupal\matching

Code

public function saveNodeProperties($is_new = FALSE) {

  // Loop through each question-answer combination
  foreach ($this->node->match as $match) {
    $match['feedback'] = isset($match['feedback']) ? $match['feedback'] : '';

    // match_id is not so it is a new question.
    if (empty($match['match_id']) || $this->node
      ->isNewRevision()) {
      if (!empty($match['question']) && !empty($match['answer'])) {
        $sql = "INSERT INTO {quiz_matching_node} (nid, vid, question, answer, feedback) VALUES (%d, %d, '%s', '%s', '%s')";

        // TODO Please review the conversion of this statement to the D7 database API syntax.

        /* db_query($sql, $this->node->id(), $this->node->getRevisionId(), $match['question'], $match['answer'], $match['feedback']) */
        $id = db_insert('quiz_matching_node')
          ->fields(array(
          'nid' => $this->node
            ->id(),
          'vid' => $this->node
            ->getRevisionId(),
          'question' => $match['question'],
          'answer' => $match['answer'],
          'feedback' => $match['feedback'],
        ))
          ->execute();
      }
    }
    else {
      if (empty($match['question']) && empty($match['answer'])) {

        // remove sub question.
        // TODO Please review the conversion of this statement to the D7 database API syntax.

        /* db_query("DELETE FROM {quiz_matching_node} WHERE match_id = %d", $match['match_id']) */
        db_delete('quiz_matching_node')
          ->condition('match_id', $match['match_id'])
          ->execute();
      }
      else {

        // update sub question.

        //$sql = "UPDATE {quiz_matching_node} SET question = '%s', answer = '%s', feedback = '%s' WHERE match_id = %d";

        // TODO Please review the conversion of this statement to the D7 database API syntax.

        /* db_query($sql, $match['question'], $match['answer'], $match['feedback'], $match['match_id']) */
        db_update('quiz_matching_node')
          ->fields(array(
          'question' => $match['question'],
          'answer' => $match['answer'],
          'feedback' => $match['feedback'],
        ))
          ->condition('match_id', $match['match_id'])
          ->execute();
      }
    }
  }
}