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