Алгоритм расчета координат для редактора 3 - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Алгоритм расчета координат для редактора 3.php
- <?php
- $coefficient = 300;
- $levels = [
- 0 => [
- "sector_id" => 61,
- "name" => "Parter 1",
- "position" => [
- "radius"=> 0,
- "x" => 0,
- "y"=> 0
- ],
- "controlPoints" => [
- [
- "radius" => 0,
- "x" => 198,
- "y" => 120
- ],
- [
- "radius" => 0,
- "x" => 198,
- "y" => 173
- ],
- [
- "radius" => 0,
- "x" => 198,
- "y" => 227
- ],
- [
- "radius" => 0,
- "x" => 198,
- "y" => 281
- ],
- [
- "radius" => 0,
- "x" => 216,
- "y" => 281
- ],
- [
- "radius" => 0,
- "x" => 235,
- "y" => 281
- ],
- [
- "radius" => 0,
- "x" => 254,
- "y" => 282
- ],
- [
- "radius" => 0,
- "x" => 254,
- "y" => 120
- ],
- [
- "radius" => 0,
- "x" => 198,
- "y" => 120
- ],
- [
- "radius" => 0,
- "x" => 198,
- "y" => 120
- ]
- ],
- "seats" => [
- 0 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "3",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 61
- ],
- "position" => [
- "radius" => 0,
- "x" => 80,
- "y" => 40
- ],
- ],
- 1 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "1",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 61
- ],
- "position" => [
- "radius" => 0,
- "x" => 40,
- "y" => 40
- ],
- ],
- 2 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "2",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 61
- ],
- "position" => [
- "radius" => 0,
- "x" => 60,
- "y" => 40
- ],
- ],
- 3 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "4",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 61
- ],
- "position" => [
- "radius" => 0,
- "x" => 100,
- "y" => 40
- ],
- ],
- 4 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "5",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 61
- ],
- "position" => [
- "radius" => 0,
- "x" => 120,
- "y" => 40
- ],
- ],
- ]
- ],
- 1 => [
- "sector_id" => 68,
- "name" => "Balkon 2 top",
- "position" => [
- "radius"=> 0,
- "x" => 0,
- "y"=> 0
- ],
- "controlPoints" => [
- [
- "radius" => 0,
- "x" => 240,
- "y" => 76
- ],
- [
- "radius" => 0,
- "x" => 240,
- "y" => 80
- ],
- [
- "radius" => 0,
- "x" => 240,
- "y" => 83
- ],
- [
- "radius" => 0,
- "x" => 240,
- "y" => 86
- ],
- [
- "radius" => 0,
- "x" => 266,
- "y" => 86
- ],
- [
- "radius" => 0,
- "x" => 291,
- "y" => 86
- ],
- [
- "radius" => 0,
- "x" => 317,
- "y" => 86
- ],
- [
- "radius" => 0,
- "x" => 317,
- "y" => 76
- ],
- [
- "radius" => 0,
- "x" => 240,
- "y" => 76
- ],
- [
- "radius" => 0,
- "x" => 240,
- "y" => 76
- ]
- ],
- "seats" => [
- 0 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "1",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 68
- ],
- "position" => [
- "radius" => 0,
- "x" => 40,
- "y" => 40
- ],
- ],
- 1 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "2",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 68
- ],
- "position" => [
- "radius" => 0,
- "x" => 60,
- "y" => 40
- ],
- ],
- 2 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "3",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 68
- ],
- "position" => [
- "radius" => 0,
- "x" => 80,
- "y" => 40
- ],
- ],
- 3 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "4",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 68
- ],
- "position" => [
- "radius" => 0,
- "x" => 100,
- "y" => 40
- ],
- ],
- 4 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "5",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 68
- ],
- "position" => [
- "radius" => 0,
- "x" => 120,
- "y" => 40
- ],
- ],
- ]
- ],
- 2 => [
- "sector_id" => 79,
- "name" => "Balkon 3 S2",
- "position" => [
- "radius"=> 0,
- "x" => 0,
- "y"=> 0
- ],
- "controlPoints" => [
- [
- "radius" => 0,
- "x" => 384,
- "y" => 389
- ],
- [
- "radius" => 0,
- "x" => 341,
- "y" => 357
- ],
- [
- "radius" => 0,
- "x" => 382,
- "y" => 300
- ],
- [
- "radius" => 0,
- "x" => 426,
- "y" => 331
- ],
- ],
- "seats" => [
- 0 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "3",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 61
- ],
- "position" => [
- "radius" => 0,
- "x" => 80,
- "y" => 40
- ],
- ],
- 1 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "1",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 61
- ],
- "position" => [
- "radius" => 0,
- "x" => 40,
- "y" => 40
- ],
- ],
- 2 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "2",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 61
- ],
- "position" => [
- "radius" => 0,
- "x" => 60,
- "y" => 40
- ],
- ],
- 3 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "4",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 61
- ],
- "position" => [
- "radius" => 0,
- "x" => 100,
- "y" => 40
- ],
- ],
- 4 => [
- "additional_properties" => [
- "row" => "1",
- "place_name" => "5",
- "place_count" => 1,
- "price_type" => 1,
- "sector_id" => 61
- ],
- "position" => [
- "radius" => 0,
- "x" => 120,
- "y" => 40
- ],
- ],
- ]
- ],
- ];
- $maxSchemaY = 0;
- $lastSeatXInPreviousLevel = [];
- $firstSeatXInLevel = [];
- $coefficientXByLevel = [];
- $data = [];
- foreach($levels as $level) {
- array_walk($level['controlPoints'], function($point) use (&$maxSchemaY) {
- $maxSchemaY = max($maxSchemaY, $point['y']);
- });
- }
- var_dump('maxSchemaY');
- var_dump($maxSchemaY);
- foreach($levels as $level) {
- $firstSeatXInLevel = [];
- array_walk($level['seats'], function($seat) use (&$firstSeatXInLevel) {
- if (!isset($firstSeatXInLevel['x']) //если в секторе ещё не записан первый Х или на данный момент Х больше, чем у этого места
- or $firstSeatXInLevel['x'] > $seat['position']['x']) {
- $firstSeatXInLevel['x'] = $seat['position']['x']; //то записываем координаты этого места в крайнее место в секторе
- $firstSeatXInLevel['y'] = $seat['position']['y'];
- }
- });
- var_dump('firstSeatInLevel');
- var_dump($firstSeatXInLevel);
- foreach ($level['seats'] as $place) {
- $place['position']['y'] = $maxSchemaY - $place['position']['y'] + $coefficient;
- var_dump('lastSeatXInPreviousLevel');
- var_dump($lastSeatXInPreviousLevel);
- if (!empty($lastSeatXInPreviousLevel) && !isset($coefficientXByLevel[$level['sector_id']])) { //если есть данные о последнем месте предыдущего сектора и ещё нет коэффициента сдвига по координате X этого сектора, то высчитываем его
- $coefficientXByLevel[$level['sector_id']] = $lastSeatXInPreviousLevel['x'] - $firstSeatXInLevel['x'] + $coefficient;
- } elseif (empty($lastSeatXInPreviousLevel)) $coefficientXByLevel[$level['sector_id']] = 0;
- $place['position']['x'] = $place['position']['x'] + $coefficientXByLevel[$level['sector_id']];
- if (!isset($lastSeatXInPreviousLevel['x']) //если в секторе ещё не записан последний Х или на данный момент Х меньше, чем у этого места
- or $lastSeatXInPreviousLevel['x'] < $place['position']['x']) {
- $lastSeatXInPreviousLevel['x'] = $place['position']['x']; //то записываем координаты этого места в крайнее место в секторе
- $lastSeatXInPreviousLevel['y'] = $place['position']['y'];
- }
- $data[$level['sector_id']][] = [
- 'category' => 'place',
- 'type' => 'Circle',
- 'additional_properties' => $place['additional_properties'],
- 'position' => [
- 'radius' => 0,
- 'x' => $place['position']['x'],
- 'y' => $place['position']['y'],
- ]
- ];
- }
- var_dump('data');
- var_dump($data[$level['sector_id']]);
- }