xref: /webtrees/app/Elements/SourceMediaType.php (revision e1d4873415658b71cd9ad8e02c7fbd03be753d89)
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 strtolower;
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 strtolower(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