HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/teamdemo.sports-crowd.com/app/Http/Controllers/SeasonsController.php
<?php

namespace App\Http\Controllers;

use DataTables;
use App\Season;
use Illuminate\Http\Request;

class SeasonsController extends Controller
{
    public function index($tournament_id)
    {
        return view('seasons.list', compact('tournament_id'));
    }

    public function create($tournament_id)
    {
        return view('seasons.create', compact('tournament_id'));
    }

    public function store(Request $request)
    {
        if (!Season::where('name', $request->input('name'))->first()) {
            if (Season::create($request->all())) {
                return response(array("r" => true, "type" => "success", "title" => "", "m" => __('messages.created_successfully'), "data" => null));
            } else {
                return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.error_creating'), "data" => null));
            }
        } else {
            return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.already_exists', ['name' => $request->input('name')]), "data" => null));
        }
    }

    public function show($id)
    {
        return redirect()->back();
    }

    public function edit($season_id, $tournament_id)
    {
        $season = Season::findOrFail($season_id);
        return view('seasons.edit', compact('season', 'tournament_id'));
    }

    public function update(Request $request, $id)
    {
        if (!Season::where([['id', '!=', $id], ['name', $request->input('name')]])->first()) {
            if (Season::where('id', $id)->update(array_slice($request->except('logo'), 1))) {
                return response(array("r" => true, "type" => "success", "title" => "", "m" => __('messages.updated_successfully'), "data" => null));
            } else {
                return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.error_updating'), "data" => null));
            }
        } else {
            return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.already_exists', ['name' => $request->input('name')]), "data" => null));
        }
    }

    public function destroy($season_id)
    {
        try {
            if (Season::where('id', $season_id)->delete()) {
                return response(array("r" => true, "type" => "success", "title" => "", "m" => __('messages.deleted_successfully'), "data" => null));
            } else {
                return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.error_removing'), "data" => null));
            }
        } catch (\Illuminate\Database\QueryException $e) {
            return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.delete_relation_data'), "data" => null));
        }
    }

    public function tableFilter($tournament_id)
    {
        $obj = Season::select('id', 'name', 'start', 'end', 'is_suscription', 'tournament_id', 'active')
            ->with('tournament')
            ->where('tournament_id', $tournament_id);

        return DataTables::of($obj)
            ->addColumn('actions', function ($obj) {
                if ($this->validateRolePermissions('ticketing', 'administrator') || $this->validateRolePermissions('ticketing', 'supervisor'))
                    return '
                            <i class="fa fa-soccer-ball-o iconMini" onClick="goToEvents(' . $obj->id . ')" data-id="' . $obj->id . '" data-toggle="tooltip" title="Eventos" data-placement="bottom"  style="cursor:pointer;"></i>
                            <i class="fa fa-pencil iconMini" onClick="clickEdit(' . $obj->id . ', ' . $obj->tournament_id . ')" data-id="' . $obj->id . '" data-toggle="tooltip" data-placement="bottom"  style="cursor:pointer;"></i>
                            <i class="fa fa-trash iconMini" onClick="clickDelete(' . $obj->id . ', ' . $obj->tournament_id . ')" data-id="' . $obj->id . '" data-toggle="tooltip" data-placement="bottom"  style="cursor:pointer;"></i>
                            ';
                else if ($this->validateRolePermissions('ticketing', 'seller'))
                    return '<i class="fa fa-soccer-ball-o iconMini" onClick="goToEvents(' . $obj->id . ')" data-id="' . $obj->id . '" data-toggle="tooltip" title="Eventos" data-placement="bottom"  style="cursor:pointer;"></i>';
                else
                    return '';
            })
            ->editColumn('is_suscription', function ($obj) {
                if ($this->validateRolePermissions('ticketing', 'administrator') || $this->validateRolePermissions('ticketing', 'supervisor'))
                    if ($obj->is_suscription == 0) {
                        return '<div class="switch"><label><div class="checkbox checbox-switch switch-success"> <label> ' . __('messages.no') . ' <input type="checkbox" onChange="chk_suscription(' . $obj->id . ')" data-id="' . $obj->id . '" id="check_is_suscription' . $obj->id . '" name="check_is_suscription" /> <span></span>' . __('messages.yes') . ' </label></div> </label> </div>';
                    } else {
                        return '<div class="switch"><label> <div class="checkbox checbox-switch switch-success"> <label>   ' . __('messages.no') . ' <input type="checkbox" onChange="chk_suscription(' . $obj->id . ')" data-id="' . $obj->id . '" id="check_is_suscription' . $obj->id . '" name="check_is_suscription" checked="" /> <span></span> ' . __('messages.yes') . ' </label> </div>  </label> </div>';
                    }
                else
                    return $obj->is_suscription ? 'SI' : 'NO';
            })
            ->editColumn('active', function ($obj) {
                if ($this->validateRolePermissions('ticketing', 'administrator') || $this->validateRolePermissions('ticketing', 'supervisor'))
                    if ($obj->active == 0) {
                        return '<div class="switch"><label><div class="checkbox checbox-switch switch-success"> <label> ' . __('messages.no') . ' <input type="checkbox" onChange="chk(' . $obj->id . ')" data-id="' . $obj->id . '" id="Checkactive' . $obj->id . '" name="Checkactivo" /> <span></span>' . __('messages.yes') . ' </label></div> </label> </div>';
                    } else {
                        return '<div class="switch"><label> <div class="checkbox checbox-switch switch-success"> <label>   ' . __('messages.no') . ' <input type="checkbox" onChange="chk(' . $obj->id . ')" data-id="' . $obj->id . '" id="Checkactive' . $obj->id . '" name="Checkactivo" checked="" />
                                <span></span> ' . __('messages.yes') . ' </label> </div>  </label> </div>';
                    }
                else
                    return $obj->active ? 'SI' : 'NO';
            })
            ->editColumn('start', function ($obj) {
                return $obj->start ? \Carbon\Carbon::parse($obj->start)->format('Y-m-d h:i:s A') : '';
            })
            ->editColumn('end', function ($obj) {
                return $obj->end ? \Carbon\Carbon::parse($obj->end)->format('Y-m-d h:i:s A') : '';
            })
            ->rawColumns(['is_suscription', 'active', 'actions'])
            ->make(true);
    }

    public function activate(Request $request)
    {
        try {
            $id = $request['id'];
            $state = $request['state'];

            $season = Season::find($id);
            $season->active = $state;
            $season->update();

            return array('r' => true, 'd' => null, 'm' => __('messages.updated_successfully'));
        } catch (\Throwable $th) {
            return array('r' => false, 'd' => null, 'm' => __('messages.error_updating'));
        }
    }

    public function suscription(Request $request)
    {
        try {
            $id = $request['id'];
            $state = $request['state'];

            $season = Season::find($id);
            $season->is_suscription = $state;
            $season->update();
            return array('r' => true, 'd' => null, 'm' => __('messages.updated_successfully'));
        } catch (\Throwable $th) {
            return array('r' => false, 'd' => null, 'm' => __('messages.error_updating'));
        }
    }
}