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/elite/coordParser/JsonHelper.php
<?php

namespace coordParser;

class JsonHelper
{

    private string $jsMapFilename = __DIR__ . '/../public/commimMap.json';

    private array $fields;

    private array $table;

    public function setFields(array $fields): self
    {
        $this->fields = $fields;

        return $this;
    }

    public function setTable(array $table): self
    {
        $this->table = $table;

        return $this;
    }


    /** Создания кеш файла JSON и файла для карты */
    public function createJson(): self
    {
        $json = [];
        foreach ($this->table as $rowNum => $row) {
            foreach ($row as $colNum => $cell) {
                $fieldName = $this->fields[$colNum];
                switch ($fieldName) {
                    case 'objArea':
                        $cell = empty($cell) ? null : floatval(str_replace(',', '.', $cell));
                        break;
                    case 'choice':
                        $cell = 'да' === mb_strtolower($cell);
                        break;
                    case 'longitude':
                    case 'latitude':
                        $cell = empty($cell) ? null : floatval($cell);
                        break;
                    case 'images':
                        $images = array_filter(explode(PHP_EOL, $cell));
                        $cell = [];
                        foreach ($images as $image) {
                            $cell[] = ['src' => $image];
                        }
                        break;
                    default:
                        break;
                }
                $json[$rowNum][$fieldName] = $cell;
            }
        }

        $json = json_encode(array_values($json), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
        file_put_contents($this->jsMapFilename, $json);

        return $this;
    }

}