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 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 Factory::submission() 41 * 42 * @param Tree $tree 43 * 44 * @return Closure 45 */ 46 public static function rowMapper(Tree $tree): Closure 47 { 48 return Factory::submission()->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 Factory::submission() 61 * 62 * @return Submission|null 63 */ 64 public static function getInstance(string $xref, Tree $tree, string $gedcom = null): ?Submission 65 { 66 return Factory::submission()->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', '=', self::RECORD_TYPE) 83 ->value('o_gedcom'); 84 } 85 86 /** 87 * Generate a private version of this record 88 * 89 * @param int $access_level 90 * 91 * @return string 92 */ 93 protected function createPrivateGedcomRecord(int $access_level): string 94 { 95 return '0 @' . $this->xref . "@ SUBM\n1 NAME " . I18N::translate('Private'); 96 } 97 /** 98 * Extract names from the GEDCOM record. 99 * 100 * @return void 101 */ 102 public function extractNames(): void 103 { 104 $this->getAllNames[] = [ 105 'type' => self::RECORD_TYPE, 106 'sort' => I18N::translate('Submission'), 107 'full' => I18N::translate('Submission'), 108 'fullNN' => I18N::translate('Submission'), 109 ]; 110 } 111} 112