xref: /webtrees/app/Module/NotesTabModule.php (revision 1062a1429914c995339f502856821457aa975a5a)
18c2e8227SGreg Roach<?php
28c2e8227SGreg Roach/**
38c2e8227SGreg Roach * webtrees: online genealogy
4*1062a142SGreg 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;
248c2e8227SGreg Roach
258c2e8227SGreg Roach/**
268c2e8227SGreg Roach * Class NotesTabModule
278c2e8227SGreg Roach */
28e2a378d3SGreg Roachclass NotesTabModule extends AbstractModule implements ModuleTabInterface {
2976692c8bSGreg Roach	/** @var Fact[] A list facts for this note. */
308c2e8227SGreg Roach	private $facts;
318c2e8227SGreg Roach
328c2e8227SGreg Roach	/** {@inheritdoc} */
338c2e8227SGreg Roach	public function getTitle() {
348c2e8227SGreg Roach		return /* I18N: Name of a module */ I18N::translate('Notes');
358c2e8227SGreg Roach	}
368c2e8227SGreg Roach
378c2e8227SGreg Roach	/** {@inheritdoc} */
388c2e8227SGreg Roach	public function getDescription() {
398c2e8227SGreg Roach		return /* I18N: Description of the “Notes” module */ I18N::translate('A tab showing the notes attached to an individual.');
408c2e8227SGreg Roach	}
418c2e8227SGreg Roach
428c2e8227SGreg Roach	/** {@inheritdoc} */
438c2e8227SGreg Roach	public function defaultTabOrder() {
448c2e8227SGreg Roach		return 40;
458c2e8227SGreg Roach	}
468c2e8227SGreg Roach
478c2e8227SGreg Roach	/** {@inheritdoc} */
488c2e8227SGreg Roach	public function hasTabContent() {
494b9ff166SGreg Roach		global $WT_TREE;
504b9ff166SGreg Roach
514b9ff166SGreg Roach		return Auth::isEditor($WT_TREE) || $this->getFactsWithNotes();
528c2e8227SGreg Roach	}
538c2e8227SGreg Roach
548c2e8227SGreg Roach	/** {@inheritdoc} */
558c2e8227SGreg Roach	public function isGrayedOut() {
568c2e8227SGreg Roach		return !$this->getFactsWithNotes();
578c2e8227SGreg Roach	}
588c2e8227SGreg Roach
598c2e8227SGreg Roach	/** {@inheritdoc} */
608c2e8227SGreg Roach	public function getTabContent() {
61877e7017SGreg Roach		global $controller;
628c2e8227SGreg Roach
638c2e8227SGreg Roach		ob_start();
648c2e8227SGreg Roach		?>
65e0486a06SGreg Roach		<table class="table wt-facts-table">
6615d603e7SGreg Roach			<tr>
67a8d8be3bSmakitso				<td colspan="2">
6807660c67SGreg Roach					<label>
6923c362a9SGreg Roach						<input id="show-level-2-notes" type="checkbox">
7015d603e7SGreg Roach						<?= I18N::translate('Show all notes') ?>
7107660c67SGreg Roach					</label>
72673157b0SGreg Roach				</td>
73673157b0SGreg Roach			</tr>
74dc46b574SDavid Drury
758c2e8227SGreg Roach		<?php
768c2e8227SGreg Roach		foreach ($this->getFactsWithNotes() as $fact) {
778c2e8227SGreg Roach			if ($fact->getTag() == 'NOTE') {
783d7a8a4cSGreg Roach				FunctionsPrintFacts::printMainNotes($fact, 1);
798c2e8227SGreg Roach			} else {
808c2e8227SGreg Roach				for ($i = 2; $i < 4; ++$i) {
813d7a8a4cSGreg Roach					FunctionsPrintFacts::printMainNotes($fact, $i);
828c2e8227SGreg Roach				}
838c2e8227SGreg Roach			}
848c2e8227SGreg Roach		}
858c2e8227SGreg Roach		if (!$this->getFactsWithNotes()) {
86e0486a06SGreg Roach			echo '<tr><td colspan="2">', I18N::translate('There are no notes for this individual.'), '</td></tr>';
878c2e8227SGreg Roach		}
888c2e8227SGreg Roach
898c2e8227SGreg Roach		// New note link
908c2e8227SGreg Roach		if ($controller->record->canEdit()) {
918c2e8227SGreg Roach			?>
9215d603e7SGreg Roach			<tr>
93e0486a06SGreg Roach				<th scope="row">
9415d603e7SGreg Roach					<?= GedcomTag::getLabel('NOTE') ?>
95e0486a06SGreg Roach				</th>
96e0486a06SGreg Roach				<td>
9715d603e7SGreg Roach					<a href="edit_interface.php?action=add&amp;ged=<?= $controller->record->getTree()->getNameHtml() ?>&amp;xref=<?= $controller->record->getXref() ?>&amp;fact=NOTE">
9815d603e7SGreg Roach						<?= I18N::translate('Add a note') ?>
998c2e8227SGreg Roach					</a>
1008c2e8227SGreg Roach				</td>
1018c2e8227SGreg Roach			</tr>
10215d603e7SGreg Roach			<tr>
103e0486a06SGreg Roach				<th scope="row">
10415d603e7SGreg Roach					<?= GedcomTag::getLabel('SHARED_NOTE') ?>
105e0486a06SGreg Roach				</th>
106e0486a06SGreg Roach				<td>
10715d603e7SGreg Roach					<a href="edit_interface.php?action=add&amp;ged=<?= $controller->record->getTree()->getNameHtml() ?>&amp;xref=<?= $controller->record->getXref() ?>&amp;fact=SHARED_NOTE">
10815d603e7SGreg Roach						<?= I18N::translate('Add a shared note') ?>
1098c2e8227SGreg Roach					</a>
1108c2e8227SGreg Roach				</td>
1118c2e8227SGreg Roach			</tr>
1128c2e8227SGreg Roach		<?php
1138c2e8227SGreg Roach		}
1148c2e8227SGreg Roach		?>
1158c2e8227SGreg Roach		</table>
116877e7017SGreg Roach		<script>
11715d603e7SGreg Roach			//persistent_toggle("show-level-2-notes", ".row_note2");
118877e7017SGreg Roach		</script>
1198c2e8227SGreg Roach		<?php
1208c2e8227SGreg Roach
1218c2e8227SGreg Roach		return '<div id="' . $this->getName() . '_content">' . ob_get_clean() . '</div>';
1228c2e8227SGreg Roach	}
1238c2e8227SGreg Roach
1248c2e8227SGreg Roach	/**
1258c2e8227SGreg Roach	 * Get all the facts for an individual which contain notes.
1268c2e8227SGreg Roach	 *
1278c2e8227SGreg Roach	 * @return Fact[]
1288c2e8227SGreg Roach	 */
1298c2e8227SGreg Roach	private function getFactsWithNotes() {
1308c2e8227SGreg Roach		global $controller;
1318c2e8227SGreg Roach
1328c2e8227SGreg Roach		if ($this->facts === null) {
1338c2e8227SGreg Roach			$facts = $controller->record->getFacts();
1348c2e8227SGreg Roach			foreach ($controller->record->getSpouseFamilies() as $family) {
1358c2e8227SGreg Roach				if ($family->canShow()) {
1368c2e8227SGreg Roach					foreach ($family->getFacts() as $fact) {
1378c2e8227SGreg Roach						$facts[] = $fact;
1388c2e8227SGreg Roach					}
1398c2e8227SGreg Roach				}
1408c2e8227SGreg Roach			}
14113abd6f3SGreg Roach			$this->facts = [];
1428c2e8227SGreg Roach			foreach ($facts as $fact) {
1438c2e8227SGreg Roach				if (preg_match('/(?:^1|\n\d) NOTE/', $fact->getGedcom())) {
1448c2e8227SGreg Roach					$this->facts[] = $fact;
1458c2e8227SGreg Roach				}
1468c2e8227SGreg Roach			}
1473d7a8a4cSGreg Roach			Functions::sortFacts($this->facts);
1488c2e8227SGreg Roach		}
1498c2e8227SGreg Roach
1508c2e8227SGreg Roach		return $this->facts;
1518c2e8227SGreg Roach	}
1528c2e8227SGreg Roach
1538c2e8227SGreg Roach	/** {@inheritdoc} */
1548c2e8227SGreg Roach	public function canLoadAjax() {
15515d603e7SGreg Roach		return false;
1568c2e8227SGreg Roach	}
1578c2e8227SGreg Roach
1588c2e8227SGreg Roach	/** {@inheritdoc} */
1598c2e8227SGreg Roach	public function getPreLoadContent() {
1608c2e8227SGreg Roach		return '';
1618c2e8227SGreg Roach	}
1628c2e8227SGreg Roach}
163