/** * 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; }
/** * @return \yii\db\ActiveQuery */ public function getPriceTypes() { return $this->hasMany(PriceTypes::className(), ['currency_code' => 'currency_code']); }
/** * Finds the PriceTypes model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return PriceTypes the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = PriceTypes::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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); } }
public function getAllPrices() { if ($this->_prices) { return $this->_prices; } if ($this->id) { $id = $this->id; } else { $id = 0; } $this->_prices = Prices::find()->select('*')->rightJoin(PriceTypes::tableName() . ' as price_types', Prices::tableName() . '.price_type_id = price_types.id AND ' . Prices::tableName() . '.product_id =' . (int) $id)->where('price_types.status != :status', ['status' => PriceTypes::STATUS_INACTIVE])->orderBy('price_types.order')->all(); /* $this->_prices = PriceTypes::find() ->where(PriceTypes::tableName().'.status != :status', ['status'=>PriceTypes::STATUS_INACTIVE]) ->orderBy('price_types.order') ->joinWith(['prices'=>function($query) use ($id) { if($id){ return $query->where(Prices::tableName().'.product_id=:product_id', [':product_id' => $id]); } }])->all();*/ return $this->_prices; }
/** * @return \yii\db\ActiveQuery */ public function getPriceType() { return $this->hasOne(PriceTypes::className(), ['id' => 'price_type_id']); }