'There are no more booth spaces left', ]; protected $cartId; protected $cartItemId; public function __construct(array $options) { Qs_Options::setConstructorOptions($this, $options); if (empty($this->cartId)) { throw new Exception('Cart ID is not defined'); } } public function isValid($tradeShowId) { if (!($info = $this->getInfo($tradeShowId))) { throw new Exception('Failed to get trade show registration info'); } if (empty($info['limit']) || $info['limit'] > $info['registered'] + $info['inCart']) { return true; } if ($info['registered'] < $info['limit']) { $this->_messages[self::IN_CART] = $this->createInCartMessage($info); } else { $this->_error(self::NO_BOOTH_SPACE); } return false; } public function isCartValid($tradeShowId) { if (!($info = $this->getInfo($tradeShowId))) { throw new Exception('Failed to get trade show registration info'); } if (empty($info['limit']) || $info['limit'] >= $info['registered'] + $info['inCart']) { return true; } if ($info['registered'] < $info['limit']) { $this->_messages[self::IN_CART] = $this->createInCartMessage($info); } else { $this->_error(self::NO_BOOTH_SPACE); } return false; } private function getInfo($tradeShowId) { return (new TradeShowModel())->getBothSpaceInfo($tradeShowId, $this->getCartId()); } public function getCartId() { return $this->cartId; } public function setCartId($cartId) { $this->cartId = $cartId; return $this; } private function createInCartMessage($info) { $info['left'] = $info['limit'] - $info['registered']; $message = Qs_Translate::getPlural([ 'There is {left} booth space left', 'There are {left} booth spaces left' ], $info['left']); $message .= $info['left'] < $info['inCart'] ? ' but ' : ' and '; $message .= Qs_Translate::getPlural([ '{inCart} Exhibitor registration is in your cart.', '{inCart} Exhibitor registrations are in your cart.', ], $info['inCart']); $message = str_replace( 'your cart', 'your cart', $message ); return Qs_String::fill($message, $info, '{}'); } }