xref: /webtrees/resources/views/modules/media-list/page.phtml (revision ac71572d8462e396ed5a307f05b29381e49f9e6e)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\Auth;
6use Fisharebest\Webtrees\I18N;
7use Fisharebest\Webtrees\Media;
8use Fisharebest\Webtrees\MediaFile;
9use Fisharebest\Webtrees\Module\ModuleListInterface;
10use Fisharebest\Webtrees\Registry;
11use Fisharebest\Webtrees\Services\LinkedRecordService;
12use Fisharebest\Webtrees\Tree;
13use Illuminate\Support\Collection;
14
15/**
16 * @var int                   $count
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 bool                  $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    <div class="row">
41        <label class="col-sm-3 col-form-label wt-page-options-label" for="folder">
42            <?= I18N::translate('Folder') ?>
43        </label>
44        <div class="col-sm-3 wt-page-options-value">
45            <?= view('components/select', ['name' => 'folder', 'selected' => $folder, 'options' => $folders]) ?>
46            <?= view('components/checkbox-inline', ['label' => /* I18N: Label for check-box */ I18N::translate('Include subfolders'), 'name' => 'subdirs', 'checked' => $subdirs]) ?>
47        </div>
48
49        <label class="col-sm-3 col-form-label wt-page-options-label" for="max">
50            <?= I18N::translate('Media objects per page') ?>
51        </label>
52        <div class="col-sm-3 wt-page-options-value">
53            <?= view('components/select-number', ['name' => 'max', 'selected' => $max, 'options' => [10, 20, 30, 40, 50, 75, 100, 150, 200]]) ?>
54        </div>
55    </div>
56
57    <div class="row">
58        <label class="col-sm-3 col-form-label wt-page-options-label" for="format">
59            <?= I18N::translate('Type') ?>
60        </label>
61
62        <div class="col-sm-3 wt-page-options-value">
63            <?= view('components/select', ['name' => 'format', 'id' => 'format', 'selected' => $format, 'options' => ['' => ''] + $formats]) ?>
64        </div>
65
66        <div class="col-sm-3 col-form-label wt-page-options-label"></div>
67
68        <div class="col-sm-3 wt-page-options-value"></div>
69    </div>
70
71    <div class="row">
72        <label class="col-sm-3 col-form-label wt-page-options-label" for="filter">
73            <?= I18N::translate('Search filters') ?>
74        </label>
75        <div class="col-sm-3 wt-page-options-value">
76            <input type="text" class="form-control" name="filter" id="filter" value="<?= e($filter) ?>">
77        </div>
78
79        <div class="col-sm-3 col-form-label wt-page-options-label"></div>
80
81        <div class="col-sm-3 wt-page-options-value">
82            <input type="hidden" name="page" value="1">
83            <button type="submit" class="btn btn-primary">
84                <?= /* I18N: A button label. */ I18N::translate('search') ?>
85            </button>
86            <a class="btn btn-secondary" href="<?= e($module->listUrl($tree)) ?>">
87                <?= /* I18N: A button label. */ I18N::translate('reset') ?>
88            </a>
89        </div>
90    </div>
91
92    <?= csrf_field() ?>
93</form>
94
95<div class="wt-page-content">
96    <p class="text-center mt-4"><?= I18N::translate('Media objects found') ?> <?= I18N::number($count) ?></p>
97    <?php if ($media_objects->isNotEmpty()) : ?>
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()) {
136                                        if (Auth::isEditor($tree)) {
137                                            echo Registry::elementFactory()->make('OBJE:FILE')->labelValue($media_file->filename(), $media_object->tree());
138
139                                            foreach ($media_file->attributes() as $label => $value) {
140                                                $label = '<span class="label">' . $label . '</span>';
141                                                $value = '<span class="value">' . $value . '</span>';
142
143                                                echo '<div>' . I18N::translate(/* I18N: e.g. "Occupation: farmer" */ '%1$s: %2$s', $label, $value) . '</div>';
144                                            }
145                                        }
146                                    } else {
147                                        echo '<p class="alert alert-danger">', /* I18N: %s is a filename */ I18N::translate('The file “%s” does not exist.', e($media_file->filename())), '</p>';
148                                    }
149                                    ?>
150                                </p>
151                            <?php endif ?>
152                        </div>
153                        <div class="card-footer">
154                            <?php foreach ($linked_record_service->linkedIndividuals($media_object) as $record) : ?>
155                                <?= view('icons/individual') ?>
156                                <a href="<?= e($record->url()) ?>"><?= $record->fullName() ?></a>
157                                <br>
158                            <?php endforeach ?>
159
160                            <?php foreach ($linked_record_service->linkedFamilies($media_object) as $record) : ?>
161                                <?= view('icons/family') ?>
162                                <a href="<?= e($record->url()) ?>"><?= $record->fullName() ?></a>
163                                <br>
164                            <?php endforeach ?>
165
166                            <?php foreach ($linked_record_service->linkedSources($media_object) as $record) : ?>
167                                <?= view('icons/source') ?>
168                                <a href="<?= e($record->url()) ?>"><?= $record->fullName() ?></a>
169                                <br>
170                            <?php endforeach ?>
171
172                            <?php foreach ($linked_record_service->linkedLocations($media_object) as $record) : ?>
173                                <?= view('icons/location') ?>
174                                <a href="<?= e($record->url()) ?>"><?= $record->fullName() ?></a>
175                                <br>
176                            <?php endforeach ?>
177                        </div>
178                    </div>
179                </div>
180            <?php endforeach ?>
181        </div>
182
183        <?= view('modules/media-list/pagination', ['module' => $module, 'page' => $page, 'pages' => $pages, 'folder' => $folder, 'subdirs' => $subdirs, 'filter' => $filter, 'format' => $format, 'max' => $max, 'tree' => $tree]) ?>
184    <?php endif ?>
185</div>
186