Show count of pending pilot registrations; pagination

This commit is contained in:
Nabeel Shahzad
2017-12-22 14:48:15 -06:00
parent 7103278bb8
commit 50ede116ca
9 changed files with 70 additions and 52 deletions

View File

@@ -2,17 +2,21 @@
namespace App\Http\Controllers\Admin;
use App\Repositories\PirepRepository;
use Illuminate\Http\Request;
use App\Repositories\PirepRepository;
use App\Repositories\UserRepository;
class DashboardController extends BaseController
{
private $pirepRepo;
private $pirepRepo, $userRepo;
public function __construct(
PirepRepository $pirepRepo
PirepRepository $pirepRepo,
UserRepository $userRepo
) {
$this->pirepRepo = $pirepRepo;
$this->userRepo = $userRepo;
}
/**
@@ -28,6 +32,7 @@ class DashboardController extends BaseController
return view('admin.dashboard.index', [
'feed' => $feed,
'pending_pireps' => $this->pirepRepo->getPendingCount(),
'pending_users' => $this->userRepo->getPendingCount(),
]);
}
}

View File

@@ -36,19 +36,15 @@ class UserController extends BaseController
$this->userRepo = $userRepo;
}
/**
* Display a listing of the User.
*
* @param Request $request
* @return Response
*/
public function index(Request $request)
{
$this->userRepo->pushCriteria(new RequestCriteria($request));
$Users = $this->userRepo->all();
$users = $this->userRepo
->orderBy('created_at', 'desc')
->paginate();
return view('admin.users.index', [
'users' => $Users,
'users' => $users,
]);
}

View File

@@ -2,6 +2,7 @@
namespace App\Repositories;
use App\Models\Enums\PirepState;
use App\Models\Pirep;
use App\Models\User;
use App\Repositories\Traits\CacheableRepository;
@@ -15,6 +16,7 @@ class PirepRepository extends BaseRepository implements CacheableInterface
'user_id',
'flight_id',
'status',
'state',
];
public function model()
@@ -46,7 +48,10 @@ class PirepRepository extends BaseRepository implements CacheableInterface
*/
public function getPendingCount(User $user = null)
{
$where = [];
$where = [
'state' => PirepState::PENDING,
];
if ($user !== null) {
$where['user_id'] = $user->id;
}

View File

@@ -1,6 +1,7 @@
<?php
namespace App\Repositories;
use App\Models\Enums\PilotState;
use App\Models\User;
use App\Repositories\Traits\CacheableRepository;
use Prettus\Repository\Contracts\CacheableInterface;
@@ -14,10 +15,25 @@ class UserRepository extends BaseRepository implements CacheableInterface
'email' => 'like',
'home_airport_id',
'curr_airport_id',
'state'
];
public function model()
{
return User::class;
}
/**
* Number of PIREPs that are pending
* @return mixed
*/
public function getPendingCount()
{
$where = [
'state' => PilotState::PENDING,
];
$users = $this->orderBy('created_at', 'desc')->findWhere($where)->count();
return $users;
}
}