$transaction = $DB->start_delegated_transaction(); if ($notice != null) { $todb->id = $notice->id; $DB->update_record('facetoface_notice', $todb); } else { $notice = new stdClass(); $notice->id = $DB->insert_record('facetoface_notice', $todb); } foreach ($customfields as $field) { $fieldname = "custom_$field->shortname"; if (empty($fromform->$fieldname)) { $fromform->$fieldname = ''; // need to be able to clear fields } facetoface_save_customfield_value($field->id, $fromform->$fieldname, $notice->id, 'notice'); } $transaction->allow_commit(); redirect($returnurl); } else if ($notice != null) { // Edit mode // Set values for the form $toform = new stdClass(); $toform->name = $notice->name; $toform->text['text'] = $notice->text; foreach ($customfields as $field) { $fieldname = "custom_$field->shortname"; $toform->$fieldname = facetoface_get_customfield_value($field, $notice->id, 'notice'); }
$transaction->force_transaction_rollback(); // Logging and events trigger. $params = array('context' => $modulecontext, 'objectid' => $facetoface->id); $event = \mod_facetoface\event\add_session_failed::create($params); $event->add_record_snapshot('facetoface', $facetoface); $event->trigger(); print_error('error:couldnotaddsession', 'facetoface', $returnurl); } } foreach ($customfields as $field) { $fieldname = "custom_{$field->shortname}"; if (!isset($fromform->{$fieldname})) { $fromform->{$fieldname} = ''; // Need to be able to clear fields. } if (!facetoface_save_customfield_value($field->id, $fromform->{$fieldname}, $sessionid, 'session')) { $transaction->force_transaction_rollback(); print_error('error:couldnotsavecustomfield', 'facetoface', $returnurl); } } // Save trainer roles. if (isset($fromform->trainerrole)) { facetoface_update_trainers($sessionid, $fromform->trainerrole); } // Retrieve record that was just inserted/updated. if (!($session = facetoface_get_session($sessionid))) { $transaction->force_transaction_rollback(); print_error('error:couldnotfindsession', 'facetoface', $returnurl); } // Update calendar entries. facetoface_update_calendar_entries($session, $facetoface);