function _quiz_categorized_update_terms in Quiz 7
Same name and namespace in other branches
- 8.4 quiz.admin.inc \_quiz_categorized_update_terms()
- 6.4 quiz.admin.inc \_quiz_categorized_update_terms()
- 7.6 quiz.admin.inc \_quiz_categorized_update_terms()
- 7.4 quiz.admin.inc \_quiz_categorized_update_terms()
- 7.5 quiz.admin.inc \_quiz_categorized_update_terms()
Update the categoriez belonging to a quiz with categorized random questions.
Helper function for quiz_categorized_form_submit
1 call to _quiz_categorized_update_terms()
- quiz_categorized_form_submit in ./
quiz.admin.inc - Submit the categorized form
File
- ./
quiz.admin.inc, line 688 - Administrator interface for Quiz module.
Code
function _quiz_categorized_update_terms(&$form, &$form_state) {
$ids = array(
'weight',
'max_score',
'number',
);
$changed = array();
$removed = array();
$num_questions = 0;
foreach ($form_state['values'] as $key => $existing) {
if (!is_numeric($key)) {
continue;
}
if (!$existing['remove']) {
$num_questions += $existing['number'];
}
foreach ($ids as $id) {
if ($existing[$id] != $form[$key][$id]['#default_value'] && !$existing['remove']) {
$existing['nid'] = $form_state['values']['nid'];
$existing['vid'] = $form_state['values']['vid'];
$existing['tid'] = $key;
$changed[] = $form[$key]['name']['#value'];
drupal_write_record('quiz_terms', $existing, array(
'vid',
'tid',
));
break;
}
elseif ($existing['remove']) {
db_delete('quiz_terms')
->condition('tid', $key)
->condition('vid', $form_state['values']['vid'])
->execute();
$removed[] = $form[$key]['name']['#value'];
break;
}
}
}
if (!empty($changed)) {
drupal_set_message(t('Updates were made for the following terms: %terms', array(
'%terms' => implode(', ', $changed),
)));
}
if (!empty($removed)) {
drupal_set_message(t('The following terms were removed: %terms', array(
'%terms' => implode(', ', $removed),
)));
}
return $num_questions;
}