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/comfama.sports-crowd.com/app/Services/TicketParametersService.php
<?php

namespace App\Services;

use App\TicketParameter;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;

class TicketParametersService
{

    public function getParameterObject()
    {
        $data = new \stdClass();
        $parameters = TicketParameter::select('key', 'value')->get();
        foreach ($parameters as $parameter) {
            $key = $parameter->key;
            $value = $parameter->value;
            $data->$key = $value;
        }
        return $data;
    }

    public function saveParameters(Request $request)
    {
        try {
            $this->createOrUpdateParam($request, 'number_transfers');
            $this->createOrUpdateParam($request, 'send_mail_tickets_app_purchase');
            $this->createOrUpdateParam($request, 'send_mail_tickets_web_purchase');
            $this->createOrUpdateParam($request, 'enable_transfer_ticket');
            $this->createOrUpdateParam($request, 'enable_download_button');
            $this->createOrUpdateParam($request, 'enable_tyc');
            $this->createOrUpdateParam($request, 'ticket_button');
            $this->createOrUpdateParam($request, 'subscriber_button');
            $this->createOrUpdateParam($request, 'enable_validate_doors');

            if ($request->file('terms')) {
                $extension = $request->file('terms')->getClientOriginalExtension();
                $filenametostore = 'ticket_terms' . '.' . $extension;

                Storage::disk('s3')->put(config('s3.default') . '/ticket/' . $filenametostore, fopen($request->file('terms'), 'r+'), 'public');
                $url = config('filesystems.disks.s3.url') . '/ticket/' . $filenametostore;
                TicketParameter::updateOrCreate(
                    ['key' => 'terms'],
                    ['key' => 'terms', 'value' => $url]
                );
            }
            if ($request->file('app_ticketing_background')) {
                $filenametostore = 'subscriber.png';

                Storage::disk('s3')->put(config('s3.default') . '/ticket/' . $filenametostore, fopen($request->file('app_ticketing_background'), 'r+'), 'public');
                $url = config('filesystems.disks.s3.url') . '/ticket/' . $filenametostore;
                TicketParameter::updateOrCreate(
                    ['key' => 'app_ticketing_background'],
                    ['key' => 'app_ticketing_background', 'value' => $url]
                );
            }
            if ($request->file('web_ticketing_background')) {
                $filenametostore = 'webTicketingBackground.jpg';

                Storage::disk('s3')->put(config('s3.default') . '/web_customization/' . $filenametostore, fopen($request->file('web_ticketing_background'), 'r+'), 'public');
                $url = config('filesystems.disks.s3.url') . '/web_customization/' . $filenametostore;
                TicketParameter::updateOrCreate(
                    ['key' => 'web_ticketing_background'],
                    ['key' => 'web_ticketing_background', 'value' => $url]
                );
            }
            Cache::forget('parametersTickets');
            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 validateSendingEmailTickets($origin)
    {
        $sendMail = false;
        if ($origin == 'app') {
            $sendMail = $this->getParametersValue('send_mail_tickets_app_purchase');
        } else if ($origin == 'web') {
            $sendMail = $this->getParametersValue('send_mail_tickets_web_purchase');
        }
        $sendMail = filter_var($sendMail, FILTER_VALIDATE_BOOLEAN);
        return $sendMail;
    }

    public function getParametersValue($key)
    {
        $parameter = TicketParameter::where('key', $key)->first();
        return $parameter ? $parameter->value : '';
    }

    private function createOrUpdateParam(Request $request, $key)
    {
        if ($request[$key]) {
            TicketParameter::updateOrCreate(
                ['key' => $key],
                ['key' => $key, 'value' => $request[$key]]
            );
        }
    }
}