1*1635452cSGreg Roach<?php 2*1635452cSGreg Roach 3*1635452cSGreg Roach/** 4*1635452cSGreg Roach * webtrees: online genealogy 5*1635452cSGreg Roach * Copyright (C) 2019 webtrees development team 6*1635452cSGreg Roach * This program is free software: you can redistribute it and/or modify 7*1635452cSGreg Roach * it under the terms of the GNU General Public License as published by 8*1635452cSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9*1635452cSGreg Roach * (at your option) any later version. 10*1635452cSGreg Roach * This program is distributed in the hope that it will be useful, 11*1635452cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*1635452cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*1635452cSGreg Roach * GNU General Public License for more details. 14*1635452cSGreg Roach * You should have received a copy of the GNU General Public License 15*1635452cSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16*1635452cSGreg Roach */ 17*1635452cSGreg Roach 18*1635452cSGreg Roachdeclare(strict_types=1); 19*1635452cSGreg Roach 20*1635452cSGreg Roachnamespace Fisharebest\Webtrees; 21*1635452cSGreg Roach 22*1635452cSGreg Roachuse Closure; 23*1635452cSGreg Roachuse Exception; 24*1635452cSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SubmissionPage; 25*1635452cSGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 26*1635452cSGreg Roachuse stdClass; 27*1635452cSGreg Roach 28*1635452cSGreg Roach/** 29*1635452cSGreg Roach * A GEDCOM submission (SUBN) object. 30*1635452cSGreg Roach * These records are only used when transferring data between two obsolete systems. 31*1635452cSGreg Roach * There is no need to create them - but we may encounter them in imported GEDCOM files. 32*1635452cSGreg Roach */ 33*1635452cSGreg Roachclass Submission extends GedcomRecord 34*1635452cSGreg Roach{ 35*1635452cSGreg Roach public const RECORD_TYPE = 'SUBN'; 36*1635452cSGreg Roach 37*1635452cSGreg Roach protected const ROUTE_NAME = SubmissionPage::class; 38*1635452cSGreg Roach 39*1635452cSGreg Roach /** 40*1635452cSGreg Roach * A closure which will create a record from a database row. 41*1635452cSGreg Roach * 42*1635452cSGreg Roach * @param Tree $tree 43*1635452cSGreg Roach * 44*1635452cSGreg Roach * @return Closure 45*1635452cSGreg Roach */ 46*1635452cSGreg Roach public static function rowMapper(Tree $tree): Closure 47*1635452cSGreg Roach { 48*1635452cSGreg Roach return static function (stdClass $row) use ($tree): Submission { 49*1635452cSGreg Roach $submission = Submission::getInstance($row->o_id, $tree, $row->o_gedcom); 50*1635452cSGreg Roach assert($submission instanceof Submission); 51*1635452cSGreg Roach 52*1635452cSGreg Roach return $submission; 53*1635452cSGreg Roach }; 54*1635452cSGreg Roach } 55*1635452cSGreg Roach 56*1635452cSGreg Roach /** 57*1635452cSGreg Roach * Get an instance of a submission object. For single records, 58*1635452cSGreg Roach * we just receive the XREF. For bulk records (such as lists 59*1635452cSGreg Roach * and search results) we can receive the GEDCOM data as well. 60*1635452cSGreg Roach * 61*1635452cSGreg Roach * @param string $xref 62*1635452cSGreg Roach * @param Tree $tree 63*1635452cSGreg Roach * @param string|null $gedcom 64*1635452cSGreg Roach * 65*1635452cSGreg Roach * @throws Exception 66*1635452cSGreg Roach * 67*1635452cSGreg Roach * @return Submission|null 68*1635452cSGreg Roach */ 69*1635452cSGreg Roach public static function getInstance(string $xref, Tree $tree, string $gedcom = null): ?Submission 70*1635452cSGreg Roach { 71*1635452cSGreg Roach $record = parent::getInstance($xref, $tree, $gedcom); 72*1635452cSGreg Roach 73*1635452cSGreg Roach if ($record instanceof self) { 74*1635452cSGreg Roach return $record; 75*1635452cSGreg Roach } 76*1635452cSGreg Roach 77*1635452cSGreg Roach return null; 78*1635452cSGreg Roach } 79*1635452cSGreg Roach 80*1635452cSGreg Roach /** 81*1635452cSGreg Roach * Fetch data from the database 82*1635452cSGreg Roach * 83*1635452cSGreg Roach * @param string $xref 84*1635452cSGreg Roach * @param int $tree_id 85*1635452cSGreg Roach * 86*1635452cSGreg Roach * @return string|null 87*1635452cSGreg Roach */ 88*1635452cSGreg Roach protected static function fetchGedcomRecord(string $xref, int $tree_id): ?string 89*1635452cSGreg Roach { 90*1635452cSGreg Roach return DB::table('other') 91*1635452cSGreg Roach ->where('o_id', '=', $xref) 92*1635452cSGreg Roach ->where('o_file', '=', $tree_id) 93*1635452cSGreg Roach ->where('o_type', '=', self::RECORD_TYPE) 94*1635452cSGreg Roach ->value('o_gedcom'); 95*1635452cSGreg Roach } 96*1635452cSGreg Roach 97*1635452cSGreg Roach /** 98*1635452cSGreg Roach * Generate a private version of this record 99*1635452cSGreg Roach * 100*1635452cSGreg Roach * @param int $access_level 101*1635452cSGreg Roach * 102*1635452cSGreg Roach * @return string 103*1635452cSGreg Roach */ 104*1635452cSGreg Roach protected function createPrivateGedcomRecord(int $access_level): string 105*1635452cSGreg Roach { 106*1635452cSGreg Roach return '0 @' . $this->xref . "@ SUBM\n1 NAME " . I18N::translate('Private'); 107*1635452cSGreg Roach } 108*1635452cSGreg Roach /** 109*1635452cSGreg Roach * Extract names from the GEDCOM record. 110*1635452cSGreg Roach * 111*1635452cSGreg Roach * @return void 112*1635452cSGreg Roach */ 113*1635452cSGreg Roach public function extractNames(): void 114*1635452cSGreg Roach { 115*1635452cSGreg Roach $this->getAllNames[] = [ 116*1635452cSGreg Roach 'type' => self::RECORD_TYPE, 117*1635452cSGreg Roach 'sort' => I18N::translate('Submission'), 118*1635452cSGreg Roach 'full' => I18N::translate('Submission'), 119*1635452cSGreg Roach 'fullNN' => I18N::translate('Submission'), 120*1635452cSGreg Roach ]; 121*1635452cSGreg Roach } 122*1635452cSGreg Roach} 123