2016-11-27 00:29:57 +00:00
|
|
|
<?php
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-08-24 02:34:11 +00:00
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
2016-11-27 00:29:57 +00:00
|
|
|
|
2017-08-27 19:55:25 +00:00
|
|
|
use Pterodactyl\Models\Subuser;
|
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
|
|
|
use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
|
2016-11-27 00:29:57 +00:00
|
|
|
|
2017-08-24 02:34:11 +00:00
|
|
|
class SubuserRepository extends EloquentRepository implements SubuserRepositoryInterface
|
2016-11-27 00:29:57 +00:00
|
|
|
{
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return the model backing this repository.
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function model(): string
|
2016-11-27 00:29:57 +00:00
|
|
|
{
|
2017-08-24 02:34:11 +00:00
|
|
|
return Subuser::class;
|
2016-11-27 00:29:57 +00:00
|
|
|
}
|
2017-08-26 18:31:18 +00:00
|
|
|
|
2017-08-26 23:08:11 +00:00
|
|
|
/**
|
2017-10-28 02:42:53 +00:00
|
|
|
* Return a subuser with the associated server relationship.
|
2017-08-26 23:08:11 +00:00
|
|
|
*/
|
2017-11-05 18:38:39 +00:00
|
|
|
public function loadServerAndUserRelations(Subuser $subuser, bool $refresh = false): Subuser
|
2017-08-26 23:08:11 +00:00
|
|
|
{
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$subuser->relationLoaded('server') || $refresh) {
|
2017-10-28 02:42:53 +00:00
|
|
|
$subuser->load('server');
|
2017-09-04 23:12:13 +00:00
|
|
|
}
|
|
|
|
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$subuser->relationLoaded('user') || $refresh) {
|
2017-11-05 18:38:39 +00:00
|
|
|
$subuser->load('user');
|
|
|
|
}
|
|
|
|
|
2017-10-28 02:42:53 +00:00
|
|
|
return $subuser;
|
2017-09-04 23:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-28 02:42:53 +00:00
|
|
|
* Return a subuser with the associated permissions relationship.
|
2017-09-04 23:12:13 +00:00
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function getWithPermissions(Subuser $subuser, bool $refresh = false): Subuser
|
2017-09-04 23:12:13 +00:00
|
|
|
{
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$subuser->relationLoaded('permissions') || $refresh) {
|
2017-10-28 02:42:53 +00:00
|
|
|
$subuser->load('permissions');
|
|
|
|
}
|
2017-09-04 23:12:13 +00:00
|
|
|
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$subuser->relationLoaded('user') || $refresh) {
|
2017-10-28 02:42:53 +00:00
|
|
|
$subuser->load('user');
|
2017-08-26 23:08:11 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 02:42:53 +00:00
|
|
|
return $subuser;
|
2017-08-26 23:08:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-24 01:45:25 +00:00
|
|
|
/**
|
2017-11-05 22:07:50 +00:00
|
|
|
* Return a subuser and associated permissions given a user_id and server_id.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-09-24 01:45:25 +00:00
|
|
|
*/
|
2017-11-05 22:07:50 +00:00
|
|
|
public function getWithPermissionsUsingUserAndServer(int $user, int $server): Subuser
|
2017-09-24 01:45:25 +00:00
|
|
|
{
|
|
|
|
$instance = $this->getBuilder()->with('permissions')->where([
|
|
|
|
['user_id', '=', $user],
|
|
|
|
['server_id', '=', $server],
|
|
|
|
])->first();
|
|
|
|
|
|
|
|
if (is_null($instance)) {
|
2021-01-23 20:33:34 +00:00
|
|
|
throw new RecordNotFoundException();
|
2017-09-24 01:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
2016-11-27 00:29:57 +00:00
|
|
|
}
|