public function search($params)
 {
     $query = Cellarwines::find();
     $query->joinWith(['cellar', 'wine', 'cellarLoc', 'wine.winery', 'wine.wineVarietal']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['attributes' => ['cellar_name' => ['asc' => ['cellar_name' => SORT_ASC], 'desc' => ['cellar_name' => SORT_DESC]], 'loc_name' => ['asc' => ['loc_name' => SORT_ASC], 'desc' => ['loc_name' => SORT_DESC]], 'winery_name' => ['asc' => ['winery_name' => SORT_ASC], 'desc' => ['winery_name' => SORT_DESC]], 'wine_name' => ['asc' => ['wine_name' => SORT_ASC], 'desc' => ['wine_name' => SORT_DESC]], 'wine_year' => ['asc' => ['wine_year' => SORT_ASC], 'desc' => ['wine_year' => SORT_DESC]], 'varietal_name' => ['asc' => ['varietal_name' => SORT_ASC], 'desc' => ['varietal_name' => SORT_DESC]]]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'cellar_id' => $this->cellar_id, 'wine_id' => $this->wine_id, 'quantity' => $this->quantity, 'rating' => $this->rating, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'cost' => $this->cost, 'cellar_loc_id' => $this->cellar_loc_id])->andFilterWhere(['like', 'locations.loc_name', $this->loc_name])->andFilterWhere(['like', 'wineries.winery_name', $this->winery_name])->andFilterWhere(['like', 'wines.wine_year', $this->wine_year]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Cellarwines::find();
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'cellar_id' => $this->cellar_id, 'wine_id' => $this->wine_id, 'quantity' => $this->quantity, 'rating' => $this->rating, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'cost' => $this->cost, 'cellar_loc_id' => $this->cellar_loc_id]);
     return $dataProvider;
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCellarwines()
 {
     return $this->hasMany(Cellarwines::className(), ['cellar_id' => 'id']);
 }
 /**
  * Finds the Cellarwines model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Cellarwines the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Cellarwines::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }