xref: /webtrees/resources/views/modules/media-list/page.phtml (revision 5bfc689774bb9a6401271c4ed15a6d50652c991b)
1<?php
2
3use Fisharebest\Webtrees\Auth;
4use Fisharebest\Webtrees\I18N;
5use Fisharebest\Webtrees\Media;
6use Fisharebest\Webtrees\MediaFile;
7use Fisharebest\Webtrees\Module\ModuleListInterface;
8use Fisharebest\Webtrees\Registry;
9use Fisharebest\Webtrees\Services\LinkedRecordService;
10use Fisharebest\Webtrees\Tree;
11use Illuminate\Support\Collection;
12use League\Flysystem\FilesystemOperator;
13
14/**
15 * @var int                   $count
16 * @var FilesystemOperator    $data_filesystem
17 * @var string                $filter
18 * @var string                $folder
19 * @var array<string>         $folders
20 * @var string                $format
21 * @var array<string>         $formats
22 * @var LinkedRecordService   $linked_record_service
23 * @var int                   $max
24 * @var Collection<int,Media> $media_objects
25 * @var ModuleListInterface   $module
26 * @var int                   $page
27 * @var int                   $pages
28 * @var string                $subdirs
29 * @var string                $title
30 * @var Tree                  $tree
31 */
32
33?>
34
35<h2 class="wt-page-title">
36    <?= $title ?>
37</h2>
38
39<form method="post" class="wt-page-options wt-page-options-media-list d-print-none">
40    <?= csrf_field() ?>
41
42    <div class="row form-group">
43        <label class="col-sm-3 col-form-label wt-page-options-label" for="folder">
44            <?= I18N::translate('Folder') ?>
45        </label>
46        <div class="col-sm-3 wt-page-options-value">
47            <?= view('components/select', ['name' => 'folder', 'selected' => $folder, 'options' => $folders]) ?>
48            <?= view('components/checkbox-inline', ['label' => /* I18N: Label for check-box */ I18N::translate('Include subfolders'), 'name' => 'subdirs', 'checked' => $subdirs === '1']) ?>
49        </div>
50
51        <label class="col-sm-3 col-form-label wt-page-options-label" for="max">
52            <?= I18N::translate('Media objects per page') ?>
53        </label>
54        <div class="col-sm-3 wt-page-options-value">
55            <?= view('components/select-number', ['name' => 'max', 'selected' => $max, 'options' => [10, 20, 30, 40, 50, 75, 100, 150, 200]]) ?>
56        </div>
57    </div>
58
59    <div class="row form-group">
60        <label class="col-sm-3 col-form-label wt-page-options-label" for="format">
61            <?= I18N::translate('Type') ?>
62        </label>
63
64        <div class="col-sm-3 wt-page-options-value">
65            <?= view('components/select', ['name' => 'format', 'id' => 'format', 'selected' => $format, 'options' => ['' => ''] + $formats]) ?>
66        </div>
67
68        <div class="col-sm-3 col-form-label wt-page-options-label"></div>
69
70        <div class="col-sm-3 wt-page-options-value"></div>
71    </div>
72
73    <div class="row form-group">
74        <label class="col-sm-3 col-form-label wt-page-options-label" for="filter">
75            <?= I18N::translate('Search filters') ?>
76        </label>
77        <div class="col-sm-3 wt-page-options-value">
78            <input type="text" class="form-control" name="filter" id="filter" value="<?= e($filter) ?>">
79        </div>
80
81        <div class="col-sm-3 col-form-label wt-page-options-label"></div>
82
83        <div class="col-sm-3 wt-page-options-value">
84            <button type="submit" name="go" value="1" class="btn btn-primary">
85                <?= /* I18N: A button label. */ I18N::translate('search') ?>
86            </button>
87            <a class="btn btn-secondary" href="<?= e($module->listUrl($tree)) ?>">
88                <?= /* I18N: A button label. */ I18N::translate('reset') ?>
89            </a>
90        </div>
91    </div>
92</form>
93
94<div class="wt-page-content">
95    <p class="text-center mt-4"><?= I18N::translate('Media objects found') ?> <?= I18N::number($count) ?></p>
96    <?php if ($media_objects->isNotEmpty()) : ?>
97
98        <?= view('modules/media-list/pagination', ['module' => $module, 'page' => $page, 'pages' => $pages, 'folder' => $folder, 'subdirs' => $subdirs, 'filter' => $filter, 'format' => $format, 'max' => $max, 'tree' => $tree]) ?>
99
100        <div class="row row-cols-1 row-cols-sm-2 row-cols-lg-3 g-4">
101            <?php foreach ($media_objects as $n => $media_object) : ?>
102                <div class="col">
103                    <div class="card h-100">
104                        <div class="card-header">
105                            <h4 class="card-title">
106                                <a href="<?= e($media_object->url()) ?>"><?= $media_object->fullName() ?></a>
107                            </h4>
108                        </div>
109                        <div class="card-body">
110                            <?php foreach ($media_object->mediaFiles() as $media_file) : ?>
111                                <?= $media_file->displayImage(300, 200, 'contain', ['class' => 'img-fluid']) ?>
112                            <?php endforeach ?>
113
114                            <?php $media_file = $media_object->mediaFiles()->first() ?>
115                            <?php if ($media_file instanceof MediaFile): ?>
116                                <p class="card-text">
117                                    <?php
118                                    // Show file details
119                                    $mediatype = $media_file->type();
120                                    if ($media_file->type() !== '') {
121                                        $element = Registry::elementFactory()->make('OBJE:FILE:FORM:TYPE');
122                                        echo $element->labelValue($media_file->type(), $media_object->tree());
123                                    }
124
125                                    foreach ($media_object->facts(['SOUR']) as $fact) {
126                                        echo view('fact-gedcom-fields', ['gedcom' => $fact->gedcom(), 'parent' => $media_object->tag(), 'tree' => $tree]);
127                                    }
128
129                                    foreach ($media_object->facts(['NOTE']) as $fact) {
130                                        echo view('fact-gedcom-fields', ['gedcom' => $fact->gedcom(), 'parent' => $media_object->tag(), 'tree' => $tree]);
131                                    }
132
133                                    if ($media_file->isExternal()) {
134                                        echo Registry::elementFactory()->make('OBJE:FILE')->labelValue($media_file->filename(), $media_object->tree());
135                                    } elseif ($media_file->fileExists($data_filesystem)) {
136                                        echo Registry::elementFactory()->make('OBJE:FILE:FORM')->labelValue($media_file->mimeType(), $media_object->tree());
137                                        if (Auth::isEditor($tree)) {
138                                            echo Registry::elementFactory()->make('OBJE:FILE')->labelValue($media_file->filename(), $media_object->tree());
139                                        }
140                                        if (Auth::isEditor($tree)) {
141                                            foreach ($media_file->attributes($data_filesystem) as $label => $value) {
142                                                $label = '<span class="label">' . $label . '</span>';
143                                                $value = '<span class="value">' . $value . '</span>';
144
145                                                echo '<div>' . I18N::translate(/* I18N: e.g. "Occupation: farmer" */ '%1$s: %2$s', $label, $value) . '</div>';
146                                            }
147                                        }
148                                    } else {
149                                        echo '<p class="alert alert-danger">', /* I18N: %s is a filename */ I18N::translate('The file “%s” does not exist.', e($media_file->filename())), '</p>';
150                                    }
151                                    ?>
152                                </p>
153                            <?php endif ?>
154                        </div>
155                        <div class="card-footer">
156                            <?php foreach ($linked_record_service->linkedIndividuals($media_object) as $record) : ?>
157                                <?= view('icons/individual') ?>
158                                <a href="<?= e($record->url()) ?>"><?= $record->fullName() ?></a>
159                                <br>
160                            <?php endforeach ?>
161
162                            <?php foreach ($linked_record_service->linkedFamilies($media_object) as $record) : ?>
163                                <?= view('icons/family') ?>
164                                <a href="<?= e($record->url()) ?>"><?= $record->fullName() ?></a>
165                                <br>
166                            <?php endforeach ?>
167
168                            <?php foreach ($linked_record_service->linkedSources($media_object) as $record) : ?>
169                                <?= view('icons/source') ?>
170                                <a href="<?= e($record->url()) ?>"><?= $record->fullName() ?></a>
171                                <br>
172                            <?php endforeach ?>
173
174                            <?php foreach ($linked_record_service->linkedLocations($media_object) as $record) : ?>
175                                <?= view('icons/location') ?>
176                                <a href="<?= e($record->url()) ?>"><?= $record->fullName() ?></a>
177                                <br>
178                            <?php endforeach ?>
179                        </div>
180                    </div>
181                </div>
182            <?php endforeach ?>
183        </div>
184
185        <?= view('modules/media-list/pagination', ['module' => $module, 'page' => $page, 'pages' => $pages, 'folder' => $folder, 'subdirs' => $subdirs, 'filter' => $filter, 'format' => $format, 'max' => $max, 'tree' => $tree]) ?>
186    <?php endif ?>
187</div>
188