Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PriceModel::find();
     $query->select(['price.*', 'product.*']);
     $query->joinWith(['product']);
     $query->orderBy(['product.name' => SORT_ASC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('1=0');
         return $dataProvider;
     }
     $query->andFilterWhere(['product_id' => $this->product_id, 'price_category_id' => $this->price_category_id, 'price' => $this->price, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andWhere(['like', 'lower(product.name)', strtolower($this->product_name)]);
     $query->andWhere(['like', 'lower(product.code)', strtolower($this->product_code)]);
     return $dataProvider;
 }
Example #2
0
 /**
  * Finds the Price model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $product_id
  * @param integer $price_category_id
  * @return Price the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($product_id, $price_category_id)
 {
     if (($model = Price::findOne(['product_id' => $product_id, 'price_category_id' => $price_category_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPrices()
 {
     return $this->hasMany(Price::className(), ['price_category_id' => 'id']);
 }