diff --git a/app/Jobs/SetupAccount.php b/app/Jobs/SetupAccount.php index 461115b08..3adb82b43 100644 --- a/app/Jobs/SetupAccount.php +++ b/app/Jobs/SetupAccount.php @@ -9,6 +9,7 @@ use App\Models\LifeEventCategory; use App\Models\LifeEventType; use App\Models\Module; use App\Models\RelationshipGroupType; +use App\Models\RelationshipType; use App\Models\Template; use App\Models\TemplatePage; use App\Models\User; @@ -175,6 +176,22 @@ class SetupAccount implements ShouldQueue 'module_id' => $module->id, ]); + // family summary + $module = (new CreateModule)->execute([ + 'account_id' => $this->user->account_id, + 'author_id' => $this->user->id, + 'name' => trans('app.module_family_summary'), + 'type' => Module::TYPE_FAMILY_SUMMARY, + 'can_be_deleted' => false, + ]); + (new AssociateModuleToTemplatePage)->execute([ + 'account_id' => $this->user->account_id, + 'author_id' => $this->user->id, + 'template_id' => $this->template->id, + 'template_page_id' => $templatePageContact->id, + 'module_id' => $module->id, + ]); + // important dates $module = (new CreateModule)->execute([ 'account_id' => $this->user->account_id, @@ -513,31 +530,43 @@ class SetupAccount implements ShouldQueue 'name' => trans('account.relationship_type_partner'), 'name_reverse_relationship' => trans('account.relationship_type_partner'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => false, + 'type' => RelationshipType::TYPE_LOVE, ], [ 'name' => trans('account.relationship_type_spouse'), 'name_reverse_relationship' => trans('account.relationship_type_spouse'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => false, + 'type' => RelationshipType::TYPE_LOVE, ], [ 'name' => trans('account.relationship_type_date'), 'name_reverse_relationship' => trans('account.relationship_type_date'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], [ 'name' => trans('account.relationship_type_lover'), 'name_reverse_relationship' => trans('account.relationship_type_lover'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], [ 'name' => trans('account.relationship_type_inlovewith'), 'name_reverse_relationship' => trans('account.relationship_type_lovedby'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], [ 'name' => trans('account.relationship_type_ex'), 'name_reverse_relationship' => trans('account.relationship_type_ex'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], ]); @@ -555,31 +584,43 @@ class SetupAccount implements ShouldQueue 'name' => trans('account.relationship_type_parent'), 'name_reverse_relationship' => trans('account.relationship_type_child'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => false, + 'type' => RelationshipType::TYPE_CHILD, ], [ 'name' => trans('account.relationship_type_sibling'), 'name_reverse_relationship' => trans('account.relationship_type_sibling'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], [ 'name' => trans('account.relationship_type_grandparent'), 'name_reverse_relationship' => trans('account.relationship_type_grandchild'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], [ 'name' => trans('account.relationship_type_uncle'), 'name_reverse_relationship' => trans('account.relationship_type_nephew'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], [ 'name' => trans('account.relationship_type_cousin'), 'name_reverse_relationship' => trans('account.relationship_type_cousin'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], [ 'name' => trans('account.relationship_type_godfather'), 'name_reverse_relationship' => trans('account.relationship_type_godson'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], ]); @@ -596,11 +637,15 @@ class SetupAccount implements ShouldQueue 'name' => trans('account.relationship_type_friend'), 'name_reverse_relationship' => trans('account.relationship_type_friend'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], [ 'name' => trans('account.relationship_type_bestfriend'), 'name_reverse_relationship' => trans('account.relationship_type_bestfriend'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], ]); @@ -617,16 +662,22 @@ class SetupAccount implements ShouldQueue 'name' => trans('account.relationship_type_colleague'), 'name_reverse_relationship' => trans('account.relationship_type_colleague'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], [ 'name' => trans('account.relationship_type_subordinate'), 'name_reverse_relationship' => trans('account.relationship_type_boss'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], [ 'name' => trans('account.relationship_type_mentor'), 'name_reverse_relationship' => trans('account.relationship_type_protege'), 'relationship_group_type_id' => $group->id, + 'can_be_deleted' => true, + 'type' => null, ], ]); } diff --git a/app/Models/Module.php b/app/Models/Module.php index 94aeaa2ed..fabfafa71 100644 --- a/app/Models/Module.php +++ b/app/Models/Module.php @@ -18,6 +18,7 @@ class Module extends Model const TYPE_NOTES = 'notes'; const TYPE_CONTACT_NAMES = 'contact_names'; const TYPE_AVATAR = 'avatar'; + const TYPE_FAMILY_SUMMARY = 'family_summary'; const TYPE_COMPANY = 'company'; const TYPE_FEED = 'feed'; const TYPE_GENDER_PRONOUN = 'gender_pronoun'; diff --git a/app/Models/RelationshipType.php b/app/Models/RelationshipType.php index 799c22577..0fb8c99a2 100644 --- a/app/Models/RelationshipType.php +++ b/app/Models/RelationshipType.php @@ -16,8 +16,8 @@ class RelationshipType extends Model /** * Possible types. */ - const TYPE_FAMILY = 'family'; - const TYPE_LOVE = 'love'; + const TYPE_LOVE = 'family'; + const TYPE_CHILD = 'child'; /** * The attributes that are mass assignable. @@ -29,6 +29,7 @@ class RelationshipType extends Model 'name', 'name_reverse_relationship', 'can_be_deleted', + 'type', ]; /** diff --git a/domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php b/domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php index 162d9e0d4..c8766a30a 100644 --- a/domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php +++ b/domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php @@ -14,6 +14,7 @@ use App\Contact\ManageLoans\Web\ViewHelpers\ModuleLoanViewHelper; use App\Contact\ManageNotes\Web\ViewHelpers\ModuleNotesViewHelper; use App\Contact\ManagePets\Web\ViewHelpers\ModulePetsViewHelper; use App\Contact\ManagePronouns\Web\ViewHelpers\ModuleGenderPronounViewHelper; +use App\Contact\ManageRelationships\Web\ViewHelpers\ModuleFamilySummaryViewHelper; use App\Contact\ManageRelationships\Web\ViewHelpers\ModuleRelationshipViewHelper; use App\Contact\ManageReminders\Web\ViewHelpers\ModuleRemindersViewHelper; use App\Contact\ManageTasks\Web\ViewHelpers\ModuleContactTasksViewHelper; @@ -147,6 +148,10 @@ class ContactShowViewHelper $data = ModuleCompanyViewHelper::data($contact); } + if ($module->type == Module::TYPE_FAMILY_SUMMARY) { + $data = ModuleFamilySummaryViewHelper::data($contact, $user); + } + $modulesCollection->push([ 'id' => $module->id, 'type' => $module->type, diff --git a/domains/Contact/ManageRelationships/Web/ViewHelpers/ModuleFamilySummaryViewHelper.php b/domains/Contact/ManageRelationships/Web/ViewHelpers/ModuleFamilySummaryViewHelper.php new file mode 100644 index 000000000..c431bdc01 --- /dev/null +++ b/domains/Contact/ManageRelationships/Web/ViewHelpers/ModuleFamilySummaryViewHelper.php @@ -0,0 +1,106 @@ +vault->account->relationshipGroupTypes() + ->where('type', RelationshipGroupType::TYPE_LOVE) + ->first(); + + $loveRelationships = $loveRelationshipType->types() + ->where('type', RelationshipType::TYPE_LOVE) + ->get(); + + $loveRelationshipsCollection = self::getRelations($loveRelationships, $contact, $user); + + $familyRelationshipType = $contact->vault->account->relationshipGroupTypes() + ->where('type', RelationshipGroupType::TYPE_FAMILY) + ->first(); + + $familyRelationships = $familyRelationshipType->types() + ->where('type', RelationshipType::TYPE_CHILD) + ->get(); + + $familyRelationshipsCollection = self::getRelations($familyRelationships, $contact, $user); + + return [ + 'family_relationships' => $familyRelationshipsCollection, + 'love_relationships' => $loveRelationshipsCollection, + ]; + } + + private static function getRelations(EloquentCollection $collection, Contact $contact, User $user): Collection + { + $relationshipsCollection = collect(); + $counter = 0; + foreach ($collection as $relationshipType) { + $relations = DB::table('relationships') + ->join('contacts', 'relationships.contact_id', '=', 'contacts.id') + ->join('relationship_types', 'relationships.relationship_type_id', '=', 'relationship_types.id') + ->select('relationships.id as main_id', 'relationship_types.id', 'relationships.contact_id', 'relationships.related_contact_id') + ->where('relationships.relationship_type_id', $relationshipType->id) + ->where(function ($query) use ($contact) { + $query->where('relationships.contact_id', $contact->id) + ->orWhere('relationships.related_contact_id', $contact->id); + }) + ->get(); + + if ($relations->count() == 0) { + continue; + } + + foreach ($relations as $relation) { + if ($relation->contact_id == $contact->id) { + $relatedContact = Contact::find($relation->related_contact_id); + } else { + continue; + } + + $relationshipsCollection->push([ + 'id' => $counter, + 'contact' => self::getContact($relatedContact, $user), + ]); + } + $counter++; + } + + return $relationshipsCollection; + } + + private static function getContact(Contact $contact, User $user): array + { + return [ + 'id' => $contact->id, + 'name' => $contact->name, + 'avatar' => AvatarHelper::getSVG($contact), + 'age' => $contact->age, + 'url' => [ + 'show' => $contact->listed ? route('contact.show', [ + 'vault' => $contact->vault->id, + 'contact' => $contact->id, + ]) : null, + ], + ]; + } +} diff --git a/domains/Settings/ManageRelationshipTypes/Services/CreateRelationshipType.php b/domains/Settings/ManageRelationshipTypes/Services/CreateRelationshipType.php index 70a3cf417..6e42f0ecc 100644 --- a/domains/Settings/ManageRelationshipTypes/Services/CreateRelationshipType.php +++ b/domains/Settings/ManageRelationshipTypes/Services/CreateRelationshipType.php @@ -25,6 +25,7 @@ class CreateRelationshipType extends BaseService implements ServiceInterface 'name' => 'required|string|max:255', 'name_reverse_relationship' => 'required|string|max:255', 'can_be_deleted' => 'required|boolean', + 'type' => 'nullable|string|max:255', ]; } @@ -59,6 +60,7 @@ class CreateRelationshipType extends BaseService implements ServiceInterface 'name' => $data['name'], 'name_reverse_relationship' => $data['name_reverse_relationship'], 'can_be_deleted' => $data['can_be_deleted'], + 'type' => $this->valueOrNull($data, 'type'), ]); CreateAuditLog::dispatch([ diff --git a/domains/Settings/ManageRelationshipTypes/Services/DestroyRelationshipGroupType.php b/domains/Settings/ManageRelationshipTypes/Services/DestroyRelationshipGroupType.php index 1a4d8dc9f..dd7f1136d 100644 --- a/domains/Settings/ManageRelationshipTypes/Services/DestroyRelationshipGroupType.php +++ b/domains/Settings/ManageRelationshipTypes/Services/DestroyRelationshipGroupType.php @@ -47,6 +47,7 @@ class DestroyRelationshipGroupType extends BaseService implements ServiceInterfa $this->validateRules($data); $type = RelationshipGroupType::where('account_id', $data['account_id']) + ->where('can_be_deleted', true) ->findOrFail($data['relationship_group_type_id']); CreateAuditLog::dispatch([ diff --git a/domains/Settings/ManageRelationshipTypes/Services/DestroyRelationshipType.php b/domains/Settings/ManageRelationshipTypes/Services/DestroyRelationshipType.php index fd967ba96..e6e594a59 100644 --- a/domains/Settings/ManageRelationshipTypes/Services/DestroyRelationshipType.php +++ b/domains/Settings/ManageRelationshipTypes/Services/DestroyRelationshipType.php @@ -52,6 +52,7 @@ class DestroyRelationshipType extends BaseService implements ServiceInterface ->findOrFail($data['relationship_group_type_id']); $type = RelationshipType::where('relationship_group_type_id', $data['relationship_group_type_id']) + ->where('can_be_deleted', true) ->findOrFail($data['relationship_type_id']); CreateAuditLog::dispatch([ diff --git a/resources/js/Pages/Vault/Contact/Show.vue b/resources/js/Pages/Vault/Contact/Show.vue index 2796a19de..642de9c96 100644 --- a/resources/js/Pages/Vault/Contact/Show.vue +++ b/resources/js/Pages/Vault/Contact/Show.vue @@ -19,9 +19,9 @@