summaryrefslogtreecommitdiff
path: root/site/app/Http/Controllers/FKSearchController.php
blob: efa6c8aeccfa9330883184a2da320af0eb3ff2e4 (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
<?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\Input;

use App\Libraries\Utility;

class FKSearchController extends Controller {
	/**
	* Shows the index page.
	*
	* @return Response
	*/
	public function showPage(Request $request) {

		/*
		* Sorting
		*/
		$sort_by = Input::get("sort");
		switch ($sort_by) {
		case("price"):
		    $sort_by = "discounted_price";
		    break;
		case("discounted_price"):
		    $sort_by = "discounted_price";
		    break;
		case("name"):
		    $sort_by = "name";
		    break;
		case("shop"):
		    $sort_by = "shop";
		    break;
		case("procent"):
		    $sort_by = "procent";
		    break;
		case("time"):
		    $sort_by = "created_at";
		    break;
		case("created_at"):
		    $sort_by = "created_at";
		    break;
		default:
		    $sort_by = "created_at";
		    break;
		}

		$order_by = $request->input("order");
		if ( "desc" != $order_by ) {
			if ( "created_at" == $sort_by &&"asc" != $order_by ) {
		    		$order_by = "desc";
			} else {
		    		$order_by = "asc";
			}
		}

		$query = Input::get("q");
		$q = "%" . Utility::escapeLike($query) . "%";
	    	$data = DB::table('all_view')->whereNotNull('url')->where('name', 'like', $q)->orWhere('spirit_type', 'like', $q)->orWhere('shop', 'like', $q)->orderBy($sort_by, $order_by)->paginate(20);
	    	$count = DB::table('all_view')->whereNotNull('url')->where('name', 'like', $q)->orWhere('spirit_type', 'like', $q)->orWhere('shop', 'like', $q);

		$query_string = "";
		$query_params = Input::except('page');
		foreach( $query_params as $key => $value) {
			$query_string .= "&" . $key . "=" . $value;
		}
		$query_string = ltrim($query_string, "&");

		/*
		* For strftime() in view.
		*/
		#setlocale(LC_TIME, 'de_DE.utf8');

		return view('fk-search', ['data' => $data, 'count' => $count, 'search_phrase' => $query, 'rss_feed' => '/angebote/search/feed/?' . $query_string ]);
	}
}