xref: /webtrees/app/Header.php (revision bb03c9f048b83092098d5e46c2ab323ae7e2b314)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees;
21
22use Closure;
23use Exception;
24use Fisharebest\Webtrees\Http\RequestHandlers\HeaderPage;
25use Illuminate\Database\Capsule\Manager as DB;
26
27use function app;
28
29/**
30 * A GEDCOM header (HEAD) object.
31 */
32class Header extends GedcomRecord
33{
34    public const RECORD_TYPE = 'HEAD';
35
36    protected const ROUTE_NAME = HeaderPage::class;
37
38    /**
39     * A closure which will create a record from a database row.
40     *
41     * @deprecated since 2.0.4.  Will be removed in 2.1.0 - Use Factory::header()
42     *
43     * @param Tree $tree
44     *
45     * @return Closure
46     */
47    public static function rowMapper(Tree $tree): Closure
48    {
49        return Factory::header()->mapper($tree);
50    }
51
52    /**
53     * Get an instance of a header object. For single records,
54     * we just receive the XREF. For bulk records (such as lists
55     * and search results) we can receive the GEDCOM data as well.
56     *
57     * @deprecated since 2.0.4.  Will be removed in 2.1.0 - Use Factory::header()
58     *
59     * @param string      $xref
60     * @param Tree        $tree
61     * @param string|null $gedcom
62     *
63     * @return Header|null
64     */
65    public static function getInstance(string $xref, Tree $tree, string $gedcom = null): ?Header
66    {
67        return Factory::header()->make($xref, $tree, $gedcom);
68    }
69
70    /**
71     * Generate a private version of this record
72     *
73     * @param int $access_level
74     *
75     * @return string
76     */
77    protected function createPrivateGedcomRecord(int $access_level): string
78    {
79        return '0 HEAD' . $this->xref . "@ SUBM\n1 NAME " . I18N::translate('Private');
80    }
81
82    /**
83     * Extract names from the GEDCOM record.
84     *
85     * @return void
86     */
87    public function extractNames(): void
88    {
89        $this->getAllNames[] = [
90            'type'   => self::RECORD_TYPE,
91            'sort'   => I18N::translate('Header'),
92            'full'   => I18N::translate('Header'),
93            'fullNN' => I18N::translate('Header'),
94        ];
95    }
96}
97