Esempio n. 1
0
 protected function findModel($id)
 {
     if (($model = FieldVariant::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested field does not exist.');
     }
 }
Esempio n. 2
0
 public function beforeDelete()
 {
     foreach ($this->hasMany(FieldValue::className(), ['field_id' => 'id'])->all() as $frv) {
         $frv->delete();
     }
     foreach ($this->hasMany(FieldVariant::className(), ['field_id' => 'id'])->all() as $fv) {
         $fv->delete();
     }
     return true;
 }
Esempio n. 3
0
 public function search($params)
 {
     $query = FieldVariant::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'field_id' => $this->field_id]);
     $query->andFilterWhere(['like', 'value', $this->value]);
     return $dataProvider;
 }
Esempio n. 4
0
 public function flush()
 {
     $this->fieldVariants = [];
     $values = FieldValue::find()->where(['item_id' => $this->owner->id])->with('field')->all();
     foreach ($values as $value) {
         if ($value->variant_id) {
             $this->fieldVariants[$value->field->slug] = FieldVariant::findOne($value->variant_id)->value;
         } else {
             $this->fieldVariants[$value->field->slug] = $value->value;
         }
     }
     return true;
 }
Esempio n. 5
0
 public function getVariant()
 {
     return $this->hasOne(FieldVariant::className(), ['id' => 'variant_id']);
 }
Esempio n. 6
0
 public function actionEditVariant()
 {
     $name = yii::$app->request->post('name');
     $value = yii::$app->request->post('value');
     $pk = unserialize(base64_decode(yii::$app->request->post('pk')));
     FieldVariant::saveEdit($pk, $name, $value);
 }
Esempio n. 7
0
 public static function saveEdit($id, $name, $value)
 {
     $setting = FieldVariant::findOne($id);
     $setting->{$name} = $value;
     $setting->save();
 }