toArray(); $response[$model->getUpdatedAtColumn()] = $this->formatTimestamp($model->updated_at); $response[$model->getCreatedAtColumn()] = $this->formatTimestamp($model->created_at); $resources = $model->servers()->select(['memory', 'disk'])->get(); $response['allocated_resources'] = [ 'memory' => $resources->sum('memory'), 'disk' => $resources->sum('disk'), ]; return $response; } /** * Return the allocations associated with this node. * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * * @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException */ public function includeAllocations(Node $node) { if (!$this->authorize(AdminAcl::RESOURCE_ALLOCATIONS)) { return $this->null(); } $node->loadMissing('allocations'); return $this->collection( $node->getRelation('allocations'), $this->makeTransformer(AllocationTransformer::class), 'allocation' ); } /** * Return the database host associated with this node. * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * * @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException */ public function includeDatabaseHost(Node $node) { if (!$this->authorize(AdminAcl::RESOURCE_DATABASE_HOSTS)) { return $this->null(); } $node->loadMissing('databaseHost'); $databaseHost = $node->getRelation('databaseHost'); if (is_null($databaseHost)) { return new NullResource(); } return $this->item( $node->getRelation('databaseHost'), $this->makeTransformer(DatabaseHostTransformer::class), 'databaseHost' ); } /** * Return the location associated with this node. * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * * @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException */ public function includeLocation(Node $node) { if (!$this->authorize(AdminAcl::RESOURCE_LOCATIONS)) { return $this->null(); } $node->loadMissing('location'); return $this->item( $node->getRelation('location'), $this->makeTransformer(LocationTransformer::class), 'location' ); } /** * Return the mounts associated with this node. * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * * @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException */ public function includeMounts(Node $node) { if (!$this->authorize(AdminAcl::RESOURCE_MOUNTS)) { return $this->null(); } $node->loadMissing('mounts'); return $this->collection( $node->getRelation('mounts'), $this->makeTransformer(MountTransformer::class), 'mount' ); } /** * Return the servers associated with this node. * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * * @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException */ public function includeServers(Node $node) { if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) { return $this->null(); } $node->loadMissing('servers'); return $this->collection( $node->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), 'server' ); } }