/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PriceTypes::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'order' => $this->order, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'currency_code', $this->currency_code])->andFilterWhere(['like', 'currency_symbol', $this->currency_symbol])->andFilterWhere(['like', 'data', $this->data])->andFilterWhere(['like', 'icon', $this->icon]); return $dataProvider; }
public function validateStatus($attribute, $params) { if ($this->{$attribute} != self::STATUS_DEFAULT_PRICE && $this->{$attribute} != self::STATUS_ON_RBAC) { return; } $query = PriceTypes::find(); if ($this->{$attribute} == self::STATUS_DEFAULT_PRICE) { $query->andWhere(['status' => self::STATUS_DEFAULT_PRICE]); $message = StoreCube::t('storecube', 'VALIDATE_DEFAULT_PRICE'); } // in next version /*elseif($this->$attribute == self::STATUS_ON_RBAC) { $query->andWhere(['status' => self::STATUS_ON_RBAC]); //add data string conversions $message = StoreCube::t('storecube', 'VALIDATE_ON_RBAC'); }*/ if ($this->getIsNewRecord()) { $exists = $query->exists(); } else { // if current $model is in the database already we can't use exists() $models = $query->limit(2)->all(); $n = count($models); if ($n === 1) { $exists = $this->getOldPrimaryKey() != $this->getPrimaryKey(); } else { $exists = $n > 1; } } if ($exists) { $this->addError($attribute, $message); } }