_tradeShowId = (int) $tradeShowId; $this->_tradeShowObj = null; $this->_tradeShowData = null; return $this; } public function getTradeShowId() { if (null == $this->_tradeShowId) { throw new Qs_Exception_EmptyPropertyException($this, '_tradeShowId'); } return $this->_tradeShowId; } public function getTradeShowData($field = null, $default = null) { if (null === $this->_tradeShowData) { $this->_tradeShowData = $this->_getTradeShowFromDb($this->getTradeShowId()); } return (null === $field) ? $this->_tradeShowData : Qs_Array::get($this->_tradeShowData, $field, $default); } protected function _getTradeShowFromDb($tradeShowId) { $select = $this->_db->select(); $select->from($this->_getPair('TradeShow', 'ts'), ['*']); $select->where('ts.id = ?', $tradeShowId, Qs_Db::INT_TYPE); return $this->_db->fetchRow($select); } public function getTradeShowObj() { if (null === $this->_tradeShowObj) { $this->_tradeShowObj = new TradeShowObj(['primaryKey' => $this->getTradeShowId()]); } return $this->_tradeShowObj; } protected function _joinVendor(\Zend_Db_Select $select) { $select->joinLeft( $this->_getPair('TradeShowVendor', 'tsv'), '`tsv`.`registrationId` = `tsr`.`id`' ); return $this; } protected function _joinAttendee(\Zend_Db_Select $select) { $select->joinLeft( $this->_getPair('TradeShowAttendee', 'tsa'), '`tsa`.`registrationId` = `tsr`.`id`', ['userId', 'firstName', 'lastName', 'companyName', 'nickname', 'email'] ); return $this; } protected function _insertVendorData(array $data) { $this->_getTable('TradeShowVendor')->insert([ 'registrationId' => $this->_primaryKey, 'exhibitorCompanyName' => $data['exhibitorCompanyName'], 'contactName' => $data['contactName'], 'contactEmail' => $data['contactEmail'], 'contactPhone' => $data['contactPhone'], 'boothSpace' => $data['boothSpace'], 'electricityHookUp' => $data['electricityHookUp'], 'notes' => $data['notes'] ]); return $this; } protected function _insertAttendeeData(array $data) { $attendeeList = $this->_prepareAttendeeList($data['userId']); foreach ($attendeeList as $attendee) { $this->_getTable('TradeShowAttendee')->insert([ 'registrationId' => $this->_primaryKey, 'userId' => $attendee['userId'], 'companyName' => $attendee['companyName'], 'firstName' => $attendee['firstName'], 'nickname' => $attendee['nickname'], 'lastName' => $attendee['lastName'], 'email' => $attendee['email'], ]); } return $this; } protected function _prepareAttendeeList($attendeeList) { $result = []; foreach ($attendeeList as $attendee) { if ($attendee['userId']) { /* set by Autocomplite */ $userData = $this->_getUserInfoList($attendee['userId']); } else { /* set Manually */ $userData = $this->_parseUserInfo($attendee['_userId']); } $result[] = $userData; } return $result; } /** * @param int $userId * @return array */ protected function _getUserInfoList($userId) { $select = $this->_db->select(); $select->from($this->_getPair('User', 'u'), ['userId' => 'id', 'firstName', 'nickname', 'lastName', 'email']); $select->joinLeft($this->_getPair('Company', 'c'), 'c.id = u.companyId', ['companyName' => 'name']); $select->where('`u`.`id` = ? ', $userId, \Qs_Db::INT_TYPE); return $this->_db->fetchRow($select); } /** * Parse user firstName and lastName * @param string $userNameString * @return array */ protected function _parseUserInfo($userNameString) { $matches = []; $userInfo = []; if (preg_match('/(?^[a-zA-Z.-]+)\s(?[a-zA-Z.-\s]+)/', $userNameString, $matches)) { $userInfo = [ 'userId' => null, 'companyName' => null, 'firstName' => $matches['firstName'], 'nickname' => null, 'lastName' => $matches['lastName'] ]; } return $userInfo; } /** * @param string|null $value allowed values: 'y', null * @return int Return count updated rows * @throws Qs_Exception */ public function setBought($value = 'y') { if (!in_array($value, array('y', null))) { throw new Qs_Exception('Incorrect "bought" value.'); } if (!$this->getPrimaryKey()) { throw new Qs_Exception('Primary key is not defined.'); } return $this->_getTable()->updateByKey(array('bought' => $value), $this->getPrimaryKey()); } /** * @param array $data * Example: array('paymentDate' => '2014-05-29', 'paymentType' => 'cash') * @return int Return count updated rows * @throws Qs_Exception */ public function setPaymentInfo($data) { if (!array_key_exists('paymentDate', $data) || !$data['paymentDate']) { throw new Qs_Exception('Incorrect "paymentDate" value.'); } if (!array_key_exists('paymentType', $data) || !$data['paymentType']) { throw new Qs_Exception('Incorrect "paymentType" value.'); } if (!$this->getPrimaryKey()) { throw new Qs_Exception('Primary key is not defined.'); } return $this->_getTable()->updateByKey( array( 'paymentDate' => $data['paymentDate'], 'paymentType' => $data['paymentType'], 'registrationDate' => date('Y-m-d H:i:s') ), $this->getPrimaryKey() ); } }