summaryrefslogtreecommitdiff
path: root/app/Http/Controllers/IndexController.php
blob: 2c34a55ad801115fe6bb0a6978c3c2ca5d626614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php                                                                                                                                                                                                                
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Helpers\CryptoHelper;

use Illuminate\Support\Facades\DB;
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 angebote(Request $request) {

	    $views = array("whisky", "wodka", "gin", "rum", "misc");
	    $cache_angebote = "";

	    if ( Cache::has('angebote_index') ) {
		    $data = Cache::get('angebote_index');
	    } else {

		    #$data = $this->getAngeboteData($request);
		    $data = Helper::getAngeboteData();

		    Cache::put('angebote_index', $data , 6000); // 100 minutes
	    }
	    if ( Cache::has('angebote_count') ) {
		    $count = Cache::get('angebote_count');
	    } else {
		    #$count = DB::select("SELECT count(*) as count FROM all_view")[0];
		    $count = Helper::getAngeboteCount();
		    Cache::put('angebote_count', $count, 6000); // 100 minutes
	    }

	    #$count = DB::select("SELECT count(*) as count FROM all_view")[0];

	    return view('angebote_index', ['data' => $data, 'views' => $views, 'hits' => $count])->render();
    }

    public function index(Request $request) {
		    $views = array("whisky", "wodka", "gin", "rum", "misc");

		    if ( Cache::has('angebote_index') ) {
			    $data = Cache::get('angebote_index');
		    } else {

			    #$data = $this->getAngeboteData($request);
			    $data = Helper::getAngeboteData();

			    Cache::put('angebote_index', $data , 6000); // 100 minutes
		    }
		    if ( Cache::has('angebote_count') ) {
			    $count= Cache::get('angebote_count');
		    } else {
			    #$count = DB::select("SELECT count(*) as count FROM all_view")[0];
		    	    $count = Helper::getAngeboteCount();
			    Cache::put('angebote_count', $count, 6000); // 100 minutes
		    }
		    if ( Cache::has('cocktail_count') ) {
			    $cocktail_count= Cache::get('cocktail_count');
		    } else {
			    /*
			    $cocktails = new Cocktail;
			    $cocktail_count = $cocktails->count();
			     */
			    $cocktail_count = Helper::getCocktailCount();
			    Cache::put('cocktail_count', $cocktail_count, 6000); // 100 minutes
		    }

	    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 = "";

		    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;
    }
}