diff --git a/app/Modules/Plan7/Http/Livewire/Plan7SelectorLivewire.php b/app/Modules/Plan7/Http/Livewire/Plan7SelectorLivewire.php index ec91cc8..a71cadc 100644 --- a/app/Modules/Plan7/Http/Livewire/Plan7SelectorLivewire.php +++ b/app/Modules/Plan7/Http/Livewire/Plan7SelectorLivewire.php @@ -8,21 +8,39 @@ class Plan7SelectorLivewire extends Component { public $mode = 'new'; public $containerId; + public $filter = []; + public $allObjects; public $types; public $access; - public $bs; + public $summary; public $room; public $objects = []; - private $api = 'https://plan7.ru/catalog/exp/json/?token=0754c5e6a3824322&zk=614'; + private $apiSummary = 'https://plan7.ru/catalog/exp/json/summary/?token=0754c5e6a3824322&zk=614'; + private $apiAll = 'https://plan7.ru/catalog/exp/json/?token=0754c5e6a3824322&zk=614'; public function mount($containerId = 'plan7__selector') { $this->containerId = $containerId; + $this->getSummary(); $this->getData(); } + + private function getSummary() { + $URL = $this->apiSummary; + $opt = []; + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $URL); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + $fields = http_build_query($opt); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $fields); + $out = curl_exec($curl); + $this->summary = json_decode($out, true); + curl_close($curl); + } private function getData() { - $URL = $this->api; + $URL = $this->apiAll; $opt = []; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $URL); @@ -39,28 +57,61 @@ private function getData() public function setHouse($id) { - $this->bs = $id; - $this->room = null; + $this->filter['bs'] = $id; } public function setRoom($id) { $this->room = $this->allObjects['data'][$id]; + $this->filter['id'] = $id; + } + public function resetFilter() { + $this->filter = []; } - public function start() { $this->mode = 'select'; + $this->filter = []; $this->getData(); } public function done() { $this->mode = 'selected'; - $this->bs = null; - $this->room = null; + $this->filter = []; } public function render() { $objs = []; - if (!$this->bs && !$this->room) { + if (count($this->filter)) { + foreach ($this->allObjects['data'] as $key => $room) { + if ($room['access'] != 0) { + if (array_key_exists('id', $this->filter) && $this->filter['id'] && $room['id'] != $this->filter['id']) { + continue; + } + if (array_key_exists('bs', $this->filter) && $this->filter['bs'] && $room['bs'] != $this->filter['bs']) { + continue; + } + if (array_key_exists('type', $this->filter) && $this->filter['type'] && $room['type'] != $this->filter['type']) { + continue; + } + if (array_key_exists('min_area', $this->filter) && $room['area'] < $this->filter['min_area']) { + continue; + } + if (array_key_exists('max_area', $this->filter) && $room['area'] > $this->filter['max_area']) { + continue; + } + $room['mode'] = 'room'; + $objs[] = $room; + } + } + } else { + foreach ($this->allObjects['values']['bs'] as $key => $house) { + $objs[] = [ + 'mode' => 'bs', + 'id' => $house['id'], + 'name' => $house['name'], + ]; + } + } + /*if (!$this->bs && !$this->room) { foreach ($this->allObjects['values']['bs'] as $key => $house) { $objs[] = [ 'mode' => 'bs', @@ -69,7 +120,7 @@ public function render() ]; } } elseif ($this->bs && !$this->room) { - foreach ($this->allObjects['data'] as $key => $room) { + foreach ($this->allObjects['data'] as $key => $room) { if ($room['access'] != 0) { $room['mode'] = 'room'; $objs[] = $room; @@ -82,7 +133,7 @@ public function render() $objs[] = $room; } } - } + }*/ return view('plan7::livewire.selector', [ 'objs' => $objs ]); diff --git a/app/Modules/Plan7/Views/livewire/selector.blade.php b/app/Modules/Plan7/Views/livewire/selector.blade.php index bd24dc9..7067160 100644 --- a/app/Modules/Plan7/Views/livewire/selector.blade.php +++ b/app/Modules/Plan7/Views/livewire/selector.blade.php @@ -1,9 +1,28 @@
- +
+ @if($room) +
+
+ {{ (($room['type'] == 0) ? $room['room'] . ' комн. ' . mb_strtolower($this->types[$room['type']]) : $this->types[$room['type']]) }} +
+
+
Помещение: {{ $room['name'] }}
+
Площадь: {{ $room['area'] }}
+
Этаж: {{ $room['level'] }}
+
+
+ @endif + +
+