$communuty->userid = $USER->id; $communuty->timecreated = time(); $msg = get_string('msgErroComunidadeEdicao', 'block_webgd_community'); try { $transaction = $DB->start_delegated_transaction(); $msg = get_string('msgErroComunidadeRegistro', 'block_webgd_community'); if ($idCommunity = $DB->insert_record(TableResouces::$TABLE_PAGE_COMMUNITY, $communuty, true)) { $msg = get_string('msgComunidadeCadastradaSucesso', 'block_webgd_community'); } $users = optional_param_array('users', 0, PARAM_INT); foreach ($users as $idUser) { $communutyUser = new stdClass(); $communutyUser->community = $idCommunity; $communutyUser->admin = 0; $communutyUser->userid = $idUser; $DB->insert_record(TableResouces::$TABLE_PAGE_COMMUNITY_USER, $communutyUser); } //ADMIN $communutyUser->admin = 1; $communutyUser->userid = $USER->id; $DB->insert_record(TableResouces::$TABLE_PAGE_COMMUNITY_USER, $communutyUser); $transaction->allow_commit(); redirect($CFG->wwwroot . "/blocks/webgd_community/view.php?community={$idCommunity}", $msg, 10); } catch (Exception $e) { $transaction->rollback($e); redirect($CFG->wwwroot . '/blocks/webgd_community/module.php', $msg, 10); } } else { $mform->display(); } echo $OUTPUT->footer();