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/heifetz/heifetz-app/models/UsersMeta.php
<?php

namespace Models;

use Core\DbLib\NewDbModel;
use Core\Models\CoreHelper;

/**
 * @property int $user_id
 * @property string $key
 * @property string $value
 * @property int $company_id
 */
class UsersMeta extends NewDbModel
{

    static string $tableName = 'users_meta';

    static array $primaryKeys = ['user_id', 'key', 'value', 'company_id'];

    const TICKET_SOUND_NOTIFICATION = 'ticket_sound_notification';

    public static array $keys = [
        self::TICKET_SOUND_NOTIFICATION,
    ];

    public static function getRules(): array
    {
        return [
            'user_id' => 'required|integer',
            'key' => 'required|size:255',
            'value' => 'required|text',
        ];
    }

    protected static function getTranslations(): array
    {
        return [
            'user_id' => 'ID пользователя',
            'key' => 'Ключ',
            'value' => 'Значение',
        ];
    }

    public static function getByUserIdAndKey(int $userId, string $key): ?string
    {
        $value = self::model(['value'])->where('user_id = ?', $userId)->where('key = ?', $key)->fetchCol();

        return $value[0] ?? null;
    }

    public static function add(int $userId, string $key, string $value): void
    {
        if (!in_array($key, self::$keys)) {
            return;
        }
        $newUserMeta = new self();
        $newUserMeta->user_id = $userId;
        $newUserMeta->key = $key;
        $newUserMeta->value = $value;
        $newUserMeta->save();
    }

    public static function removeMeta(int $userId, string $key): void
    {
        self::delete(['user_id' => $userId, 'key' => $key, 'company_id' => CoreHelper::$companyId]);
    }

}