mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 14:06:53 +01:00 
			
		
		
		
	 da195fd2fe
			
		
	
	
		da195fd2fe
		
			
		
	
	
	
	
		
			
			* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
		
			
				
	
	
		
			73 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Transformers\Api\Application;
 | |
| 
 | |
| use App\Models\Node;
 | |
| use App\Models\Server;
 | |
| use League\Fractal\Resource\Item;
 | |
| use App\Models\Allocation;
 | |
| use League\Fractal\Resource\NullResource;
 | |
| 
 | |
| class AllocationTransformer extends BaseTransformer
 | |
| {
 | |
|     /**
 | |
|      * Relationships that can be loaded onto allocation transformations.
 | |
|      */
 | |
|     protected array $availableIncludes = ['node', 'server'];
 | |
| 
 | |
|     /**
 | |
|      * Return the resource name for the JSONAPI output.
 | |
|      */
 | |
|     public function getResourceName(): string
 | |
|     {
 | |
|         return Allocation::RESOURCE_NAME;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param  Allocation  $allocation
 | |
|      */
 | |
|     public function transform($allocation): array
 | |
|     {
 | |
|         return [
 | |
|             'id' => $allocation->id,
 | |
|             'ip' => $allocation->ip,
 | |
|             'alias' => $allocation->ip_alias,
 | |
|             'port' => $allocation->port,
 | |
|             'notes' => $allocation->notes,
 | |
|             'assigned' => !is_null($allocation->server_id),
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Load the node relationship onto a given transformation.
 | |
|      */
 | |
|     public function includeNode(Allocation $allocation): Item|NullResource
 | |
|     {
 | |
|         if (!$this->authorize(Node::RESOURCE_NAME)) {
 | |
|             return $this->null();
 | |
|         }
 | |
| 
 | |
|         return $this->item(
 | |
|             $allocation->node,
 | |
|             $this->makeTransformer(NodeTransformer::class),
 | |
|             Node::RESOURCE_NAME
 | |
|         );
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Load the server relationship onto a given transformation.
 | |
|      */
 | |
|     public function includeServer(Allocation $allocation): Item|NullResource
 | |
|     {
 | |
|         if (!$this->authorize(Server::RESOURCE_NAME) || !$allocation->server) {
 | |
|             return $this->null();
 | |
|         }
 | |
| 
 | |
|         return $this->item(
 | |
|             $allocation->server,
 | |
|             $this->makeTransformer(ServerTransformer::class),
 | |
|             Server::RESOURCE_NAME
 | |
|         );
 | |
|     }
 | |
| }
 |