Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Repositories/Eloquent/SubuserRepository.php
7460 views
1
<?php
2
3
namespace Pterodactyl\Repositories\Eloquent;
4
5
use Pterodactyl\Models\Subuser;
6
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
7
use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
8
9
class SubuserRepository extends EloquentRepository implements SubuserRepositoryInterface
10
{
11
/**
12
* Return the model backing this repository.
13
*/
14
public function model(): string
15
{
16
return Subuser::class;
17
}
18
19
/**
20
* Return a subuser with the associated server relationship.
21
*/
22
public function loadServerAndUserRelations(Subuser $subuser, bool $refresh = false): Subuser
23
{
24
if (!$subuser->relationLoaded('server') || $refresh) {
25
$subuser->load('server');
26
}
27
28
if (!$subuser->relationLoaded('user') || $refresh) {
29
$subuser->load('user');
30
}
31
32
return $subuser;
33
}
34
35
/**
36
* Return a subuser with the associated permissions relationship.
37
*/
38
public function getWithPermissions(Subuser $subuser, bool $refresh = false): Subuser
39
{
40
if (!$subuser->relationLoaded('permissions') || $refresh) {
41
$subuser->load('permissions');
42
}
43
44
if (!$subuser->relationLoaded('user') || $refresh) {
45
$subuser->load('user');
46
}
47
48
return $subuser;
49
}
50
51
/**
52
* Return a subuser and associated permissions given a user_id and server_id.
53
*
54
* @throws RecordNotFoundException
55
*/
56
public function getWithPermissionsUsingUserAndServer(int $user, int $server): Subuser
57
{
58
$instance = $this->getBuilder()->with('permissions')->where([
59
['user_id', '=', $user],
60
['server_id', '=', $server],
61
])->first();
62
63
if (is_null($instance)) {
64
throw new RecordNotFoundException();
65
}
66
67
return $instance;
68
}
69
}
70
71