2019-09-27 06:31:13 +02:00
|
|
|
<?php
|
2020-07-01 03:06:40 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-07-01 03:06:40 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @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,
|
2019-12-29 23:06:42 +01:00
|
|
|
'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) : '',
|
2019-12-29 23:06:42 +01:00
|
|
|
'company_id' => $activity->company_id ? (string) $this->encodePrimaryKey($activity->company_id) : '',
|
2019-11-29 12:15:50 +01:00
|
|
|
'user_id' => (string) $this->encodePrimaryKey($activity->user_id),
|
2019-12-29 23:06:42 +01:00
|
|
|
'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) : '',
|
2019-12-29 23:06:42 +01:00
|
|
|
'payment_id' => $activity->payment_id ? (string) $this->encodePrimaryKey($activity->payment_id) : '',
|
|
|
|
'credit_id' => $activity->credit_id ? (string) $this->encodePrimaryKey($activity->credit_id) : '',
|
2020-09-06 11:38:10 +02:00
|
|
|
'updated_at' => (int) $activity->updated_at,
|
|
|
|
'created_at' => (int) $activity->created_at,
|
2019-12-29 23:06:42 +01:00
|
|
|
'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,
|
2019-12-29 23:06:42 +01:00
|
|
|
'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) : '',
|
2019-12-30 22:59:12 +01:00
|
|
|
'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)
|
|
|
|
{
|
2021-09-05 11:46:47 +02:00
|
|
|
$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
|
|
|
}
|