xref: /webtrees/app/Http/RequestHandlers/CreateMediaObjectModal.php (revision a04bb9a236e92915034f97b1229f5d47c9bc750f)
1d4265d07SGreg Roach<?php
2d4265d07SGreg Roach
3d4265d07SGreg Roach/**
4d4265d07SGreg Roach * webtrees: online genealogy
5d4265d07SGreg Roach * Copyright (C) 2019 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
15d4265d07SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16d4265d07SGreg Roach */
17d4265d07SGreg Roach
18d4265d07SGreg Roachdeclare(strict_types=1);
19d4265d07SGreg Roach
20d4265d07SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
21d4265d07SGreg Roach
22d4265d07SGreg Roachuse Fisharebest\Webtrees\Services\MediaFileService;
23d4265d07SGreg Roachuse Fisharebest\Webtrees\Tree;
24*a04bb9a2SGreg Roachuse League\Flysystem\FilesystemInterface;
25d4265d07SGreg Roachuse Psr\Http\Message\ResponseInterface;
26d4265d07SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
27d4265d07SGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
28d4265d07SGreg Roach
29d4265d07SGreg Roachuse function assert;
30d4265d07SGreg Roach
31d4265d07SGreg Roach/**
32d4265d07SGreg Roach * Show a form to create a new media object.
33d4265d07SGreg Roach */
34d4265d07SGreg Roachclass CreateMediaObjectModal implements RequestHandlerInterface
35d4265d07SGreg Roach{
36d4265d07SGreg Roach    /** @var MediaFileService */
37d4265d07SGreg Roach    private $media_file_service;
38d4265d07SGreg Roach
39d4265d07SGreg Roach    /**
40d4265d07SGreg Roach     * CreateMediaObjectModal constructor.
41d4265d07SGreg Roach     *
42d4265d07SGreg Roach     * @param MediaFileService $media_file_service
43d4265d07SGreg Roach     */
44d4265d07SGreg Roach    public function __construct(MediaFileService $media_file_service)
45d4265d07SGreg Roach    {
46d4265d07SGreg Roach        $this->media_file_service = $media_file_service;
47d4265d07SGreg Roach    }
48d4265d07SGreg Roach
49d4265d07SGreg Roach    /**
50d4265d07SGreg Roach     * @param ServerRequestInterface $request
51d4265d07SGreg Roach     *
52d4265d07SGreg Roach     * @return ResponseInterface
53d4265d07SGreg Roach     */
54d4265d07SGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
55d4265d07SGreg Roach    {
56d4265d07SGreg Roach        $tree = $request->getAttribute('tree');
57d4265d07SGreg Roach        assert($tree instanceof Tree);
58d4265d07SGreg Roach
59*a04bb9a2SGreg Roach        $data_filesystem = $request->getAttribute('filesystem.data');
60*a04bb9a2SGreg Roach        assert($data_filesystem instanceof FilesystemInterface);
61*a04bb9a2SGreg Roach
62d4265d07SGreg Roach        return response(view('modals/create-media-object', [
63d4265d07SGreg Roach            'max_upload_size' => $this->media_file_service->maxUploadFilesize(),
64d4265d07SGreg Roach            'media_types'     => $this->media_file_service->mediaTypes(),
65*a04bb9a2SGreg Roach            'unused_files'    => $this->media_file_service->unusedFiles($tree, $data_filesystem),
66d4265d07SGreg Roach            'tree'            => $tree,
67d4265d07SGreg Roach        ]));
68d4265d07SGreg Roach    }
69d4265d07SGreg Roach}
70