private function ScaleQuestion::existingCollection in Quiz 7.5
Same name and namespace in other branches
- 8.6 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleQuestion.php \ScaleQuestion::existingCollection()
- 8.5 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleQuestion.php \ScaleQuestion::existingCollection()
- 7.6 question_types/scale/scale.classes.inc \ScaleQuestion::existingCollection()
- 7.4 question_types/scale/scale.classes.inc \ScaleQuestion::existingCollection()
Finds out if a collection already exists.
Parameters
array $alternatives: This is the collection that will be compared with the database.
int $answer_collection_id: If we are matching a set of alternatives with a given collection that exists in the database.
int $last_id: The id of the last alternative we compared with.
Return value
bool TRUE if the collection exists, FALSE otherwise.
1 call to ScaleQuestion::existingCollection()
- ScaleQuestion::saveAnswerCollection in question_types/
scale/ scale.classes.inc - Stores|Identifies the answer collection.
File
- question_types/
scale/ scale.classes.inc, line 238 - Scale classes.
Class
- ScaleQuestion
- Extension of QuizQuestion.
Code
private function existingCollection(array $alternatives, $answer_collection_id = NULL, $last_id = NULL) {
$my_alts = isset($answer_collection_id) ? $alternatives : array_reverse($alternatives);
// Find all answers identical to the next answer in $alternatives.
$sql = 'SELECT id, answer_collection_id FROM {quiz_scale_answer} WHERE answer = :answer';
$args[':answer'] = array_pop($my_alts);
// Filter on collection id.
if (isset($answer_collection_id)) {
$sql .= ' AND answer_collection_id = :acid';
$args[':acid'] = $answer_collection_id;
}
// Filter on alternative id (If we are investigating a specific
// collection, the alternatives needs to be in a correct order).
if (isset($last_id)) {
$sql .= ' AND id = :id';
$args[':id'] = $last_id + 1;
}
$res = db_query($sql, $args);
if (!($res_o = $res
->fetch())) {
return FALSE;
}
/*
* If all alternatives has matched make sure the collection we are
* comparing against in the database doesn't have more alternatives.
*/
if (count($my_alts) == 0) {
$res_o2 = db_query('SELECT * FROM {quiz_scale_answer}
WHERE answer_collection_id = :answer_collection_id
AND id = :id', array(
':answer_collection_id' => $answer_collection_id,
':id' => $last_id + 2,
))
->fetch();
return $res_o2 ? FALSE : $answer_collection_id;
}
// Do a recursive call to this function on all answer collection candidates.
do {
$col_id = $this
->existingCollection($my_alts, $res_o->answer_collection_id, $res_o->id);
if ($col_id) {
return $col_id;
}
} while ($res_o = $res
->fetch());
return FALSE;
}