/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ArrayDataProvider
  */
 public function search($params = [])
 {
     $caloriesQuery = RecipeRepository::getCaloriesQuery('dr.recipe_id')->createCommand()->sql;
     $proteinsQuery = RecipeRepository::getProteinsQuery('dr.recipe_id')->createCommand()->sql;
     $fatsQuery = RecipeRepository::getFatsQuery('dr.recipe_id')->createCommand()->sql;
     $carbohydratesQuery = RecipeRepository::getCarbohydratesQuery('dr.recipe_id')->createCommand()->sql;
     $query = IngredientEntity::find()->select(['(\'' . IngredientEntity::TYPE_WEIGHT . '\') AS type', 'r.id', 'r.name', 'dr.weight', "({$caloriesQuery}) * `dr`.`weight` AS `calories`", "({$proteinsQuery}) * `dr`.`weight` AS `protein`", "({$fatsQuery}) * `dr`.`weight` AS `fat`", "({$carbohydratesQuery}) * `dr`.`weight` AS `carbohydrate`"])->from(['dr' => Diary::diary2recipesTableName()])->leftJoin(['r' => Recipe::tableName()], 'r.id = dr.recipe_id')->where(['dr.diary_id' => $this->id])->orderBy('calories DESC');
     $dataProvider = new ArrayDataProvider(['allModels' => $query->all(), 'sort' => ['attributes' => ['name', 'weight', 'calories', 'protein', 'fat', 'carbohydrate'], 'defaultOrder' => ['name' => SORT_ASC]], 'pagination' => false]);
     return $dataProvider;
 }
 /**
  * @param array $params
  * @return ArrayDataProvider
  */
 public function search($params = [])
 {
     $query = IngredientEntity::find()->select(['(\'' . IngredientEntity::TYPE_WEIGHT . '\') AS type', 'p.id', 'p.name', 'rp.weight', '`rp`.`weight`*`p`.`calories` AS `calories`', '`rp`.`weight`*`p`.`protein` AS `protein`', '`rp`.`weight`*`p`.`fat` AS `fat`', '`rp`.`weight`*`p`.`carbohydrate` AS `carbohydrate`'])->from(['rp' => Recipe::recipe2productsTableName()])->leftJoin(['p' => Product::tableName()], 'p.id = rp.product_id')->where(['rp.recipe_id' => $this->id])->orderBy('calories DESC');
     $dataProvider = new ArrayDataProvider(['allModels' => $query->all(), 'sort' => ['attributes' => ['name', 'weight', 'calories', 'protein', 'fat', 'carbohydrate'], 'defaultOrder' => ['name' => SORT_ASC]], 'pagination' => false]);
     return $dataProvider;
 }