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/Models/WorkCompleteCertificateChangeLog.php
<?php

namespace App\Models;

use App\Repository\Wcc\WccRepository;
use App\User;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * @property int $id
 * @property int $work_complete_certificate_id
 * @property int $user_id
 * @property string $field
 * @property string $old_value
 * @property string $new_value
 * @property int $type
 * @property string $created_at
 * @property string $updated_at
 *
 * @property WorkCompleteCertificate $workCompleteCertificate
 * @property User $user
 */
class WorkCompleteCertificateChangeLog extends BaseModel
{

    protected $fillable = [
        'work_complete_certificate_id',
        'user_id',
        'field',
        'old_value',
        'new_value',
        'type',
    ];

    const TYPE_CREATE = 1;
    const TYPE_UPDATE = 2;
    const TYPE_DELETE = 3;

    public function getDate(): string
    {
        $text = $this->created_at->format('d.m.Y') . '</br>';
        $text .= $this->created_at->format('H:i:s');

        return $text;
    }

    public static function getLogLabel(string $field): string
    {
        switch ($field) {
            case 'article':
                return 'Артикул';
            case 'serial_number':
                return 'Серийный номер';
            case 'amount':
                return 'Количество';
            case 'name':
                return 'Название ТМЦ';
            case 'work_description':
                return 'Описание работ';
            case 'executor':
                return 'Исполнитель';
            case 'client':
                return 'Заказчик';
            case 'device_name':
                return 'Устройство';
        }

        return 'Неизвестное поле (' . $field . ')';
    }

    public function getText(): string
    {
        $fieldName = self::getLogLabel($this->field);

        if (in_array($this->field, ['deleted_item', 'new_item'])) {
            $text = 'Была ' . ($this->field === 'deleted_item' ? 'удалена' : 'создана') . ' ТМЦ: ';
            $workCompleteCertificateItem = WccRepository::getWorkCompleteCertificateItem($this->new_value);
            $text .= 'артикул <strong>' . $workCompleteCertificateItem->article . '</strong>, ';
            $text .= 'наименование <strong>' . $workCompleteCertificateItem->name . '</strong>, ';
            $text .= 'количество <strong>' . $workCompleteCertificateItem->amount . '</strong>, ';
        } elseif (isset($this->old_value, $this->new_value)) {
            $text = 'Изменено поле «' . $fieldName . '» с ';
            $text .= '<strong>' . $this->old_value . '</strong>';
            $text .= ' на ';
            $text .= '<strong>' . $this->new_value . '</strong> ';
        } elseif (isset($this->new_value)) {
            $text = 'В поле «' . $fieldName . '» установлено значение ';
            $text .= '<strong>' . $this->new_value . '</strong> ';
        } else {
            $text = 'В поле «' . $fieldName . '» убрали значение, было ';
            $text .= '<strong>' . $this->old_value . '</strong> ';
        }

        if (isset($this->user_id)) {
            $text .= __('users.byUser') . ' <strong>' . $this->user->getName() . '</strong> ';
        } else {
            $text .= __('users.userNotSpecified');
        }

        return $text;
    }

    // MARK: - Relations

    public function workCompleteCertificate(): BelongsTo
    {
        return $this->belongsTo(WorkCompleteCertificate::class)->withTrashed();
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class)->withTrashed();
    }

}