xref: /webtrees/app/Repository.php (revision 1e71bdc0ba6fc5add8fed9a3beb51cfca09e47dd)
1<?php
2namespace Fisharebest\Webtrees;
3
4/**
5 * webtrees: online genealogy
6 * Copyright (C) 2015 webtrees development team
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * Class Repository - Class file for a Repository (REPO) object
21 */
22class Repository extends GedcomRecord {
23	const RECORD_TYPE = 'REPO';
24	const URL_PREFIX = 'repo.php?rid=';
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	 * @return Repository|null
36	 */
37	public static function getInstance($xref, Tree $tree, $gedcom = null) {
38		$record = parent::getInstance($xref, $tree, $gedcom);
39
40		if ($record instanceof Repository) {
41			return $record;
42		} else {
43			return null;
44		}
45	}
46
47	/** {@inheritdoc} */
48	protected static function fetchGedcomRecord($xref, $gedcom_id) {
49		static $statement = null;
50
51		if ($statement === null) {
52			$statement = Database::prepare("SELECT o_gedcom FROM `##other` WHERE o_id=? AND o_file=?");
53		}
54
55		return $statement->execute(array($xref, $gedcom_id))->fetchOne();
56	}
57
58	/** {@inheritdoc} */
59	protected function createPrivateGedcomRecord($access_level) {
60		return '0 @' . $this->xref . "@ REPO\n1 NAME " . I18N::translate('Private');
61	}
62
63	/** {@inheritdoc} */
64	public function extractNames() {
65		parent::extractNamesFromFacts(1, 'NAME', $this->getFacts('NAME'));
66	}
67}
68