public function ScaleQuestion::getPresetCollections in Quiz 6.4
Same name and namespace in other branches
- 8.6 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleQuestion.php \ScaleQuestion::getPresetCollections()
- 8.5 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleQuestion.php \ScaleQuestion::getPresetCollections()
- 6.6 question_types/scale/scale.classes.inc \ScaleQuestion::getPresetCollections()
- 7.6 question_types/scale/scale.classes.inc \ScaleQuestion::getPresetCollections()
- 7 question_types/scale/scale.classes.inc \ScaleQuestion::getPresetCollections()
- 7.4 question_types/scale/scale.classes.inc \ScaleQuestion::getPresetCollections()
- 7.5 question_types/scale/scale.classes.inc \ScaleQuestion::getPresetCollections()
Get all available presets for the current user.
Parameters
$with_defaults:
Return value
array holding all the preset collections as an array of objects. each object in the array has the following properties: ->alternatives(array) ->name(string) ->for_all(int, 0|1)
1 call to ScaleQuestion::getPresetCollections()
- ScaleQuestion::getCreationForm in question_types/
scale/ scale.classes.inc - Implementation of getCreationForm
File
- question_types/
scale/ scale.classes.inc, line 414 - The main classes for the scale question type.
Class
- ScaleQuestion
- Extension of QuizQuestion.
Code
public function getPresetCollections($with_defaults = FALSE) {
global $user;
$collections = array();
// array holding data for each collection
$scale_element_names = array();
$sql = 'SELECT DISTINCT ac.id AS answer_collection_id, a.answer, ac.for_all
FROM {quiz_scale_user} au
JOIN {quiz_scale_answer_collection} ac ON(au.answer_collection_id = ac.id)
JOIN {quiz_scale_answer} a ON(a.answer_collection_id = ac.id)
WHERE au.uid = %d';
if ($with_defaults) {
$sql .= ' OR ac.for_all = 1';
}
$sql .= ' ORDER BY au.answer_collection_id, a.id';
$res = db_query($sql, $user->uid);
$col_id = NULL;
// Populate the $collections array
while (true) {
if (!($res_o = db_fetch_object($res)) || $res_o->answer_collection_id != $col_id) {
/*
* We have gone through all elements for one answer collection,
* and needs to store the answer collection name and id in the options array...
*/
if (isset($col_id)) {
$num_scale_elements = count($collections[$col_id]->alternatives);
$collections[$col_id]->name = check_plain($collections[$col_id]->alternatives[0] . ' - ' . $collections[$col_id]->alternatives[$num_scale_elements - 1] . ' (' . $num_scale_elements . ')');
}
// Break the loop if there are no more answer collections to process
if (!$res_o) {
break;
}
// Init the next collection in the $collections array
$col_id = $res_o->answer_collection_id;
if (!isset($collections[$col_id])) {
$collections[$col_id] = new stdClass();
$collections[$col_id]->alternatives = array();
$collections[$col_id]->for_all = $res_o->for_all;
}
}
$collections[$col_id]->alternatives[] = check_plain($res_o->answer);
}
return $collections;
}