Skip to content

Commit 5b3bb61

Browse files
author
Sam Collins
committed
Updated Gear to be like Licences with name and ID
1 parent a969f76 commit 5b3bb61

14 files changed

Lines changed: 238 additions & 17 deletions

File tree

app/Http/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Kernel extends HttpKernel
3232
],
3333

3434
'api' => [
35+
\Barryvdh\Cors\HandleCors::class,
3536
'throttle:60,1',
3637
],
3738
];
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace App\Modules\ArmaLife\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
use App\Http\Requests;
8+
use App\Http\Controllers\Controller;
9+
use App\Modules\ArmaLife\Repositories\Eloquent\PlayerRepository;
10+
use App\Modules\ArmaLife\Repositories\Eloquent\VehicleRepository;
11+
use App\Modules\ArmaLife\Repositories\Eloquent\HouseRepository;
12+
13+
14+
class ArmaLifeController extends Controller
15+
{
16+
/**
17+
* @var PlayerRepository
18+
*/
19+
protected $playerRepository;
20+
21+
/**
22+
* @var VehicleRepository
23+
*/
24+
protected $vehicleRepository;
25+
26+
/**
27+
* @var HouseRepository
28+
*/
29+
protected $houseRepository;
30+
31+
public function __construct(PlayerRepository $playerRepository, VehicleRepository $vehicleRepository, HouseRepository $houseRepository)
32+
{
33+
$this->playerRepository = $playerRepository;
34+
$this->vehicleRepository = $vehicleRepository;
35+
$this->houseRepository = $houseRepository;
36+
}
37+
38+
public function dashboard()
39+
{
40+
$cash = (int) $this->playerRepository->cash();
41+
$bank = (int) $this->playerRepository->bank();
42+
$total = $cash + $bank;
43+
44+
return [
45+
'data' => [
46+
'cash' => $cash,
47+
'bank' => $bank,
48+
'total' => $total,
49+
'vehicles' => $this->vehicleRepository->count(),
50+
'houses' => $this->houseRepository->count(),
51+
'players' => $this->playerRepository->count(),
52+
'newest' => $this->playerRepository->newest(),
53+
'cops' => $this->playerRepository->cops(),
54+
'medics' => $this->playerRepository->medics(),
55+
'admins' => $this->playerRepository->admins(),
56+
'donators' => $this->playerRepository->donators()
57+
]
58+
];
59+
}
60+
}

app/Modules/ArmaLife/Http/routes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
Route::group(['prefix' => 'api/v1/armalife'], function() {
1515
Route::get('player/table/{limit?}', 'PlayerController@table');
16-
Route::get('house/table/{limit?}', 'HouseController@table');
16+
Route::get('house/table/{limit?}', 'HouseController@table');
17+
Route::get('dashboard', 'ArmaLifeController@dashboard');
1718
Route::resource('player', PlayerController::class);
1819
Route::resource('vehicle', VehicleController::class);
1920
Route::resource('house', HouseController::class);

app/Modules/ArmaLife/Repositories/Eloquent/HouseRepository.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@ public function boot()
3636
{
3737
$this->pushCriteria(app(RequestCriteria::class));
3838
}
39+
40+
public function count()
41+
{
42+
return $this->model->count();
43+
}
3944
}

app/Modules/ArmaLife/Repositories/Eloquent/PlayerRepository.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,45 @@ public function boot()
3636
{
3737
$this->pushCriteria(app(RequestCriteria::class));
3838
}
39+
40+
public function cash()
41+
{
42+
return $this->model->sum('cash');
43+
}
44+
45+
public function bank()
46+
{
47+
return $this->model->sum('bankacc');
48+
}
49+
50+
public function newest()
51+
{
52+
$newest = $this->model->orderBy('insert_time', 'desc')->first();
53+
return ['uid' => $newest->uid, 'name' => $newest->name];
54+
}
55+
56+
public function cops()
57+
{
58+
return $this->model->select('uid', 'name', 'coplevel')->where('coplevel', '>=', 1)->orderBy('coplevel', 'desc')->get();
59+
}
60+
61+
public function medics()
62+
{
63+
return $this->model->select('uid', 'name', 'mediclevel')->where('mediclevel', '>=', 1)->orderBy('mediclevel', 'desc')->get();
64+
}
65+
66+
public function admins()
67+
{
68+
return $this->model->select('uid', 'name', 'adminlevel')->where('adminlevel', '>=', 1)->orderBy('adminlevel', 'desc')->get();
69+
}
70+
71+
public function donators()
72+
{
73+
return $this->model->select('uid', 'name', 'donorlevel')->where('donorlevel', '>=', 1)->orderBy('donorlevel', 'desc')->get();
74+
}
75+
76+
public function count()
77+
{
78+
return $this->model->count();
79+
}
3980
}

app/Modules/ArmaLife/Repositories/Eloquent/VehicleRepository.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ public function boot()
3232
{
3333
$this->pushCriteria(app(RequestCriteria::class));
3434
}
35+
36+
public function count()
37+
{
38+
return $this->model->count();
39+
}
3540
}

app/Modules/ArmaLife/Repositories/HouseRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
*/
1111
interface HouseRepository extends RepositoryInterface
1212
{
13-
13+
public function count();
1414
}

app/Modules/ArmaLife/Repositories/PlayerRepository.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,17 @@
1010
*/
1111
interface PlayerRepository extends RepositoryInterface
1212
{
13-
13+
public function cash();
14+
15+
public function bank();
16+
17+
public function newest();
18+
19+
public function cops();
20+
21+
public function medics();
22+
23+
public function admins();
24+
25+
public function donators();
1426
}

app/Modules/ArmaLife/Repositories/VehicleRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
*/
1111
interface VehicleRepository extends RepositoryInterface
1212
{
13-
13+
public function count();
1414
}

app/Modules/ArmaLife/Services/ArrayParser.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,35 @@ public static function decode($array)
1313
// todo: cleanup legacy code
1414
public static function inventory($items)
1515
{
16-
if ($items != '"[]"' && $items != '' && $items != null) {
17-
preg_match_all("/`([^`]*)`/", $items, $matches);
18-
$allItems = array_count_values($matches[1]);
19-
unset($allItems['']);
20-
foreach ($allItems as $item => $count) {
21-
$inventory[trans('item.'.$item)] = $count;
22-
}
23-
return $inventory;
16+
// if ($items != '"[]"' && $items != '' && $items != null) {
17+
// preg_match_all("/`([^`]*)`/", $items, $matches);
18+
// $allItems = array_count_values($matches[1]);
19+
// unset($allItems['']);
20+
// foreach ($allItems as $item => $count) {
21+
// $inventory[trans('item.'.$item)] = $count;
22+
// }
23+
// return $inventory;
24+
// }
25+
// return false;
26+
27+
if ($items == '"[]"' && $items == '' && $items == null) {
28+
return false;
29+
}
30+
31+
preg_match_all("/`([^`]*)`/", $items, $matches);
32+
$allItems = array_count_values($matches[1]);
33+
34+
$parsedInventory = [];
35+
unset($allItems['']);
36+
foreach ($allItems as $key => $count) {
37+
array_push($parsedInventory, [
38+
'id' => $key,
39+
'name' => trans('item.'.$key),
40+
'count' => $count
41+
]);
2442
}
25-
return false;
43+
44+
return $parsedInventory;
2645
}
2746

2847
public static function stats($stats)

0 commit comments

Comments
 (0)