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