HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
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/ipsremont-demo/app/Services/PlaceholderService.php
<?php

namespace App\Services;

class PlaceholderService
{

    protected array $recipientPlaceholders;
    protected array $servicePlaceholders;
    protected array $orderPlaceholders;
    protected array $repairPlaceholders;
    protected array $newServicePlaceholdersArray;
    protected array $acttcPlaceholders;
    protected array $shipmentPlaceholders;

    protected static array $recipientLabels = [
        '{recipient_name}' => 'placeholder.recipient_name',
        '{recipient_email}' => 'placeholder.recipient_email',
        '{login}' => 'placeholder.login',
        '{password}' => 'placeholder.password',
        '{recovery_link}' => 'placeholder.recovery_link',
        '{domain}' => 'placeholder.domain',
    ];

    protected static array $serviceLabels = [
        '{contact_name}' => 'placeholder.contact_name',
        '{contact_email}' => 'placeholder.contact_email',
        '{contact_phone}' => 'placeholder.contact_phone',
        '{contact_additional_phone}' => 'placeholder.contact_additional_phone',
        '{contact_branch}' => 'placeholder.contact_branch',

        '{service_company_name}' => 'services.company_name',
        '{service_inn}' => 'services.inn',
        '{service_additional_info}' => 'services.additional_info',

        '{service_country}' => 'services.country',
        '{service_city}' => 'services.city',
        '{service_address}' => 'services.address',
        '{service_email}' => 'services.email',
        '{service_phone}' => 'services.phone',

        '{service_company_data}' => 'services.company_data',
    ];
    protected static array $newServiceLabels = [
        '{new_contact_name}' => 'placeholder.contact_name',
        '{new_contact_email}' => 'placeholder.contact_email',
        '{new_contact_phone}' => 'placeholder.contact_phone',
        '{new_contact_additional_phone}' => 'placeholder.contact_additional_phone',
        '{new_contact_branch}' => 'placeholder.contact_branch',

        '{new_service_company_name}' => 'services.company_name',
        '{new_service_inn}' => 'services.inn',
        '{new_service_additional_info}' => 'services.additional_info',

        '{new_service_country}' => 'services.country',
        '{new_service_city}' => 'services.city',
        '{new_service_address}' => 'services.address',
        '{new_service_email}' => 'services.email',
        '{new_service_phone}' => 'services.phone',

        '{new_service_company_data}' => 'services.company_data',
    ];

    protected static array $orderLabels = [
        '{order_number}' => 'placeholder.order_number',
        '{order_status}' => 'placeholder.order_status',
        '{order_price}' => 'placeholder.order_price',
        '{order_repair}' => 'placeholder.order_repair',
        '{order_country}' => 'placeholder.country',
        '{order_city}' => 'placeholder.city',
        '{order_address}' => 'placeholder.address',
    ];

    protected static array $repairLabels = [
        '{repair_number}' => 'placeholder.repair_number',
        '{repair_status}' => 'placeholder.repair_status',
        '{repair_price}' => 'placeholder.repair_price',
        '{repair_device}' => 'placeholder.repair_device',
        '{repair_additional_info}' => 'placeholder.repair_additional_info',
        '{repair_sold_at}' => 'placeholder.repair_sold_at',
        '{repair_date}' => 'placeholder.repair_date',
    ];

    protected static array $acttcLabels = [
        '{acttc_number}' => 'placeholder.acttc_number',
        '{reason_of_impossibility_of_repair}' => 'placeholder.reason_of_impossibility_of_repair',
        '{act_status}' => 'placeholder.act_status',
        '{confirmation_link}' => 'placeholder.confirmation_link',
        '{reason_for_confirmation}' => 'placeholder.reason_for_confirmation',
        '{download_act_file}' => 'placeholder.download_act_file',
    ];

    protected static array $shipmentLabels = [
        '{track_number}' => 'placeholder.track_number',
        '{postal_service}' => 'placeholder.postal_service',
        '{status}' => 'placeholder.status',
        '{status_update_date}' => 'placeholder.status_update_date',
    ];

