xref: /webtrees/app/Elements/SourceMediaType.php (revision 7573bc3d78289b103f95e1640a3adf9095277886)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2022 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Elements;
21
22use Fisharebest\Webtrees\I18N;
23
24use function strtoupper;
25use function uasort;
26
27/**
28 * SOURCE_MEDIA_TYPE := {Size=1:15}
29 * [ audio | book | card | electronic | fiche | film | magazine |
30 * manuscript | map | newspaper | photo | tombstone | video ]
31 * A code, selected from one of the media classifications choices above, that indicates the type of
32 * material in which the referenced source is stored.
33 */
34class SourceMediaType extends AbstractElement
35{
36    public const TYPE_AUDIO       = 'AUDIO';
37    public const TYPE_BOOK        = 'BOOK';
38    public const TYPE_CARD        = 'CARD';
39    public const TYPE_CERTIFICATE = 'CERTIFICATE';
40    public const TYPE_COAT        = 'COAT';
41    public const TYPE_DOCUMENT    = 'DOCUMENT';
42    public const TYPE_ELECTRONIC  = 'ELECTRONIC';
43    public const TYPE_FICHE       = 'FICHE';
44    public const TYPE_FILM        = 'FILM';
45    public const TYPE_MAGAZINE    = 'MAGAZINE';
46    public const TYPE_MANUSCRIPT  = 'MANUSCRIPT';
47    public const TYPE_MAP         = 'MAP';
48    public const TYPE_NEWSPAPER   = 'NEWSPAPER';
49    public const TYPE_OTHER       = 'OTHER';
50    public const TYPE_PAINTING    = 'PAINTING';
51    public const TYPE_PHOTO       = 'PHOTO';
52    public const TYPE_TOMBSTONE   = 'TOMBSTONE';
53    public const TYPE_VIDEO       = 'VIDEO';
54
55    protected const MAXIMUM_LENGTH = 15;
56
57    /**
58     * Convert a value to a canonical form.
59     *
60     * @param string $value
61     *
62     * @return string
63     */
64    public function canonical(string $value): string
65    {
66        return strtoupper(parent::canonical($value));
67    }
68
69    /**
70     * A list of controlled values for this element
71     *
72     * @return array<int|string,string>
73     */
74    public function values(): array
75    {
76        // *** indicates custom values
77        $values = [
78            ''            => '',
79            self::TYPE_AUDIO       => /* I18N: Type of media object */ I18N::translate('Audio'),
80            self::TYPE_BOOK        => /* I18N: Type of media object */ I18N::translate('Book'),
81            self::TYPE_CARD        => /* I18N: Type of media object */ I18N::translate('Card'),
82            self::TYPE_CERTIFICATE => /* I18N: Type of media object */ I18N::translate('Certificate'),
83            self::TYPE_COAT        => /* I18N: Type of media object */ I18N::translate('Coat of arms'),
84            self::TYPE_DOCUMENT    => /* I18N: Type of media object */ I18N::translate('Document'),
85            self::TYPE_ELECTRONIC  => /* I18N: Type of media object */ I18N::translate('Electronic'),
86            self::TYPE_FICHE       => /* I18N: Type of media object */ I18N::translate('Microfiche'),
87            self::TYPE_FILM        => /* I18N: Type of media object */ I18N::translate('Microfilm'),
88            self::TYPE_MAGAZINE    => /* I18N: Type of media object */ I18N::translate('Magazine'),
89            self::TYPE_MANUSCRIPT  => /* I18N: Type of media object */ I18N::translate('Manuscript'),
90            self::TYPE_MAP         => /* I18N: Type of media object */ I18N::translate('Map'),
91            self::TYPE_NEWSPAPER   => /* I18N: Type of media object */ I18N::translate('Newspaper'),
92            self::TYPE_OTHER       => /* I18N: Type of media object */ I18N::translate('Other'),
93            self::TYPE_PAINTING    => /* I18N: Type of media object */ I18N::translate('Painting'),
94            self::TYPE_PHOTO       => /* I18N: Type of media object */ I18N::translate('Photo'),
95            self::TYPE_TOMBSTONE   => /* I18N: Type of media object */ I18N::translate('Tombstone'),
96            self::TYPE_VIDEO       => /* I18N: Type of media object */ I18N::translate('Video'),
97        ];
98
99        uasort($values, I18N::comparator());
100
101        return $values;
102    }
103}
104