function scale_manage_collection_form in Quiz 7.6
Same name and namespace in other branches
- 8.6 question_types/quiz_scale/quiz_scale.module \scale_manage_collection_form()
- 8.4 question_types/scale/scale.module \scale_manage_collection_form()
- 8.5 question_types/quiz_scale/quiz_scale.module \scale_manage_collection_form()
- 6.6 question_types/scale/scale.module \scale_manage_collection_form()
- 6.4 question_types/scale/scale.module \scale_manage_collection_form()
- 7 question_types/scale/scale.module \scale_manage_collection_form()
- 7.4 question_types/scale/scale.module \scale_manage_collection_form()
- 7.5 question_types/scale/scale.module \scale_manage_collection_form()
Form for changing and deleting the current users preset answer collections.
Users with the Edit global presets permissions can also add new global presets here.
Parameters
$form_state:
Return value
form
1 string reference to 'scale_manage_collection_form'
- scale_menu in question_types/
scale/ scale.module - Implements hook_menu().
File
- question_types/
scale/ scale.module, line 167 - The main file for scale.
Code
function scale_manage_collection_form($form, &$form_state) {
global $user;
$edit_globals_access = user_access('Edit global presets');
// We create an instance of ScaleQuestion. We want to use some of its methods.
$scale_question = new ScaleQuestion(new stdClass());
$collections = $scale_question
->getPresetCollections($edit_globals_access);
// If user is allowed to edit global answer collections he is also allowed to add new global presets
if ($edit_globals_access) {
$new_col = new stdClass();
$new_col->for_all = 1;
$new_col->name = t('New global collection(available to all users)');
$collections['new'] = $new_col;
}
$form = array();
if (count($collections) == 0) {
$form['no_col'] = array(
'#markup' => t("You don't have any preset collections."),
);
return $form;
}
// Populate the form
foreach ($collections as $col_id => $obj) {
$form["collection{$col_id}"] = array(
'#type' => 'fieldset',
'#title' => $collections[$col_id]->name,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'scale_manage_collection_form',
);
$alternatives = isset($collections[$col_id]->alternatives) ? $collections[$col_id]->alternatives : array();
for ($i = 0; $i < variable_get('scale_max_num_of_alts', 10); $i++) {
$form["collection{$col_id}"]["alternative{$i}"] = array(
'#title' => t('Alternative !i', array(
'!i' => $i + 1,
)),
'#size' => 60,
'#maxlength' => 256,
'#type' => 'textfield',
'#default_value' => isset($alternatives[$i]) ? $alternatives[$i] : '',
'#required' => $i < 2 && $col_id != 'new',
);
}
if ($col_id != 'new') {
if ($edit_globals_access) {
$form["collection{$col_id}"]['for_all'] = array(
'#type' => 'checkbox',
'#title' => t('Available to all users'),
'#default_value' => $collections[$col_id]->for_all,
);
}
$form["collection{$col_id}"]['to-do'] = array(
'#type' => 'radios',
'#title' => t('What will you do?'),
'#default_value' => '0',
'#options' => array(
t('Save changes, do not change questions using this preset'),
t('Save changes, and change your own questions who uses this preset'),
t('Delete this preset(This will not affect existing questions)'),
),
);
}
else {
$form["collection{$col_id}"]["to-do"] = array(
'#type' => 'value',
'#value' => 3,
);
$form["collection{$col_id}"]["for_all"] = array(
'#type' => 'value',
'#value' => 1,
);
}
}
$form['process'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
$form['#submit'][] = 'scale_collection_form_submit';
if ($edit_globals_access) {
$form['#validate'][] = 'scale_collection_form_validate';
}
$form['#tree'] = TRUE;
return $form;
}