    public function __construct()
    {
        $this->recipientPlaceholders = [];
        $this->servicePlaceholders = [];
        $this->orderPlaceholders = [];
        $this->repairPlaceholders = [];
        $this->newServicePlaceholdersArray = [];
        $this->acttcPlaceholders = [];
        $this->shipmentPlaceholders = [];
    }

    public static function renderPlaceholders($type, $toRemove = [], $passwordType = '*', $add = [])
    {
        switch ($type) {
            case 'recipient':
                $labels = self::$recipientLabels;
                break;
            case 'service':
                $labels = self::$serviceLabels;
                break;
            case 'new-service':
                $labels = self::$newServiceLabels;
                break;
            case 'order':
                $labels = self::$orderLabels;
                break;
            case 'repair':
                $labels = self::$repairLabels;
                break;
            case 'acttc':
                $labels = self::$acttcLabels;
                break;
            case 'shipment':
                $labels = self::$shipmentLabels;
                break;
            default:
                $labels = [];
                break;
        }

        if (!empty($toRemove)) {
            foreach ($toRemove as $key) {
                if (array_key_exists($key, $labels)) {
                    unset($labels[$key]);
                }
            }
        }

        if (!empty($add)) {
            foreach ($add as $key => $value) {
                $labels[$key] = $value;
            }
        }

        $res = '<h3 class="font-size-xlg text-dark font-weight-bold mb-6">' . __('placeholder.' . $type . 'Title') . '</h3>
                    <div class="row">
                        <div class="col-lg-6">';
        $left_col = ceil(count($labels) / 2);
        $i = 1;

        foreach ($labels as $key => $label) {
            $res .= '<div class="d-flex align-items-center mb-10">
                    <div class="d-flex flex-column font-weight-bold">
                        <p class="mb-1 font-size-lg">' . $key . '</p>
                        <span class="text-muted font-weight-bold">' . __($label) . '</span>
                    </div>
                </div>';
            if ($i == $left_col) {
                $res .= '</div><div class="col-lg-6">';
            }
            $i++;
        }
        $res .= '</div></div>';

        echo $res;
    }

    protected function initServiceCompanyData($address = null): string
    {
        $service = $this->getServicePlaceholders();
        $table = '<table>';

        if ($address) {
            foreach ($service as $key => $item) {
                if ($key == '{service_country}') {
                    $table .= '<tr><td>' . __(self::$serviceLabels[$key]) . '</td><td>' . $address->country . '</td></tr>';
                } elseif ($key == '{service_city}') {
                    $table .= '<tr><td>' . __(self::$serviceLabels[$key]) . '</td><td>' . $address->city . '</td></tr>';
                } elseif ($key == '{service_address}') {
                    $table .= '<tr><td>' . __(self::$serviceLabels[$key]) . '</td><td>' . $address->address . '</td></tr>';
                } elseif ($key == '{service_email}') {
                    $table .= '<tr><td>' . __(self::$serviceLabels[$key]) . '</td><td>' . $address->email . '</td></tr>';
                } elseif ($key == '{service_phone}') {
                    $table .= '<tr><td>' . __(self::$serviceLabels[$key]) . '</td><td>' . $address->phone . '</td></tr>';
                } else {
                    $table .= '<tr><td>' . __(self::$serviceLabels[$key]) . '</td><td>' . $item . '</td></tr>';
                }
            }
        } else {
            foreach ($service as $key => $item) {
                $table .= '<tr><td>' . __(self::$serviceLabels[$key]) . '</td><td>' . $item . '</td></tr>';
            }
        }

        $table .= '</table>';

        return $table;
    }

