1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* rmarchiv.tk |
5
|
|
|
* (c) 2016-2017 by Marcel 'ryg' Hering |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace App\Http\Controllers; |
9
|
|
|
|
10
|
|
|
use App\Models\Developer; |
11
|
|
|
use App\Models\Game; |
12
|
|
|
use App\Models\User; |
13
|
|
|
|
14
|
|
|
class AutocompleteController extends Controller |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* returns autocomplete values for games |
18
|
|
|
* @param $term |
19
|
|
|
* @return \Illuminate\Http\JsonResponse |
20
|
|
|
*/ |
21
|
|
|
public function search($term) |
22
|
|
|
{ |
23
|
|
|
$result = []; |
24
|
|
|
|
25
|
|
|
$games = Game::search($term)->get(); |
26
|
|
|
|
27
|
|
|
foreach ($games as $g) { |
28
|
|
|
$result[] = [ |
29
|
|
|
'id' => $g->id, |
30
|
|
|
'title' => $g->title, |
31
|
|
|
'value' => '<div class="searchresult">'.\View::make('_partials.inline_gamebox', ['game' => $g])->render().'</div>', |
32
|
|
|
]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return \Response::json($result); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
View Code Duplication |
public function developer($term) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$result = []; |
41
|
|
|
|
42
|
|
|
$devs = Developer::where('name', 'like', '%'.$term.'%')->get(); |
43
|
|
|
|
44
|
|
|
foreach ($devs as $dev) { |
45
|
|
|
$result[] = ['id' => $dev->id, 'value' => $dev->name]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return \Response::json($result); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function game($term) |
52
|
|
|
{ |
53
|
|
|
$result = []; |
54
|
|
|
|
55
|
|
|
$games = \DB::table('games') |
56
|
|
|
->select([ |
57
|
|
|
'id', |
58
|
|
|
'title', |
59
|
|
|
'subtitle', |
60
|
|
|
]) |
61
|
|
|
->where('title', 'like', '%'.$term.'%') |
62
|
|
|
->orWhere('subtitle', 'like', '%'.$term.'%') |
63
|
|
|
->get(); |
64
|
|
|
|
65
|
|
|
foreach ($games as $g) { |
66
|
|
|
if (is_null($g->subtitle) || $g->subtitle == '') { |
67
|
|
|
$result[] = ['id' => $g->id, 'value' => $g->title]; |
68
|
|
|
} else { |
69
|
|
|
$result[] = ['id' => $g->id, 'value' => $g->title.' -=- '.$g->subtitle]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return \Response::json($result); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function faqcat($term) |
77
|
|
|
{ |
78
|
|
|
$result = []; |
79
|
|
|
|
80
|
|
|
//$devs = Developer::whereName($term)->get(); |
|
|
|
|
81
|
|
|
$devs = \DB::table('faq') |
82
|
|
|
->select(['id', 'cat']) |
83
|
|
|
->where('faq.cat', 'like', '%'.$term.'%') |
84
|
|
|
->groupBy('faq.cat') |
85
|
|
|
->get(); |
86
|
|
|
|
87
|
|
|
foreach ($devs as $dev) { |
88
|
|
|
$result[] = ['id' => $dev->id, 'value' => $dev->cat]; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return \Response::json($result); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
View Code Duplication |
public function awardpage($term) |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
$result = []; |
97
|
|
|
$aw = \DB::table('award_pages')->get(); |
|
|
|
|
98
|
|
|
|
99
|
|
|
foreach ($aw as $item) { |
100
|
|
|
$result[] = [ |
101
|
|
|
'id' => $item->id, |
102
|
|
|
'value' => $item->title, |
103
|
|
|
]; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return \Response::json($result); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
View Code Duplication |
public function awardcat($term) |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
$result = []; |
112
|
|
|
$aw = \DB::table('award_cats')->get(); |
|
|
|
|
113
|
|
|
|
114
|
|
|
foreach ($aw as $item) { |
115
|
|
|
$result[] = [ |
116
|
|
|
'id' => $item->id, |
117
|
|
|
'value' => $item->title, |
118
|
|
|
]; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
return \Response::json($result); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
View Code Duplication |
public function awardsubcat($term) |
|
|
|
|
125
|
|
|
{ |
126
|
|
|
$result = []; |
127
|
|
|
$aw = \DB::table('award_subcats')->get(); |
|
|
|
|
128
|
|
|
|
129
|
|
|
foreach ($aw as $item) { |
130
|
|
|
$result[] = [ |
131
|
|
|
'id' => $item->id, |
132
|
|
|
'value' => $item->title, |
133
|
|
|
]; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return \Response::json($result); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
View Code Duplication |
public function user($term) |
|
|
|
|
140
|
|
|
{ |
141
|
|
|
$result = []; |
142
|
|
|
$users = User::where('name', 'like', '%'.$term.'%')->get(); |
|
|
|
|
143
|
|
|
|
144
|
|
|
foreach ($users as $user) { |
145
|
|
|
$result[] = [ |
146
|
|
|
'id' => $user->id, |
147
|
|
|
'value' => $user->name, |
148
|
|
|
]; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return \Response::json($result); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.