_doc->getAuth()->isLoggedIn()) { $this->_actions = array_merge($this->_actions, ['insertVendor', 'insertAttendee']); } $params = $this->getRestParams(); $action = Qs_Request::getPostValue('action'); if ($action && in_array($action, $this->_actions)) { $this->_action = $action; } elseif ( 1 === count($params) && $params[0] && ('y' == $this->_getDataObj()->setPrimaryKeyByAlias($params[0])->getData('enabled')) ) { $this->_action = 'view'; } else { $this->_do404(); } return parent::_initAction(); } protected function _getVendorForm(array $options = []) { $options = array_merge($this->_getVendorFormOptions(), $options); $form = $this->_getFormInstance('vendor', $options); $form->setDefaults(); return $form; } protected function _getVendorFormOptions() { $options = [ 'tradeShowId' => $this->_getDataObj()->getPrimaryKey(), 'tradeShowObj' => $this->_getDataObj(), 'userAutocompleteUrl' => UserAutocompleteView::getUserAutocompleteUrl4TradeShow(), 'userSide' => true, 'cartId' => $this->_getCart()->getCartId() ]; return $options; } protected function _initVendorForm(&$item, Qs_Form $form = null) { if (null === $form) { $options = []; $form = $this->_getVendorForm($options); } $form->setAttrib('id', 'add-vendor-form'); $item['addVendorFormHtml'] = $form->render(); return $this; } protected function _getAttendeeForm(array $options = []) { $options = array_merge($this->_getAttendeeFormOptions(), $options); $form = $this->_getFormInstance('attendee', $options); $form->setDefaults(); return $form; } protected function _getAttendeeFormOptions() { $options = [ 'tradeShowObj' => $this->_getDataObj(), 'userAutocompleteUrl' => UserAutocompleteView::getUserAutocompleteUrl4TradeShow(), 'userSide' => true, 'cartId' => $this->_getCart()->getCartId() ]; return $options; } protected function _initAttendeeForm(&$item, Qs_Form $form = null) { $options = []; $form = $this->_getAttendeeForm($options); $form->setAttrib('id', 'add-attendee-form'); $item['addAttendeeFormHtml'] = $form->render(); return $this; } protected function _doView() { $item = $this->_getViewItem(); $this->_initPageSeo($item); $this->_addItem($item); $this->_postView(); return $this; } /** * @param \Qs_Form $form Initialized form from _doInsertVendor|_doInsertAttendee action * @return array|null */ protected function _getViewItem(Qs_Form $form = null) { $item = $this->_getDataObj()->getData(); Obj::preparePricingData($item); $item['calendarUrl'] = EventView::getPageUrlByType(ConfigForm::TYPE_CALENDAR); $item['tpl'] = $this->getTemplate('view.tpl'); $now = date('Y-m-d H:i:s'); if ($now <= $item['registrationEndTime'] && $now >= $item['registrationStartTime']) { $item['showPrices'] = true; if (($item['registrationAllowed'] = $this->_doc->getAuth()->isLoggedIn())) { $boothSpaceValidator = new IsBoothSpace(['cartId' => $this->_getCart()->getCartId()]); if ($item['noBoothSpace'] = !$boothSpaceValidator->isValid($item['id'])) { $item['noBoothSpaceMessage'] = current($boothSpaceValidator->getMessages()); } else { $this->_initVendorForm($item); } $this->_initAttendeeForm($item); } else { LoginView::setSessionRedirectPageAlias(CURRENT_PAGE); $loginForm = $this->getLoginForm(); $this->_doc->addScript('js/jquery.defaultHint.js'); $this->_doc->addInitFunction('$("#' . $loginForm->getId() . '").defaultHint', [['useWrapper' => true]]); $item['loginForm'] = [ 'containerId' => 'tradeshow-login-block', 'html' => $loginForm->render(), ]; } } else { $item['showPrices'] = false; $item['registrationAllowed'] = false; } $item['ebDeadlineInFuture'] = (date("Y-m-d H:i:s") <= date("Y-m-d H:i:s", strtotime($item['ebDeadline']))) ? true : false; return $item; } protected function getLoginForm() { $loginView = new LoginView(); $form = $loginView->getLoginBlockForm(['hasBecomeMemberButton' => true]); $form->prependId(); $form->initRender(); return $form; } protected function _doInsertVendorAjax() { $form = $this->_getVendorForm(); $this->_displayJson($form->validateAjax()); } protected function _doInsertVendor() { $vendorObj = $this->_getDataObj()->getVendorObj(); $form = $this->_getVendorForm(); if ($form->validate()) { $data = $form->getValues(); $vendorObj->initFromForm($data); if (false === $vendorObj->insert()) { $this->_setBackErrors($vendorObj->getErrors()); } else { $this->_addItemToCart(Entity::TYPE_VENDOR); $this->_postInsert(); } $this->_doBack(); } else { $item = $this->_getViewItem(); $this->_addItem($item); } return $this; } protected function _doInsertAttendeeAjax() { $form = $this->_getAttendeeForm(); $this->_displayJson($form->validateAjax()); } protected function _doInsertAttendee() { $attendeeObj = $this->_getDataObj()->getAttendeeObj(); $form = $this->_getAttendeeForm(); if ($form->validate()) { $data = $form->getValues(); $attendeeObj->initFromForm($data); if (false === $attendeeObj->insert()) { $this->_setBackErrors($attendeeObj->getErrors()); } else { $this->_addItemToCart(Entity::TYPE_SINGLE_ATTENDEE); $this->_postInsert(); } $this->_doBack(); } else { $item = $this->_getViewItem(); $this->_addItem($item); } return $this; } protected function _postInsert() { parent::_postInsert(); if (!$this->_doc->getAuth()->getIdentity()) { \App_ECommerce_Checkout_LoginBlock_View::setSessionValue('skipLogin', true); } if (($url = \Qs_SiteMap::findFirst(null, ['type' => 'ECommerce_Cart_'], null, 'url'))) { \Qs_Http::redirect($url); } return $this; } /** * add item to CartItem */ protected function _addItemToCart($itemType) { $tradeShowData = $this->getData(); if ($itemType == Entity::TYPE_VENDOR) { $vendorObj = $this->_getDataObj()->getVendorObj(); $vendorData = $vendorObj->getData(); $item = $this->_prepareCartItemData($tradeShowData, $vendorData); $this->_getCart()->addItem($item); } else { $attendeeObj = $this->_getDataObj()->getAttendeeObj(); $attendeeData = $attendeeObj->getData(); foreach ($attendeeData as $attendee) { $item = $this->_prepareCartItemData($tradeShowData, $attendee); $this->_getCart()->addItem($item); } } return $this; } protected function _prepareCartItemData(array $tradeShowData, array $itemData) { $cartItemData = [ 'cartItemType' => CartItemObj::ITEM_TYPE, 'recordType' => $itemData['recordType'], 'productId' => $itemData['registrationId'], 'productCategoryId' => $tradeShowData['id'], 'title' => $tradeShowData['title'], 'quantity' => 1, 'price' => $itemData['amount'], 'applyShipping' => 'n', 'applyTax' => 'n' ]; $cartItemObj = new CartItemObj(); $cartItemObj->setCartItemData($cartItemData); $descriptions = $cartItemObj->getDescriptions(); $item = $cartItemObj->getCartItemData(); $item['shortDescription'] = $descriptions['shortDescription']; $item['description'] = $descriptions['description']; return $item; } public static function getViewUrl($alias = null) { if (!$alias) { $alias = '%s'; } return static::getPage('url') . '/' . $alias; } }