/** * Attach existing attribute to existing object type. * @param int $objectTypeId * @param int $attributeId * * @throws \yii\base\UserException */ public static function attachAttributeToObjectType($objectTypeId, $attributeId) { $objectType = ObjectTypes::getItem($objectTypeId); $attribute = Attributes::getItem($attributeId); $objectType->attachAttribute($attribute->id); }
/** * Updates an existing Attributes model. * If update is successful, the browser will be redirected to the 'view' page. * * @param string $id * * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $attachInfo = $objectType = null; $attachedTo = new ArrayDataProvider(['allModels' => AttributesAttached::find()->where(['attr_id' => $model->id])->with('objectType')->all(), 'pagination' => ['pageSize' => 10]]); $attachedToId = Yii::$app->request->getQueryParam('object_type_id'); if ($attachedToId) { $objectType = ObjectTypes::getItem($attachedToId); $attachInfo = $objectType->getAttributesAttached()->where(['attr_id' => $model->id])->one(); } if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($attachInfo) { if ($attachInfo->load(Yii::$app->request->post()) && $attachInfo->save()) { return $this->redirect(Yii::$app->request->getReferrer()); } } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'attrTypes' => $this->getAttributeTypes(), 'attachInfo' => $attachInfo, 'objectType' => $objectType, 'attachedTo' => $attachedTo]); } }