setTemplate('latest.block', 'listings'); $this->setKey('latest'); $this->setTitle(_t('listings', 'New Listings')); $this->limit = 10; } public function data() { $data = parent::data(); if (! $this->limit) { return false; } $this->loadItems($this->prepareItemsFilter(), [ 'orderBy' => 'publicated_order DESC, id DESC', ]); if (empty($this->items)) { return false; } return $data; } public function prepareItemsFilter() { $filter = array_merge($this->itemsFilter, [ 'is_publicated' => 1, 'status' => Listings::STATUS_PUBLICATED, ]); if ($this->regionID > 0) { $filter[':region-filter'] = $this->regionID; } elseif ($this->region_filter) { $filter[':region-filter'] = Geo::filter('id'); } if ($this->categoryId > 0) { $filter[':cat-filter'] = $this->categoryId; } return $filter; } public function settingsForm($form) { $form->text('title', _t('@listings', 'Title'), _t('listings', 'New Listings', true)); $form->images('icon', _t('@listings', 'Icon'), 1) ->preload(bff::path('/static/img/default/icon_last.svg')); $form->number('limit', _t('@listings', 'Number'), 0, 0, 1, 20); if ($this->perlineCustomizable) { $form->radio('perline', _t('@listings', 'Density'), 5) ->option(5, _t('@listings', '5 in row')) ->option(4, _t('@listings', '4 in row')); } $form->checkbox('region_filter', _t('@listings', 'Take region filter in account'), $this->region_filter) ->tip(_t('@listings', 'display listings based on the current region')) ->hidden(! Listings::geoFilterEnabled()); } }