File: /var/www/elite/coordParser/commimParse.php
<?php
use coordParser\CommimAddress;
use coordParser\CommimParser;
ini_set('max_execution_time', '-1');
ini_set('display_errors', '1');
require __DIR__ . '/../vendor/autoload.php';
try {
$commimAddress = new CommimAddress();
} catch (Throwable $exception) {
print_r($exception->getMessage() . PHP_EOL);
die;
}
$commimParser = new CommimParser();
$header = [
'obj_id' => 'int',
'addr_print' => 'string',
'obj_type_name' => 'string',
'prf_name' => 'string',
'addr_whole_nmb' => 'string',
'addr_build' => 'string',
'addr_letter' => 'string',
'flat_number' => 'string',
'obj_kd_nmb' => 'string',
'reg_name' => 'string',
'obj_area' => 'float',
'obj_reestr_num' => 'string',
'obj_reestr_num_date' => 'string',
'pravo' => 'string',
'purpose_name' => 'string',
'encumbrance_name' => 'string',
'city_part' => 'string',
'land_cadastr_cost' => 'string',
'book_cost_value' => 'string',
'residual_cost_value' => 'string',
'residual_cost_date' => 'string',
'details' => 'string',
'longitude' => 'float',
'latitude' => 'float',
'choice' => 'bool',
'images' => 'string',
];
$map = [
'obj_id' => 'objId',
'addr_print' => 'addrPrint',
'obj_type_name' => 'objTypeName',
'prf_name' => 'prfName',
'addr_whole_nmb' => 'addrWholeNmb',
'addr_build' => 'addrBuild',
'addr_letter' => 'addrLetter',
'flat_number' => 'flatNumber',
'obj_kd_nmb' => 'objKdNmb',
'reg_name' => 'regName',
'obj_area' => 'objArea',
'obj_reestr_num' => 'objReestrNum',
'obj_reestr_num_date' => 'objReestrNumDate',
'pravo' => 'pravo',
'purpose_name' => 'purposeName',
'encumbrance_name' => 'encumbranceName',
'city_part' => 'cityPart',
'land_cadastr_cost' => 'landCadastrCost',
'book_cost_value' => 'bookCostValue',
'residual_cost_value' => 'residualCostValue',
'residual_cost_date' => 'residualCostDate',
'details' => 'details',
];
$data = $commimParser->getData();
$count = $data->filtered;
$offset = 20;
print_r('Найдено: ' . $count . PHP_EOL);
$totalPages = round($count / $offset);
print_r('Всего страниц: ' . $totalPages . PHP_EOL);
$page = 8990;
$items = $data->items;
do {
print_r('Страница: ' . $page . '/' . $totalPages . PHP_EOL);
foreach ($items as $item) {
$row = [];
foreach ($item as $key => $value) {
$row[] = $value ?? ' ';
}
$table[] = $row;
}
$data = $commimParser->getData(++$page);
$items = $data->items;
try {
foreach ($items as $index => $row) {
$fieldIndex = 0;
$newRow = [];
foreach ($header as $key => $type) {
$field = $map[$key];
switch ($type) {
case 'int':
$newRow[$fieldIndex] = (int) $row->$field;
break;
case 'float':
$newRow[$fieldIndex] = (float) str_replace(',', '.', $row->$field);
break;
case 'bool':
$newRow[$fieldIndex] = (bool) $row->$field;
break;
case 'string':
default:
$newRow[$fieldIndex] = (string) $row->$field;
break;
}
$fieldIndex++;
}
$item = array_combine(array_keys($header), $newRow);
$commimAddress->add($item);
}
} catch (Throwable $exception) {
print_r($exception->getMessage());
}
} while (!empty($items));
$indices = array_flip($header);
array_shift($table);