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;
|
|
|
|
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
|
|
|
{
|
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
|
|
|
{
|
2020-09-13 18:29:47 +00:00
|
|
|
return $this->getBuilder()->withCount('servers')->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',
|
|
|
|
]);
|
|
|
|
|
2020-09-13 18:29:47 +00:00
|
|
|
$instance = $this->getBuilder()->get($this->getColumns());
|
2017-07-22 18:55:30 +00:00
|
|
|
|
|
|
|
return $instance->transform(function ($item) {
|
|
|
|
$item->md5 = md5(strtolower($item->email));
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
});
|
|
|
|
}
|
2020-04-11 19:56:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|