DONE: layout letter with letterhead and footer, notification for newly...
This commit is contained in:
@@ -8,24 +8,32 @@ use Modules\User\Repositories\Contracts\UserRepositoryInterface;
|
||||
|
||||
class UserRepository implements UserRepositoryInterface
|
||||
{
|
||||
private function applySearch($query, string $search): void
|
||||
{
|
||||
if (empty($search)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'ILIKE', "%{$search}%")
|
||||
->orWhere('ic_number', 'ILIKE', "%{$search}%")
|
||||
->orWhere('email', 'ILIKE', "%{$search}%")
|
||||
->orWhere('phone_number', 'ILIKE', "%{$search}%")
|
||||
->orWhere('member_number', 'ILIKE', "%{$search}%")
|
||||
->orWhereHas('roles', function ($roleQuery) use ($search) {
|
||||
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Users with pagination and search
|
||||
*/
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '')
|
||||
{
|
||||
$query = User::visibleTo(auth()->user())->excludeDevelopersUnlessDeveloper()->orderBy('name');
|
||||
$query = User::excludeDevelopersUnlessDeveloper()->orderBy('name');
|
||||
|
||||
if (! empty($search)) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'ILIKE', "%{$search}%");
|
||||
$q->orWhere('ic_number', 'ILIKE', "%{$search}%");
|
||||
$q->orWhere('email', 'ILIKE', "%{$search}%");
|
||||
$q->orWhere('phone_number', 'ILIKE', "%{$search}%");
|
||||
$q->orWhereHas('roles', function ($roleQuery) use ($search) {
|
||||
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
});
|
||||
}
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
@@ -46,38 +54,60 @@ class UserRepository implements UserRepositoryInterface
|
||||
'email',
|
||||
'position',
|
||||
'status',
|
||||
'ic_number',
|
||||
'phone_number',
|
||||
'member_number',
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
];
|
||||
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'name';
|
||||
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
|
||||
|
||||
$query = User::visibleTo(auth()->user())->excludeDevelopersUnlessDeveloper()
|
||||
$query = User::excludeDevelopersUnlessDeveloper()
|
||||
->with([
|
||||
'roles:id,name,guard_name'
|
||||
])
|
||||
->orderBy($sortBy, $sortOrder);
|
||||
|
||||
if (! empty($search)) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'ILIKE', "%{$search}%")
|
||||
->orWhere('ic_number', 'ILIKE', "%{$search}%")
|
||||
->orWhere('email', 'ILIKE', "%{$search}%")
|
||||
->orWhere('phone_number', 'ILIKE', "%{$search}%")
|
||||
->orWhereHas('roles', function ($roleQuery) use ($search) {
|
||||
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
$q->orWhere('ic_number', 'ILIKE', "%{$search}%");
|
||||
$q->orWhere('email', 'ILIKE', "%{$search}%");
|
||||
$q->orWhere('phone_number', 'ILIKE', "%{$search}%");
|
||||
$q->orWhereHas('roles', function ($roleQuery) use ($search) {
|
||||
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
});
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
if (! empty($status)) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
|
||||
// Add status filter
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get soft-deleted Users with their relationships and pagination
|
||||
*/
|
||||
public function getDeletedWithRelationsPaginated(
|
||||
int $perPage = 10,
|
||||
string $search = '',
|
||||
string $status = '',
|
||||
string $sortBy = 'deleted_at',
|
||||
string $sortOrder = 'desc'
|
||||
) {
|
||||
$allowedSortColumns = [
|
||||
'id',
|
||||
'name',
|
||||
'email',
|
||||
'position',
|
||||
'status',
|
||||
'member_number',
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
];
|
||||
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'deleted_at';
|
||||
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
|
||||
|
||||
$query = User::onlyTrashed()
|
||||
->excludeDevelopersUnlessDeveloper()
|
||||
->with([
|
||||
'roles:id,name,guard_name',
|
||||
])
|
||||
->orderBy($sortBy, $sortOrder);
|
||||
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
if (! empty($status)) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
@@ -90,19 +120,9 @@ class UserRepository implements UserRepositoryInterface
|
||||
*/
|
||||
public function getAllWithRelations(string $search = ''): Collection
|
||||
{
|
||||
$query = User::visibleTo(auth()->user())->excludeDevelopersUnlessDeveloper()->orderBy('name');
|
||||
$query = User::excludeDevelopersUnlessDeveloper()->orderBy('name');
|
||||
|
||||
if (! empty($search)) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'ILIKE', "%{$search}%")
|
||||
->orWhere('ic_number', 'ILIKE', "%{$search}%")
|
||||
->orWhere('email', 'ILIKE', "%{$search}%")
|
||||
->orWhere('phone_number', 'ILIKE', "%{$search}%")
|
||||
->orWhereHas('roles', function ($roleQuery) use ($search) {
|
||||
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
});
|
||||
}
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
@@ -136,24 +156,36 @@ class UserRepository implements UserRepositoryInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find soft-deleted User by ID
|
||||
*/
|
||||
public function findTrashedById(string $id): ?User
|
||||
{
|
||||
return User::onlyTrashed()->with(['roles'])->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore a soft-deleted User
|
||||
*/
|
||||
public function restore(string $id): bool
|
||||
{
|
||||
$user = User::onlyTrashed()->find($id);
|
||||
|
||||
if ($user) {
|
||||
return (bool) $user->restore();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Ranks
|
||||
*/
|
||||
public function all(string $search = ''): Collection
|
||||
{
|
||||
$query = User::visibleTo(auth()->user())->excludeDevelopersUnlessDeveloper()->orderBy('name');
|
||||
$query = User::excludeDevelopersUnlessDeveloper()->orderBy('name');
|
||||
|
||||
if (! empty($search)) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'ILIKE', "%{$search}%")
|
||||
->orWhere('ic_number', 'ILIKE', "%{$search}%")
|
||||
->orWhere('email', 'ILIKE', "%{$search}%")
|
||||
->orWhere('phone_number', 'ILIKE', "%{$search}%")
|
||||
->orWhereHas('roles', function ($roleQuery) use ($search) {
|
||||
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
});
|
||||
}
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user