db = Qs_Db::getInstance(); } public function getBothSpaceInfo($tradeShowId, $cartId) { $select = $this->db->select(); $select->from(Qs_Db::getPair('TradeShow', 'ts'), [ 'limit' => 'boothSpaceLimit', 'registered' => $this->getRegisteredVendorsCountExpr(), 'inCart' => $this->getInCartVendorsCountExpr($cartId), ]); $select->where('`ts`.`id` = ?', $tradeShowId, Qs_Db::INT_TYPE); $info = $select->getAdapter()->fetchRow($select); $info['is'] = max($info['limit'] - $info['registered'], 0); return $info; } public function getIsBoothSpaceExpr() { return new Zend_Db_Expr('ISNULL(`ts`.`boothSpaceLimit`) ' . 'OR `ts`.`boothSpaceLimit` > (' . $this->getRegisteredVendorsCountExpr() . ')'); } public function getRegisteredVendorsCountExpr() { $select = $this->db->select(); $select->from(Qs_Db::getPair('TradeShowRegistration', 'tsr'), 'COUNT(*)'); $select->where('`tsr`.`tradeShowId` = `ts`.`id`'); $select->where('`tsr`.`recordType` = ?', Entity::TYPE_VENDOR); $select->where('`tsr`.`bought` = ?', 'y'); return new Zend_Db_Expr('(' . $select . ')'); } public function getInCartVendorsCountExpr($cartId) { $select = Qs_Db::getSelect(); $select->from(Qs_Db::getPair('CartItem', 'ci'), ['COUNT(*)']); $select->joinLeft(Qs_Db::getPair('TradeShowRegistration', 'tsr'), '`ci`.`productId` = `tsr`.`id`', []); $select->where('`ci`.`cartId` = ?', $cartId, Qs_Db::INT_TYPE); $select->where('`ci`.`cartItemType` = ?', CartItemObj::ITEM_TYPE); $select->where('`tsr`.`recordType` = ?', Entity::TYPE_VENDOR); $select->where('`tsr`.`bought` = ?', 'n'); return new Zend_Db_Expr('(' . $select . ')'); } public static function getAttendeeNameExpr() { return new Zend_Db_Expr('CONCAT_WS(" ", `tsa`.`firstName`, `tsa`.`lastName`)'); } public static function getRegistrationAllowedExpr($alias = 'ts') { $expr = "{$alias}.registrationStartTime < NOW() AND {$alias}.registrationEndTime > NOW()"; return new Zend_Db_Expr($expr); } public static function getAttendeeAutocompleteTitle(array $attendee) { return (empty($attendee['nickname']) ? $attendee['firstName'] : $attendee['nickname']) . " " . $attendee['lastName'] . (empty($attendee['companyName']) ? '' : ', ' . $attendee['companyName']); } }