1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Transformers/ActivityTransformer.php

155 lines
5.3 KiB
PHP
Raw Normal View History

2019-09-27 06:31:13 +02:00
<?php
2020-07-01 03:06:40 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2020-07-01 03:06:40 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
2020-07-01 03:06:40 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2020-07-01 03:06:40 +02:00
*/
2019-09-27 06:31:13 +02:00
namespace App\Transformers;
use App\Models\Activity;
2021-09-05 11:40:50 +02:00
use App\Models\Backup;
2022-05-27 10:25:32 +02:00
use App\Models\ClientContact;
use App\Models\Invoice;
use App\Models\Task;
use App\Models\User;
2019-09-27 06:31:13 +02:00
use App\Utils\Traits\MakesHash;
class ActivityTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [];
/**
* @var array
*/
2021-09-05 11:40:50 +02:00
protected $availableIncludes = [
2022-05-27 10:25:32 +02:00
'history',
'user',
'client',
'contact',
'recurring_invoice',
'invoice',
'credit',
'quote',
'payment',
'expense',
'task',
2021-09-05 11:40:50 +02:00
];
2019-09-27 06:31:13 +02:00
/**
* @param Activity $activity
*
* @return array
*/
public function transform(Activity $activity)
{
return [
'id' => (string) $this->encodePrimaryKey($activity->id),
'activity_type_id' => (string) $activity->activity_type_id,
'client_id' => $activity->client_id ? (string) $this->encodePrimaryKey($activity->client_id) : '',
2021-06-27 11:20:56 +02:00
'recurring_invoice_id' => $activity->recurring_invoice_id ? (string) $this->encodePrimaryKey($activity->recurring_invoice_id) : '',
2022-01-14 11:55:01 +01:00
'recurring_expense_id' => $activity->recurring_expense_id ? (string) $this->encodePrimaryKey($activity->recurring_expense_id) : '',
'company_id' => $activity->company_id ? (string) $this->encodePrimaryKey($activity->company_id) : '',
'user_id' => (string) $this->encodePrimaryKey($activity->user_id),
'invoice_id' => $activity->invoice_id ? (string) $this->encodePrimaryKey($activity->invoice_id) : '',
2020-11-30 08:43:33 +01:00
'quote_id' => $activity->quote_id ? (string) $this->encodePrimaryKey($activity->quote_id) : '',
'payment_id' => $activity->payment_id ? (string) $this->encodePrimaryKey($activity->payment_id) : '',
'credit_id' => $activity->credit_id ? (string) $this->encodePrimaryKey($activity->credit_id) : '',
'updated_at' => (int) $activity->updated_at,
'created_at' => (int) $activity->created_at,
'expense_id' => $activity->expense_id ? (string) $this->encodePrimaryKey($activity->expense_id) : '',
2019-09-27 06:31:13 +02:00
'is_system' => (bool) $activity->is_system,
'contact_id' => $activity->contact_id ? (string) $this->encodePrimaryKey($activity->contact_id) : '',
'task_id' => $activity->task_id ? (string) $this->encodePrimaryKey($activity->task_id) : '',
2020-07-08 08:54:16 +02:00
'token_id' => $activity->token_id ? (string) $this->encodePrimaryKey($activity->token_id) : '',
'notes' => $activity->notes ? (string) $activity->notes : '',
'ip' => (string) $activity->ip,
2019-09-27 06:31:13 +02:00
];
}
2021-09-05 11:40:50 +02:00
public function includeHistory(Activity $activity)
{
$transformer = new InvoiceHistoryTransformer($this->serializer);
2021-09-05 11:40:50 +02:00
return $this->includeItem($activity->backup, $transformer, Backup::class);
}
2022-05-27 10:25:32 +02:00
public function includeClient(Activity $activity)
{
$transformer = new ClientTransformer($this->serializer);
return $this->includeItem($activity->client, $transformer, Client::class);
}
public function includeContact(Activity $activity)
{
$transformer = new ClientContactTransformer($this->serializer);
return $this->includeItem($activity->contact, $transformer, ClientContact::class);
}
public function includeRecurringInvoice(Activity $activity)
{
$transformer = new RecurringInvoiceTransformer($this->serializer);
return $this->includeItem($activity->recurring_invoice, $transformer, RecurringInvoice::class);
}
public function includeQuote(Activity $activity)
{
$transformer = new RecurringInvoiceTransformer($this->serializer);
return $this->includeItem($activity->quote, $transformer, Quote::class);
}
public function includeInvoice(Activity $activity)
{
$transformer = new InvoiceTransformer($this->serializer);
return $this->includeItem($activity->invoice, $transformer, Invoice::class);
}
public function includeCredit(Activity $activity)
{
$transformer = new CreditTransformer($this->serializer);
return $this->includeItem($activity->credit, $transformer, Credit::class);
}
public function includePayment(Activity $activity)
{
$transformer = new PaymentTransformer($this->serializer);
return $this->includeItem($activity->payment, $transformer, Payment::class);
}
public function includeUser(Activity $activity)
{
$transformer = new UserTransformer($this->serializer);
return $this->includeItem($activity->user, $transformer, User::class);
}
public function includeExpense(Activity $activity)
{
$transformer = new ExpenseTransformer($this->serializer);
return $this->includeItem($activity->expense, $transformer, Expense::class);
}
public function includeTask(Activity $activity)
{
$transformer = new TaskTransformer($this->serializer);
return $this->includeItem($activity->task, $transformer, Task::class);
}
2019-09-27 06:31:13 +02:00
}