2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
|
|
|
|
2017-06-11 03:28:44 +00:00
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
2015-12-06 18:58:49 +00:00
|
|
|
|
2017-08-05 22:26:30 +00:00
|
|
|
use Pterodactyl\Models\User;
|
2018-01-05 04:49:50 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2017-08-19 03:19:06 +00:00
|
|
|
use Pterodactyl\Repositories\Concerns\Searchable;
|
2018-01-05 04:49:50 +00:00
|
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
2017-07-01 20:29:49 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
2017-06-11 03:28:44 +00:00
|
|
|
|
2017-08-19 03:19:06 +00:00
|
|
|
class UserRepository extends EloquentRepository implements UserRepositoryInterface
|
2016-12-07 22:46:38 +00:00
|
|
|
{
|
2017-08-19 03:19:06 +00:00
|
|
|
use Searchable;
|
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return the model backing this repository.
|
2015-12-06 18:58:49 +00:00
|
|
|
*
|
2018-01-05 04:49:50 +00:00
|
|
|
* @return string
|
2017-07-08 19:07:51 +00:00
|
|
|
*/
|
2017-06-11 03:28:44 +00:00
|
|
|
public function model()
|
2015-12-06 18:58:49 +00:00
|
|
|
{
|
2017-06-11 03:28:44 +00:00
|
|
|
return User::class;
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|
|
|
|
|
2017-07-08 19:07:51 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return all users with counts of servers and subusers of servers.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
2017-07-08 19:07:51 +00:00
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function getAllUsersWithCounts(): LengthAwarePaginator
|
2017-07-01 20:29:49 +00:00
|
|
|
{
|
2018-01-05 04:49:50 +00:00
|
|
|
return $this->getBuilder()->withCount('servers', 'subuserOf')
|
2018-01-06 00:27:47 +00:00
|
|
|
->search($this->getSearchTerm())
|
2018-01-05 04:49:50 +00:00
|
|
|
->paginate(50, $this->getColumns());
|
2017-06-11 03:28:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 18:55:30 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return all matching models for a user in a format that can be used for dropdowns.
|
|
|
|
*
|
2018-05-21 00:00:50 +00:00
|
|
|
* @param string|null $query
|
2018-01-05 04:49:50 +00:00
|
|
|
* @return \Illuminate\Support\Collection
|
2017-07-22 18:55:30 +00:00
|
|
|
*/
|
2018-05-21 00:00:50 +00:00
|
|
|
public function filterUsersByQuery(?string $query): Collection
|
2017-07-22 18:55:30 +00:00
|
|
|
{
|
2018-01-05 04:49:50 +00:00
|
|
|
$this->setColumns([
|
2017-07-22 18:55:30 +00:00
|
|
|
'id', 'email', 'username', 'name_first', 'name_last',
|
|
|
|
]);
|
|
|
|
|
2018-01-06 18:49:32 +00:00
|
|
|
$instance = $this->getBuilder()->search($query)->get($this->getColumns());
|
2017-07-22 18:55:30 +00:00
|
|
|
|
|
|
|
return $instance->transform(function ($item) {
|
|
|
|
$item->md5 = md5(strtolower($item->email));
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
});
|
|
|
|
}
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|