public function addRecipe($book_id, $recipe_id) { $book = RecipeBook::find($book_id); $recipe = Recipe::find($recipe_id); $recipe->recipeBooks()->attach($book->id); return $recipe; }
public function buildQuery($query = null) { if ($query == null) { $query = Recipe::query(); } if (Input::has('query')) { $term = Input::get('query'); $query->where(function ($q) use($term) { $q->where('recipes.description', 'like', "%{$term}%")->orWhere('recipes.presentation', 'like', "%{$term}%"); }); $this->params['query'] = $term; } if (Input::has('title')) { $title = Input::get('title'); $query->where('recipes.title', 'like', "%{$title}%"); $this->params['title'] = $title; } if (Input::has('category')) { $category = Input::get('category'); if ($category != '*') { $query->where('category', '=', $category); $this->params['category'] = $category; } } if ($this->cookbook != '*') { $query->where('cookbook', '=', $this->cookbook); $this->params['cookbook'] = $this->cookbook; } elseif (Input::has('cookbook') && Input::get('cookbook') != '*') { $cookbook = Input::get('cookbook'); $query->where('cookbook', '=', $cookbook); $this->params['cookbook'] = $cookbook; } return $query; }
public function testParsingIngredientsHeaders() { $ingredients = "1.5 theelepels olie\n## Voor de hoofdmoot\n30 kilo aardappels\nZout\n##Afwerking\n1,6g poeder\n willekeurig\n"; $parsed = Recipe::parseIngredientsFromText($ingredients); $this->assertNull($parsed[0]->header); $this->assertEquals('Voor de hoofdmoot', $parsed[1]->header); $this->assertEquals('Voor de hoofdmoot', $parsed[2]->header); $this->assertEquals('Afwerking', $parsed[4]->header); $this->assertEquals('Afwerking', $parsed[5]->header); }
/** * 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; }
public function search($input) { $query = Recipe::query(); $columns = Schema::getColumnListing('recipes'); $attributes = array(); foreach ($columns as $attribute) { if (isset($input[$attribute]) and !empty($input[$attribute])) { $query->where($attribute, $input[$attribute]); $attributes[$attribute] = $input[$attribute]; } else { $attributes[$attribute] = null; } } return [$query->get(), $attributes]; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $this->addParam('categoryId', $params); $caloriesSql = self::getCaloriesQuery('`r`.`id`')->createCommand()->sql; $proteinsSql = self::getProteinsQuery('`r`.`id`')->createCommand()->sql; $fatsSql = self::getFatsQuery('`r`.`id`')->createCommand()->sql; $carbohydratesSql = self::getCarbohydratesQuery('`r`.`id`')->createCommand()->sql; $query = Recipe::find()->select(['r.*', 'categoryName' => 'c.name', 'calories' => "({$caloriesSql})", 'proteins' => "({$proteinsSql})", 'fats' => "({$fatsSql})", 'carbohydrates' => "({$carbohydratesSql})"])->from(self::tableName() . ' `r`')->leftJoin(RecipeCategory::tableName() . ' `c`', '`c`.`id` = `r`.`category_id`'); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere([]); $query->andFilterWhere(['like', '`r`.`name`', $this->name])->andFilterWhere(['like', '`r`.`description`', $this->description])->andFilterWhere(['like', '`c`.`name`', $this->categoryName])->andFilterWhere(['category_id' => $this->categoryId]); $dataProvider->sort = ['attributes' => ['name', 'categoryName', 'calories', 'proteins', 'fats', 'carbohydrates']]; return $dataProvider; }
public function run() { DB::table('recipes')->delete(); $deployerRecipes = ['cakephp' => ['name' => 'deployer-cakephp-recipe', 'description' => 'This recipe is specifically for deploying CakePHP 3 projects.', 'body' => <<<EOF <?php require 'recipe/cakephp.php'; EOF ], 'codeigniter' => ['name' => 'deployer-codeigniter-recipe', 'description' => 'This recipe is specifically for deploying CodeIgniter projects.', 'body' => <<<EOF <?php require 'recipe/codeigniter.php'; EOF ], 'common' => ['name' => 'deployer-common-recipe', 'description' => 'This recipe is the basis of all other recipes', 'body' => <<<EOF <?php require 'recipe/common.php'; EOF ], 'composer' => ['name' => 'deployer-composer-recipe', 'description' => 'This recipe is specifically for deploying projects which uses composer.', 'body' => <<<EOF <?php require 'recipe/composer.php'; EOF ], 'drupal7' => ['name' => 'deployer-drupal7-recipe', 'description' => 'This recipe is specifically for deploying Drupal 7 projects.', 'body' => <<<EOF <?php require 'recipe/drupal7.php'; EOF ], 'drupal8' => ['name' => 'deployer-drupal8-recipe', 'description' => 'This recipe is specifically for deploying Drupal 8 projects.', 'body' => <<<EOF <?php require 'recipe/drupal8.php'; EOF ], 'fuelphp' => ['name' => 'deployer-fuelphp-recipe', 'description' => 'This recipe is specifically for deploying FuelPHP projects.', 'body' => <<<EOF <?php require 'recipe/fuelphp.php'; EOF ], 'laravel' => ['name' => 'deployer-laravel-recipe', 'description' => 'This recipe is specifically for deploying Laravel projects.', 'body' => <<<EOF <?php require 'recipe/laravel.php'; EOF ], 'magento' => ['name' => 'deployer-magento-recipe', 'description' => 'This recipe is specifically for deploying Magento projects.', 'body' => <<<EOF <?php require 'recipe/magento.php'; EOF ], 'symfony' => ['name' => 'deployer-symfony-recipe', 'description' => 'This recipe is specifically for deploying Symfony projects.', 'body' => <<<EOF <?php require 'recipe/symfony.php'; EOF ], 'symfony3' => ['name' => 'deployer-symfony3-recipe', 'description' => 'This recipe is specifically for deploying Symfony 3 projects.', 'body' => <<<EOF <?php require 'recipe/symfony3.php'; EOF ], 'wordpress' => ['name' => 'deployer-wordpress-recipe', 'description' => 'This recipe is specifically for deploying WordPress projects.', 'body' => <<<EOF <?php require 'recipe/wordpress.php'; EOF ], 'yii' => ['name' => 'deployer-yii-recipe', 'description' => 'This recipe is specifically for deploying Yii projects.', 'body' => <<<EOF <?php require 'recipe/yii.php'; EOF ], 'yii2-app-advanced' => ['name' => 'deployer-yii2-app-advanced-recipe', 'description' => 'This recipe is specifically for deploying Yii 2 Advanced Project Template projects.', 'body' => <<<EOF <?php require 'recipe/yii2-app-advanced.php'; EOF ], 'yii2-app-basic' => ['name' => 'deployer-yii2-app-basic-recipe', 'description' => 'This recipe is specifically for deploying Yii 2 Basic Project Template projects.', 'body' => <<<EOF <?php require 'recipe/yii2-app-basic.php'; EOF ], 'zend_framework' => ['name' => 'deployer-zend_framework-recipe', 'description' => 'This recipe is specifically for deploying Zend Framework projects.', 'body' => <<<EOF <?php require 'recipe/zend_framework.php'; EOF ]]; foreach ($deployerRecipes as $recipe) { Recipe::create(['name' => $recipe['name'], 'description' => $recipe['description'], 'body' => $recipe['body']]); } }
/** * Finds the Recipe model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Recipe the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Recipe::findById($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return array */ public function getIngredientsListItems() { return Recipe::getItems($this->recipeCategoryId); }
/** * @param integer $id * @return Query */ public static function getRecipeCaloriesQuery($id) { /** * SELECT * SUM(`dr`.`weight` * COALESCE(( * SELECT * SUM(`prod`.`calories`*`rp`.`weight`)/SUM(`rp`.`weight`) * FROM `recipe_products` `rp` * LEFT JOIN `product` `prod` ON `prod`.`id` = `rp`.`product_id` * WHERE `rp`.`recipe_id` = `dr`.`recipe_id` * ), 0)) * FROM `diary_recipes` `dr` * WHERE `dr`.`diary_id` = `d`.`id` */ $productCaloriesSql = (new Query())->select('SUM(`prod`.`calories`*`rp`.`weight`)/SUM(`rp`.`weight`)')->from(Recipe::recipe2productsTableName() . ' `rp`')->leftJoin(Product::tableName() . ' `prod`', '`prod`.`id` = `rp`.`product_id`')->where('`rp`.`recipe_id` = `dr`.`recipe_id`')->createCommand()->sql; return (new Query())->select("SUM(`dr`.`weight`*COALESCE(({$productCaloriesSql}),0)) AS `recipeCalories`")->from(Diary::diary2recipesTableName() . ' `dr`')->where("`dr`.`diary_id` = {$id}"); }
public function destroy($id) { $recipe = Recipe::find($id); $recipe->delete(); return $recipe; }
/** * @return \yii\db\ActiveQuery */ public function getRecipes() { return $this->hasMany(Recipe::className(), ['id' => 'recipe_id'])->viaTable(Recipe::recipe2productsTableName(), ['product_id' => 'id']); }
/** * @param array|string|integer $params * @return Portion */ public static function searchOne($params) { $where = is_array($params) ? $params : ['p.id' => $params]; return Portion::find()->select(['p.*', 'p.weight', 'categoryName' => 'c.name', 'recipeName' => 'r.name', 'calories' => 'SUM(`rp`.`weight`*`prod`.`calories`)/SUM(`rp`.`weight`)*`p`.`weight`', 'proteins' => 'SUM(`rp`.`weight`*`prod`.`protein`)/SUM(`rp`.`weight`)*`p`.`weight`', 'fats' => 'SUM(`rp`.`weight`*`prod`.`fat`)/SUM(`rp`.`weight`)*`p`.`weight`', 'carbohydrates' => 'SUM(`rp`.`weight`*`prod`.`carbohydrate`)/SUM(`rp`.`weight`)*`p`.`weight`'])->from(['p' => Portion::tableName()])->innerJoin(['r' => Recipe::tableName()], '`r`.`id` = `p`.`recipe_id`')->innerJoin(['rp' => Recipe::recipe2productsTableName()], '`rp`.`recipe_id` = `r`.`id`')->leftJoin(['c' => RecipeCategory::tableName()], '`c`.`id` = `r`.`category_id`')->leftJoin(['prod' => Product::tableName()], '`prod`.`id` = `rp`.`product_id`')->where($where)->one(); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $recipe = Recipe::findOrFail($id); return view('recipe.show', compact('recipe')); }
/** * @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; }
/** * @return \yii\db\ActiveQuery */ public function getRecipes() { return $this->hasMany(Recipe::className(), ['id' => 'recipe_id'])->viaTable(self::menu2RecipeTableName(), ['menu_id' => 'id']); }
/** * @param integer|string $id * @return Query */ public static function getPortionsCountQuery($id) { //portionsCount return (new Query())->select('COUNT(*) AS `portionsCount`')->from(Portion::tableName() . ' `p`')->leftJoin(Recipe::tableName() . ' `r`', '`r`.`id` = `p`.`recipe_id`')->where("`r`.`category_id` = {$id}"); }
/** * Display the specified resource. * * @param \App\Models\Recipe $recipe * @return Response */ public function show(Recipe $recipe) { $recipeProject = $recipe->getProjects()->toArray(); return view('recipes.show')->with('recipe', $recipe)->with('recipeProject', $recipeProject); }
public function unbookmark($tracking_nr) { $list = static::DEFAULT_LIST; $language = Input::get('language', static::$default_language); $recipe = Recipe::select('id')->where('tracking_nr', '=', $tracking_nr)->where('language', '=', $language)->first(); if (!$recipe) { abort(500); } DB::table('recipe_bookmarks')->where('recipe_id', $recipe['id'])->where('user_id', Auth::user()->id)->where('list', $list)->delete(); return redirect()->route('recipes.show', ['recipes' => $tracking_nr])->with('lang', $language); }