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