function CourseObjectAccessConditional::optionsForm in Course 6
Same name and namespace in other branches
- 7.2 plugins/course_object_access/conditional.inc \CourseObjectAccessConditional::optionsForm()
- 7 plugins/course_object_access/conditional.inc \CourseObjectAccessConditional::optionsForm()
Handlers can declare a form.
Overrides CourseHandler::optionsForm
File
- plugins/
course/ access/ conditional.inc, line 77
Class
Code
function optionsForm() {
$form = array();
$config = $this
->getOptions();
ctools_include('dependent');
$form['conditional_type'] = array(
'#title' => t('Event'),
'#type' => 'select',
'#options' => array(
'',
'started' => t('User started course object.'),
'completed' => t('User completed course object.'),
),
'#description' => t('This sets the conditional behavior.'),
);
$options = array(
'',
);
foreach ($this
->getCourseObject()
->getCourse()
->getObjects() as $courseObject) {
$options[$courseObject
->getId()] = $courseObject
->getTitle();
}
if (module_exists('duration_element')) {
$conditional_time = duration_create();
$conditional_time
->set_seconds($config['conditional_time']);
$conditional_time
->normalize();
$form['conditional_time'] = array(
'#title' => t('Time'),
'#type' => 'duration_combo',
'#description' => t('Length of time after the event happens when this course object should be accessible.'),
'#largest_metric' => 'days',
'#smallest_metric' => 'minutes',
'#default_value' => $conditional_time,
);
}
else {
$form['conditional_time'] = array(
'#title' => t('Time'),
'#type' => 'textfield',
'#size' => 8,
'#description' => t('Length of time in seconds after the event happens when this course object should be accessible.'),
'#default_value' => $config['conditional_time'],
);
}
$form['conditional_object'] = array(
'#title' => t('Course object'),
'#type' => 'select',
'#options' => $options,
'#description' => t('The course object to check for the type and time of conditional display.'),
);
$form['conditional_hidden'] = array(
'#title' => t('Hide object until ready'),
'#type' => 'checkbox',
'#description' => t('This will prevent the course object from appearing in the course outline until it is ready.'),
);
$conditional_dependent = array(
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-plugins-access-conditional-conditional-type' => array(
'completed',
'started',
),
),
);
foreach (element_children($form) as $key) {
if ($key != 'conditional_time') {
$form[$key]['#default_value'] = $config[$key];
}
if ($key != 'conditional_type' && $key != 'conditional_time') {
$form[$key] += $conditional_dependent;
}
}
return $form;
}