mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 01:07:33 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php namespace App\Ninja\Transformers;
 | 
						|
 | 
						|
use App\Models\Account;
 | 
						|
use App\Models\Task;
 | 
						|
use App\Models\Client;
 | 
						|
use League\Fractal;
 | 
						|
 | 
						|
/**
 | 
						|
 * @SWG\Definition(definition="Task", @SWG\Xml(name="Task"))
 | 
						|
 */
 | 
						|
 | 
						|
class TaskTransformer extends EntityTransformer
 | 
						|
{
 | 
						|
    /**
 | 
						|
    * @SWG\Property(property="id", type="integer", example=1, readOnly=true)
 | 
						|
    * @SWG\Property(property="amount", type="float", example=10, readOnly=true)
 | 
						|
    * @SWG\Property(property="invoice_id", type="integer", example=1)
 | 
						|
    */
 | 
						|
    protected $availableIncludes = [
 | 
						|
        'client',
 | 
						|
    ];
 | 
						|
 | 
						|
 | 
						|
    public function __construct(Account $account)
 | 
						|
    {
 | 
						|
        parent::__construct($account);
 | 
						|
 | 
						|
    }
 | 
						|
 | 
						|
    public function includeClient(Task $task)
 | 
						|
    {
 | 
						|
        if ($task->client) {
 | 
						|
            $transformer = new ClientTransformer($this->account, $this->serializer);
 | 
						|
            return $this->includeItem($task->client, $transformer, 'client');
 | 
						|
        } else {
 | 
						|
            return null;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public function transform(Task $task)
 | 
						|
    {
 | 
						|
        return [
 | 
						|
            'id' => (int) $task->public_id,
 | 
						|
            'account_key' => $this->account->account_key,
 | 
						|
            'user_id' => (int) $task->user->public_id + 1,
 | 
						|
            'description' => $task->description,
 | 
						|
            'duration' => $task->getDuration()
 | 
						|
        ];
 | 
						|
    }
 | 
						|
} |