private function ScaleQuestion::excistingCollection in Quiz 6.4
Same name and namespace in other branches
- 6.6 question_types/scale/scale.classes.inc \ScaleQuestion::excistingCollection()
- 7 question_types/scale/scale.classes.inc \ScaleQuestion::excistingCollection()
Finds out if a collection already exists.
Parameters
$alternatives: This is the collection that will be compared with the database.
$answer_collection_id: If we are matching a set of alternatives with a given collection that exists in the database.
$last_id - The id of the last alternative we compared with.:
Return value
TRUE if the collection exists FALSE otherwise
1 call to ScaleQuestion::excistingCollection()
- ScaleQuestion::saveAnswerCollection in question_types/
scale/ scale.classes.inc - Stores the answer collection to the database, or identifies an existing collection.
File
- question_types/
scale/ scale.classes.inc, line 207 - The main classes for the scale question type.
Class
- ScaleQuestion
- Extension of QuizQuestion.
Code
private function excistingCollection(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 = \'%s\'';
// Filter on collection id
if (isset($answer_collection_id)) {
$sql .= ' AND answer_collection_id = %d';
}
// 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 = %d';
}
$res = db_query($sql, array_pop($my_alts), $answer_collection_id, $last_id + 1);
if (!($res_o = db_fetch_object($res))) {
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) {
$sql = 'SELECT * FROM {quiz_scale_answer}
WHERE answer_collection_id = %d
AND id = %d';
$res_o2 = db_fetch_object(db_query($sql, $answer_collection_id, $last_id + 2));
return $res_o2 == FALSE ? $answer_collection_id : FALSE;
}
// Do a recursive call to this function on all answer collection candidates
do {
$col_id = $this
->excistingCollection($my_alts, $res_o->answer_collection_id, $res_o->id);
if ($col_id) {
return $col_id;
}
} while ($res_o = db_fetch_object($res));
return FALSE;
}