1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2018 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16declare(strict_types=1); 17 18namespace Fisharebest\Webtrees; 19 20use Illuminate\Database\Capsule\Manager as DB; 21 22/** 23 * A GEDCOM repository (REPO) object. 24 */ 25class Repository extends GedcomRecord 26{ 27 const RECORD_TYPE = 'REPO'; 28 const ROUTE_NAME = 'repository'; 29 30 /** 31 * Get an instance of a repository object. For single records, 32 * we just receive the XREF. For bulk records (such as lists 33 * and search results) we can receive the GEDCOM data as well. 34 * 35 * @param string $xref 36 * @param Tree $tree 37 * @param string|null $gedcom 38 * 39 * @throws \Exception 40 * 41 * @return Repository|null 42 */ 43 public static function getInstance(string $xref, Tree $tree, string $gedcom = null) 44 { 45 $record = parent::getInstance($xref, $tree, $gedcom); 46 47 if ($record instanceof Repository) { 48 return $record; 49 } 50 51 return null; 52 } 53 54 /** 55 * Fetch data from the database 56 * 57 * @param string $xref 58 * @param int $tree_id 59 * 60 * @return null|string 61 */ 62 protected static function fetchGedcomRecord(string $xref, int $tree_id) 63 { 64 return DB::table('other') 65 ->where('o_id', '=', $xref) 66 ->where('o_file', '=', $tree_id) 67 ->where('o_type', '=', self::RECORD_TYPE) 68 ->value('o_gedcom'); 69 } 70 71 /** 72 * Generate a private version of this record 73 * 74 * @param int $access_level 75 * 76 * @return string 77 */ 78 protected function createPrivateGedcomRecord(int $access_level): string 79 { 80 return '0 @' . $this->xref . "@ REPO\n1 NAME " . I18N::translate('Private'); 81 } 82 83 /** 84 * Extract names from the GEDCOM record. 85 * 86 * @return void 87 */ 88 public function extractNames() 89 { 90 parent::extractNamesFromFacts(1, 'NAME', $this->facts(['NAME'])); 91 } 92} 93