protected function loadEavAttributes() { if (!$this->isAttributesLoaded) { $modelTable = EavEntityModel::tableName(); $entityTable = EavEntity::tableName(); $attributeTable = EavAttribute::tableName(); $entityToAttributeTable = '{{%eav_entity_attribute}}'; $attributes = EavAttribute::find()->innerJoin($entityToAttributeTable, "{$attributeTable}.id = {$entityToAttributeTable}.attribute_id")->innerJoin($entityTable, "{$entityToAttributeTable}.entity_id = {$entityTable}.id")->innerJoin($modelTable, "{$entityTable}.model_id = {$modelTable}.id")->andWhere(["{$modelTable}.entity_model" => $this->ownerClassName])->andWhere(["{$entityTable}.category_id" => $this->getEavCatgoryId()])->orderBy(['order' => SORT_DESC])->all(); $validators = $this->owner->getValidators(); foreach ($attributes as $attribute) { $this->eavAttributes->{$attribute['name']} = $attribute; $validators[] = \yii\validators\Validator::createValidator('safe', $this->owner, [$attribute['name']], []); } $this->isAttributesLoaded = true; } }
protected function loadValue($entityModel, $catgoryId, $itemId) { $modelTable = EavEntityModel::tableName(); $valueTable = EavValue::tableName(); $entityTable = EavEntity::tableName(); $value = EavValue::find()->innerJoin($entityTable, "{$valueTable}.entity_id = {$entityTable}.id")->innerJoin($modelTable, "{$entityTable}.model_id = {$modelTable}.id")->andWhere(["entity_model" => $entityModel])->andWhere(["category_id" => $catgoryId])->andWhere(["item_id" => $itemId])->andWhere(["attribute_id" => $this->getPrimaryKey()])->one(); return $value ? $value : null; }