setTemplate('form/page', 'listings'); $this->setKey('form_page'); $this->withSeoSettings('add', 'listings')->breadcrumb()->titleH1(); $this->setTitle(_t('@listings', 'Listings / Form')); $this->useBreadcrumbs(); $this->titleh1 = _t('item-form', 'Place Listing'); } public function data() { $data = parent::data(); # Breadcrumbs $this->breadcrumbs->add(_t('listings', 'Listings'), ($this->request->user() ? Listings::url('my.items') : Listings::url('items.search') )); $this->breadcrumbs->add($this->titleh1); return $data; } public function edit($id = 0) { if (! $this->request->user()) { return $this->errors->error404(); } if (! $id) { return $this->errors->error404(); } $this->loadSettings(); return $this->handle($id); } public function handle($id = 0) { $this->itemId = $id; $form = $this->getForm(); $companyID = User::companyID(); $userID = User::id(); $form->load($id); if ($id) { if (empty($form->item['id'])) { return $this->errors->error404(); } $this->titleh1 = _t('item-form', 'Editing Listing'); if ($form->item['user_id'] != User::id()) { return $this->forbiddenMessage($this->titleh1, _t('item-form', 'You are not the owner of this listing')); } if ($form->item['status'] == Listings::STATUS_NOTACTIVATED) { return $this->forbiddenMessage($this->titleh1, _t('item-form', 'Listing is not yet active')); } if ($form->item['status'] == Listings::STATUS_BLOCKED && !$form->item['moderated']) { return $this->forbiddenMessage($this->titleh1, _t('item-form', 'Listing awaits moderator review')); } } else { $publisherOnlyCompany = Listings::publisher(Listings::PUBLISHER_COMPANY) || (Listings::publisher(Listings::PUBLISHER_USER_TO_COMPANY) && $companyID); if (! $userID && Listings::publisherAuth()) { return Redirect::to(Users::url('login', ['ref' => Listings::url('item.add')])); } if ($publisherOnlyCompany) { if (! $userID) { return Listings::showInlineMessage(_t('item-form', 'Only logged in users can publish listings'), [ 'auth' => true ]); } if (! $companyID) { return Listings::showInlineMessage(_t('item-form', 'You need to open a company to publish a listing.', [ 'link' => 'href="' . Business::url('company.open') . '"' ])); } elseif (!Business::model()->companyActive($companyID)) { return Listings::showInlineMessage(_t('item-form', 'Only activated company can publish listings.', [ 'link' => 'href="' . Business::url('my.listings') . '"', ])); } } $cat = $this->request->get('cat', TYPE_UINT); if ($cat) { $form->loadCategory($cat); } } return $this; } /** * Item form block * @return ItemForm|mixed */ public function getForm() { return $this->getBlock('form'); } public function blocks() { $this->addBlock('form', ItemForm::class); $this->addBlock('alert', ItemAlert::class, function (ItemAlert $block) { $block->form = $this->getForm(); }); } public function seo() { if (! $this->itemId) { $this->request->urlCorrection(Listings::url('item.add')); $this->seo->canonicalUrl(Listings::url('item.add', [], true)); } $this->seoMacrosRegionsData(); $this->seoApply(); } public function seoSettings() { $this->seoMacrosRegions(); } }