public function MatchingQuestion::saveNodeProperties in Quiz 7.5
Same name and namespace in other branches
- 6.4 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()
- 7.6 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()
- 7 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()
- 7.4 question_types/matching/matching.classes.inc \MatchingQuestion::saveNodeProperties()
Implementation of saveNodeProperties().
Overrides QuizQuestion::saveNodeProperties
See also
QuizQuestion::saveNodeProperties()
File
- question_types/
matching/ matching.classes.inc, line 36 - 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' => intval($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();
}
}
}
}