%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /mnt/tnb2/git/loslex/app/Http/Controllers/
Upload File :
Create Path :
Current File : //mnt/tnb2/git/loslex/app/Http/Controllers/ContestController.php

<?php

namespace App\Http\Controllers;

use App\Http\Requests\ContestUpdateRequest;
use App\Models\Contest;
use App\Models\ContestCategory;
use App\Models\ContestDivision;
use App\Models\ContestLevel;
use App\Models\Range;
use App\Models\User;
use App\Workers\RegistrationExporter;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Illuminate\View\View;

class ContestController extends Controller
{
    /* Display a listing of the resource. */
    public function index(Request $request) : View
    {
        return view('contests.list', [
            'contests' => Contest::orderBy('date')->get(),
        ]);
    }

    /* Display the specified resource. */
    public function show(Contest $contest) : View
    {
        return view('contests.show', [
            'contest' => $contest,
            'user' => Auth::user(),
        ]);
    }

    /* Show the form for creating a new resource. */
    public function create(Request $request) : View
    {
        return view('contests.edit', [
            'contest' => null,
            'ranges' => Range::where('is_active', 1)->orderBy('name')->get(),
            'orggroups' => Auth::user()->organizer_groups,
            'organizators' => User::get(),
            'contestlevels' => ContestLevel::where('is_active', 1)->get(),
            'contestcategories' => ContestCategory::where('is_active', 1)->get(),
        ]);
    }

    /* Show the form for editing the specified resource. */
    public function edit(Contest $contest): View
    {
        return view('contests.edit', [
            'contest' => $contest,
            'ranges' => Range::orderBy('name')->get(),
            'orggroups' => Auth::user()->organizer_groups,
            'organizators' => User::get(),
        ]);
    }

    public function maintain(Contest $contest): View
    {
        return view('contests.maintain', [
            'contest' => $contest,
            'users' => User::get(),
        ]);
    }

    /* Toggle publish status of the contest */
    public function publish(Contest $contest): RedirectResponse
    {
        $contest->published = !$contest->published;
        $contest->save();

        return back();
    }

    /* Store a newly created resource in storage. */
    public function store(ContestUpdateRequest $request): RedirectResponse
    {
        $contestData = new Contest;
        $contestData->fill($request->validated());
        $contestData->fillSettings($request);
        $contestData->psmatchguid = Str::uuid();

        $contest = $contestData->save();
        return redirect(route('contest.show', $contestData->id));
    }

    /* Update the specified resource in storage. */
    public function update(ContestUpdateRequest $request, Contest $contest): RedirectResponse
    {
        $contest->fill($request->validated());
        $contest->fillSettings($request);

        $contest->save();
        return redirect(route('contest.show', $contest->id));
    }

    /* Remove the specified resource from storage. */
    public function destroy(Contest $contest)
    {
    }

    /* Calls ExportRegistration model class to create export and returns finalized file */
    public function export(Contest $contest, string $type)
    {
        $regExport = new RegistrationExporter($contest, $type);

        return Storage::disk('contests')->download($regExport->filename);
        // return Storage::disk('contests')->get($regExport->filename);
    }
}

Zerion Mini Shell 1.0