1d4265d07SGreg Roach<?php 2d4265d07SGreg Roach 3d4265d07SGreg Roach/** 4d4265d07SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6d4265d07SGreg Roach * This program is free software: you can redistribute it and/or modify 7d4265d07SGreg Roach * it under the terms of the GNU General Public License as published by 8d4265d07SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9d4265d07SGreg Roach * (at your option) any later version. 10d4265d07SGreg Roach * This program is distributed in the hope that it will be useful, 11d4265d07SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12d4265d07SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13d4265d07SGreg Roach * GNU General Public License for more details. 14d4265d07SGreg 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/>. 16d4265d07SGreg Roach */ 17d4265d07SGreg Roach 18d4265d07SGreg Roachdeclare(strict_types=1); 19d4265d07SGreg Roach 20d4265d07SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21d4265d07SGreg Roach 226b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 23d4265d07SGreg Roachuse Fisharebest\Webtrees\Services\MediaFileService; 24b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 25d4265d07SGreg Roachuse Psr\Http\Message\ResponseInterface; 26d4265d07SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 27d4265d07SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 28d4265d07SGreg Roach 29d4265d07SGreg Roach/** 30d4265d07SGreg Roach * Show a form to create a new media object. 31d4265d07SGreg Roach */ 32d4265d07SGreg Roachclass CreateMediaObjectModal implements RequestHandlerInterface 33d4265d07SGreg Roach{ 34c4943cffSGreg Roach private MediaFileService $media_file_service; 35d4265d07SGreg Roach 36d4265d07SGreg Roach /** 37d4265d07SGreg Roach * @param MediaFileService $media_file_service 38d4265d07SGreg Roach */ 39d4265d07SGreg Roach public function __construct(MediaFileService $media_file_service) 40d4265d07SGreg Roach { 41d4265d07SGreg Roach $this->media_file_service = $media_file_service; 42d4265d07SGreg Roach } 43d4265d07SGreg Roach 44d4265d07SGreg Roach /** 45d4265d07SGreg Roach * @param ServerRequestInterface $request 46d4265d07SGreg Roach * 47d4265d07SGreg Roach * @return ResponseInterface 48d4265d07SGreg Roach */ 49d4265d07SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 50d4265d07SGreg Roach { 51b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 52455a30feSGreg Roach $max_upload_size = $this->media_file_service->maxUploadFilesize(); 53455a30feSGreg Roach $media_types = Registry::elementFactory()->make('OBJE:FILE:FORM:TYPE')->values(); 549458f20aSGreg Roach $unused_files = $this->media_file_service->unusedFiles($tree); 55a04bb9a2SGreg Roach 56d4265d07SGreg Roach return response(view('modals/create-media-object', [ 57455a30feSGreg Roach 'max_upload_size' => $max_upload_size, 58455a30feSGreg Roach 'media_types' => $media_types, 59d4265d07SGreg Roach 'tree' => $tree, 60455a30feSGreg Roach 'unused_files' => $unused_files, 61d4265d07SGreg Roach ])); 62d4265d07SGreg Roach } 63d4265d07SGreg Roach} 64