Skip to content

Commit 9f72afc

Browse files
authored
Merge branch 'develop' into feature/admin-notifications
2 parents 0a8372a + 905deef commit 9f72afc

24 files changed

Lines changed: 429 additions & 139 deletions

app/Http/Controllers/Admin/Data/PromptController.php

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,76 @@ public function postSortPromptCategory(Request $request, PromptService $service)
150150
**********************************************************************************************/
151151

152152
/**
153-
* Shows the prompt category index.
153+
* Shows the prompt index.
154154
*
155155
* @return \Illuminate\Contracts\Support\Renderable
156156
*/
157157
public function getPromptIndex(Request $request) {
158-
$query = Prompt::query();
159-
$data = $request->only(['prompt_category_id', 'name']);
158+
$query = Prompt::query()->with('category');
159+
$data = $request->only(['prompt_category_id', 'name', 'sort', 'open_prompts']);
160160
if (isset($data['prompt_category_id']) && $data['prompt_category_id'] != 'none') {
161-
$query->where('prompt_category_id', $data['prompt_category_id']);
161+
if ($data['prompt_category_id'] == 'withoutOption') {
162+
$query->whereNull('prompt_category_id');
163+
} else {
164+
$query->where('prompt_category_id', $data['prompt_category_id']);
165+
}
162166
}
163167
if (isset($data['name'])) {
164168
$query->where('name', 'LIKE', '%'.$data['name'].'%');
165169
}
166170

171+
if (isset($data['open_prompts'])) {
172+
switch ($data['open_prompts']) {
173+
case 'open':
174+
$query->open(true);
175+
break;
176+
case 'closed':
177+
$query->open(false);
178+
break;
179+
case 'any':
180+
default:
181+
// Don't filter
182+
break;
183+
}
184+
}
185+
186+
if (isset($data['sort'])) {
187+
switch ($data['sort']) {
188+
case 'alpha':
189+
$query->sortAlphabetical();
190+
break;
191+
case 'alpha-reverse':
192+
$query->sortAlphabetical(true);
193+
break;
194+
case 'category':
195+
$query->sortCategory();
196+
break;
197+
case 'newest':
198+
$query->sortNewest();
199+
break;
200+
case 'oldest':
201+
$query->sortNewest(true);
202+
break;
203+
case 'start':
204+
$query->sortStart();
205+
break;
206+
case 'start-reverse':
207+
$query->sortStart(true);
208+
break;
209+
case 'end':
210+
$query->sortEnd();
211+
break;
212+
case 'end-reverse':
213+
$query->sortEnd(true);
214+
break;
215+
}
216+
} else {
217+
$query->sortCategory();
218+
}
219+
167220
return view('admin.prompts.prompts', [
168221
'prompts' => $query->paginate(20)->appends($request->query()),
169-
'categories' => ['none' => 'Any Category'] + PromptCategory::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
222+
'categories' => ['none' => 'Any Category'] + ['withoutOption' => 'Without Category'] + PromptCategory::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
170223
]);
171224
}
172225

