. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Elements\CustomElement; use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Registry; use Fisharebest\Webtrees\Services\ClipboardService; use Fisharebest\Webtrees\Services\IndividualFactsService; use Fisharebest\Webtrees\Services\ModuleService; use Illuminate\Support\Collection; use function view; /** * Class IndividualFactsTabModule */ class IndividualFactsTabModule extends AbstractModule implements ModuleTabInterface { use ModuleTabTrait; private ClipboardService $clipboard_service; private IndividualFactsService $individual_facts_service; private ModuleService $module_service; /** * @param ClipboardService $clipboard_service * @param IndividualFactsService $individual_facts_service * @param ModuleService $module_service */ public function __construct( ClipboardService $clipboard_service, IndividualFactsService $individual_facts_service, ModuleService $module_service ) { $this->clipboard_service = $clipboard_service; $this->individual_facts_service = $individual_facts_service; $this->module_service = $module_service; } /** * How should this module be identified in the control panel, etc.? * * @return string */ public function title(): string { /* I18N: Name of a module/tab on the individual page. */ return I18N::translate('Facts and events'); } /** * A sentence describing what this module does. * * @return string */ public function description(): string { /* I18N: Description of the “Facts and events” module */ return I18N::translate('A tab showing the facts and events of an individual.'); } /** * The default position for this tab. It can be changed in the control panel. * * @return int */ public function defaultTabOrder(): int { return 1; } /** * A greyed out tab has no actual content, but may perhaps have * options to create content. * * @param Individual $individual * * @return bool */ public function isGrayedOut(Individual $individual): bool { return false; } /** * Generate the HTML content of this tab. * * @param Individual $individual * * @return string */ public function getTabContent(Individual $individual): string { // Which facts and events are handled by other modules? $sidebar_facts = $this->module_service ->findByComponent(ModuleSidebarInterface::class, $individual->tree(), Auth::user()) ->map(fn (ModuleSidebarInterface $sidebar): Collection => $sidebar->supportedFacts()) ->flatten(); $tab_facts = $this->module_service ->findByComponent(ModuleTabInterface::class, $individual->tree(), Auth::user()) ->map(fn (ModuleTabInterface $tab): Collection => $tab->supportedFacts()) ->flatten(); $indi_exclude_facts = $sidebar_facts->merge($tab_facts); $fam_exclude_facts = new Collection(['FAM:CHAN', 'FAM:_UID', 'FAM:HUSB', 'FAM:WIFE', 'FAM:CHIL']); $individual_facts = $this->individual_facts_service->individualFacts($individual, $indi_exclude_facts); $family_facts = $this->individual_facts_service->familyFacts($individual, $fam_exclude_facts); $relative_facts = $this->individual_facts_service->relativeFacts($individual); $associate_facts = $this->individual_facts_service->associateFacts($individual); $historic_facts = $this->individual_facts_service->historicFacts($individual); $individual_facts = $individual_facts ->merge($family_facts) ->merge($relative_facts) ->merge($associate_facts) ->merge($historic_facts); $individual_facts = Fact::sortFacts($individual_facts); // Facts of relatives take the form 1 EVEN / 2 TYPE Event of Individual // Ensure custom tags from there are recognised Registry::elementFactory()->registerTags(['INDI:EVEN:CEME' => new CustomElement('Cemetery')]); return view('modules/personal_facts/tab', [ 'can_edit' => $individual->canEdit(), 'clipboard_facts' => $this->clipboard_service->pastableFacts($individual), 'has_associate_facts' => $associate_facts->isNotEmpty(), 'has_historic_facts' => $historic_facts->isNotEmpty(), 'has_relative_facts' => $relative_facts->isNotEmpty(), 'individual' => $individual, 'facts' => $individual_facts, ]); } /** * Is this tab empty? If so, we don't always need to display it. * * @param Individual $individual * * @return bool */ public function hasTabContent(Individual $individual): bool { return true; } /** * Can this tab load asynchronously? * * @return bool */ public function canLoadAjax(): bool { return false; } /** * This module handles the following facts - so don't show them on the "Facts and events" tab. * * @return Collection */ public function supportedFacts(): Collection { // We don't actually displaye these facts, but they are displayed // outside the tabs/sidebar systems. This just forces them to be excluded here. return new Collection(['INDI:NAME', 'INDI:SEX', 'INDI:OBJE']); } }