summaryrefslogtreecommitdiff
path: root/app/Libraries
diff options
context:
space:
mode:
authorhorus2022-09-25 02:34:42 +0200
committerhorus2022-09-25 02:34:42 +0200
commitacbe243bcd4c2dade2a834ce6bdedf46d1d10ae2 (patch)
tree0f12c3a667b3b4c4f451d874601bc63b726679c1 /app/Libraries
parent1c5a5b7cb014843f533d1473c5b3c6d6350acb40 (diff)
downloadkategorischeraperitif-acbe243bcd4c2dade2a834ce6bdedf46d1d10ae2.tar.gz
Sitemap, Cache etc
Diffstat (limited to 'app/Libraries')
-rw-r--r--app/Libraries/Helper.php55
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
+ }
}