_data = $this->prepareSignupFormData($this->_data); return $this; } public function prepareSignupFormData(array $data) { return $this->_prepareAttendeeList($data['attendeeId']); } public function insert(array $data = null) { $data = (null === $data) ? $this->_data : $data; $this->_db->beginTransaction(); $this->_clearErrors(); try { foreach ($data as $key => $value) { unset($value['id']); $this->_primaryKey = $this->_getTable()->insert($value); $this->_insertDependency($value); $this->_data[$key]['registrationId'] = $this->_primaryKey; } $this->_db->commit(); } catch (Exception $e) { $this->_db->rollBack(); Qs_Debug::processException($e); return false; } return $this->_primaryKey; } protected function _insertDependency(array $data) { $this->_insertAttendeeData($data); return $this; } protected function _insertAttendeeData(array $attendee) { $this->_getTable('TradeShowAttendee')->insert([ 'registrationId' => $this->_primaryKey, 'userId' => $attendee['attendeeId'], 'companyName' => $attendee['companyName'], 'firstName' => $attendee['firstName'], 'nickname' => $attendee['nickname'], 'lastName' => $attendee['lastName'], 'email' => $attendee['email'], ]); return $this; } protected function _prepareAttendeeList($attendeeList) { $result = []; $attendeePrice = $this->_prepareAttendeePrice(); foreach ($attendeeList as $attendee) { if ($attendee['attendeeId']) { /* set by Autocomplite */ $userData = $this->_getUserInfoList($attendee['attendeeId']); $itemData = [ 'tradeShowId' => $this->getTradeShowId(), 'recordType' => Entity::TYPE_SINGLE_ATTENDEE, 'paymentType' => null, 'paymentDate' => null, 'bought' => "n", 'amount' => $attendeePrice ]; $result[] = array_merge($userData, $itemData); } } return $result; } protected function _prepareAttendeePrice() { $tradeShow = $this->getTradeShowData(); TradeShowObj::preparePricingData($tradeShow); return (float) $tradeShow['boothRepresentativePrice']; } public function update(array $data = null) { throw new Exception('Not supported'); } protected function _getCart() { if (null === $this->_cart) { $this->_cart = new App_ECommerce_Cart_Obj(); $this->_cart->setPrimaryKey($this->_cart->getCartId()); } return $this->_cart; } /** * Filter bought and in cart attendees of current user * @param string $alias EventAttendee table alias * @return array */ public function getWhere($alias = null) { $aliasPrefix = (null === $alias) ? '' : "`{$alias}`."; $inCartExpr = $this->_getInCartExpr($alias); $where[] = new Zend_Db_Expr( "{$aliasPrefix}`bought` = 'y' OR ({$aliasPrefix}`bought` IS NULL AND EXISTS({$inCartExpr}))" ); return $where; } /** * @param string $alias EventAttendee table alias * @return \Zend_Db_Expr */ protected function _getInCartExpr($alias = null) { $aliasPrefix = (null === $alias) ? '' : "`{$alias}`."; $_cartId = (int) $this->_getCart()->getCartId(); $_cartItemTable = Qs_Db::getTableName('CartItem'); $sql = "SELECT 1 FROM `{$_cartItemTable}` `ci` " . "WHERE `ci`.`cartId` = {$_cartId} " . " AND `ci`.`productId` = {$aliasPrefix}`id` " . "LIMIT 1"; return new Zend_Db_Expr($sql); } }