summaryrefslogtreecommitdiff
path: root/site/app/Http/Controllers/IndexController.php
blob: c0056d913b8682afef8a98e110af21ec37b84f9b (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
<?php                                                                                                                                                                                                                
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Helpers\CryptoHelper;

use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;

class IndexController extends Controller {
    /**
     * Shows the index page.
     *
     * @return Response
     */
    public function showPage(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, original_price, discounted_price, procent, '' AS linktext FROM ". $view ."_view WHERE original_price > 19.98 ORDER BY procent DESC LIMIT 1)";
	    }

	    // removes the last union
	    #$query .= substr($query, -1, strlen(" UNION "));
	    #echo "<pre>";
	    #var_dump($query); exit;

	    /*
	    $dbh = DB::connection('mysql')->getPdo();
	    $stmt = $dbh->prepare($query);
	    $stmt->execute();

	    $data = $stmt->fetchAll(\PDO::FETCH_ASSOC);
	     */


	    #var_dump($query); exit;
	    $data = DB::select($query);
		#$data = DB::table('whisky_view')->orderBy('procent', 'DESC')->limit(100)->simplePaginate(20);

        return view('index', ['data' => $data]);
    }
}