function course_outline_overview_form_submit in Course 6
Same name and namespace in other branches
- 7.2 includes/course.outline.inc \course_outline_overview_form_submit()
- 7 includes/course.outline.inc \course_outline_overview_form_submit()
Submit handler.
1 string reference to 'course_outline_overview_form_submit'
- course_outline_overview_form in includes/
course.outline.inc - Form constructor for course outline form.
File
- includes/
course.outline.inc, line 348 - course_outline.inc
Code
function course_outline_overview_form_submit(&$form, &$form_state) {
$node = node_load($form['nid']['#value']);
// Get form state values for object elements on the course outline overview:
// - An associative array of course objects, keyed by ID. The ID for already
// saved objects is {course_outline}.coid, but for AHAH created objects the
// key is a generated unique ID until save.
// - coid: The key loaded from the database. If empty, the object is new.
// - module: The implementing module name (course_quiz etc).
// - object_type: The course object key as defined by
// hook_course_handlers().
$objects = $form_state['values']['course_outline']['objects'];
// Sort by weight so we can renumber.
uasort($objects, '_course_outline_overview_form_cmp_function');
$i = -50;
foreach ($objects as $object_key => $object) {
// Get each course object settings saved form values, which are not on the
// outline overview form.
if (!($courseObject = course_get_course_object_by_id($object_key))) {
// For non-JS, no settings have been saved. We have to construct a new
// course object.
$courseObject = course_get_course_object($object);
}
$options = $courseObject
->getOptions();
// Renumber weights to the way draggable table would do it in case of no JS.
$courseObject
->setOption('weight', $i++);
// We only save overview objects with a selected component, whether loaded
// from the database or AHAH created.
if (isset($object['object_type'])) {
// Delete database loaded objects that are on the chopping block.
$is_loaded = $object['coid'];
if ($options['delete'] && $is_loaded) {
if ($options['delete_instance']) {
// Also delete related object instance(s) if specified.
$courseObject
->delete();
}
course_outline_delete_object($object);
}
elseif (!$options['delete']) {
// If we get this far, save the object.
$courseObject
->save();
}
}
}
// Clear the editing session.
unset($_SESSION['course'][$node->nid]['editing']);
drupal_set_message('Updated course.');
// @todo use form #redirect instead of drupal_goto()?
drupal_goto("node/{$node->nid}/course-outline");
}