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 */ 16namespace Fisharebest\Webtrees; 17 18/** 19 * A GEDCOM repository (REPO) object. 20 */ 21class Repository extends GedcomRecord 22{ 23 const RECORD_TYPE = 'REPO'; 24 const ROUTE_NAME = 'repository'; 25 26 /** 27 * Get an instance of a repository object. For single records, 28 * we just receive the XREF. For bulk records (such as lists 29 * and search results) we can receive the GEDCOM data as well. 30 * 31 * @param string $xref 32 * @param Tree $tree 33 * @param string|null $gedcom 34 * 35 * @throws \Exception 36 * 37 * @return Repository|null 38 */ 39 public static function getInstance(string $xref, Tree $tree, string $gedcom = null) 40 { 41 $record = parent::getInstance($xref, $tree, $gedcom); 42 43 if ($record instanceof Repository) { 44 return $record; 45 } else { 46 return null; 47 } 48 } 49 50 /** 51 * Fetch data from the database 52 * 53 * @param string $xref 54 * @param int $tree_id 55 * 56 * @return null|string 57 */ 58 protected static function fetchGedcomRecord(string $xref, int $tree_id) 59 { 60 return Database::prepare( 61 "SELECT o_gedcom FROM `##other` WHERE o_id = :xref AND o_file = :tree_id AND o_type = 'REPO'" 62 )->execute([ 63 'xref' => $xref, 64 'tree_id' => $tree_id, 65 ])->fetchOne(); 66 } 67 68 /** 69 * Generate a private version of this record 70 * 71 * @param int $access_level 72 * 73 * @return string 74 */ 75 protected function createPrivateGedcomRecord($access_level): string 76 { 77 return '0 @' . $this->xref . "@ REPO\n1 NAME " . I18N::translate('Private'); 78 } 79 80 /** 81 * Extract names from the GEDCOM record. 82 * 83 * @return void 84 */ 85 public function extractNames() 86 { 87 parent::extractNamesFromFacts(1, 'NAME', $this->getFacts('NAME')); 88 } 89} 90