11635452cSGreg Roach<?php 21635452cSGreg Roach 31635452cSGreg Roach/** 41635452cSGreg Roach * webtrees: online genealogy 5*89f7189bSGreg Roach * Copyright (C) 2021 webtrees development team 61635452cSGreg Roach * This program is free software: you can redistribute it and/or modify 71635452cSGreg Roach * it under the terms of the GNU General Public License as published by 81635452cSGreg Roach * the Free Software Foundation, either version 3 of the License, or 91635452cSGreg Roach * (at your option) any later version. 101635452cSGreg Roach * This program is distributed in the hope that it will be useful, 111635452cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 121635452cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 131635452cSGreg Roach * GNU General Public License for more details. 141635452cSGreg Roach * You should have received a copy of the GNU General Public License 15*89f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 161635452cSGreg Roach */ 171635452cSGreg Roach 181635452cSGreg Roachdeclare(strict_types=1); 191635452cSGreg Roach 201635452cSGreg Roachnamespace Fisharebest\Webtrees; 211635452cSGreg Roach 221635452cSGreg Roachuse Closure; 231635452cSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SubmissionPage; 241635452cSGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 251635452cSGreg Roach 261635452cSGreg Roach/** 271635452cSGreg Roach * A GEDCOM submission (SUBN) object. 281635452cSGreg Roach * These records are only used when transferring data between two obsolete systems. 291635452cSGreg Roach * There is no need to create them - but we may encounter them in imported GEDCOM files. 301635452cSGreg Roach */ 311635452cSGreg Roachclass Submission extends GedcomRecord 321635452cSGreg Roach{ 331635452cSGreg Roach public const RECORD_TYPE = 'SUBN'; 341635452cSGreg Roach 351635452cSGreg Roach protected const ROUTE_NAME = SubmissionPage::class; 361635452cSGreg Roach 371635452cSGreg Roach /** 381635452cSGreg Roach * A closure which will create a record from a database row. 391635452cSGreg Roach * 40bb03c9f0SGreg Roach * @deprecated since 2.0.4. Will be removed in 2.1.0 - Use Factory::submission() 41bb03c9f0SGreg Roach * 421635452cSGreg Roach * @param Tree $tree 431635452cSGreg Roach * 441635452cSGreg Roach * @return Closure 451635452cSGreg Roach */ 461635452cSGreg Roach public static function rowMapper(Tree $tree): Closure 471635452cSGreg Roach { 486b9cb339SGreg Roach return Registry::submissionFactory()->mapper($tree); 491635452cSGreg Roach } 501635452cSGreg Roach 511635452cSGreg Roach /** 521635452cSGreg Roach * Get an instance of a submission object. For single records, 531635452cSGreg Roach * we just receive the XREF. For bulk records (such as lists 541635452cSGreg Roach * and search results) we can receive the GEDCOM data as well. 551635452cSGreg Roach * 561635452cSGreg Roach * @param string $xref 571635452cSGreg Roach * @param Tree $tree 581635452cSGreg Roach * @param string|null $gedcom 591635452cSGreg Roach * 60bb03c9f0SGreg Roach * @deprecated since 2.0.4. Will be removed in 2.1.0 - Use Factory::submission() 611635452cSGreg Roach * 621635452cSGreg Roach * @return Submission|null 631635452cSGreg Roach */ 641635452cSGreg Roach public static function getInstance(string $xref, Tree $tree, string $gedcom = null): ?Submission 651635452cSGreg Roach { 666b9cb339SGreg Roach return Registry::submissionFactory()->make($xref, $tree, $gedcom); 671635452cSGreg Roach } 681635452cSGreg Roach 691635452cSGreg Roach /** 701635452cSGreg Roach * Fetch data from the database 711635452cSGreg Roach * 721635452cSGreg Roach * @param string $xref 731635452cSGreg Roach * @param int $tree_id 741635452cSGreg Roach * 751635452cSGreg Roach * @return string|null 761635452cSGreg Roach */ 771635452cSGreg Roach protected static function fetchGedcomRecord(string $xref, int $tree_id): ?string 781635452cSGreg Roach { 791635452cSGreg Roach return DB::table('other') 801635452cSGreg Roach ->where('o_id', '=', $xref) 811635452cSGreg Roach ->where('o_file', '=', $tree_id) 8202467d32SGreg Roach ->where('o_type', '=', static::RECORD_TYPE) 831635452cSGreg Roach ->value('o_gedcom'); 841635452cSGreg Roach } 851635452cSGreg Roach 861635452cSGreg Roach /** 871635452cSGreg Roach * Generate a private version of this record 881635452cSGreg Roach * 891635452cSGreg Roach * @param int $access_level 901635452cSGreg Roach * 911635452cSGreg Roach * @return string 921635452cSGreg Roach */ 931635452cSGreg Roach protected function createPrivateGedcomRecord(int $access_level): string 941635452cSGreg Roach { 951635452cSGreg Roach return '0 @' . $this->xref . "@ SUBM\n1 NAME " . I18N::translate('Private'); 961635452cSGreg Roach } 971635452cSGreg Roach /** 981635452cSGreg Roach * Extract names from the GEDCOM record. 991635452cSGreg Roach * 1001635452cSGreg Roach * @return void 1011635452cSGreg Roach */ 1021635452cSGreg Roach public function extractNames(): void 1031635452cSGreg Roach { 1041635452cSGreg Roach $this->getAllNames[] = [ 10502467d32SGreg Roach 'type' => static::RECORD_TYPE, 1061635452cSGreg Roach 'sort' => I18N::translate('Submission'), 1071635452cSGreg Roach 'full' => I18N::translate('Submission'), 1081635452cSGreg Roach 'fullNN' => I18N::translate('Submission'), 1091635452cSGreg Roach ]; 1101635452cSGreg Roach } 1111635452cSGreg Roach} 112