loadDefaultDecoratorsIsDisabled()) { return $this; } $decorators = $this->getDecorators(); if (empty($decorators)) { $this->addDecorator('ProductList') ->addDecorator('Errors') ->addDecorator('Description', ['tag' => 'p', 'class' => 'description']) ->addDecorator('HtmlTag', [ 'tag' => 'dd', 'class' => 'event-products', 'id' => ['callback' => [get_class($this), 'resolveElementId']] ]) ->addDecorator('Label', ['tag' => 'dt']); } return $this; } public function getEventId() { if (null == $this->_eventId) { throw new \Exception('Required property "' . __CLASS__ . '->_eventId" is missing'); } return $this->_eventId; } public function setEventId($eventId) { $this->_eventId = $eventId; $this->_products = null; return $this; } public function isValid($value, $context = null) { if (parent::isValid($value, $context)) { $this->_validateProducts($this->getValue()); } return !$this->hasErrors(); } protected function _validateProducts($value) { $productIds = Qs_Array::fetchColAll((array) $this->getProducts(), 'id'); foreach ((array) $value as $productId => $count) { if (!in_array($productId, $productIds)) { $this->addError('Unknown product ID "' . $productId . '"'); continue; } if ($count < 0) { $this->addError('Quantity can\'t be less than zero "' . $count . '"'); } } return $this; } public function getProducts() { if (null === $this->_products) { $this->_products = EventModel::readProducts($this->getEventId()); } return $this->_products; } }