1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 23:52:33 +01:00
invoiceninja/app/Transformers/ActivityTransformer.php

249 lines
7.6 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
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. 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;
2023-10-26 04:57:44 +02:00
use App\Models\Activity;
2023-08-08 11:44:52 +02:00
use App\Models\Backup;
use App\Models\Client;
2023-10-26 04:57:44 +02:00
use App\Models\ClientContact;
2023-08-08 11:44:52 +02:00
use App\Models\Credit;
use App\Models\Expense;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PurchaseOrder;
2023-10-26 04:57:44 +02:00
use App\Models\Quote;
use App\Models\RecurringInvoice;
use App\Models\Task;
use App\Models\User;
use App\Models\Vendor;
use App\Models\VendorContact;
2019-09-27 06:31:13 +02:00
use App\Utils\Traits\MakesHash;
class ActivityTransformer extends EntityTransformer
{
use MakesHash;
2023-08-21 03:29:31 +02:00
protected array $defaultIncludes = [];
2019-09-27 06:31:13 +02:00
/**
* @var array
*/
2023-08-21 03:29:31 +02:00
protected array $availableIncludes = [
2022-05-27 10:25:32 +02:00
'history',
'user',
'client',
'contact',
'recurring_invoice',
'invoice',
'credit',
'quote',
'payment',
'expense',
'task',
'purchase_order',
'vendor',
'vendor_contact',
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) : '',
'purchase_order_id' => $activity->purchase_order_id ? (string) $this->encodePrimaryKey($activity->purchase_order_id) : '',
'vendor_id' => $activity->vendor_id ? (string) $this->encodePrimaryKey($activity->vendor_id) : '',
'vendor_contact_id' => $activity->vendor_contact_id ? (string) $this->encodePrimaryKey($activity->vendor_contact_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->client_contact_id ? (string) $this->encodePrimaryKey($activity->client_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)
{
2023-12-12 00:46:23 +01:00
if (!$activity->client) {
return null;
}
2022-05-27 10:25:32 +02:00
$transformer = new ClientTransformer($this->serializer);
return $this->includeItem($activity->client, $transformer, Client::class);
}
public function includeVendor(Activity $activity)
{
2023-12-12 00:46:23 +01:00
if (!$activity->vendor) {
return null;
}
$transformer = new VendorTransformer($this->serializer);
return $this->includeItem($activity->vendor, $transformer, Vendor::class);
}
2022-05-27 10:25:32 +02:00
public function includeContact(Activity $activity)
{
2023-12-12 00:46:23 +01:00
if (!$activity->contact) {
return null;
}
2022-05-27 10:25:32 +02:00
$transformer = new ClientContactTransformer($this->serializer);
return $this->includeItem($activity->contact, $transformer, ClientContact::class);
}
public function includeVendorContact(Activity $activity)
{
2023-12-12 00:46:23 +01:00
if (!$activity->vendor_contact) {
return null;
}
$transformer = new VendorContactTransformer($this->serializer);
return $this->includeItem($activity->vendor_contact, $transformer, VendorContact::class);
}
2022-05-27 10:25:32 +02:00
public function includeRecurringInvoice(Activity $activity)
{
2023-12-12 00:46:23 +01:00
if (!$activity->recurring_invoice) {
return null;
}
2022-05-27 10:25:32 +02:00
$transformer = new RecurringInvoiceTransformer($this->serializer);
return $this->includeItem($activity->recurring_invoice, $transformer, RecurringInvoice::class);
}
public function includePurchaseOrder(Activity $activity)
{
2023-12-12 00:46:23 +01:00
if (!$activity->purchase_order) {
return null;
}
$transformer = new PurchaseOrderTransformer($this->serializer);
2023-12-12 00:46:23 +01:00
return $this->includeItem($activity->purchase_order, $transformer, PurchaseOrder::class);
}
2022-05-27 10:25:32 +02:00
public function includeQuote(Activity $activity)
{
2023-12-12 00:46:23 +01:00
if (!$activity->quote) {
return null;
}
2022-05-27 10:25:32 +02:00
$transformer = new RecurringInvoiceTransformer($this->serializer);
return $this->includeItem($activity->quote, $transformer, Quote::class);
}
public function includeInvoice(Activity $activity)
{
2023-12-12 00:46:23 +01:00
if (!$activity->invoice) {
return null;
}
2022-05-27 10:25:32 +02:00
$transformer = new InvoiceTransformer($this->serializer);
return $this->includeItem($activity->invoice, $transformer, Invoice::class);
}
public function includeCredit(Activity $activity)
{
2023-12-12 00:46:23 +01:00
if (!$activity->credit) {
return null;
}
2022-05-27 10:25:32 +02:00
$transformer = new CreditTransformer($this->serializer);
return $this->includeItem($activity->credit, $transformer, Credit::class);
}
public function includePayment(Activity $activity)
{
2023-12-12 00:46:23 +01:00
if (!$activity->payment) {
return null;
}
2022-05-27 10:25:32 +02:00
$transformer = new PaymentTransformer($this->serializer);
return $this->includeItem($activity->payment, $transformer, Payment::class);
}
public function includeUser(Activity $activity)
{
2023-12-12 00:46:23 +01:00
if (!$activity->user) {
return null;
}
2022-05-27 10:25:32 +02:00
$transformer = new UserTransformer($this->serializer);
return $this->includeItem($activity->user, $transformer, User::class);
}
public function includeExpense(Activity $activity)
{
2023-12-12 00:46:23 +01:00
if (!$activity->expense) {
return null;
}
2022-05-27 10:25:32 +02:00
$transformer = new ExpenseTransformer($this->serializer);
return $this->includeItem($activity->expense, $transformer, Expense::class);
}
public function includeTask(Activity $activity)
{
2023-12-12 00:46:23 +01:00
if (!$activity->task) {
return null;
}
2022-05-27 10:25:32 +02:00
$transformer = new TaskTransformer($this->serializer);
return $this->includeItem($activity->task, $transformer, Task::class);
}
2019-09-27 06:31:13 +02:00
}