    protected function initNewServiceCompanyData($address = null): string
    {
        $service = $this->getNewServicePlaceholdersArray();
        $table = '<table>';

        if ($address) {
            foreach ($service as $key => $item) {
                if ($key == '{new_service_country}') {
                    $table .= '<tr><td>' . __(self::$newServiceLabels[$key]) . '</td><td>' . $address->country . '</td></tr>';
                } elseif ($key == '{new_service_city}') {
                    $table .= '<tr><td>' . __(self::$newServiceLabels[$key]) . '</td><td>' . $address->city . '</td></tr>';
                } elseif ($key == '{new_service_address}') {
                    $table .= '<tr><td>' . __(self::$newServiceLabels[$key]) . '</td><td>' . $address->address . '</td></tr>';
                } elseif ($key == '{new_service_email}') {
                    $table .= '<tr><td>' . __(self::$newServiceLabels[$key]) . '</td><td>' . $address->email . '</td></tr>';
                } elseif ($key == '{new_service_phone}') {
                    $table .= '<tr><td>' . __(self::$newServiceLabels[$key]) . '</td><td>' . $address->phone . '</td></tr>';
                } else {
                    $table .= '<tr><td>' . __(self::$newServiceLabels[$key]) . '</td><td>' . $item . '</td></tr>';
                }
            }
        } else {
            foreach ($service as $key => $item) {
                $table .= '<tr><td>' . __(self::$newServiceLabels[$key]) . '</td><td>' . $item . '</td></tr>';
            }
        }

        $table .= '</table>';

        return $table;
    }

    public function initRecipientPlaceholder($model)
    {
        $this->recipientPlaceholders['{recipient_name}'] = $model->name;
        $this->recipientPlaceholders['{recipient_email}'] = $model->email;
        $this->recipientPlaceholders['{login}'] = $model->email;
        $this->recipientPlaceholders['{password}'] = $model->open_password;
        $this->recipientPlaceholders['{recovery_link}'] = config('app.url') . '/password/reset/' . base64_encode($model->email . time());
        $this->recipientPlaceholders['{domain}'] = config('app.url');
    }

    public function initServicePlaceholder($model, $address = null, $new = null)
    {
        $this->servicePlaceholders['{contact_name}'] = $model->user->name;
        $this->servicePlaceholders['{contact_email}'] = $model->user->email;
        $this->servicePlaceholders['{contact_phone}'] = $model->user->phone;
        $this->servicePlaceholders['{contact_additional_phone}'] = $model->user->additional_phone;
        $this->servicePlaceholders['{contact_branch}'] = $model->user->branch->name ?? '';

        if (!$new) {
            $this->servicePlaceholders['{service_company_name}'] = $model->name;
            $this->servicePlaceholders['{service_inn}'] = $model->inn;
            $this->servicePlaceholders['{service_additional_info}'] = $model->additional_info;

            $fl = 0;
            if (!$address) {
                $address = $model->getAddress();
            } else {
                $fl = 1;
            }

            $this->servicePlaceholders['{service_country}'] = $address->country ?? '';
            $this->servicePlaceholders['{service_city}'] = $address->city ?? '';
            $this->servicePlaceholders['{service_address}'] = $address->address ?? '';
            $this->servicePlaceholders['{service_email}'] = $address->email ?? '';
            $this->servicePlaceholders['{service_phone}'] = $address->phone ?? '';

            if ($fl) {
                $this->servicePlaceholders['{service_company_data}'] = $this->initServiceCompanyData($model->getAddress());
            } else {
                $this->servicePlaceholders['{service_company_data}'] = $this->initServiceCompanyData();
            }
        } else {
            $this->servicePlaceholders['{service_company_name}'] = $address->name;
            $this->servicePlaceholders['{service_inn}'] = $address->inn;
            $this->servicePlaceholders['{service_additional_info}'] = $address->additional_info;
            $this->servicePlaceholders['{service_country}'] = $address->country;
            $this->servicePlaceholders['{service_city}'] = $address->city;
            $this->servicePlaceholders['{service_address}'] = $address->address;
            $this->servicePlaceholders['{service_email}'] = $address->email;
            $this->servicePlaceholders['{service_phone}'] = $address->phone;
            $this->servicePlaceholders['{service_company_data}'] = $this->initServiceCompanyData();
        }
    }

