function quiz_admin_list_questions_ac in Quiz 6.6
Same name and namespace in other branches
- 6.3 quiz.admin.inc \quiz_admin_list_questions_ac()
- 6.5 quiz.admin.inc \quiz_admin_list_questions_ac()
Autocompletion function for quiz questions.
1 string reference to 'quiz_admin_list_questions_ac'
- quiz_menu in ./
quiz.module - Implementation of hook_menu().
File
- ./
quiz.admin.inc, line 440 - Administrator interface for Quiz module.
Code
function quiz_admin_list_questions_ac($vid, $string = '') {
$type_map = _quiz_get_question_types();
$values = array_keys($type_map);
$placeholder = db_placeholders($values, 'varchar');
$query = strtolower($string);
$sql = "SELECT n.nid, n.title, n.type\n FROM {node} n\n INNER JOIN {node_revisions} r ON n.vid = r.vid\n WHERE n.type IN ({$placeholder})\n AND n.status = 1\n AND (LOWER(n.title) LIKE '%%%s%%' OR LOWER(r.body) LIKE '%%%s%%')";
array_push($values, $query, $query);
$result = db_query_range(db_rewrite_sql($sql), $values, 0, 20);
$matches = array();
while ($node = db_fetch_object($result)) {
$type = $type_map[$node->type]['name'];
$key = sprintf('%s [type:%s, id:%d]', check_plain($node->title), check_plain($type), $node->nid);
$matches[$key] = $key;
}
drupal_json($matches);
}