setTemplate('map.block', 'geo'); $this->setKey('map'); $this->setTitle(_t('geo', 'Map')); } public function data() { $data = parent::data(); if (! $this->regionID) { $regionID = Geo::coveringRegion(); if (is_array($regionID)) { $filter = Geo::filter(); if (! empty($filter['id']) && in_array($filter['id'], $regionID)) { # применим карту для страны из фильтра $this->regionID = $filter['id']; } else { $this->regionID = reset($regionID); } } else { $this->regionID = $regionID; } } if ($this->cities_list) { $region = Geo::regionData($this->regionID); $filter = [ 'enabled' => 1, ['fav', '>', 0], ['numleft', '>', $region['numleft'] ?? 0], ['numright', '<', $region['numright'] ?? 0], ]; $regions = Geo::model()->regionsListing($filter, ['orderBy' => 'fav', 'keyBy' => 'id', 'fields' => ['parents']]); $items = Listings::model()->itemsCountByFilter([ 'cat_id' => 0, 'region_id' => array_keys($regions), 'delivery' => 0, ], ['region_id', 'items'], false, 60); $items = func::array_transparent($items, 'region_id', true); $data['regions'] = []; if (!empty($regions)) { foreach ($regions as &$v) { $v['items'] = $items[ $v['id'] ]['items'] ?? 0; $v['l'] = Listings::url('items.search', Geo::regionParents($v)['keys'] ?? []); } unset($v); } if ($this->order === 'items') { uasort($regions, function ($a, $b) { if ($a['numlevel'] == $b['numlevel']) { return $a['items'] < $b['items']; } return $a['numlevel'] < $b['numlevel']; }); } $data['regions'] = $regions; } $data['map'] = Geo::regionMap($this->regionID, [ 'lang' => $this->language, 'counters' => $this->counters, ]); return $data; } public function settingsForm($form) { $form ->text('title', _t('@geo', 'Title'), _t('geo', 'Listings on the map', true)) ->images('icon', _t('@geo', 'Icon'), 1) ->preload(bff::path('/static/img/default/icon_map.svg')) ->number('width', _t('@geo', 'Width'), 1, 0, 1, $this->width) ->select('width_measure', '', $this->width_measure) ->option('percent', '%') ->option('px', _t('@', 'px')) ->width(70) ->together('width') ->checkbox('counters', _t('@site', 'Counters'), $this->counters) ->label(_t('@', 'Display')) ->checkbox('cities_list', _t('@geo', 'List of cities'), $this->cities_list) ->label(_t('@', 'Display')) ->select( 'order', _t('@geo', 'Sort Cities') . '
(' . _t('@', 'list') . ')', $this->order ) ->option('items', _t('@geo', 'By the number of listings')) ->option('fav', _t('@geo', 'Order in the admin panel')) ->visibleIf('cities_list', true) ; } }