Example #1
0
        $name = $mform->get_new_filename('attachment');
        $random = rand();
        $name = $random . '_' . $name;
        $path = "{$CFG->dataroot}/webgd_community/{$name}";
        $msg = get_string('msgErro', 'block_webgd_community');
        if ($mform->save_file('attachment', $path, true)) {
            try {
                $transaction = $DB->start_delegated_transaction();
                $post = new stdClass();
                $post->community = $idCommunity;
                $post->userid = $USER->id;
                $post->time = time();
                $post->type = 'movie';
                $idPost = $webgdDao->insertRecordInTableCommunityPost($post);
                $arquivo = new stdClass();
                $arquivo->post = $idPost;
                $arquivo->name = $data->nome;
                $arquivo->path = $path;
                $webgdDao->insertRecordInTableCommunityMedia($arquivo);
                $transaction->allow_commit();
                $msg = 'Video Cadastrado com sucesso';
            } catch (Exception $e) {
                $transaction->rollback($e);
            }
        }
    }
    redirect("{$CFG->wwwroot}/blocks/webgd_community/view.php?community={$idCommunity}", $msg, 10);
} else {
    $mform->display();
}
echo $OUTPUT->footer();