1e3544cb2SGreg Roach<?php 2e3544cb2SGreg Roach 3e3544cb2SGreg Roach/** 4e3544cb2SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6e3544cb2SGreg Roach * This program is free software: you can redistribute it and/or modify 7e3544cb2SGreg Roach * it under the terms of the GNU General Public License as published by 8e3544cb2SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9e3544cb2SGreg Roach * (at your option) any later version. 10e3544cb2SGreg Roach * This program is distributed in the hope that it will be useful, 11e3544cb2SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12e3544cb2SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13e3544cb2SGreg Roach * GNU General Public License for more details. 14e3544cb2SGreg Roach * You should have received a copy of the GNU General Public License 15e3544cb2SGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16e3544cb2SGreg Roach */ 17e3544cb2SGreg Roach 18e3544cb2SGreg Roachdeclare(strict_types=1); 19e3544cb2SGreg Roach 20e3544cb2SGreg Roachnamespace Fisharebest\Webtrees\Module; 21e3544cb2SGreg Roach 22e3544cb2SGreg Roachuse Fisharebest\Webtrees\Fact; 23e3544cb2SGreg Roachuse Fisharebest\Webtrees\I18N; 24e3544cb2SGreg Roach 25e3544cb2SGreg Roachuse function e; 26e3544cb2SGreg Roach 27e3544cb2SGreg Roach/** 28e3544cb2SGreg Roach * Trait ModuleMapLinkTrait - default implementation of ModuleMapLinkInterface 29e3544cb2SGreg Roach */ 30e3544cb2SGreg Roachtrait ModuleMapLinkTrait 31e3544cb2SGreg Roach{ 32e3544cb2SGreg Roach /** 33e3544cb2SGreg Roach * How should this module be identified in the control panel, etc.? 34e3544cb2SGreg Roach * 35e3544cb2SGreg Roach * @return string 36e3544cb2SGreg Roach */ 37e3544cb2SGreg Roach public function title(): string 38e3544cb2SGreg Roach { 39e3544cb2SGreg Roach return $this->providerName() . ' — ' . I18N::translate('Map link'); 40e3544cb2SGreg Roach } 41e3544cb2SGreg Roach 42e3544cb2SGreg Roach public function description(): string 43e3544cb2SGreg Roach { 44e3544cb2SGreg Roach return I18N::translate('Show the location of an event on an external map.'); 45e3544cb2SGreg Roach } 46e3544cb2SGreg Roach 47e3544cb2SGreg Roach /** 48e3544cb2SGreg Roach * @param Fact $fact 49e3544cb2SGreg Roach * 50e3544cb2SGreg Roach * @return string 51e3544cb2SGreg Roach */ 52e3544cb2SGreg Roach public function mapLink(Fact $fact): string 53e3544cb2SGreg Roach { 54e3544cb2SGreg Roach if ($this->isMapAvailableForLocation($fact)) { 55e3544cb2SGreg Roach $icon = $this->icon(); 56e3544cb2SGreg Roach $url = $this->mapUrl($fact); 57e3544cb2SGreg Roach $title = I18N::translate('View this location using %s', $this->providerName()); 58e3544cb2SGreg Roach 59e3544cb2SGreg Roach return '<a href="' . e($url) . '" rel="nofollow" target="_top" title="' . $title . '">' . $icon . '</a>'; 60e3544cb2SGreg Roach } 61e3544cb2SGreg Roach 62e3544cb2SGreg Roach return ''; 63e3544cb2SGreg Roach } 64e3544cb2SGreg Roach 65e3544cb2SGreg Roach /** 66e3544cb2SGreg Roach * Name of the map provider. 67e3544cb2SGreg Roach * 68e3544cb2SGreg Roach * @return string 69e3544cb2SGreg Roach */ 70e3544cb2SGreg Roach protected function providerName(): string 71e3544cb2SGreg Roach { 72e3544cb2SGreg Roach return 'example.com'; 73e3544cb2SGreg Roach } 74e3544cb2SGreg Roach 75e3544cb2SGreg Roach /** 76e3544cb2SGreg Roach * @param Fact $fact 77e3544cb2SGreg Roach * 78e3544cb2SGreg Roach * @return bool 79e3544cb2SGreg Roach */ 80e3544cb2SGreg Roach protected function isMapAvailableForLocation(Fact $fact): bool 81e3544cb2SGreg Roach { 82e3544cb2SGreg Roach return $fact->latitude() !== null && $fact->longitude() !== null; 83e3544cb2SGreg Roach } 84e3544cb2SGreg Roach 85e3544cb2SGreg Roach /** 86e3544cb2SGreg Roach * @return string 87e3544cb2SGreg Roach */ 88e3544cb2SGreg Roach protected function icon(): string 89e3544cb2SGreg Roach { 90e3544cb2SGreg Roach return 'icon'; 91e3544cb2SGreg Roach } 92e3544cb2SGreg Roach 93e3544cb2SGreg Roach /** 94e3544cb2SGreg Roach * @param Fact $fact 95e3544cb2SGreg Roach * 96e3544cb2SGreg Roach * @return string 97e3544cb2SGreg Roach */ 9849528f2bSGreg Roach protected function mapUrl(Fact $fact): string 99e3544cb2SGreg Roach { 100e3544cb2SGreg Roach return 'https://example.com'; 101e3544cb2SGreg Roach } 102e3544cb2SGreg Roach} 103