示例#1
0
 public function setValue($entityModel, $catgoryId, $itemId, $value)
 {
     if (!isset($this->_value) || !$this->_value) {
         $this->_value = $this->loadValue($entityModel, $catgoryId, $itemId);
     }
     if (!$this->_value) {
         if (!($eavModel = EavEntityModel::findOne(['entity_model' => $entityModel]))) {
             throw new InvalidParamException(Yii::t('yee/eav', 'Model was not found.'));
         }
         if (!($eavEntity = EavEntity::findOne(['model_id' => $eavModel->id, 'category_id' => $catgoryId]))) {
             throw new InvalidParamException(Yii::t('yee/eav', 'Entity was not found.'));
         }
         $eavValue = new EavValue(['entity_id' => $eavEntity->id, 'attribute_id' => $this->getPrimaryKey(), 'item_id' => $itemId, 'value' => $value]);
         if (!$eavValue->save()) {
             throw new \yii\db\Exception(Yii::t('yee/eav', 'An error occurred during creation of EavValue record.'));
         }
         $this->_value = $eavValue;
     }
     $this->_value->value = $value;
 }
 public function actionGetCategories()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $model_id = (int) Yii::$app->getRequest()->post('model_id');
     $model = EavEntityModel::findOne($model_id);
     if ($model) {
         try {
             $model = new $model->entity_model();
             if ($model instanceof EavCategories) {
                 $categories = $model->getEavCategories();
                 if ($categories && !empty($categories)) {
                     $categories = ArrayHelper::merge(['' => Yii::t('yee', 'Not Selected')], $categories);
                     $dropDown = Html::dropDownList('entityCategory', null, $categories, ['id' => 'entityCategory', 'class' => 'form-control']);
                     return ['list' => $dropDown];
                 }
             }
         } catch (Exception $exc) {
             return null;
         }
     }
     return null;
 }