xref: /webtrees/app/Submission.php (revision 24f2a3af38709f9bf0a739b30264240d20ba34e8)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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;
21
22use Closure;
23use Fisharebest\Webtrees\Http\RequestHandlers\SubmissionPage;
24use Illuminate\Database\Capsule\Manager as DB;
25
26/**
27 * A GEDCOM submission (SUBN) object.
28 * These records are only used when transferring data between two obsolete systems.
29 * There is no need to create them - but we may encounter them in imported GEDCOM files.
30 */
31class Submission extends GedcomRecord
32{
33    public const RECORD_TYPE = 'SUBN';
34
35    protected const ROUTE_NAME = SubmissionPage::class;
36
37    /**
38     * A closure which will create a record from a database row.
39     *
40     * @deprecated since 2.0.4.  Will be removed in 2.1.0 - Use Registry::submissionFactory()
41     *
42     * @param Tree $tree
43     *
44     * @return Closure
45     */
46    public static function rowMapper(Tree $tree): Closure
47    {
48        return Registry::submissionFactory()->mapper($tree);
49    }
50
51    /**
52     * Get an instance of a submission object. For single records,
53     * we just receive the XREF. For bulk records (such as lists
54     * and search results) we can receive the GEDCOM data as well.
55     *
56     * @param string      $xref
57     * @param Tree        $tree
58     * @param string|null $gedcom
59     *
60     * @deprecated since 2.0.4.  Will be removed in 2.1.0 - Use Registry::submissionFactory()
61     *
62     * @return Submission|null
63     */
64    public static function getInstance(string $xref, Tree $tree, string $gedcom = null): ?Submission
65    {
66        return Registry::submissionFactory()->make($xref, $tree, $gedcom);
67    }
68
69    /**
70     * Fetch data from the database
71     *
72     * @param string $xref
73     * @param int    $tree_id
74     *
75     * @return string|null
76     */
77    protected static function fetchGedcomRecord(string $xref, int $tree_id): ?string
78    {
79        return DB::table('other')
80            ->where('o_id', '=', $xref)
81            ->where('o_file', '=', $tree_id)
82            ->where('o_type', '=', static::RECORD_TYPE)
83            ->value('o_gedcom');
84    }
85
86    /**
87     * Extract names from the GEDCOM record.
88     *
89     * @return void
90     */
91    public function extractNames(): void
92    {
93        $this->getAllNames[] = [
94            'type'   => static::RECORD_TYPE,
95            'sort'   => I18N::translate('Submission'),
96            'full'   => I18N::translate('Submission'),
97            'fullNN' => I18N::translate('Submission'),
98        ];
99    }
100}
101