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\I18N; 238c2e8227SGreg Roach 248c2e8227SGreg Roach/** 258c2e8227SGreg Roach * Class MediaTabModule 268c2e8227SGreg Roach */ 27e2a378d3SGreg Roachclass MediaTabModule extends AbstractModule implements ModuleTabInterface { 2876692c8bSGreg Roach /** @var Fact[] A list of facts with media objects. */ 298c2e8227SGreg Roach private $facts; 308c2e8227SGreg Roach 318c2e8227SGreg Roach /** {@inheritdoc} */ 328c2e8227SGreg Roach public function getTitle() { 338c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('Media'); 348c2e8227SGreg Roach } 358c2e8227SGreg Roach 368c2e8227SGreg Roach /** {@inheritdoc} */ 378c2e8227SGreg Roach public function getDescription() { 388c2e8227SGreg Roach return /* I18N: Description of the “Media” module */ I18N::translate('A tab showing the media objects linked to an individual.'); 398c2e8227SGreg Roach } 408c2e8227SGreg Roach 418c2e8227SGreg Roach /** {@inheritdoc} */ 428c2e8227SGreg Roach public function defaultTabOrder() { 438c2e8227SGreg Roach return 50; 448c2e8227SGreg Roach } 458c2e8227SGreg Roach 468c2e8227SGreg Roach /** {@inheritdoc} */ 478c2e8227SGreg Roach public function hasTabContent() { 484b9ff166SGreg Roach global $WT_TREE; 494b9ff166SGreg Roach 504b9ff166SGreg Roach return Auth::isEditor($WT_TREE) || $this->getFactsWithMedia(); 518c2e8227SGreg Roach } 528c2e8227SGreg Roach 538c2e8227SGreg Roach /** {@inheritdoc} */ 548c2e8227SGreg Roach public function isGrayedOut() { 558c2e8227SGreg Roach return !$this->getFactsWithMedia(); 568c2e8227SGreg Roach } 578c2e8227SGreg Roach 588c2e8227SGreg Roach /** {@inheritdoc} */ 598c2e8227SGreg Roach public function getTabContent() { 608c2e8227SGreg Roach ob_start(); 61e0486a06SGreg Roach echo '<table class="table wt-facts-table">'; 62e0486a06SGreg Roach echo '<tbody>'; 638c2e8227SGreg Roach foreach ($this->getFactsWithMedia() as $fact) { 648c2e8227SGreg Roach if ($fact->getTag() == 'OBJE') { 653d7a8a4cSGreg Roach FunctionsPrintFacts::printMainMedia($fact, 1); 668c2e8227SGreg Roach } else { 678c2e8227SGreg Roach for ($i = 2; $i < 4; ++$i) { 683d7a8a4cSGreg Roach FunctionsPrintFacts::printMainMedia($fact, $i); 698c2e8227SGreg Roach } 708c2e8227SGreg Roach } 718c2e8227SGreg Roach } 728c2e8227SGreg Roach ?> 73e0486a06SGreg Roach </tbody> 748c2e8227SGreg Roach </table> 758c2e8227SGreg Roach <?php 76e0486a06SGreg Roach if (!$this->getFactsWithMedia()) { 77e0486a06SGreg Roach echo '<p>', I18N::translate('There are no media objects for this individual.'), '</p>'; 78e0486a06SGreg Roach } 79e0486a06SGreg Roach 808c2e8227SGreg Roach return '<div id="' . $this->getName() . '_content">' . ob_get_clean() . '</div>'; 818c2e8227SGreg Roach } 828c2e8227SGreg Roach 838c2e8227SGreg Roach /** 848c2e8227SGreg Roach * Get all the facts for an individual which contain media objects. 858c2e8227SGreg Roach * 868c2e8227SGreg Roach * @return Fact[] 878c2e8227SGreg Roach */ 888c2e8227SGreg Roach private function getFactsWithMedia() { 898c2e8227SGreg Roach global $controller; 908c2e8227SGreg Roach 918c2e8227SGreg Roach if ($this->facts === null) { 928c2e8227SGreg Roach $facts = $controller->record->getFacts(); 938c2e8227SGreg Roach foreach ($controller->record->getSpouseFamilies() as $family) { 948c2e8227SGreg Roach if ($family->canShow()) { 958c2e8227SGreg Roach foreach ($family->getFacts() as $fact) { 968c2e8227SGreg Roach $facts[] = $fact; 978c2e8227SGreg Roach } 988c2e8227SGreg Roach } 998c2e8227SGreg Roach } 10013abd6f3SGreg Roach $this->facts = []; 1018c2e8227SGreg Roach foreach ($facts as $fact) { 1028c2e8227SGreg Roach if (preg_match('/(?:^1|\n\d) OBJE @' . WT_REGEX_XREF . '@/', $fact->getGedcom())) { 1038c2e8227SGreg Roach $this->facts[] = $fact; 1048c2e8227SGreg Roach } 1058c2e8227SGreg Roach } 1063d7a8a4cSGreg Roach Functions::sortFacts($this->facts); 1078c2e8227SGreg Roach } 1088c2e8227SGreg Roach 1098c2e8227SGreg Roach return $this->facts; 1108c2e8227SGreg Roach } 1118c2e8227SGreg Roach 1128c2e8227SGreg Roach /** {@inheritdoc} */ 1138c2e8227SGreg Roach public function canLoadAjax() { 11415d603e7SGreg Roach return false; 1158c2e8227SGreg Roach } 1168c2e8227SGreg Roach 1178c2e8227SGreg Roach /** {@inheritdoc} */ 1188c2e8227SGreg Roach public function getPreLoadContent() { 1198c2e8227SGreg Roach return ''; 1208c2e8227SGreg Roach } 1218c2e8227SGreg Roach} 122