diff options
Diffstat (limited to 'app/Libraries')
| -rw-r--r-- | app/Libraries/Helper.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/app/Libraries/Helper.php b/app/Libraries/Helper.php index 1e9741e..a5556fd 100644 --- a/app/Libraries/Helper.php +++ b/app/Libraries/Helper.php @@ -1,7 +1,11 @@ <?php namespace App\Libraries; use App\Libraries\Helper; +use App\Cocktail; +use App\Ingredient; use Carbon\Carbon; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Cache; class Helper { public static function escapeLike($string){ @@ -24,4 +28,55 @@ class Helper { } return false; } + + + public static function getAngeboteData() { + $views = array("whisky", "wodka", "gin", "rum", "misc"); + $query = ""; + + foreach($views as $view) { + if ($query != "") { + $query .= " UNION "; + } + $query .= " + (SELECT + name, + image_url, + spirit_type, + spirit_type AS url, + spirit_type AS angebotsname, + (SELECT MAX(procent) FROM " . $view . "_view) as procent, + '' AS linktext FROM ". $view ."_view + WHERE + original_price > 29.98 + AND + spirit_type != 'Verschiedenes' + AND + shop != 'Rum & Co' + AND + shop = 'Drankdozijn' + ORDER BY + created_at DESC, + procent DESC LIMIT 1)"; + } + + $data = DB::select($query); + + return $data; + } + + public static function getAngeboteCount() { + return DB::select("SELECT count(*) as count FROM all_view")[0]; + } + + public static function getCocktailCount() { + $cocktails = new Cocktail; + return $cocktails->count(); + } + + public static function fillCache(){ + Cache::put('angebote_count', Helper::getAngeboteCount(), 6000); // 100 minutes + Cache::put('cocktail_count', Helper::getCocktailCount(), 6000); // 100 minutes + Cache::put('angebote_index', Helper::getAngeboteData(), 6000); // 100 minutes + } } |
