xref: /webtrees/resources/views/modules/media-list/page.phtml (revision 24931b29a0237a5f5f1b8620af661ea530451af0)
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 $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                                    if ($media_file->type() !== '') {
120                                        $element = Registry::elementFactory()->make('OBJE:FILE:FORM:TYPE');
121                                        echo $element->labelValue($media_file->type(), $media_object->tree());
122                                    }
123
124                                    foreach ($media_object->facts(['SOUR']) as $fact) {
125                                        echo view('fact-gedcom-fields', ['gedcom' => $fact->gedcom(), 'parent' => $media_object->tag(), 'tree' => $tree]);
126                                    }
127
128                                    foreach ($media_object->facts(['NOTE']) as $fact) {
129                                        echo view('fact-gedcom-fields', ['gedcom' => $fact->gedcom(), 'parent' => $media_object->tag(), 'tree' => $tree]);
130                                    }
131
132                                    if ($media_file->isExternal()) {
133                                        echo Registry::elementFactory()->make('OBJE:FILE')->labelValue($media_file->filename(), $media_object->tree());
134                                    } elseif ($media_file->fileExists()) {
135                                        if (Auth::isEditor($tree)) {
136                                            echo Registry::elementFactory()->make('OBJE:FILE')->labelValue($media_file->filename(), $media_object->tree());
137
138                                            foreach ($media_file->attributes() as $label => $value) {
139                                                $label = '<span class="label">' . $label . '</span>';
140                                                $value = '<span class="value">' . $value . '</span>';
141
142                                                echo '<div>' . I18N::translate(/* I18N: e.g. "Occupation: farmer" */ '%1$s: %2$s', $label, $value) . '</div>';
143                                            }
144                                        }
145                                    } else {
146                                        echo '<p class="alert alert-danger">', /* I18N: %s is a filename */ I18N::translate('The file “%s” does not exist.', e($media_file->filename())), '</p>';
147                                    }
148                                    ?>
149                                </p>
150                            <?php endif ?>
151                        </div>
152                        <div class="card-footer">
153                            <?php foreach ($linked_record_service->linkedIndividuals($media_object) as $record) : ?>
154                                <?= view('icons/individual') ?>
155                                <a href="<?= e($record->url()) ?>"><?= $record->fullName() ?></a>
156                                <br>
157                            <?php endforeach ?>
158
159                            <?php foreach ($linked_record_service->linkedFamilies($media_object) as $record) : ?>
160                                <?= view('icons/family') ?>
161                                <a href="<?= e($record->url()) ?>"><?= $record->fullName() ?></a>
162                                <br>
163                            <?php endforeach ?>
164
165                            <?php foreach ($linked_record_service->linkedSources($media_object) as $record) : ?>
166                                <?= view('icons/source') ?>
167                                <a href="<?= e($record->url()) ?>"><?= $record->fullName() ?></a>
168                                <br>
169                            <?php endforeach ?>
170
171                            <?php foreach ($linked_record_service->linkedLocations($media_object) as $record) : ?>
172                                <?= view('icons/location') ?>
173                                <a href="<?= e($record->url()) ?>"><?= $record->fullName() ?></a>
174                                <br>
175                            <?php endforeach ?>
176                        </div>
177                    </div>
178                </div>
179            <?php endforeach ?>
180        </div>
181
182        <?= view('modules/media-list/pagination', ['module' => $module, 'page' => $page, 'pages' => $pages, 'folder' => $folder, 'subdirs' => $subdirs, 'filter' => $filter, 'format' => $format, 'max' => $max, 'tree' => $tree]) ?>
183    <?php endif ?>
184</div>
185