1d178350fSGreg Roach<?php 2d178350fSGreg Roach 3d178350fSGreg Roach/** 4d178350fSGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6d178350fSGreg Roach * This program is free software: you can redistribute it and/or modify 7d178350fSGreg Roach * it under the terms of the GNU General Public License as published by 8d178350fSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9d178350fSGreg Roach * (at your option) any later version. 10d178350fSGreg Roach * This program is distributed in the hope that it will be useful, 11d178350fSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12d178350fSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13d178350fSGreg Roach * GNU General Public License for more details. 14d178350fSGreg Roach * You should have received a copy of the GNU General Public License 15d178350fSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16d178350fSGreg Roach */ 17d178350fSGreg Roach 18d178350fSGreg Roachdeclare(strict_types=1); 19d178350fSGreg Roach 20d178350fSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21d178350fSGreg Roach 22d178350fSGreg Roachuse Fisharebest\Webtrees\Auth; 23d178350fSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 24d178350fSGreg Roachuse Fisharebest\Webtrees\I18N; 25d178350fSGreg Roachuse Fisharebest\Webtrees\Registry; 26d178350fSGreg Roachuse Fisharebest\Webtrees\Validator; 27d178350fSGreg Roachuse Psr\Http\Message\ResponseInterface; 28d178350fSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 29d178350fSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 30d178350fSGreg Roach 31d178350fSGreg Roach/** 32d178350fSGreg Roach * Reorder the media files of a media object. 33d178350fSGreg Roach */ 34d178350fSGreg Roachclass ReorderMediaFilesPage implements RequestHandlerInterface 35d178350fSGreg Roach{ 36d178350fSGreg Roach use ViewResponseTrait; 37d178350fSGreg Roach 38d178350fSGreg Roach /** 39d178350fSGreg Roach * @param ServerRequestInterface $request 40d178350fSGreg Roach * 41d178350fSGreg Roach * @return ResponseInterface 42d178350fSGreg Roach */ 43d178350fSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 44d178350fSGreg Roach { 45d178350fSGreg Roach $tree = Validator::attributes($request)->tree(); 46d178350fSGreg Roach $xref = Validator::attributes($request)->isXref()->string('xref'); 47d178350fSGreg Roach $media = Registry::mediaFactory()->make($xref, $tree); 48d178350fSGreg Roach $media = Auth::checkMediaAccess($media, true); 49d178350fSGreg Roach $title = $media->fullName() . ' — ' . I18N::translate('Re-order media'); 50d178350fSGreg Roach 51d178350fSGreg Roach if ($media->mediaFiles()->count() < 2) { 52d178350fSGreg Roach return Registry::responseFactory()->redirect(MediaPage::class, [ 53d178350fSGreg Roach 'tree' => $tree->name(), 54d178350fSGreg Roach 'xref' => $media->xref(), 55d178350fSGreg Roach ]); 56d178350fSGreg Roach } 57d178350fSGreg Roach 58d178350fSGreg Roach return $this->viewResponse('edit/reorder-media-files', [ 59d178350fSGreg Roach 'media' => $media, 60d178350fSGreg Roach 'title' => $title, 61d178350fSGreg Roach 'tree' => $tree, 62d178350fSGreg Roach ]); 63d178350fSGreg Roach } 64d178350fSGreg Roach} 65