18c2e8227SGreg Roach<?php 28c2e8227SGreg Roach/** 38c2e8227SGreg Roach * webtrees: online genealogy 41062a142SGreg Roach * Copyright (C) 2018 webtrees development team 58c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 68c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 78c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 88c2e8227SGreg Roach * (at your option) any later version. 98c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 108c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 118c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 128c2e8227SGreg Roach * GNU General Public License for more details. 138c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 148c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 158c2e8227SGreg Roach */ 1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 1776692c8bSGreg Roach 180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 190e62c4b8SGreg Roachuse Fisharebest\Webtrees\Fact; 203d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\Functions; 213d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsPrintFacts; 220e62c4b8SGreg Roachuse Fisharebest\Webtrees\GedcomTag; 230e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 24225e381fSGreg Roachuse Fisharebest\Webtrees\Individual; 258c2e8227SGreg Roach 268c2e8227SGreg Roach/** 278c2e8227SGreg Roach * Class NotesTabModule 288c2e8227SGreg Roach */ 29e2a378d3SGreg Roachclass NotesTabModule extends AbstractModule implements ModuleTabInterface { 3076692c8bSGreg Roach /** @var Fact[] A list facts for this note. */ 318c2e8227SGreg Roach private $facts; 328c2e8227SGreg Roach 338c2e8227SGreg Roach /** {@inheritdoc} */ 348c2e8227SGreg Roach public function getTitle() { 358c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('Notes'); 368c2e8227SGreg Roach } 378c2e8227SGreg Roach 388c2e8227SGreg Roach /** {@inheritdoc} */ 398c2e8227SGreg Roach public function getDescription() { 408c2e8227SGreg Roach return /* I18N: Description of the “Notes” module */ I18N::translate('A tab showing the notes attached to an individual.'); 418c2e8227SGreg Roach } 428c2e8227SGreg Roach 438c2e8227SGreg Roach /** {@inheritdoc} */ 448c2e8227SGreg Roach public function defaultTabOrder() { 458c2e8227SGreg Roach return 40; 468c2e8227SGreg Roach } 478c2e8227SGreg Roach 488c2e8227SGreg Roach /** {@inheritdoc} */ 49225e381fSGreg Roach public function hasTabContent(Individual $individual) { 50225e381fSGreg Roach return $individual->canEdit() || $this->getFactsWithNotes($individual); 518c2e8227SGreg Roach } 528c2e8227SGreg Roach 538c2e8227SGreg Roach /** {@inheritdoc} */ 54225e381fSGreg Roach public function isGrayedOut(Individual $individual) { 55225e381fSGreg Roach return !$this->getFactsWithNotes($individual); 568c2e8227SGreg Roach } 578c2e8227SGreg Roach 588c2e8227SGreg Roach /** {@inheritdoc} */ 59225e381fSGreg Roach public function getTabContent(Individual $individual) { 60*a8cd57e1SGreg Roach return view('modules/notes/tab', [ 61225e381fSGreg Roach 'can_edit' => $individual->canEdit(), 62225e381fSGreg Roach 'individual' => $individual, 63225e381fSGreg Roach 'facts' => $this->getFactsWithNotes($individual), 64225e381fSGreg Roach ]); 658c2e8227SGreg Roach } 668c2e8227SGreg Roach 678c2e8227SGreg Roach /** 688c2e8227SGreg Roach * Get all the facts for an individual which contain notes. 698c2e8227SGreg Roach * 70225e381fSGreg Roach * @param Individual $individual 71225e381fSGreg Roach * 728c2e8227SGreg Roach * @return Fact[] 738c2e8227SGreg Roach */ 74225e381fSGreg Roach private function getFactsWithNotes(Individual $individual) { 758c2e8227SGreg Roach if ($this->facts === null) { 76225e381fSGreg Roach $facts = $individual->getFacts(); 77225e381fSGreg Roach foreach ($individual->getSpouseFamilies() as $family) { 788c2e8227SGreg Roach if ($family->canShow()) { 798c2e8227SGreg Roach foreach ($family->getFacts() as $fact) { 808c2e8227SGreg Roach $facts[] = $fact; 818c2e8227SGreg Roach } 828c2e8227SGreg Roach } 838c2e8227SGreg Roach } 8413abd6f3SGreg Roach $this->facts = []; 858c2e8227SGreg Roach foreach ($facts as $fact) { 868c2e8227SGreg Roach if (preg_match('/(?:^1|\n\d) NOTE/', $fact->getGedcom())) { 878c2e8227SGreg Roach $this->facts[] = $fact; 888c2e8227SGreg Roach } 898c2e8227SGreg Roach } 903d7a8a4cSGreg Roach Functions::sortFacts($this->facts); 918c2e8227SGreg Roach } 928c2e8227SGreg Roach 938c2e8227SGreg Roach return $this->facts; 948c2e8227SGreg Roach } 958c2e8227SGreg Roach 968c2e8227SGreg Roach /** {@inheritdoc} */ 978c2e8227SGreg Roach public function canLoadAjax() { 9815d603e7SGreg Roach return false; 998c2e8227SGreg Roach } 1008c2e8227SGreg Roach} 101