1a25f0a04SGreg Roach<?php 2a25f0a04SGreg Roach/** 3a25f0a04SGreg Roach * webtrees: online genealogy 41062a142SGreg Roach * Copyright (C) 2018 webtrees development team 5a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 6a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 7a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 8a25f0a04SGreg Roach * (at your option) any later version. 9a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 10a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12a25f0a04SGreg Roach * GNU General Public License for more details. 13a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License 14a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15a25f0a04SGreg Roach */ 1676692c8bSGreg Roachnamespace Fisharebest\Webtrees; 17a25f0a04SGreg Roach 18a25f0a04SGreg Roach/** 1976692c8bSGreg Roach * A GEDCOM repository (REPO) object. 20a25f0a04SGreg Roach */ 21*c1010edaSGreg Roachclass Repository extends GedcomRecord 22*c1010edaSGreg Roach{ 23a25f0a04SGreg Roach const RECORD_TYPE = 'REPO'; 24225e381fSGreg Roach const ROUTE_NAME = 'repository'; 25a25f0a04SGreg Roach 2676692c8bSGreg Roach /** 27e71ef9d2SGreg Roach * Get an instance of a repository object. For single records, 28e71ef9d2SGreg Roach * we just receive the XREF. For bulk records (such as lists 29e71ef9d2SGreg Roach * and search results) we can receive the GEDCOM data as well. 30e71ef9d2SGreg Roach * 31e71ef9d2SGreg Roach * @param string $xref 32e71ef9d2SGreg Roach * @param Tree $tree 33e71ef9d2SGreg Roach * @param string|null $gedcom 34e71ef9d2SGreg Roach * 35e71ef9d2SGreg Roach * @throws \Exception 36e71ef9d2SGreg Roach * 37e71ef9d2SGreg Roach * @return Repository|null 38e71ef9d2SGreg Roach */ 39*c1010edaSGreg Roach public static function getInstance($xref, Tree $tree, $gedcom = null) 40*c1010edaSGreg Roach { 41e71ef9d2SGreg Roach $record = parent::getInstance($xref, $tree, $gedcom); 42e71ef9d2SGreg Roach 43e71ef9d2SGreg Roach if ($record instanceof Repository) { 44e71ef9d2SGreg Roach return $record; 45e71ef9d2SGreg Roach } else { 46e71ef9d2SGreg Roach return null; 47e71ef9d2SGreg Roach } 48e71ef9d2SGreg Roach } 49e71ef9d2SGreg Roach 50e71ef9d2SGreg Roach /** 5176692c8bSGreg Roach * Fetch data from the database 5276692c8bSGreg Roach * 5376692c8bSGreg Roach * @param string $xref 5476692c8bSGreg Roach * @param int $tree_id 5576692c8bSGreg Roach * 5676692c8bSGreg Roach * @return null|string 5776692c8bSGreg Roach */ 58*c1010edaSGreg Roach protected static function fetchGedcomRecord($xref, $tree_id) 59*c1010edaSGreg Roach { 6064d9078aSGreg Roach return Database::prepare( 6164d9078aSGreg Roach "SELECT o_gedcom FROM `##other` WHERE o_id = :xref AND o_file = :tree_id AND o_type = 'REPO'" 6213abd6f3SGreg Roach )->execute([ 6364d9078aSGreg Roach 'xref' => $xref, 6464d9078aSGreg Roach 'tree_id' => $tree_id, 6513abd6f3SGreg Roach ])->fetchOne(); 66a25f0a04SGreg Roach } 67a25f0a04SGreg Roach 6876692c8bSGreg Roach /** 6976692c8bSGreg Roach * Generate a private version of this record 7076692c8bSGreg Roach * 7176692c8bSGreg Roach * @param int $access_level 7276692c8bSGreg Roach * 7376692c8bSGreg Roach * @return string 7476692c8bSGreg Roach */ 75*c1010edaSGreg Roach protected function createPrivateGedcomRecord($access_level) 76*c1010edaSGreg Roach { 77a25f0a04SGreg Roach return '0 @' . $this->xref . "@ REPO\n1 NAME " . I18N::translate('Private'); 78a25f0a04SGreg Roach } 79a25f0a04SGreg Roach 8076692c8bSGreg Roach /** 8176692c8bSGreg Roach * Extract names from the GEDCOM record. 8276692c8bSGreg Roach */ 83*c1010edaSGreg Roach public function extractNames() 84*c1010edaSGreg Roach { 8536a0c51dSGreg Roach parent::extractNamesFromFacts(1, 'NAME', $this->getFacts('NAME')); 86a25f0a04SGreg Roach } 87a25f0a04SGreg Roach} 88