You are here

public function MatchingQuestion::saveNodeProperties in Quiz 7.6

Same name and namespace in other branches
  1. 6.4 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()
  2. 7 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()
  3. 7.4 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()
  4. 7.5 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()

Implementation of saveNodeProperties

Overrides QuizQuestion::saveNodeProperties

See also

QuizQuestion#saveNodeProperties($is_new)

File

question_types/matching/matching.classes.inc, line 37
matching.classes

Class

MatchingQuestion
Extension of QuizQuestion.

Code

public function saveNodeProperties($is_new = FALSE) {

  // Update or insert the question properties
  db_merge('quiz_matching_properties')
    ->key(array(
    'nid' => $this->node->nid,
    'vid' => $this->node->vid,
  ))
    ->fields(array(
    'choice_penalty' => $this->node->choice_penalty,
  ))
    ->execute();

  // 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 ($is_new || empty($match['match_id']) || $this->node->revision || isset($this->node->node_export_drupal_version)) {
      if (!empty($match['question']) && !empty($match['answer'])) {
        $id = db_insert('quiz_matching_node')
          ->fields(array(
          'nid' => $this->node->nid,
          'vid' => $this->node->vid,
          'question' => $match['question'],
          'answer' => $match['answer'],
          'feedback' => $match['feedback'],
        ))
          ->execute();
      }
    }
    else {
      if (empty($match['question']) && empty($match['answer'])) {

        // remove sub question.
        db_delete('quiz_matching_node')
          ->condition('match_id', $match['match_id'])
          ->execute();
      }
      else {

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