18c2e8227SGreg Roach<?php 23976b470SGreg Roach 38c2e8227SGreg Roach/** 48c2e8227SGreg Roach * webtrees: online genealogy 5a091ac74SGreg Roach * Copyright (C) 2020 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 158c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 168c2e8227SGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 2176692c8bSGreg Roach 22a091ac74SGreg Roachuse Fisharebest\Webtrees\Factory; 238d0ebef0SGreg Roachuse Fisharebest\Webtrees\Gedcom; 240e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 25225e381fSGreg Roachuse Fisharebest\Webtrees\Individual; 260e62c4b8SGreg Roachuse Fisharebest\Webtrees\Media; 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 4576692c8bSGreg Roach /** 4676692c8bSGreg Roach * A sentence describing what this module does. 4776692c8bSGreg Roach * 4876692c8bSGreg Roach * @return string 4976692c8bSGreg Roach */ 5049a243cbSGreg Roach public function description(): string 51c1010edaSGreg Roach { 52bbb76c12SGreg Roach /* I18N: Description of the “Album” module */ 53bbb76c12SGreg Roach return I18N::translate('An alternative to the “media” tab, and an enhanced image viewer.'); 548c2e8227SGreg Roach } 558c2e8227SGreg Roach 5676692c8bSGreg Roach /** 5749a243cbSGreg Roach * The default position for this tab. It can be changed in the control panel. 5876692c8bSGreg Roach * 5976692c8bSGreg Roach * @return int 6076692c8bSGreg Roach */ 61cbf4b7faSGreg Roach public function defaultTabOrder(): int 62cbf4b7faSGreg Roach { 63fb7a0427SGreg Roach return 6; 648c2e8227SGreg Roach } 658c2e8227SGreg Roach 6676692c8bSGreg Roach /** 6776692c8bSGreg Roach * Generate the HTML content of this tab. 6876692c8bSGreg Roach * 69225e381fSGreg Roach * @param Individual $individual 70225e381fSGreg Roach * 7176692c8bSGreg Roach * @return string 7276692c8bSGreg Roach */ 738f53f488SRico Sonntag public function getTabContent(Individual $individual): string 74c1010edaSGreg Roach { 75a8cd57e1SGreg Roach return view('modules/lightbox/tab', [ 76c1010edaSGreg Roach 'media_list' => $this->getMedia($individual), 77d14df12bSGreg Roach ]); 788c2e8227SGreg Roach } 798c2e8227SGreg Roach 808c2e8227SGreg Roach /** 81f4cd70d3SGreg Roach * Get the linked media objects. 828c2e8227SGreg Roach * 83225e381fSGreg Roach * @param Individual $individual 84225e381fSGreg Roach * 85f4cd70d3SGreg Roach * @return Collection<Media> 868c2e8227SGreg Roach */ 87f4cd70d3SGreg Roach private function getMedia(Individual $individual): Collection 88c1010edaSGreg Roach { 89f4cd70d3SGreg Roach $media = new Collection(); 90f4cd70d3SGreg Roach 91f4cd70d3SGreg Roach foreach ($this->getFactsWithMedia($individual) as $fact) { 928d0ebef0SGreg Roach preg_match_all('/(?:^1|\n\d) OBJE @(' . Gedcom::REGEX_XREF . ')@/', $fact->gedcom(), $matches); 93f4cd70d3SGreg Roach 94f4cd70d3SGreg Roach foreach ($matches[1] as $xref) { 95f4cd70d3SGreg Roach if (!$media->has($xref)) { 96f4cd70d3SGreg Roach $media->push(Factory::media()->make($xref, $individual->tree())); 978c2e8227SGreg Roach } 988c2e8227SGreg Roach } 998c2e8227SGreg Roach } 100cbc1590aSGreg Roach 101*8b626b9bSGreg Roach return $media->filter()->filter(Media::accessFilter()); 1028c2e8227SGreg Roach } 1038c2e8227SGreg Roach 10476692c8bSGreg Roach /** 10576692c8bSGreg Roach * Can this tab load asynchronously? 10676692c8bSGreg Roach * 10776692c8bSGreg Roach * @return bool 10876692c8bSGreg Roach */ 1098f53f488SRico Sonntag public function canLoadAjax(): bool 110c1010edaSGreg Roach { 11115d603e7SGreg Roach return false; 1128c2e8227SGreg Roach } 1138c2e8227SGreg Roach} 114