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/qas.sports-crowd.com/app/Http/Controllers/BusinessRatingController.php
<?php

namespace App\Http\Controllers;

use App\BusinessRating;
use DataTables;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use App\Http\Controllers\UtilController;

class BusinessRatingController extends Controller
{
    private $util;

    public function __construct()
    {
        $this->util = new UtilController();
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('business_rating.list');
    }

    public function indexAdd()
    {
        $info_rating = BusinessRating::select('id', 'name')
            ->where('active', true)
            ->whereNotIn('id', function ($query) {
                $query->select('business_rating_id')->from('business_ratings')->whereNotNull('business_rating_id');
            })
            ->get();
        $options  = array();
        $options2 = array();
        $options3 = array();
        $listOption = BusinessRating::select('comment',)->where('active', true)->get();
        foreach ($listOption as $key => $option) {
            array_push($options2, $option->comment);
        }
        foreach ($options2 as $key => $item) {
            $options3 = explode(',', $item);
            foreach ($options3 as $key => $item3) {
                array_push($options, $item3);
            }
        }
        return view('business_rating.create', compact('info_rating', 'options'));
    }

    public function indexEdit($id)
    {
        $businessRating = BusinessRating::findOrFail($id);
        $states = BusinessRating::select('id', 'name')
            ->where('active', true)
            ->whereNotIn('id', function ($query) {
                $query->select('business_rating_id')->from('business_ratings')->whereNotNull('business_rating_id');
            })
            ->orWhere('id', $businessRating->business_rating_id)
            ->get();

        $options = array();
        $options = explode(',', $businessRating->comment);
        return view('business_rating.edit', compact('states', 'businessRating', 'options'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
        try {
            if (BusinessRating::where('name', $request->input('name'))->first()) {
                return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.already_exists', ['name' => $request->input('tag')]), "data" => null));
            }
            if ($model = BusinessRating::create($request->all())) {
                return response(array("r" => true, "type" => "success", "title" => "", "m" => __('messages.created_successfully'), "data" => $model->id));
            } else {
                return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.error_creating'), "data" => null));
            }
        } catch (\Exception $e) {
            return response(
                array(
                    "r" => false,
                    "type" => "error",
                    "title" => "Oops...",
                    "m" => __($e->getMessage()),
                    "data" => null
                )
            );
        }
    }

    public function tableFilter()
    {
        $obj = BusinessRating::select('id', 'name', 'img', 'score', 'comment', 'active');

        return DataTables::of($obj)
            ->editColumn('img', function ($obj) {
                return $obj->img ? $this->util->generateImageColumn($obj->img, $obj->name, $obj->id) : $this->util->generateEmptyImageColumn();

                //   return $this->util->generateImageColumnRound(config('filesystems.disks.s3.url') . '/business/business_ratings/' . $obj->image, $obj->name, 'logo' . $obj->id);

            })
            ->addColumn('actions', function ($obj) {
                return '
                    <i class="fa fa-pencil iconMini" onClick="clickEdit(' . $obj->id . ')" data-id="' . $obj->id . '" data-toggle="tooltip" data-placement="bottom" title="Editar" style="cursor:pointer;"></i>
                    <i class="fa fa-trash iconMini" onClick="clickDelete(' . $obj->id . ')" data-id="' . $obj->id . '" data-toggle="tooltip" data-placement="bottom" title="Eliminar" 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(['actions', 'active', 'img'])
            ->make(true);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        try {
            if (BusinessRating::where([['id', '!=', $id], ['name', $request->input('name')]])->first()) {
                return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.already_exists', ['name' => $request->input('name')]), "data" => null));
            }
            if (BusinessRating::where('id', $id)->update($request->all())) {
                return response(array("r" => true, "type" => "success", "title" => "", "m" => __('messages.updated_successfully'), "data" => $id));
            } else {
                return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.error_updating'), "data" => null));
            }
        } catch (\Exception $e) {
            return response(
                array(
                    "r" => false,
                    "type" => "error",
                    "title" => "Oops...",
                    "m" => __($e->getMessage()),
                    "data" => null
                )
            );
        }
    }

    public function delete($id)
    {
        try {
            if (BusinessRating::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 activate(Request $request)
    {
        try {
            $id = $request['id'];
            $state = $request['state'];

            $academyState = BusinessRating::find($id);
            $academyState->active = $state;
            $academyState->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 saveImage(Request $request)
    {
        try {
            $extension = $request->file('image')->getClientOriginalExtension();
            $filenametostore = $request->id . '.' . $extension;

            Storage::disk('s3')->put(
                config('s3.business_ratings') . $filenametostore,
                fopen($request->file('image'), 'r+'),
                'public'
            );

            $url = config('filesystems.disks.s3.url') . '/business/business_ratings/' . $filenametostore;

            $rating_img = BusinessRating::find($request->id);
            $rating_img->img = $url;
            $rating_img->update();

            return response(array("r" => true, "type" => "success", "title" => "", "m" => __('messages.updated_successfully'), "data" => null));
        } catch (\Throwable $th) {
            return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.error_updating'), "data" => $th->getMessage()));
        }
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}