xref: /webtrees/app/Elements/SourceMediaType.php (revision d11be7027e34e3121be11cc025421873364403f9)
1c2ed51d1SGreg Roach<?php
2c2ed51d1SGreg Roach
3c2ed51d1SGreg Roach/**
4c2ed51d1SGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
6c2ed51d1SGreg Roach * This program is free software: you can redistribute it and/or modify
7c2ed51d1SGreg Roach * it under the terms of the GNU General Public License as published by
8c2ed51d1SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9c2ed51d1SGreg Roach * (at your option) any later version.
10c2ed51d1SGreg Roach * This program is distributed in the hope that it will be useful,
11c2ed51d1SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12c2ed51d1SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13c2ed51d1SGreg Roach * GNU General Public License for more details.
14c2ed51d1SGreg Roach * You should have received a copy of the GNU General Public License
15c2ed51d1SGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16c2ed51d1SGreg Roach */
17c2ed51d1SGreg Roach
18c2ed51d1SGreg Roachdeclare(strict_types=1);
19c2ed51d1SGreg Roach
20c2ed51d1SGreg Roachnamespace Fisharebest\Webtrees\Elements;
21c2ed51d1SGreg Roach
22c2ed51d1SGreg Roachuse Fisharebest\Webtrees\I18N;
23c2ed51d1SGreg Roach
243f810b5bSGreg Roachuse function strtoupper;
25c2ed51d1SGreg Roachuse function uasort;
26c2ed51d1SGreg Roach
27c2ed51d1SGreg Roach/**
28c2ed51d1SGreg Roach * SOURCE_MEDIA_TYPE := {Size=1:15}
29c2ed51d1SGreg Roach * [ audio | book | card | electronic | fiche | film | magazine |
30c2ed51d1SGreg Roach * manuscript | map | newspaper | photo | tombstone | video ]
31c2ed51d1SGreg Roach * A code, selected from one of the media classifications choices above, that indicates the type of
32c2ed51d1SGreg Roach * material in which the referenced source is stored.
33c2ed51d1SGreg Roach */
34c2ed51d1SGreg Roachclass SourceMediaType extends AbstractElement
35c2ed51d1SGreg Roach{
3688a03560SGreg Roach    public const VALUE_AUDIO       = 'AUDIO';
3788a03560SGreg Roach    public const VALUE_BOOK        = 'BOOK';
3888a03560SGreg Roach    public const VALUE_CARD        = 'CARD';
3988a03560SGreg Roach    public const VALUE_CERTIFICATE = 'CERTIFICATE';
4088a03560SGreg Roach    public const VALUE_COAT        = 'COAT';
4188a03560SGreg Roach    public const VALUE_DOCUMENT    = 'DOCUMENT';
4288a03560SGreg Roach    public const VALUE_ELECTRONIC  = 'ELECTRONIC';
4388a03560SGreg Roach    public const VALUE_FICHE       = 'FICHE';
4488a03560SGreg Roach    public const VALUE_FILM        = 'FILM';
4588a03560SGreg Roach    public const VALUE_MAGAZINE    = 'MAGAZINE';
4688a03560SGreg Roach    public const VALUE_MANUSCRIPT  = 'MANUSCRIPT';
4788a03560SGreg Roach    public const VALUE_MAP         = 'MAP';
4888a03560SGreg Roach    public const VALUE_NEWSPAPER   = 'NEWSPAPER';
4988a03560SGreg Roach    public const VALUE_OTHER       = 'OTHER';
5088a03560SGreg Roach    public const VALUE_PAINTING    = 'PAINTING';
5188a03560SGreg Roach    public const VALUE_PHOTO       = 'PHOTO';
5288a03560SGreg Roach    public const VALUE_TOMBSTONE   = 'TOMBSTONE';
5388a03560SGreg Roach    public const VALUE_VIDEO       = 'VIDEO';
54e1d48734SGreg Roach
55ae0043b7SGreg Roach    protected const MAXIMUM_LENGTH = 15;
56c2ed51d1SGreg Roach
57c2ed51d1SGreg Roach    /**
58c2ed51d1SGreg Roach     * Convert a value to a canonical form.
59c2ed51d1SGreg Roach     *
60c2ed51d1SGreg Roach     * @param string $value
61c2ed51d1SGreg Roach     *
62c2ed51d1SGreg Roach     * @return string
63c2ed51d1SGreg Roach     */
64c2ed51d1SGreg Roach    public function canonical(string $value): string
65c2ed51d1SGreg Roach    {
663f810b5bSGreg Roach        return strtoupper(parent::canonical($value));
67c2ed51d1SGreg Roach    }
68c2ed51d1SGreg Roach
69c2ed51d1SGreg Roach    /**
70c2ed51d1SGreg Roach     * A list of controlled values for this element
71c2ed51d1SGreg Roach     *
72c2ed51d1SGreg Roach     * @return array<int|string,string>
73c2ed51d1SGreg Roach     */
74c2ed51d1SGreg Roach    public function values(): array
75c2ed51d1SGreg Roach    {
76c2ed51d1SGreg Roach        // *** indicates custom values
77c2ed51d1SGreg Roach        $values = [
78c2ed51d1SGreg Roach            ''                      => '',
7988a03560SGreg Roach            self::VALUE_AUDIO       => /* I18N: Type of media object */ I18N::translate('Audio'),
8088a03560SGreg Roach            self::VALUE_BOOK        => /* I18N: Type of media object */ I18N::translate('Book'),
8188a03560SGreg Roach            self::VALUE_CARD        => /* I18N: Type of media object */ I18N::translate('Card'),
8288a03560SGreg Roach            self::VALUE_CERTIFICATE => /* I18N: Type of media object */ I18N::translate('Certificate'),
8388a03560SGreg Roach            self::VALUE_COAT       => /* I18N: Type of media object */ I18N::translate('Coat of arms'),
8488a03560SGreg Roach            self::VALUE_DOCUMENT   => /* I18N: Type of media object */ I18N::translate('Document'),
8588a03560SGreg Roach            self::VALUE_ELECTRONIC => /* I18N: Type of media object */ I18N::translate('Electronic'),
8688a03560SGreg Roach            self::VALUE_FICHE      => /* I18N: Type of media object */ I18N::translate('Microfiche'),
8788a03560SGreg Roach            self::VALUE_FILM       => /* I18N: Type of media object */ I18N::translate('Microfilm'),
8888a03560SGreg Roach            self::VALUE_MAGAZINE   => /* I18N: Type of media object */ I18N::translate('Magazine'),
8988a03560SGreg Roach            self::VALUE_MANUSCRIPT => /* I18N: Type of media object */ I18N::translate('Manuscript'),
9088a03560SGreg Roach            self::VALUE_MAP        => /* I18N: Type of media object */ I18N::translate('Map'),
9188a03560SGreg Roach            self::VALUE_NEWSPAPER  => /* I18N: Type of media object */ I18N::translate('Newspaper'),
9288a03560SGreg Roach            self::VALUE_OTHER      => /* I18N: Type of media object */ I18N::translate('Other'),
9388a03560SGreg Roach            self::VALUE_PAINTING   => /* I18N: Type of media object */ I18N::translate('Painting'),
9488a03560SGreg Roach            self::VALUE_PHOTO      => /* I18N: Type of media object */ I18N::translate('Photo'),
9588a03560SGreg Roach            self::VALUE_TOMBSTONE  => /* I18N: Type of media object */ I18N::translate('Tombstone'),
9688a03560SGreg Roach            self::VALUE_VIDEO      => /* I18N: Type of media object */ I18N::translate('Video'),
97c2ed51d1SGreg Roach        ];
98c2ed51d1SGreg Roach
9937646143SGreg Roach        uasort($values, I18N::comparator());
100c2ed51d1SGreg Roach
101c2ed51d1SGreg Roach        return $values;
102c2ed51d1SGreg Roach    }
103c2ed51d1SGreg Roach}
104