Skip to content

Commit

Permalink
feat: export data as json format (#4779)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Jan 11, 2022
1 parent ccf6d4f commit 8c627a2
Show file tree
Hide file tree
Showing 126 changed files with 2,786 additions and 171 deletions.
63 changes: 63 additions & 0 deletions app/ExportResources/Account/Account.php
Original file line number Diff line number Diff line change
@@ -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 changes: 33 additions & 0 deletions app/ExportResources/Account/Activity.php
Original file line number Diff line number Diff line change
@@ -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 changes: 33 additions & 0 deletions app/ExportResources/Account/ActivityType.php
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions app/ExportResources/Account/ActivityTypeCategory.php
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions app/ExportResources/Account/Addressbook.php
Original file line number Diff line number Diff line change
@@ -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 changes: 44 additions & 0 deletions app/ExportResources/Account/AddressbookSubscription.php
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions app/ExportResources/Account/LifeEventCategory.php
Original file line number Diff line number Diff line change
@@ -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 changes: 34 additions & 0 deletions app/ExportResources/Account/LifeEventType.php
Original file line number Diff line number Diff line change
@@ -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 changes: 29 additions & 0 deletions app/ExportResources/Account/Photo.php
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions app/ExportResources/Account/ReminderRule.php
Original file line number Diff line number Diff line change
@@ -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 changes: 33 additions & 0 deletions app/ExportResources/Contact/Address.php
Original file line number Diff line number Diff line change
@@ -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,
],
];
}
}
Loading

0 comments on commit 8c627a2

Please sign in to comment.