public function actionEdit($id = null) { $model = new DynamicContent(); $model->loadDefaultValues(); if ($id !== null) { $model = DynamicContent::findOne($id); } $static_values_properties = []; if (isset($_GET['DynamicContent'])) { if (isset($_GET['DynamicContent']['object_id'])) { $model->object_id = intval($_GET['DynamicContent']['object_id']); } } $property_groups_ids_for_object = (new Query())->select('id')->from(PropertyGroup::tableName())->where([])->column(); $properties = Property::find()->where(['has_static_values' => 1, 'has_slugs_in_values' => 1])->andWhere(['in', 'property_group_id', $property_groups_ids_for_object])->all(); foreach ($properties as $prop) { $static_values_properties[$prop->id] = ['has_static_values' => true, 'property' => $prop, 'static_values_select' => PropertyStaticValues::getSelectForPropertyId($prop->id)]; } $post = \Yii::$app->request->post(); if (isset($_GET['DynamicContent'])) { $post = $_GET; } if ($model->load($post) && $model->validate() && !isset($_GET['DynamicContent'])) { $save_result = $model->save(); if ($save_result) { return $this->redirectUser($model->id); } else { \Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot update data')); } } return $this->render('dynamic-content-form', ['model' => $model, 'static_values_properties' => $static_values_properties]); }
public function actionEdit($id = null) { $model = new PrefilteredPages(); $model->loadDefaultValues(); if ($id !== null) { $model = PrefilteredPages::findOne($id); } $static_values_properties = []; $property_groups_ids_for_object = (new Query())->select('id')->from(PropertyGroup::tableName())->where(['object_id' => Object::getForClass(Product::className())->id])->column(); $properties = Property::find()->andWhere(['in', 'property_group_id', $property_groups_ids_for_object])->all(); foreach ($properties as $prop) { /** @var Property $prop */ $static_values_properties[$prop->id] = ['property' => $prop, 'static_values_select' => PropertyStaticValues::getSelectForPropertyId($prop->id), 'has_static_values' => $prop->has_static_values === 1]; } $post = \Yii::$app->request->post(); if ($model->load($post) && $model->validate()) { $save_result = $model->save(); if ($save_result) { Yii::$app->session->setFlash('info', Yii::t('app', 'Object saved')); $returnUrl = Yii::$app->request->get('returnUrl', ['index', 'id' => $model->id]); switch (Yii::$app->request->post('action', 'save')) { case 'next': return $this->redirect(['edit', 'returnUrl' => $returnUrl]); case 'back': return $this->redirect($returnUrl); default: return $this->redirect(Url::toRoute(['edit', 'id' => $model->id, 'returnUrl' => $returnUrl])); } //return $this->redirect(['/backend/prefiltered-pages/edit', 'id' => $model->id]); } else { \Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot update data')); } } return $this->render('prefiltered-page-form', ['model' => $model, 'static_values_properties' => $static_values_properties]); }
public function columns($baseModelColumns) { $columns = $baseModelColumns; foreach ($this->propertyGroups as $groupId => $properties) { foreach ($properties as $key => $propertyValue) { /** @var PropertyValue $propertyValue */ $prop = Property::findById($propertyValue->property_id); if ($prop->has_static_values) { $column = ['value' => function ($model) use($prop) { return $model->property($prop->key); }, 'filter' => PropertyStaticValues::getSelectForPropertyId($propertyValue->property_id)]; } elseif ($prop->property_handler_id === 3) { $column = ['value' => function ($model) use($prop) { return $model->property($prop->key); }, 'filter' => [0 => Yii::t('app', 'No'), 1 => Yii::t('app', 'Yes')]]; } else { $column = ['value' => function ($model) use($prop) { return $model->property($prop->key); }]; } $column = ArrayHelper::merge($column, ['header' => $prop->name, 'attribute' => $prop->key, 'enableSorting' => true]); $columns[] = $column; } } return $columns; }