Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
disputedareaservice.php
1<?php
2
4
13
15{
17 protected static $instance;
18
19 private const TYPE_DISPUTED = 'DISPUTED';
20 private const CODE_CRIMEA = 'CRIMEA';
21 private const CODE_SEVASTOPOL = 'SEVASTOPOL';
22
24 private $areaRepository;
25
27 private $disputedAreas;
28
33 public function getDisputeByPoint(Point $point): ?Dispute
34 {
35 $this->loadDisputedAreas();
36
37 foreach ($this->disputedAreas as $disputedArea)
38 {
39 if (!$disputedArea->containsPoint($point))
40 {
41 continue;
42 }
43
44 $className = null;
45 switch ($disputedArea->getCode())
46 {
47 case self::CODE_CRIMEA:
48 $className = CrimeaDispute::class;
49 break;
50 case self::CODE_SEVASTOPOL:
51 $className = SevastopolDispute::class;
52 break;
53 }
54
55 if (!$className)
56 {
57 continue;
58 }
59
60 return new $className();
61 }
62
63 return null;
64 }
65
69 protected function __construct(Container $config)
70 {
71 $this->areaRepository = new AreaRepository();
72
73 parent::__construct($config);
74 }
75
76 private function loadDisputedAreas(): void
77 {
78 if (!is_null($this->disputedAreas))
79 {
80 return;
81 }
82
83 $this->disputedAreas = $this->areaRepository->findByArguments([
84 'filter' => [
85 '=TYPE' => self::TYPE_DISPUTED,
86 ],
87 'order' => [
88 'SORT' => 'DESC',
89 ]
90 ]);
91 }
92}