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

namespace Models;

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

/**
 * @property int $id
 * @property ?string $key
 * @property string $name
 * @property int $deleted
 * @property int $active
 * @property int $protected
 * @property int $company_id
 */
abstract class NewAbstractDictionary extends NewDbModel
{

    static bool $withBoolFields = false;

    public static function getNames(bool $keyById = false, bool $showDeleted = false, array $ids = [], bool $onlyActive = false): array
    {
        $companyId = CoreHelper::$companyId;
        $tableData = RedisCache::create()->getSet(static::$tableName . '_getNames_cid_' . $companyId, callback: fn() => static::$db->select('id', 'name', 'deleted', 'active')
            ->from(static::$tableName)->company()
            ->order('name', 'ASC')
            ->fetchArray(), expiration: RedisCache::DAY);

        if (!$showDeleted) {
            $tableData = array_filter($tableData, fn($item) => $item['deleted'] == (static::$withBoolFields ? false : 0));
        }

        if ($onlyActive) {
            $tableData = array_filter($tableData, fn($item) => $item['active'] == (static::$withBoolFields ? true : 1));
        }

        if (!empty($ids)) {
            $tableData = array_filter($tableData, fn($item) => in_array($item['id'], $ids));
        }

        $result = [];
        if ($keyById) {
            foreach ($tableData as $item) {
                if (isset($item['deleted']) && $item['deleted']) {
                    $item['name'] .= ' 🔴';
                }
                if (isset($item['active']) && !$item['active']) {
                    $item['name'] .= ' 🟠';
                }

                $result[$item['id']] = $item['name'];
            }
            $tableData = $result;
        }

        return $tableData;
    }

}