18c2e8227SGreg Roach<?php 23976b470SGreg Roach 38c2e8227SGreg Roach/** 48c2e8227SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 68c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 78c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 88c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 98c2e8227SGreg Roach * (at your option) any later version. 108c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 118c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 128c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 138c2e8227SGreg Roach * GNU General Public License for more details. 148c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 168c2e8227SGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 2176692c8bSGreg Roach 228d0ebef0SGreg Roachuse Fisharebest\Webtrees\Gedcom; 230e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 24225e381fSGreg Roachuse Fisharebest\Webtrees\Individual; 250e62c4b8SGreg Roachuse Fisharebest\Webtrees\Media; 26f0c88a96SGreg Roachuse Fisharebest\Webtrees\Registry; 27f4cd70d3SGreg Roachuse Illuminate\Support\Collection; 288c2e8227SGreg Roach 298c2e8227SGreg Roach/** 308c2e8227SGreg Roach * Class AlbumModule 318c2e8227SGreg Roach */ 32f4cd70d3SGreg Roachclass AlbumModule extends MediaTabModule 33c1010edaSGreg Roach{ 3476692c8bSGreg Roach /** 350cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 3676692c8bSGreg Roach * 3776692c8bSGreg Roach * @return string 3876692c8bSGreg Roach */ 3949a243cbSGreg Roach public function title(): string 40c1010edaSGreg Roach { 41bbb76c12SGreg Roach /* I18N: Name of a module */ 42bbb76c12SGreg Roach return I18N::translate('Album'); 438c2e8227SGreg Roach } 448c2e8227SGreg Roach 4549a243cbSGreg Roach public function description(): string 46c1010edaSGreg Roach { 47bbb76c12SGreg Roach /* I18N: Description of the “Album” module */ 48bbb76c12SGreg Roach return I18N::translate('An alternative to the “media” tab, and an enhanced image viewer.'); 498c2e8227SGreg Roach } 508c2e8227SGreg Roach 5176692c8bSGreg Roach /** 5249a243cbSGreg Roach * The default position for this tab. It can be changed in the control panel. 5376692c8bSGreg Roach * 5476692c8bSGreg Roach * @return int 5576692c8bSGreg Roach */ 56cbf4b7faSGreg Roach public function defaultTabOrder(): int 57cbf4b7faSGreg Roach { 58fb7a0427SGreg Roach return 6; 598c2e8227SGreg Roach } 608c2e8227SGreg Roach 6176692c8bSGreg Roach /** 6276692c8bSGreg Roach * Generate the HTML content of this tab. 6376692c8bSGreg Roach * 64225e381fSGreg Roach * @param Individual $individual 65225e381fSGreg Roach * 6676692c8bSGreg Roach * @return string 6776692c8bSGreg Roach */ 688f53f488SRico Sonntag public function getTabContent(Individual $individual): string 69c1010edaSGreg Roach { 70a8cd57e1SGreg Roach return view('modules/lightbox/tab', [ 71c1010edaSGreg Roach 'media_list' => $this->getMedia($individual), 72d14df12bSGreg Roach ]); 738c2e8227SGreg Roach } 748c2e8227SGreg Roach 758c2e8227SGreg Roach /** 76f4cd70d3SGreg Roach * Get the linked media objects. 778c2e8227SGreg Roach * 78225e381fSGreg Roach * @param Individual $individual 79225e381fSGreg Roach * 8036779af1SGreg Roach * @return Collection<int,Media> 818c2e8227SGreg Roach */ 82f4cd70d3SGreg Roach private function getMedia(Individual $individual): Collection 83c1010edaSGreg Roach { 84f4cd70d3SGreg Roach $media = new Collection(); 85f4cd70d3SGreg Roach 86f4cd70d3SGreg Roach foreach ($this->getFactsWithMedia($individual) as $fact) { 878d0ebef0SGreg Roach preg_match_all('/(?:^1|\n\d) OBJE @(' . Gedcom::REGEX_XREF . ')@/', $fact->gedcom(), $matches); 88f4cd70d3SGreg Roach 89f4cd70d3SGreg Roach foreach ($matches[1] as $xref) { 90f4cd70d3SGreg Roach if (!$media->has($xref)) { 91584075bcSGreg Roach $media->put($xref, Registry::mediaFactory()->make($xref, $individual->tree())); 928c2e8227SGreg Roach } 938c2e8227SGreg Roach } 948c2e8227SGreg Roach } 95cbc1590aSGreg Roach 968b626b9bSGreg Roach return $media->filter()->filter(Media::accessFilter()); 978c2e8227SGreg Roach } 988c2e8227SGreg Roach} 99