public function MatchingQuestion::save in Quiz 6.5
Same name and namespace in other branches
- 6.6 question_types/matching/matching.classes.inc \MatchingQuestion::save()
- 6.3 question_types/matching/matching.classes.inc \MatchingQuestion::save()
Responsible for handling insert/update of question-specific data. This is typically called from within the Node API, so there is no need to save the node. This function is only responsible for saving data specific to the implement ation.
The $is_new flag is set to TRUE whenever the node is being initially created.
A save function is required to handle the following three situations:
- A new node is created ($is_new is TRUE)
- A new node *revision* is created ($is_new is NOT set, because the node itself is not new).
- An existing node revision is modified.
Parameters
$is_new: TRUE when the node is initially created.
Overrides QuizQuestion::save
File
- question_types/
matching/ matching.classes.inc, line 30 - quiz_directions.classes
Class
- MatchingQuestion
- Implementation of Matching.
Code
public function save($is_new = FALSE) {
foreach ($this->node->match as $match) {
if (empty($match['question']) || empty($match['answer'])) {
continue;
}
$match['feedback'] = isset($match['feedback']) ? $match['feedback'] : '';
if ($is_new || $this->node->revision == 1) {
$sql = "INSERT INTO {quiz_matching_node} (nid, vid, question, answer, feedback) VALUES (%d, %d, '%s', '%s', '%s')";
db_query($sql, $this->node->nid, $this->node->vid, $match['question'], $match['answer'], $match['feedback']);
}
else {
//$match_id = $this->node->{'match_id_' . $i};
$sql = "UPDATE {quiz_matching_node} SET question = '%s', answer = '%s', feedback = '%s' WHERE match_id = %d";
db_query($sql, $match['question'], $match['answer'], $match['feedback'], $match['match_id']);
}
}
}