    public function initOrderPlaceholder($model)
    {
        $this->orderPlaceholders['{order_number}'] = $model->getNumber();
        $this->orderPlaceholders['{order_status}'] = __('statuses.order.' . $model->getStatus());
        $this->orderPlaceholders['{order_price}'] = ($model->getPrice()) ? $model->getPrice() . ' ₽' : '0 ₽';
        $this->orderPlaceholders['{order_repair}'] = __('orders.' . $model->getRepair());
        $this->orderPlaceholders['{order_country}'] = $model->getCountry();
        $this->orderPlaceholders['{order_city}'] = $model->getCity();
        $this->orderPlaceholders['{order_address}'] = $model->getAddress();
    }

    public function initRepairPlaceholder($model)
    {
        $this->repairPlaceholders['{repair_number}'] = $model->getNumber();
        $this->repairPlaceholders['{repair_status}'] = __('statuses.repair.' . $model->getStatus());
        $this->repairPlaceholders['{repair_price}'] = ($model->getPrice()) ? $model->getPrice() . ' ₽' : '0 ₽';
        $this->repairPlaceholders['{repair_device}'] = $model->getDevice()->getSerialName();
        $this->repairPlaceholders['{repair_additional_info}'] = $model->getAdditionalInfo();

        $this->repairPlaceholders['{repair_sold_at}'] = ($model->getSold())
            ? $model->sold_at->format(config('crud.formatDate')) : '';
        $this->repairPlaceholders['{repair_date}'] = ($model->getRepairDate())
            ? $model->repair_date->format(config('crud.formatDate')) : '';
    }

    public function initNewServicePlaceholder($model)
    {
        $this->servicePlaceholders['{new_contact_name}'] = $model->user->name;
        $this->servicePlaceholders['{new_contact_email}'] = $model->user->email;
        $this->servicePlaceholders['{new_contact_phone}'] = $model->user->phone;
        $this->servicePlaceholders['{new_contact_additional_phone}'] = $model->user->additional_phone;
        $this->servicePlaceholders['{new_contact_branch}'] = $model->user->branch->name ?? '';

        $this->servicePlaceholders['{new_service_company_name}'] = $model->name;
        $this->servicePlaceholders['{new_service_inn}'] = $model->inn;
        $this->servicePlaceholders['{new_service_additional_info}'] = $model->additional_info;

        $address = $model->getAddress();

        $this->servicePlaceholders['{new_service_country}'] = ($address) ? $address->country : '';
        $this->servicePlaceholders['{new_service_city}'] = ($address) ? $address->city : '';
        $this->servicePlaceholders['{new_service_address}'] = ($address) ? $address->address : '';
        $this->servicePlaceholders['{new_service_email}'] = ($address) ? $address->email : '';
        $this->servicePlaceholders['{new_service_phone}'] = ($address) ? $address->phone : '';

        $this->servicePlaceholders['{new_service_company_data}'] = $this->initNewServiceCompanyData();
    }

    public function initActtcPlaceholders($model)
    {
        $this->acttcPlaceholders['{acttc_number}'] = $model->getNumber();
        $this->acttcPlaceholders['{reason_of_impossibility_of_repair}'] = (!$model->getReasonDescription())
            ? $model->getBreakdownCause()
            : $model->getBreakdownCause() . '<br>' . $model->getReasonDescription();

        $this->acttcPlaceholders['{act_status}'] = (!$model->getAdditionalInfo())
            ? __('statuses.acttc.' . $model->getStatus())
            : __('statuses.acttc.' . $model->getStatus()) . '<br>' . $model->getAdditionalInfo();

        $this->acttcPlaceholders['{confirmation_link}'] = route('acttc.edit', $model->getId());

        $this->acttcPlaceholders['{reason_for_confirmation}'] = (!$model->getFaultDetected())
            ? $model->getReasonForConfirmation()
            : $model->getReasonForConfirmation() . '<br>' . $model->getFaultDetected();

        $this->acttcPlaceholders['{download_act_file}'] = ($model->isAllowPdf())
            ? route('acttc.pdf', $model->getId()) : '';
    }

