From 3fe0381d28d9c5844c82d908b77d3aa4b0aca737 Mon Sep 17 00:00:00 2001 From: horus Date: Fri, 7 Jan 2022 14:02:05 +0100 Subject: first release of kategorischeraperitif.de --- app/Cocktail.php | 21 +++++++++++ app/Http/Controllers/.IndexController.php.swp | Bin 0 -> 12288 bytes app/Http/Controllers/CocktailController.php | 49 ++++++++++++++++++++++++++ app/Http/Controllers/IndexController.php | 44 +++++++++++++++++------ app/Http/Controllers/ListOfferController.php | 4 +-- app/Ingredient.php | 19 ++++++++++ app/Libraries/Helper.php | 27 ++++++++++++++ 7 files changed, 151 insertions(+), 13 deletions(-) create mode 100644 app/Cocktail.php create mode 100644 app/Http/Controllers/.IndexController.php.swp create mode 100644 app/Http/Controllers/CocktailController.php create mode 100644 app/Ingredient.php create mode 100644 app/Libraries/Helper.php (limited to 'app') diff --git a/app/Cocktail.php b/app/Cocktail.php new file mode 100644 index 0000000..31f40c1 --- /dev/null +++ b/app/Cocktail.php @@ -0,0 +1,21 @@ +hasMany('App\Ingredient'); + } +} + diff --git a/app/Http/Controllers/.IndexController.php.swp b/app/Http/Controllers/.IndexController.php.swp new file mode 100644 index 0000000..52ff3e9 Binary files /dev/null and b/app/Http/Controllers/.IndexController.php.swp differ diff --git a/app/Http/Controllers/CocktailController.php b/app/Http/Controllers/CocktailController.php new file mode 100644 index 0000000..f876dfe --- /dev/null +++ b/app/Http/Controllers/CocktailController.php @@ -0,0 +1,49 @@ +count(); + return view('cocktail_index', [ "cocktail_count" => $cocktail_count ]); + } + + public function search(Request $request) { + + $ingredients = $request->input("i"); + + $cocktails = new Cocktail; + + foreach($ingredients as $q) { + $q = Helper::escapeLike($q); + $q = "%".$q."%"; + $cocktails = $cocktails->where(function($query) use ($q){ + $query->whereHas("getIngredients", function ($query) use ($q){ + $query->where('name', 'like', $q); + }); + }); + } + + $count = $cocktails->count(); + + $search_phrase = ""; + foreach(array_filter($ingredients) as $term) { + if ( $search_phrase != "" ) + $search_phrase = $search_phrase . " und "; + $search_phrase = $search_phrase . ucwords($term); + } + $search_phrase = rtrim($search_phrase, " und "); + + return view('cocktail_list', [ "cocktails" => $cocktails, "count" => $count, "search_terms" => array_filter($ingredients), "search_phrase" => $search_phrase ]); + } +} diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index d6931ba..24c5615 100644 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -8,18 +8,47 @@ use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Cache; +use App\Cocktail; +use App\Ingredient; +use App\Libraries\Helper; + class IndexController extends Controller { /** * Shows the index page. * * @return Response */ - public function showPage(Request $request) { + public function angebote(Request $request) { - if ( Cache::has('index') ) { - return Cache::get('index'); + if ( Cache::has('angebote_index') ) { + return Cache::get('angebote_index'); } else { + $views = array("whisky", "wodka", "gin", "rum", "misc"); + + $data = $this->getAngeboteData($request); + + $count = DB::select("SELECT count(*) as count FROM all_view")[0]; + + $cached_data = view('angebote_index', ['data' => $data, 'views' => $views, 'hits' => $count])->render(); + Cache::put('angebote_index', $cached_data, 6000); // 100 minutes + + return $cached_data; + } + } + + public function index(Request $request) { + $views = array("whisky", "wodka", "gin", "rum", "misc"); + $data = $this->getAngeboteData($request); + $count = DB::select("SELECT count(*) as count FROM all_view")[0]; + + $cocktails = new Cocktail; + $cocktail_count = $cocktails->count(); + + return view('index', ['data' => $data, 'views' => $views, 'hits' => $count, 'cocktail_count' => $cocktail_count])->render(); + } + + private function getAngeboteData(Request $request) { $views = array("whisky", "wodka", "gin", "rum", "misc"); $query = ""; @@ -51,13 +80,6 @@ class IndexController extends Controller { $data = DB::select($query); - $count = DB::select("SELECT count(*) as count FROM all_view")[0]; - - $cached_data = view('index', ['data' => $data, 'views' => $views, 'hits' => $count])->render(); - - Cache::put('index', $cached_data, 6000); // 100 minutes - - return $cached_data; - } + return $data; } } diff --git a/app/Http/Controllers/ListOfferController.php b/app/Http/Controllers/ListOfferController.php index 70f0cab..52ae0a0 100644 --- a/app/Http/Controllers/ListOfferController.php +++ b/app/Http/Controllers/ListOfferController.php @@ -57,7 +57,7 @@ class ListOfferController extends Controller { /* * Database query */ - $view_name = \Request::route()->getName(); + $view_name = ltrim(\Request::route()->getName(), "angebote_"); /** * Cache output @@ -78,7 +78,7 @@ class ListOfferController extends Controller { # Only used on misc_view, all_view and search. $spirit_types = DB::select('SELECT DISTINCT spirit_type FROM ' . $view_name . '_view ' . ' ORDER BY spirit_type' ); - $rss_feed = $view_name . "/feed/"; + $rss_feed = "/angebote/" . $view_name . "/feed/"; $query_string = ""; $query_params = $request->except('page'); foreach( $query_params as $key => $value) { diff --git a/app/Ingredient.php b/app/Ingredient.php new file mode 100644 index 0000000..67ef6ad --- /dev/null +++ b/app/Ingredient.php @@ -0,0 +1,19 @@ +belongsTo('App\Cocktail'); + } +} diff --git a/app/Libraries/Helper.php b/app/Libraries/Helper.php new file mode 100644 index 0000000..1e9741e --- /dev/null +++ b/app/Libraries/Helper.php @@ -0,0 +1,27 @@ +format("Y-m-d"); + } + + public static function contains($array, $str) { + foreach($array as $item) { + if ( str_contains(strtolower($str), strtolower($item) ) ) { + return true; + } + } + return false; + } +} -- cgit v1.2.3