xref: /webtrees/app/Header.php (revision bb03c9f048b83092098d5e46c2ab323ae7e2b314)
11635452cSGreg Roach<?php
21635452cSGreg Roach
31635452cSGreg Roach/**
41635452cSGreg Roach * webtrees: online genealogy
51635452cSGreg Roach * Copyright (C) 2019 webtrees development team
61635452cSGreg Roach * This program is free software: you can redistribute it and/or modify
71635452cSGreg Roach * it under the terms of the GNU General Public License as published by
81635452cSGreg Roach * the Free Software Foundation, either version 3 of the License, or
91635452cSGreg Roach * (at your option) any later version.
101635452cSGreg Roach * This program is distributed in the hope that it will be useful,
111635452cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
121635452cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
131635452cSGreg Roach * GNU General Public License for more details.
141635452cSGreg Roach * You should have received a copy of the GNU General Public License
151635452cSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
161635452cSGreg Roach */
171635452cSGreg Roach
181635452cSGreg Roachdeclare(strict_types=1);
191635452cSGreg Roach
201635452cSGreg Roachnamespace Fisharebest\Webtrees;
211635452cSGreg Roach
221635452cSGreg Roachuse Closure;
231635452cSGreg Roachuse Exception;
241635452cSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\HeaderPage;
251635452cSGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
261635452cSGreg Roach
27*bb03c9f0SGreg Roachuse function app;
281635452cSGreg Roach
291635452cSGreg Roach/**
301635452cSGreg Roach * A GEDCOM header (HEAD) object.
311635452cSGreg Roach */
321635452cSGreg Roachclass Header extends GedcomRecord
331635452cSGreg Roach{
341635452cSGreg Roach    public const RECORD_TYPE = 'HEAD';
351635452cSGreg Roach
361635452cSGreg Roach    protected const ROUTE_NAME = HeaderPage::class;
371635452cSGreg Roach
381635452cSGreg Roach    /**
391635452cSGreg Roach     * A closure which will create a record from a database row.
401635452cSGreg Roach     *
41*bb03c9f0SGreg Roach     * @deprecated since 2.0.4.  Will be removed in 2.1.0 - Use Factory::header()
42*bb03c9f0SGreg Roach     *
431635452cSGreg Roach     * @param Tree $tree
441635452cSGreg Roach     *
451635452cSGreg Roach     * @return Closure
461635452cSGreg Roach     */
471635452cSGreg Roach    public static function rowMapper(Tree $tree): Closure
481635452cSGreg Roach    {
49*bb03c9f0SGreg Roach        return Factory::header()->mapper($tree);
501635452cSGreg Roach    }
511635452cSGreg Roach
521635452cSGreg Roach    /**
531635452cSGreg Roach     * Get an instance of a header object. For single records,
541635452cSGreg Roach     * we just receive the XREF. For bulk records (such as lists
551635452cSGreg Roach     * and search results) we can receive the GEDCOM data as well.
561635452cSGreg Roach     *
57*bb03c9f0SGreg Roach     * @deprecated since 2.0.4.  Will be removed in 2.1.0 - Use Factory::header()
58*bb03c9f0SGreg Roach     *
591635452cSGreg Roach     * @param string      $xref
601635452cSGreg Roach     * @param Tree        $tree
611635452cSGreg Roach     * @param string|null $gedcom
621635452cSGreg Roach     *
631635452cSGreg Roach     * @return Header|null
641635452cSGreg Roach     */
651635452cSGreg Roach    public static function getInstance(string $xref, Tree $tree, string $gedcom = null): ?Header
661635452cSGreg Roach    {
67*bb03c9f0SGreg Roach        return Factory::header()->make($xref, $tree, $gedcom);
681635452cSGreg Roach    }
691635452cSGreg Roach
701635452cSGreg Roach    /**
711635452cSGreg Roach     * Generate a private version of this record
721635452cSGreg Roach     *
731635452cSGreg Roach     * @param int $access_level
741635452cSGreg Roach     *
751635452cSGreg Roach     * @return string
761635452cSGreg Roach     */
771635452cSGreg Roach    protected function createPrivateGedcomRecord(int $access_level): string
781635452cSGreg Roach    {
79*bb03c9f0SGreg Roach        return '0 HEAD' . $this->xref . "@ SUBM\n1 NAME " . I18N::translate('Private');
801635452cSGreg Roach    }
811635452cSGreg Roach
821635452cSGreg Roach    /**
831635452cSGreg Roach     * Extract names from the GEDCOM record.
841635452cSGreg Roach     *
851635452cSGreg Roach     * @return void
861635452cSGreg Roach     */
871635452cSGreg Roach    public function extractNames(): void
881635452cSGreg Roach    {
891635452cSGreg Roach        $this->getAllNames[] = [
901635452cSGreg Roach            'type'   => self::RECORD_TYPE,
911635452cSGreg Roach            'sort'   => I18N::translate('Header'),
921635452cSGreg Roach            'full'   => I18N::translate('Header'),
931635452cSGreg Roach            'fullNN' => I18N::translate('Header'),
941635452cSGreg Roach        ];
951635452cSGreg Roach    }
961635452cSGreg Roach}
97