    public function initShipmentPlaceholders($model)
    {
        $this->shipmentPlaceholders['{track_number}'] = $model->getTrackNumber();
        $this->shipmentPlaceholders['{postal_service}'] = $model->getDeliveryService();
        $this->shipmentPlaceholders['{status}'] = __('statuses.shipment.' . $model->getStatus());
        $this->shipmentPlaceholders['{status_update_date}'] = $model->shipment_changes[0]->updated_at->format(config('crud.formatDate'));
    }

    public function setPlaceholders($arr, $placeholders)
    {
        foreach ($placeholders as $key => $value) {
            $arr[$key] = $value;
        }

        return $arr;
    }

    public function setRecipientPlaceholder($slug, $value)
    {
        $this->recipientPlaceholders[$slug] = $value;
    }

    public function setServicePlaceholder($slug, $value)
    {
        $this->servicePlaceholders[$slug] = $value;
    }

    public function getRecipientPlaceholders(): array
    {
        return $this->recipientPlaceholders;
    }

    public function getServicePlaceholders(): array
    {
        return $this->servicePlaceholders;
    }

    public function getNewServicePlaceholdersArray(): array
    {
        return $this->newServicePlaceholdersArray;
    }

    public function getOrderPlaceholders(): array
    {
        return $this->orderPlaceholders;
    }

    public function getRepairPlaceholders(): array
    {
        return $this->repairPlaceholders;
    }

    public function getActtcPlaceholders(): array
    {
        return $this->acttcPlaceholders;
    }

    public function getShipmentPlaceholders(): array
    {
        return $this->shipmentPlaceholders;
    }

    public function getAllPlaceholders(): array
    {
        $arr = [];

        $arr = $this->setPlaceholders($arr, $this->getRecipientPlaceholders());
        $arr = $this->setPlaceholders($arr, $this->getServicePlaceholders());
        $arr = $this->setPlaceholders($arr, $this->getOrderPlaceholders());
        $arr = $this->setPlaceholders($arr, $this->getRepairPlaceholders());

        return $arr;
    }

    public function getAddressChangePlaceholders()
    {
        $arr = [];

        $arr = $this->setPlaceholders($arr, $this->getRecipientPlaceholders());
        $arr = $this->setPlaceholders($arr, $this->getServicePlaceholders());

        return $arr;
    }

    public function getNewServicePlaceholders()
    {
        $arr = [];

        $arr = $this->setPlaceholders($arr, $this->getRecipientPlaceholders());
        $arr = $this->setPlaceholders($arr, $this->getServicePlaceholders());
        $arr = $this->setPlaceholders($arr, $this->getNewServicePlaceholdersArray());

        return $arr;
    }

    public function getPlaceholdersForActtc()
    {
        $arr = [];

        $arr = $this->setPlaceholders($arr, $this->getRecipientPlaceholders());
        $arr = $this->setPlaceholders($arr, $this->getServicePlaceholders());
        $arr = $this->setPlaceholders($arr, $this->getRepairPlaceholders());
        $arr = $this->setPlaceholders($arr, $this->getActtcPlaceholders());

        return $arr;
    }

    public function getPlaceholdersForShipment()
    {
        $arr = [];

        $arr = $this->setPlaceholders($arr, $this->getRecipientPlaceholders());
        $arr = $this->setPlaceholders($arr, $this->getOrderPlaceholders());
        $arr = $this->setPlaceholders($arr, $this->getShipmentPlaceholders());

        return $arr;
    }

    public function removeRecipientPlaceholder($slug)
    {
        if (isset($this->recipientPlaceholders[$slug])) {
            unset($this->recipientPlaceholders[$slug]);
        }
    }

    public function removeServicePlaceholder($slug)
    {
        if (isset($this->servicePlaceholders[$slug])) {
            unset($this->servicePlaceholders[$slug]);
        }
    }

    public static function removeRecipientLabel($slug)
    {
        if (isset(self::$recipientLabels[$slug])) {
            unset(self::$recipientLabels[$slug]);
        }
    }

    public static function removeServiceLabel($slug)
    {
        if (isset(self::$serviceLabels[$slug])) {
            unset(self::$serviceLabels[$slug]);
        }
    }
}