app/Http/Controllers/Admin/NewsController.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,40 @@ class NewsController extends Controller {
1414
*
1515
* @return \Illuminate\Contracts\Support\Renderable
1616
*/
17-
public function getIndex() {
18-
return view('admin.news.news', [
19-
'newses' => News::orderBy('updated_at', 'DESC')->paginate(20),
17+
public function getIndex(Request $request) {
18+
$query = News::visible(Auth::user() ?? null);
19+
$data = $request->only(['title', 'sort']);
20+
if (isset($data['title'])) {
21+
$query->where('title', 'LIKE', '%'.$data['title'].'%');
22+
}
23+
24+
if (isset($data['sort'])) {
25+
switch ($data['sort']) {
26+
case 'alpha':
27+
$query->sortAlphabetical();
28+
break;
29+
case 'alpha-reverse':
30+
$query->sortAlphabetical(true);
31+
break;
32+
case 'newest':
33+
$query->sortNewest();
34+
break;
35+
case 'oldest':
36+
$query->sortNewest(true);
37+
break;
38+
case 'bump':
39+
$query->sortBump();
40+
break;
41+
case 'bump-reverse':
42+
$query->sortBump(true);
43+
break;
44+
}
45+
} else {
46+
$query->sortBump(true);
47+
}
48+
49+
return view('news.index', [
50+
'newses' => $query->paginate(20)->appends($request->query()),
2051
]);
2152
}
2253

app/Http/Controllers/Admin/SalesController.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,43 @@ class SalesController extends Controller {
1515
*
1616
* @return \Illuminate\Contracts\Support\Renderable
1717
*/
18-
public function getIndex() {
18+
public function getIndex(Request $request) {
19+
$query = Sales::visible(Auth::user() ?? null);
20+
$data = $request->only(['title', 'is_open', 'sort']);
21+
if (isset($data['is_open']) && $data['is_open'] != 'none') {
22+
$query->where('is_open', $data['is_open']);
23+
}
24+
if (isset($data['title'])) {
25+
$query->where('title', 'LIKE', '%'.$data['title'].'%');
26+
}
27+
28+
if (isset($data['sort'])) {
29+
switch ($data['sort']) {
30+
case 'alpha':
31+
$query->sortAlphabetical();
32+
break;
33+
case 'alpha-reverse':
34+
$query->sortAlphabetical(true);
35+
break;
36+
case 'newest':
37+
$query->sortNewest();
38+
break;
39+
case 'oldest':
40+
$query->sortNewest(true);
41+
break;
42+
case 'bump':
43+
$query->sortBump();
44+
break;
45+
case 'bump-reverse':
46+
$query->sortBump(true);
47+
break;
48+
}
49+
} else {
50+
$query->sortBump(true);
51+
}
52+
1953
return view('admin.sales.sales', [
20-
'saleses' => Sales::orderBy('post_at', 'DESC')->paginate(20),
54+
'saleses' => $query->paginate(20)->appends($request->query()),
2155
]);
2256
}
2357

app/Http/Controllers/NewsController.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers;
44

55
use App\Models\News;
6+
use Illuminate\Http\Request;
67
use Illuminate\Support\Facades\Auth;
78
use Illuminate\Support\Facades\View;
89

@@ -28,12 +29,45 @@ public function __construct() {
2829
*
2930
* @return \Illuminate\Contracts\Support\Renderable
3031
*/
31-
public function getIndex() {
32+
public function getIndex(Request $request) {
3233
if (Auth::check() && Auth::user()->is_news_unread) {
3334
Auth::user()->update(['is_news_unread' => 0]);
3435
}
3536

36-
return view('news.index', ['newses' => News::visible()->orderBy('updated_at', 'DESC')->paginate(10)]);
37+
$query = News::visible(Auth::user() ?? null);
38+
$data = $request->only(['title', 'sort']);
39+
if (isset($data['title'])) {
40+
$query->where('title', 'LIKE', '%'.$data['title'].'%');
41+
}
42+
43+
if (isset($data['sort'])) {
44+
switch ($data['sort']) {
45+
case 'alpha':
46+
$query->sortAlphabetical();
47+
break;
48+
case 'alpha-reverse':
49+
$query->sortAlphabetical(true);
50+
break;
51+
case 'newest':
52+
$query->sortNewest();
53+
break;
54+
case 'oldest':
55+
$query->sortNewest(true);
56+
break;
57+
case 'bump':
58+
$query->sortBump();
59+
break;
60+
case 'bump-reverse':
61+
$query->sortBump(true);
62+
break;
63+
}
64+
} else {
65+
$query->sortBump(true);
66+
}
67+
68+
return view('news.index', [
69+
'newses' => $query->paginate(10)->appends($request->query()),
70+
]);
3771
}
3872

3973
/**

app/Http/Controllers/SalesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function getIndex(Request $request) {
3535
Auth::user()->update(['is_sales_unread' => 0]);
3636
}
3737

38-
$query = Sales::visible();
38+
$query = Sales::visible(Auth::user() ?? null);
3939
$data = $request->only(['title', 'is_open', 'sort']);
4040
if (isset($data['is_open']) && $data['is_open'] != 'none') {
4141
$query->where('is_open', $data['is_open']);

app/Models/News.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,42 @@ public function scopeShouldBeVisible($query) {
112112
return $query->whereNotNull('post_at')->where('post_at', '<', Carbon::now())->where('is_visible', 0);
113113
}
114114

115+
/**
116+
* Scope a query to sort sales in alphabetical order.
117+
*
118+
* @param \Illuminate\Database\Eloquent\Builder $query
119+
* @param bool $reverse
120+
*
121+
* @return \Illuminate\Database\Eloquent\Builder
122+
*/
123+
public function scopeSortAlphabetical($query, $reverse = false) {
124+
return $query->orderBy('title', $reverse ? 'DESC' : 'ASC');
125+
}
126+
127+
/**
128+
* Scope a query to sort sales by newest first.
129+
*
130+
* @param \Illuminate\Database\Eloquent\Builder $query
131+
* @param mixed $reverse
132+
*
133+
* @return \Illuminate\Database\Eloquent\Builder
134+
*/
135+
public function scopeSortNewest($query, $reverse = false) {
136+
return $query->orderBy('id', $reverse ? 'ASC' : 'DESC');
137+
}
138+
139+
/**
140+
* Scope a query to sort sales by bump date.
141+
*
142+
* @param \Illuminate\Database\Eloquent\Builder $query
143+
* @param bool $reverse
144+
*
145+
* @return \Illuminate\Database\Eloquent\Builder
146+
*/
147+
public function scopeSortBump($query, $reverse = false) {
148+
return $query->orderBy('updated_at', $reverse ? 'DESC' : 'ASC');
149+
}
150+
115151
/**********************************************************************************************
116152
117153
ACCESSORS

app/Models/Prompt/Prompt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function scopeSortEnd($query, $reverse = false) {
229229
* @return string
230230
*/
231231
public function getDisplayNameAttribute() {
232-
return '<a href="'.$this->url.'" class="display-prompt">'.$this->name.'</a>';
232+
return '<a href="'.$this->idUrl.'" class="display-prompt">'.$this->name.'</a>';
233233
}
234234

235235
/**

app/Models/Shop/Shop.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,20 +200,22 @@ public function getMonthsAttribute() {
200200
* We dont account for is_visible here, as this is used for checking both visible and invisible shop.
201201
*/
202202
public function getIsActiveCheckAttribute() {
203-
if ($this->start_at && $this->start_at > Carbon::now()) {
204-
return false;
205-
}
206-
207-
if ($this->end_at && $this->end_at < Carbon::now()) {
208-
return false;
209-
}
210-
211-
if ($this->days && !in_array(Carbon::now()->format('l'), $this->days)) {
212-
return false;
213-
}
214-
215-
if ($this->months && !in_array(Carbon::now()->format('F'), $this->months)) {
216-
return false;
203+
if ($this->is_timed_shop) {
204+
if ($this->start_at && $this->start_at > Carbon::now()) {
205+
return false;
206+
}
207+
208+
if ($this->end_at && $this->end_at < Carbon::now()) {
209+
return false;
210+
}
211+
212+
if ($this->days && !in_array(Carbon::now()->format('l'), $this->days)) {
213+
return false;
214+
}
215+
216+
if ($this->months && !in_array(Carbon::now()->format('F'), $this->months)) {
217+
return false;
218+
}
217219
}
218220

219221
if (!$this->is_timed_shop && !$this->is_active) {

app/Services/LootService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use App\Models\Loot\Loot;
66
use App\Models\Loot\LootTable;
7-
use App\Models\Prompt\PromptReward;
7+
use App\Models\Reward\Reward;
88
use Illuminate\Support\Arr;
99
use Illuminate\Support\Facades\DB;
1010

@@ -127,7 +127,7 @@ public function deleteLootTable($table) {
127127
// Check first if the table is currently in use
128128
// - Prompts
129129
// - Box rewards (unfortunately this can't be checked easily)
130-
if (PromptReward::where('rewardable_type', 'LootTable')->where('rewardable_id', $table->id)->exists()) {
130+
if (Reward::where('rewardable_type', 'LootTable')->where('rewardable_id', $table->id)->exists()) {
131131
throw new \Exception('A prompt uses this table to distribute rewards. Please remove it from the rewards list first.');
132132
}
133133

0 commit comments

Comments
 (0)