refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
63
app/ExportResources/Account/Account.php
Normal file
63
app/ExportResources/Account/Account.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Account;
|
||||
|
||||
use App\Models\Contact\Gender;
|
||||
use App\ExportResources\User\User;
|
||||
use App\ExportResources\User\Module;
|
||||
use App\ExportResources\ExportResource;
|
||||
use App\ExportResources\Contact\Contact;
|
||||
use App\ExportResources\Contact\Document;
|
||||
use App\ExportResources\Instance\AuditLog;
|
||||
use App\ExportResources\Journal\JournalEntry;
|
||||
use App\ExportResources\Contact\ContactFieldType;
|
||||
use App\ExportResources\Relationship\Relationship;
|
||||
use App\ExportResources\Contact\Gender as GenderResource;
|
||||
|
||||
class Account extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'number_of_invitations_sent',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'data' => [
|
||||
User::countCollection($this->users),
|
||||
Contact::countCollection($this->allContacts),
|
||||
Relationship::countCollection($this->relationships),
|
||||
Addressbook::countCollection($this->addressBooks),
|
||||
AddressbookSubscription::countCollection($this->addressBookSubscriptions),
|
||||
Photo::countCollection($this->photos),
|
||||
Document::countCollection($this->documents),
|
||||
Activity::countCollection($this->activities),
|
||||
],
|
||||
'properties' => [
|
||||
'default_gender' => $this->when($this->default_gender_id !== null, function () {
|
||||
$defaultGender = Gender::where(['account_id' => $this->id])->find($this->default_gender_id);
|
||||
|
||||
return $defaultGender->uuid;
|
||||
}),
|
||||
'journal_entries' => JournalEntry::collection($this->journalEntries()->entry()->get()),
|
||||
'modules' => Module::collection($this->modules),
|
||||
'reminder_rules' => ReminderRule::collection($this->reminderRules),
|
||||
'audit_logs' => AuditLog::collection($this->auditLogs),
|
||||
],
|
||||
'instance' => [
|
||||
'activity_types' => ActivityType::collection($this->activityTypes),
|
||||
'activity_type_categories' => ActivityTypeCategory::collection($this->activityTypeCategories),
|
||||
'contact_field_types' => ContactFieldType::collection($this->contactFieldTypes),
|
||||
'genders' => GenderResource::collection($this->genders),
|
||||
'life_event_types' => LifeEventType::collection($this->lifeEventTypes),
|
||||
'life_event_categories' => LifeEventCategory::collection($this->lifeEventCategories),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
33
app/ExportResources/Account/Activity.php
Normal file
33
app/ExportResources/Account/Activity.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Account;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Activity extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'summary',
|
||||
'description',
|
||||
'happened_at',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
$this->mergeWhen($this->type !== null, function () {
|
||||
return [
|
||||
'type' => $this->type->uuid,
|
||||
];
|
||||
}),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
33
app/ExportResources/Account/ActivityType.php
Normal file
33
app/ExportResources/Account/ActivityType.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Account;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class ActivityType extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'translation_key',
|
||||
'name',
|
||||
'location_type',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
$this->mergeWhen($this->category !== null, function () {
|
||||
return [
|
||||
'category' => $this->category->uuid,
|
||||
];
|
||||
}),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/ExportResources/Account/ActivityTypeCategory.php
Normal file
19
app/ExportResources/Account/ActivityTypeCategory.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Account;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class ActivityTypeCategory extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'translation_key',
|
||||
'name',
|
||||
];
|
||||
}
|
||||
27
app/ExportResources/Account/Addressbook.php
Normal file
27
app/ExportResources/Account/Addressbook.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Account;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Addressbook extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'user' => $this->user->uuid,
|
||||
'contacts' => $this->contacts->mapUuid(),
|
||||
];
|
||||
}
|
||||
}
|
||||
44
app/ExportResources/Account/AddressbookSubscription.php
Normal file
44
app/ExportResources/Account/AddressbookSubscription.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Account;
|
||||
|
||||
use App\Models\User\SyncToken;
|
||||
use App\ExportResources\ExportResource;
|
||||
use App\ExportResources\User\SyncToken as SyncTokenResource;
|
||||
|
||||
class AddressbookSubscription extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'name',
|
||||
'uri',
|
||||
'username',
|
||||
'readonly',
|
||||
'active',
|
||||
'capabilities',
|
||||
'frequency',
|
||||
'last_syncronized_at',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
'addressbook' => $this->addressBook->uuid,
|
||||
'sync_token' => $this->syncToken,
|
||||
$this->merge(function () {
|
||||
$localSyncToken = SyncToken::where('account_id', $this->account_id)->find($this->localSyncToken);
|
||||
|
||||
return [
|
||||
'local_sync_token' => new SyncTokenResource($localSyncToken),
|
||||
];
|
||||
}),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/ExportResources/Account/LifeEventCategory.php
Normal file
27
app/ExportResources/Account/LifeEventCategory.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Account;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class LifeEventCategory extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'core_monica_data',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
'translation_key' => $this->default_life_event_category_key,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
34
app/ExportResources/Account/LifeEventType.php
Normal file
34
app/ExportResources/Account/LifeEventType.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Account;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class LifeEventType extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'name',
|
||||
'core_monica_data',
|
||||
'specific_information_structure',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
'translation_key' => $this->default_life_event_type_key,
|
||||
$this->mergeWhen($this->lifeEventCategory !== null, function () {
|
||||
return [
|
||||
'category' => $this->lifeEventCategory->uuid,
|
||||
];
|
||||
}),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
29
app/ExportResources/Account/Photo.php
Normal file
29
app/ExportResources/Account/Photo.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Account;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Photo extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'original_filename',
|
||||
'filesize',
|
||||
'mime_type',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
'dataUrl' => $this->dataUrl(),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
18
app/ExportResources/Account/ReminderRule.php
Normal file
18
app/ExportResources/Account/ReminderRule.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Account;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class ReminderRule extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'number_of_days_before',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'active',
|
||||
];
|
||||
}
|
||||
33
app/ExportResources/Contact/Address.php
Normal file
33
app/ExportResources/Contact/Address.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Address extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
'street' => $this->place->street,
|
||||
'city' => $this->place->city,
|
||||
'province' => $this->place->province,
|
||||
'postal_code' => $this->place->postal_code,
|
||||
'latitude' => $this->place->latitude,
|
||||
'longitude' => $this->place->longitude,
|
||||
'country' => $this->place->country,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
33
app/ExportResources/Contact/Call.php
Normal file
33
app/ExportResources/Contact/Call.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Call extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'called_at',
|
||||
'content',
|
||||
'contact_called',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
$this->mergeWhen($this->emotions->count() > 0, [
|
||||
'emotions' => $this->emotions->map(function ($emotion) {
|
||||
return $emotion->name;
|
||||
})->toArray(),
|
||||
]),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
106
app/ExportResources/Contact/Contact.php
Normal file
106
app/ExportResources/Contact/Contact.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\Account\Photo;
|
||||
use App\ExportResources\ExportResource;
|
||||
use App\ExportResources\Account\Activity;
|
||||
use App\ExportResources\Instance\SpecialDate;
|
||||
use App\Models\Contact\Reminder as ContactReminder;
|
||||
|
||||
class Contact extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'first_name',
|
||||
'middle_name',
|
||||
'last_name',
|
||||
'nickname',
|
||||
'description',
|
||||
'is_starred',
|
||||
'is_partial',
|
||||
'is_active',
|
||||
'is_dead',
|
||||
'job',
|
||||
'company',
|
||||
'food_preferences',
|
||||
'last_talked_to',
|
||||
'last_consulted_at',
|
||||
'number_of_views',
|
||||
'stay_in_touch_frequency',
|
||||
'stay_in_touch_trigger_date',
|
||||
'vcard',
|
||||
'distant_etag',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
'avatar' => [
|
||||
'avatar_source' => $this->avatar_source,
|
||||
'avatar_gravatar_url' => $this->avatar_gravatar_url,
|
||||
'avatar_adorable_uuid' => $this->avatar_adorable_uuid,
|
||||
'avatar_default_url' => $this->avatar_default_url,
|
||||
$this->mergeWhen($this->avatarPhoto !== null, function () {
|
||||
return ['avatar_photo' => $this->avatarPhoto->uuid];
|
||||
}),
|
||||
'has_avatar' => $this->has_avatar,
|
||||
'avatar_external_url' => $this->avatar_external_url,
|
||||
'avatar_file_name' => $this->avatar_file_name,
|
||||
'avatar_location' => $this->avatar_location,
|
||||
'gravatar_url' => $this->gravatar_url,
|
||||
'default_avatar_color' => $this->default_avatar_color,
|
||||
],
|
||||
'tags' => $this->when($this->tags->count() > 0, function () {
|
||||
return $this->tags->map(function ($tag) {
|
||||
return $tag->name;
|
||||
})->toArray();
|
||||
}),
|
||||
$this->mergeWhen($this->gender !== null, function () {
|
||||
return ['gender' => $this->gender->uuid];
|
||||
}),
|
||||
$this->mergeWhen($this->birthdate, [
|
||||
'birthdate' => new SpecialDate($this->birthdate),
|
||||
]),
|
||||
$this->mergeWhen($this->deceasedDate, [
|
||||
'deceased_date' => new SpecialDate($this->deceasedDate),
|
||||
]),
|
||||
$this->mergeWhen($this->deceased_reminder_id, function () {
|
||||
return ['deceased_reminder' => new Reminder(ContactReminder::find($this->deceased_reminder_id))];
|
||||
}),
|
||||
$this->mergeWhen($this->firstMetDate, [
|
||||
'first_met_date' => new SpecialDate($this->firstMetDate),
|
||||
]),
|
||||
$this->mergeWhen($this->getIntroducer() !== null, function () {
|
||||
return ['first_met_through' => $this->getIntroducer()->uuid];
|
||||
}),
|
||||
$this->mergeWhen($this->first_met_reminder_id !== null, function () {
|
||||
return ['first_met_reminder' => new Reminder(ContactReminder::find($this->first_met_reminder_id))];
|
||||
}),
|
||||
],
|
||||
'data' => [
|
||||
Call::countCollection($this->calls),
|
||||
ContactField::countCollection($this->contactFields),
|
||||
Debt::countCollection($this->debts),
|
||||
Gift::countCollection($this->gifts),
|
||||
Note::countCollection($this->notes),
|
||||
Reminder::countCollection($this->reminders),
|
||||
Task::countCollection($this->tasks),
|
||||
Address::countCollection($this->addresses),
|
||||
Pet::countCollection($this->pets),
|
||||
Conversation::countCollection($this->conversations),
|
||||
LifeEvent::countCollection($this->lifeEvents),
|
||||
Activity::uuidCollection($this->activities),
|
||||
Photo::uuidCollection($this->photos),
|
||||
Document::uuidCollection($this->documents),
|
||||
// Occupation::collection($this->occupations),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
29
app/ExportResources/Contact/ContactField.php
Normal file
29
app/ExportResources/Contact/ContactField.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class ContactField extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'data',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
$this->mergeWhen($this->contactFieldType !== null, function () {
|
||||
return ['type' => $this->contactFieldType->uuid];
|
||||
}),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/ExportResources/Contact/ContactFieldType.php
Normal file
22
app/ExportResources/Contact/ContactFieldType.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class ContactFieldType extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'name',
|
||||
'fontawesome_icon',
|
||||
'protocol',
|
||||
'delible',
|
||||
'type',
|
||||
];
|
||||
}
|
||||
30
app/ExportResources/Contact/Conversation.php
Normal file
30
app/ExportResources/Contact/Conversation.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Conversation extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'happened_at',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
$this->mergeWhen($this->contactFieldType !== null, function () {
|
||||
return ['contact_field_type' => $this->contactFieldType->uuid];
|
||||
}),
|
||||
'messages' => Message::collection($this->messages),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
29
app/ExportResources/Contact/Debt.php
Normal file
29
app/ExportResources/Contact/Debt.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Debt extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'amount',
|
||||
'currency',
|
||||
'status',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
'in_debt' => $this->in_debt === 'yes',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
33
app/ExportResources/Contact/Document.php
Normal file
33
app/ExportResources/Contact/Document.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Document extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'original_filename',
|
||||
'filesize',
|
||||
'type',
|
||||
'mime_type',
|
||||
'number_of_downloads',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
$this->mergeWhen(($dataUrl = $this->dataUrl()) !== null, [
|
||||
'dataUrl' => $dataUrl,
|
||||
]),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/ExportResources/Contact/Gender.php
Normal file
19
app/ExportResources/Contact/Gender.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Gender extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'name',
|
||||
'type',
|
||||
];
|
||||
}
|
||||
37
app/ExportResources/Contact/Gift.php
Normal file
37
app/ExportResources/Contact/Gift.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Gift extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'name',
|
||||
'comment',
|
||||
'url',
|
||||
'amount',
|
||||
'status',
|
||||
'date',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
$this->mergeWhen($this->recipient !== null, function () {
|
||||
return ['recipient' => $this->recipient->uuid];
|
||||
}),
|
||||
$this->mergeWhen($this->photos->count() > 0, [
|
||||
'photos' => $this->photos->mapUuid(),
|
||||
]),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/ExportResources/Contact/LifeEvent.php
Normal file
32
app/ExportResources/Contact/LifeEvent.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class LifeEvent extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'name',
|
||||
'note',
|
||||
'happened_at',
|
||||
'specific_information',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
$this->mergeWhen($this->lifeEventType != null, function () {
|
||||
return ['type' => $this->lifeEventType->uuid];
|
||||
}),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
20
app/ExportResources/Contact/Message.php
Normal file
20
app/ExportResources/Contact/Message.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Message extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'content',
|
||||
'written_at',
|
||||
'written_by_me',
|
||||
];
|
||||
}
|
||||
20
app/ExportResources/Contact/Note.php
Normal file
20
app/ExportResources/Contact/Note.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Note extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'body',
|
||||
'is_favorite',
|
||||
'favorited_at',
|
||||
];
|
||||
}
|
||||
29
app/ExportResources/Contact/Pet.php
Normal file
29
app/ExportResources/Contact/Pet.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Pet extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
$this->mergeWhen($this->petCategory !== null, function () {
|
||||
return ['category' => $this->petCategory->name];
|
||||
}),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
24
app/ExportResources/Contact/Reminder.php
Normal file
24
app/ExportResources/Contact/Reminder.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Reminder extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'initial_date',
|
||||
'title',
|
||||
'description',
|
||||
'frequency_type',
|
||||
'frequency_number',
|
||||
'delible',
|
||||
'inactive',
|
||||
];
|
||||
}
|
||||
21
app/ExportResources/Contact/Task.php
Normal file
21
app/ExportResources/Contact/Task.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Contact;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Task extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'title',
|
||||
'description',
|
||||
'completed',
|
||||
'completed_at',
|
||||
];
|
||||
}
|
||||
24
app/ExportResources/CountResourceCollection.php
Normal file
24
app/ExportResources/CountResourceCollection.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
|
||||
class CountResourceCollection extends AnonymousResourceCollection
|
||||
{
|
||||
/**
|
||||
* Transform the resource into a JSON array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'count' => $this->count(),
|
||||
'type' => Str::of($this->collects)->afterLast('\\')->kebab()->replace('-', '_'),
|
||||
'values' => parent::toArray($request),
|
||||
];
|
||||
}
|
||||
}
|
||||
137
app/ExportResources/ExportResource.php
Normal file
137
app/ExportResources/ExportResource.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Http\Resources\MissingValue;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ExportResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* The resource instance.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $columns = [];
|
||||
|
||||
/**
|
||||
* The resource instance.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $properties = null;
|
||||
|
||||
/**
|
||||
* Create a new resource instance.
|
||||
*
|
||||
* @param mixed $resource
|
||||
* @return void
|
||||
*/
|
||||
final public function __construct($resource)
|
||||
{
|
||||
$this->resource = $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new anonymous resource collection.
|
||||
*
|
||||
* @param mixed $resource
|
||||
* @return CountResourceCollection|MissingValue
|
||||
*/
|
||||
public static function countCollection($resource)
|
||||
{
|
||||
if ($resource->count() === 0) {
|
||||
return new MissingValue();
|
||||
}
|
||||
|
||||
return tap(new CountResourceCollection($resource, static::class), function ($collection) {
|
||||
if (property_exists(static::class, 'preserveKeys')) {
|
||||
$collection->preserveKeys = (new static([]))->preserveKeys === true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new anonymous resource collection.
|
||||
*
|
||||
* @param mixed $resource
|
||||
* @return MapUuidResourceCollection|MissingValue
|
||||
*/
|
||||
public static function uuidCollection($resource)
|
||||
{
|
||||
if ($resource->count() === 0) {
|
||||
return new MissingValue();
|
||||
}
|
||||
|
||||
return tap(new MapUuidResourceCollection($resource, static::class), function ($collection) {
|
||||
if (property_exists(static::class, 'preserveKeys')) {
|
||||
$collection->preserveKeys = (new static([]))->preserveKeys === true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
if (is_null($this->resource)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return is_array($this->resource)
|
||||
? $this->resource
|
||||
: $this->export($this->columns, $this->properties, $this->data());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function data(): ?array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the Insert query for the given table.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param array $properties
|
||||
* @param array $data
|
||||
* @return array|null
|
||||
*/
|
||||
protected function export(array $columns, array $properties = null, array $data = null): ?array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
if (! $this->resource->exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$result[$column] = $this->{$column};
|
||||
}
|
||||
|
||||
if ($data !== null) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (isset($result[$key]) && is_array($result[$key])) {
|
||||
$result[$key] = array_merge($result[$key], $value);
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($properties !== null) {
|
||||
$result['properties'] = array_merge(collect($properties)->mapWithKeys(function ($item, $key) {
|
||||
return ($value = $this->{$item}) !== null ? [$item => $value] : new MissingValue();
|
||||
})->toArray(), Arr::get($result, 'properties', []));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
35
app/ExportResources/Instance/AuditLog.php
Normal file
35
app/ExportResources/Instance/AuditLog.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Instance;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class AuditLog extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'author_name',
|
||||
'action',
|
||||
'objects',
|
||||
'audited_at',
|
||||
'should_appear_on_dashboard',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
'author' => $this->when($this->author !== null, function () {
|
||||
return $this->author->uuid;
|
||||
}),
|
||||
'contact' => $this->when($this->contact !== null, function () {
|
||||
return $this->contact->uuid;
|
||||
}),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/ExportResources/Instance/Emotion/Emotion.php
Normal file
27
app/ExportResources/Instance/Emotion/Emotion.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Instance\Emotion;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Emotion extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
'primary' => $this->primary->name,
|
||||
'secondary' => $this->secondary->name,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
17
app/ExportResources/Instance/SpecialDate.php
Normal file
17
app/ExportResources/Instance/SpecialDate.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Instance;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class SpecialDate extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'is_age_based',
|
||||
'is_year_unknown',
|
||||
'date',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
}
|
||||
50
app/ExportResources/Journal/JournalEntry.php
Normal file
50
app/ExportResources/Journal/JournalEntry.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Journal;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class JournalEntry extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'date',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
$data = $this->getObjectData();
|
||||
if ($data !== null) {
|
||||
switch ($data['type']) {
|
||||
case 'entry':
|
||||
return [
|
||||
'uuid' => $this->journalable->uuid,
|
||||
'properties' => [
|
||||
'type' => $data['type'],
|
||||
'title' => $data['title'],
|
||||
'post' => $data['post'],
|
||||
'date' => $data['date'],
|
||||
],
|
||||
];
|
||||
case 'day':
|
||||
return [
|
||||
'uuid' => $this->journalable->uuid,
|
||||
'properties' => [
|
||||
'type' => $data['type'],
|
||||
'rate' => $data['rate'],
|
||||
'comment' => $data['comment'],
|
||||
'day' => $data['day'],
|
||||
'month' => $data['month'],
|
||||
'year' => $data['year'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
24
app/ExportResources/MapUuidResourceCollection.php
Normal file
24
app/ExportResources/MapUuidResourceCollection.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
|
||||
class MapUuidResourceCollection extends AnonymousResourceCollection
|
||||
{
|
||||
/**
|
||||
* Transform the resource into a JSON array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'count' => $this->count(),
|
||||
'type' => Str::of($this->collects)->afterLast('\\')->kebab()->replace('-', '_'),
|
||||
'values' => $this->collection->mapUuid(),
|
||||
];
|
||||
}
|
||||
}
|
||||
25
app/ExportResources/Relationship/Relationship.php
Normal file
25
app/ExportResources/Relationship/Relationship.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\Relationship;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Relationship extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
'type' => $this->relationshipType->name,
|
||||
'contact_is' => $this->contactIs->uuid,
|
||||
'of_contact' => $this->ofContact->uuid,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
20
app/ExportResources/User/Module.php
Normal file
20
app/ExportResources/User/Module.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\User;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class Module extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'key',
|
||||
'translation_key',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'active',
|
||||
'delible',
|
||||
];
|
||||
}
|
||||
18
app/ExportResources/User/SyncToken.php
Normal file
18
app/ExportResources/User/SyncToken.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\User;
|
||||
|
||||
use App\ExportResources\ExportResource;
|
||||
|
||||
class SyncToken extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'name',
|
||||
'timestamp',
|
||||
];
|
||||
}
|
||||
61
app/ExportResources/User/User.php
Normal file
61
app/ExportResources/User/User.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\ExportResources\User;
|
||||
|
||||
use App\Models\Contact\Contact;
|
||||
use App\ExportResources\ExportResource;
|
||||
use Illuminate\Http\Resources\MissingValue;
|
||||
|
||||
class User extends ExportResource
|
||||
{
|
||||
protected $columns = [
|
||||
'uuid',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
'email_verified_at',
|
||||
'google2fa_secret',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $properties = [
|
||||
'locale',
|
||||
'metric',
|
||||
'fluid_container',
|
||||
'contacts_sort_order',
|
||||
'name_order',
|
||||
'dashboard_active_tab',
|
||||
'gifts_active_tab',
|
||||
'profile_active_tab',
|
||||
'timezone',
|
||||
'profile_new_life_event_badge_seen',
|
||||
'temperature_scale',
|
||||
];
|
||||
|
||||
public function data(): ?array
|
||||
{
|
||||
return [
|
||||
'properties' => [
|
||||
$this->mergeWhen($this->currency !== null, [
|
||||
'currency' => $this->currency->iso,
|
||||
]),
|
||||
$this->mergeWhen($this->invited_by_user_id !== null, function () {
|
||||
try {
|
||||
$invited_by_user = Contact::where('account_id', $this->account_id)
|
||||
->findOrFail($this->invited_by_user_id);
|
||||
|
||||
return [
|
||||
'invited_by_user' => $invited_by_user->uuid,
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return new MissingValue();
|
||||
}
|
||||
}),
|
||||
$this->mergeWhen($this->me !== null, function () {
|
||||
return ['me_contact' => $this->me->uuid];
|
||||
}),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user