1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2017 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16namespace Fisharebest\Webtrees\Module; 17 18use Fisharebest\Webtrees\Auth; 19use Fisharebest\Webtrees\Fact; 20use Fisharebest\Webtrees\Functions\Functions; 21use Fisharebest\Webtrees\Functions\FunctionsPrintFacts; 22use Fisharebest\Webtrees\GedcomTag; 23use Fisharebest\Webtrees\I18N; 24 25/** 26 * Class NotesTabModule 27 */ 28class NotesTabModule extends AbstractModule implements ModuleTabInterface { 29 /** @var Fact[] A list facts for this note. */ 30 private $facts; 31 32 /** {@inheritdoc} */ 33 public function getTitle() { 34 return /* I18N: Name of a module */ I18N::translate('Notes'); 35 } 36 37 /** {@inheritdoc} */ 38 public function getDescription() { 39 return /* I18N: Description of the “Notes” module */ I18N::translate('A tab showing the notes attached to an individual.'); 40 } 41 42 /** {@inheritdoc} */ 43 public function defaultTabOrder() { 44 return 40; 45 } 46 47 /** {@inheritdoc} */ 48 public function hasTabContent() { 49 global $WT_TREE; 50 51 return Auth::isEditor($WT_TREE) || $this->getFactsWithNotes(); 52 } 53 54 /** {@inheritdoc} */ 55 public function isGrayedOut() { 56 return !$this->getFactsWithNotes(); 57 } 58 59 /** {@inheritdoc} */ 60 public function getTabContent() { 61 global $controller; 62 63 ob_start(); 64 ?> 65 <table class="table wt-facts-table"> 66 <tr> 67 <td colspan="2"> 68 <label> 69 <input id="show-level-2-notes" type="checkbox"> 70 <?= I18N::translate('Show all notes') ?> 71 </label> 72 </td> 73 </tr> 74 75 <?php 76 foreach ($this->getFactsWithNotes() as $fact) { 77 if ($fact->getTag() == 'NOTE') { 78 FunctionsPrintFacts::printMainNotes($fact, 1); 79 } else { 80 for ($i = 2; $i < 4; ++$i) { 81 FunctionsPrintFacts::printMainNotes($fact, $i); 82 } 83 } 84 } 85 if (!$this->getFactsWithNotes()) { 86 echo '<tr><td colspan="2">', I18N::translate('There are no notes for this individual.'), '</td></tr>'; 87 } 88 89 // New note link 90 if ($controller->record->canEdit()) { 91 ?> 92 <tr> 93 <th scope="row"> 94 <?= GedcomTag::getLabel('NOTE') ?> 95 </th> 96 <td> 97 <a href="edit_interface.php?action=add&ged=<?= $controller->record->getTree()->getNameHtml() ?>&xref=<?= $controller->record->getXref() ?>&fact=NOTE"> 98 <?= I18N::translate('Add a note') ?> 99 </a> 100 </td> 101 </tr> 102 <tr> 103 <th scope="row"> 104 <?= GedcomTag::getLabel('SHARED_NOTE') ?> 105 </th> 106 <td> 107 <a href="edit_interface.php?action=add&ged=<?= $controller->record->getTree()->getNameHtml() ?>&xref=<?= $controller->record->getXref() ?>&fact=SHARED_NOTE"> 108 <?= I18N::translate('Add a shared note') ?> 109 </a> 110 </td> 111 </tr> 112 <?php 113 } 114 ?> 115 </table> 116 <script> 117 //persistent_toggle("show-level-2-notes", ".row_note2"); 118 </script> 119 <?php 120 121 return '<div id="' . $this->getName() . '_content">' . ob_get_clean() . '</div>'; 122 } 123 124 /** 125 * Get all the facts for an individual which contain notes. 126 * 127 * @return Fact[] 128 */ 129 private function getFactsWithNotes() { 130 global $controller; 131 132 if ($this->facts === null) { 133 $facts = $controller->record->getFacts(); 134 foreach ($controller->record->getSpouseFamilies() as $family) { 135 if ($family->canShow()) { 136 foreach ($family->getFacts() as $fact) { 137 $facts[] = $fact; 138 } 139 } 140 } 141 $this->facts = []; 142 foreach ($facts as $fact) { 143 if (preg_match('/(?:^1|\n\d) NOTE/', $fact->getGedcom())) { 144 $this->facts[] = $fact; 145 } 146 } 147 Functions::sortFacts($this->facts); 148 } 149 150 return $this->facts; 151 } 152 153 /** {@inheritdoc} */ 154 public function canLoadAjax() { 155 return false; 156 } 157 158 /** {@inheritdoc} */ 159 public function getPreLoadContent() { 160 return ''; 161 } 162} 163