setTemplate('account/items/list', 'listings'); $this->setTitle(_t('@listings', 'List')); $this->setKey('ListBlock'); } /** * Create item blocks from items data * @return mixed|void */ protected function beforeRender() { if (parent::beforeRender() === false) { return false; } foreach ($this->items as $key => $item) { $this->items[$key] = $this->itemBlock($item); } } public function data() { $data = parent::data(); $settings = [ 'servicesEnabled' => 0, 'viewStatistics' => $this->viewStatistics, ]; if (bff::servicesEnabled('listings')) { # бесплатное поднятие $settings['servicesEnabled'] = 1; $up = Listings::itemServices('up'); if ($up) { $settings['upfree_days'] = $up->getFreePeriod(); $settings['upauto_enabled'] = $up->isAutoEnabled(); if ($settings['upfree_days'] > 0) { $settings['upfree_to'] = strtotime('-' . $settings['upfree_days'] . ' days'); } } # формируем данные об активных услугах объявлений Listings::itemServices()->addCabinetItemsListActiveServices($this->items); $settings['svc_url'] = function ($svc, $item) { return Listings::url('item.promote', ['id' => $item['id'], 'svc' => $svc, 'from' => 'cabinet']); }; } $this->itemSettings = $settings; return $data; } /** * Set items data * @param array $items */ public function setItems(array $items) { $this->items = $items; } /** * Set item view class * @param string $view */ public function setItemView(string $view) { $this->itemView = $view; } /** * Load items data & return filter * @param array $filter * @param bool $idsOnly * @return mixed */ public function loadItems($filter = [], $idsOnly = false) { if ($idsOnly) { $filter['onlyIDs'] = true; return Listings::model()->itemsListMy($filter); } /** @var ItemsPage $parent */ $parent = $this->getParentPage(); $parent->total = Listings::model()->itemsListMy($filter, true); if ($parent->total > 0) { $pageSize = $parent->pageSizesList[$parent->pageSize]['c']; $pages = new Pagination($parent->total, $pageSize, '?' . Pagination::PAGE_PARAM); $parent->pages = $pages->view([], tpl::PGN_COMPACT); $this->items = Listings::model()->itemsListMy($filter, false, [ 'limit' => $pages->getLimit(), 'offset' => $pages->getOffset(), 'orderBy' => 'id ' . ($parent->orderBy ? 'ASC' : 'DESC'), ]); $parent->page = $pages->getCurrentPage(); # Prepare default items images $list = new ListListBlock(); $list->setItems($this->items); $list->prepareItems(); $this->items = $list->items; } } /** * Create item block * @param array $item item data * @return ItemBlock|mixed */ protected function itemBlock(array $item) { $class = $this->itemView; return new $class($this->defaults([ 'item' => $item, ], $this->itemSettings)); } public function settingsForm($form) { $form->select('viewStatistics', _t('@listings', 'Listing statistics visibility'), $this->viewStatistics) ->option(1, _t('@', 'Enabled')) ->option(0, _t('@', 'Disabled')) ; } }