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

69 lines
2.7 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
*
* @copyright Copyright (c) 2021. 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;
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 = [
'history'
];
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) : '',
'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);
}
2019-09-27 06:31:13 +02:00
}