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/agile-selling-wpb/app/Http/Controllers/MatchEventsController.php
<?php

namespace App\Http\Controllers;

use DataTables;
use App\Team;
use App\Ticket;
use App\MatchEvent;
use App\Tournament;
use Illuminate\Http\Request;

class MatchEventsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('matchevents.list');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $tournaments = Tournament::where('active', true)->orderBy('name','asc')->get();
        $teams = Team::where([['is_main', false],['active', true]])->orderBy('name','asc')->get();
        $team_main = Team::where([['is_main', true],['active', true]])->first();
        return view('matchevents.create', compact("tournaments",'teams','team_main'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        if ($team = MatchEvent::create(array_merge($request->all(), ['code' => $this->codeOrder()]))) {
            return response(array("r" => true, "type" => "success", "title" => "", "m" => __('messages.created_successfully'), "data" => $team->id));
        } else {
            return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.error_creating'), "data" => null));
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        return redirect()->back();
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $event = MatchEvent::findOrFail($id);
        $tournaments = Tournament::where('active', true)->orderBy('name','asc')->get();
        $teams = Team::where([['is_main', false],['active', true]])->orderBy('name','asc')->get();
        $team_main = Team::where([['is_main', true],['active', true]])->first();
        return view('matchevents.edit', compact('event','tournaments','teams','team_main'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        if (MatchEvent::where('id', $id)->update(array_slice($request->all(), 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));
        }
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        try {
            if (MatchEvent::where('id', $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()
    {
        $obj = MatchEvent::select('id', 'name', 'code', 'date_name','event_start_sale', 'event_end_sale', 'event_start', 'tournament_id', 'active')->with('tournament');

        return DataTables::of($obj)
            ->addColumn('actions', function ($obj) {
                return '
                <i class="fa fa-dollar iconMini " onClick="eventPrice(' . $obj->id . ')" data-id="' . $obj->id . '" data-toggle="tooltip" data-placement="bottom"  style="cursor:pointer;"></i>
                <i class="fa fa-eye iconMini " onClick="clickInfoEvent(' . $obj->id . ')" data-id="' . $obj->id . '" data-toggle="tooltip" data-placement="bottom"  style="cursor:pointer;"></i>
                <i class="fa fa-pencil iconMini " onClick="clickEdit(' . $obj->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 . ')" data-id="' . $obj->id . '" data-toggle="tooltip" data-placement="bottom"  style="cursor:pointer;"></i>
            ';
            })
            ->editColumn('active', function ($obj) {
                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>';
                }
            })
            ->rawColumns(['active','actions'])
            ->make(true);
    }

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

            $team = MatchEvent::find($id);
            $team->active = $state;
            $team->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 detailTicketsBuy($id){
        return view("matcheventTickets.index_match_event_tickets", compact('id'));
    }

    public function tableFilterTickets($match_event_id)
    {
        try {
            $obj = Ticket::where('match_event_id', $match_event_id)->with(['ticket_main','match_event','ticket_type','seat','ticket_status','user'])->orderBy('created_at', 'desc');
            return DataTables::of($obj)
            ->addColumn('actions', function ($obj) use ($match_event_id){
                return '
                    <i class="fa fa-edit iconMini " onClick="changeStateTicket(' . $obj->id . ', ' . $match_event_id . ')" data-id="' . $obj->id . '" data-toggle="tooltip" data-placement="bottom"  style="cursor:pointer;"></i>
                    <a href="/ticket/pdf/' . $obj->code_ticket . '" target="_blank" title="Imprimir"><i class="fa fa-print iconMini "></i></a>
                ';
            })
            ->rawColumns(['actions'])
            ->make(true);
        } catch (\Throwable $th) {
            return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.error_global'), "data" => $th->getMessage()));
        }
    }
}