summaryrefslogtreecommitdiff
path: root/app/Http
diff options
context:
space:
mode:
authorhorus2022-01-07 14:02:05 +0100
committerhorus2022-01-07 14:02:12 +0100
commit3fe0381d28d9c5844c82d908b77d3aa4b0aca737 (patch)
tree2ce0641a2a78a2bfe84c6f576947279db6b68ad3 /app/Http
parentbb95c3083b20687dcea427351270f0d835598fdb (diff)
downloadkategorischeraperitif-3fe0381d28d9c5844c82d908b77d3aa4b0aca737.tar.gz
first release of kategorischeraperitif.de
Diffstat (limited to 'app/Http')
-rw-r--r--app/Http/Controllers/.IndexController.php.swpbin0 -> 12288 bytes
-rw-r--r--app/Http/Controllers/CocktailController.php49
-rw-r--r--app/Http/Controllers/IndexController.php44
-rw-r--r--app/Http/Controllers/ListOfferController.php4
4 files changed, 84 insertions, 13 deletions
diff --git a/app/Http/Controllers/.IndexController.php.swp b/app/Http/Controllers/.IndexController.php.swp
new file mode 100644
index 0000000..52ff3e9
--- /dev/null
+++ b/app/Http/Controllers/.IndexController.php.swp
Binary files 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 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+use App\Cocktail;
+use App\Ingredient;
+use App\Libraries\Helper;
+
+class CocktailController extends Controller
+{
+
+ public function index()
+ {
+ $cocktails = new Cocktail;
+ $cocktail_count = $cocktails->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) {