1c9c6f2ecSGreg Roach<?php 2c9c6f2ecSGreg Roach 3c9c6f2ecSGreg Roach/** 4c9c6f2ecSGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6c9c6f2ecSGreg Roach * This program is free software: you can redistribute it and/or modify 7c9c6f2ecSGreg Roach * it under the terms of the GNU General Public License as published by 8c9c6f2ecSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9c9c6f2ecSGreg Roach * (at your option) any later version. 10c9c6f2ecSGreg Roach * This program is distributed in the hope that it will be useful, 11c9c6f2ecSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12c9c6f2ecSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13c9c6f2ecSGreg Roach * GNU General Public License for more details. 14c9c6f2ecSGreg Roach * You should have received a copy of the GNU General Public License 15c9c6f2ecSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16c9c6f2ecSGreg Roach */ 17c9c6f2ecSGreg Roach 18c9c6f2ecSGreg Roachdeclare(strict_types=1); 19c9c6f2ecSGreg Roach 20c9c6f2ecSGreg Roachnamespace Fisharebest\Webtrees\Module; 21c9c6f2ecSGreg Roach 222bcd31b3SGreg Roachuse Fisharebest\Webtrees\FlashMessages; 23c9c6f2ecSGreg Roachuse Fisharebest\Webtrees\I18N; 24748dbe15SGreg Roachuse Fisharebest\Webtrees\Validator; 252bcd31b3SGreg Roachuse Psr\Http\Message\ResponseInterface; 262bcd31b3SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 272bcd31b3SGreg Roach 282bcd31b3SGreg Roachuse function redirect; 29c9c6f2ecSGreg Roach 30c9c6f2ecSGreg Roach/** 31c9c6f2ecSGreg Roach * Class MapLocationOpenRouteService - use geonames to find locations 32c9c6f2ecSGreg Roach */ 33c9c6f2ecSGreg Roachclass MapGeoLocationOpenRouteService extends AbstractModule implements ModuleConfigInterface, ModuleMapGeoLocationInterface 34c9c6f2ecSGreg Roach{ 35c9c6f2ecSGreg Roach use ModuleConfigTrait; 36c9c6f2ecSGreg Roach use ModuleMapGeoLocationTrait; 37c9c6f2ecSGreg Roach 38c9c6f2ecSGreg Roach /** 39c9c6f2ecSGreg Roach * Name of the map provider. 40c9c6f2ecSGreg Roach * 41c9c6f2ecSGreg Roach * @return string 42c9c6f2ecSGreg Roach */ 43c9c6f2ecSGreg Roach public function title(): string 44c9c6f2ecSGreg Roach { 45c9c6f2ecSGreg Roach return /* I18N: https://openrouteservice.org */ I18N::translate('OpenRouteService'); 46c9c6f2ecSGreg Roach } 472bcd31b3SGreg Roach 482bcd31b3SGreg Roach /** 492bcd31b3SGreg Roach * Should this module be enabled when it is first installed? 502bcd31b3SGreg Roach * 512bcd31b3SGreg Roach * @return bool 522bcd31b3SGreg Roach */ 532bcd31b3SGreg Roach public function isEnabledByDefault(): bool 542bcd31b3SGreg Roach { 552bcd31b3SGreg Roach return false; 562bcd31b3SGreg Roach } 572bcd31b3SGreg Roach 582bcd31b3SGreg Roach /** 592bcd31b3SGreg Roach * @return ResponseInterface 602bcd31b3SGreg Roach */ 612bcd31b3SGreg Roach public function getAdminAction(): ResponseInterface 622bcd31b3SGreg Roach { 632bcd31b3SGreg Roach $this->layout = 'layouts/administration'; 642bcd31b3SGreg Roach 652bcd31b3SGreg Roach return $this->viewResponse('modules/openrouteservice/config', [ 662bcd31b3SGreg Roach 'api_key' => $this->getPreference('api_key'), 672bcd31b3SGreg Roach 'title' => $this->title(), 682bcd31b3SGreg Roach ]); 692bcd31b3SGreg Roach } 702bcd31b3SGreg Roach 712bcd31b3SGreg Roach /** 722bcd31b3SGreg Roach * @param ServerRequestInterface $request 732bcd31b3SGreg Roach * 742bcd31b3SGreg Roach * @return ResponseInterface 752bcd31b3SGreg Roach */ 762bcd31b3SGreg Roach public function postAdminAction(ServerRequestInterface $request): ResponseInterface 772bcd31b3SGreg Roach { 78748dbe15SGreg Roach $api_key = Validator::parsedBody($request)->string('api_key'); 792bcd31b3SGreg Roach 80748dbe15SGreg Roach $this->setPreference('api_key', $api_key); 812bcd31b3SGreg Roach 822bcd31b3SGreg Roach FlashMessages::addMessage(I18N::translate('The preferences for the module “%s” have been updated.', $this->title()), 'success'); 832bcd31b3SGreg Roach 842bcd31b3SGreg Roach return redirect($this->getConfigLink()); 852bcd31b3SGreg Roach } 86c9c6f2ecSGreg Roach} 87