misc_pterodactyl-panel/app/Repositories/Eloquent/UserRepository.php

71 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Repositories\Eloquent;
2017-08-05 22:26:30 +00:00
use Pterodactyl\Models\User;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
class UserRepository extends EloquentRepository implements UserRepositoryInterface
2016-12-07 22:46:38 +00:00
{
/**
* Return the model backing this repository.
*
* @return string
*/
public function model()
{
return User::class;
}
/**
* Return all users with counts of servers and subusers of servers.
*
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function getAllUsersWithCounts(): LengthAwarePaginator
{
return $this->getBuilder()->withCount('servers')->paginate(50, $this->getColumns());
}
/**
* Return all matching models for a user in a format that can be used for dropdowns.
*
* @param string|null $query
* @return \Illuminate\Support\Collection
*/
public function filterUsersByQuery(?string $query): Collection
{
$this->setColumns([
'id', 'email', 'username', 'name_first', 'name_last',
]);
$instance = $this->getBuilder()->get($this->getColumns());
return $instance->transform(function ($item) {
$item->md5 = md5(strtolower($item->email));
return $item;
});
}
/**
* Returns a user with the given id in a format that can be used for dropdowns.
*
* @param int $id
* @return \Pterodactyl\Models\Model
*/
public function filterById(int $id): \Pterodactyl\Models\Model
{
$this->setColumns([
'id', 'email', 'username', 'name_first', 'name_last',
]);
$model = $this->getBuilder()->findOrFail($id, $this->getColumns())->getModel();
$model->md5 = md5(strtolower($model->email));
return $model;
}
}