xref: /webtrees/app/Submission.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\SubmissionPage;
251635452cSGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
261635452cSGreg Roach
271635452cSGreg Roach/**
281635452cSGreg Roach * A GEDCOM submission (SUBN) object.
291635452cSGreg Roach * These records are only used when transferring data between two obsolete systems.
301635452cSGreg Roach * There is no need to create them - but we may encounter them in imported GEDCOM files.
311635452cSGreg Roach */
321635452cSGreg Roachclass Submission extends GedcomRecord
331635452cSGreg Roach{
341635452cSGreg Roach    public const RECORD_TYPE = 'SUBN';
351635452cSGreg Roach
361635452cSGreg Roach    protected const ROUTE_NAME = SubmissionPage::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::submission()
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::submission()->mapper($tree);
501635452cSGreg Roach    }
511635452cSGreg Roach
521635452cSGreg Roach    /**
531635452cSGreg Roach     * Get an instance of a submission 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     *
571635452cSGreg Roach     * @param string      $xref
581635452cSGreg Roach     * @param Tree        $tree
591635452cSGreg Roach     * @param string|null $gedcom
601635452cSGreg Roach     *
61*bb03c9f0SGreg Roach     * @deprecated since 2.0.4.  Will be removed in 2.1.0 - Use Factory::submission()
621635452cSGreg Roach     *
631635452cSGreg Roach     * @return Submission|null
641635452cSGreg Roach     */
651635452cSGreg Roach    public static function getInstance(string $xref, Tree $tree, string $gedcom = null): ?Submission
661635452cSGreg Roach    {
67*bb03c9f0SGreg Roach        return Factory::submission()->make($xref, $tree, $gedcom);
681635452cSGreg Roach    }
691635452cSGreg Roach
701635452cSGreg Roach    /**
711635452cSGreg Roach     * Fetch data from the database
721635452cSGreg Roach     *
731635452cSGreg Roach     * @param string $xref
741635452cSGreg Roach     * @param int    $tree_id
751635452cSGreg Roach     *
761635452cSGreg Roach     * @return string|null
771635452cSGreg Roach     */
781635452cSGreg Roach    protected static function fetchGedcomRecord(string $xref, int $tree_id): ?string
791635452cSGreg Roach    {
801635452cSGreg Roach        return DB::table('other')
811635452cSGreg Roach            ->where('o_id', '=', $xref)
821635452cSGreg Roach            ->where('o_file', '=', $tree_id)
831635452cSGreg Roach            ->where('o_type', '=', self::RECORD_TYPE)
841635452cSGreg Roach            ->value('o_gedcom');
851635452cSGreg Roach    }
861635452cSGreg Roach
871635452cSGreg Roach    /**
881635452cSGreg Roach     * Generate a private version of this record
891635452cSGreg Roach     *
901635452cSGreg Roach     * @param int $access_level
911635452cSGreg Roach     *
921635452cSGreg Roach     * @return string
931635452cSGreg Roach     */
941635452cSGreg Roach    protected function createPrivateGedcomRecord(int $access_level): string
951635452cSGreg Roach    {
961635452cSGreg Roach        return '0 @' . $this->xref . "@ SUBM\n1 NAME " . I18N::translate('Private');
971635452cSGreg Roach    }
981635452cSGreg Roach    /**
991635452cSGreg Roach     * Extract names from the GEDCOM record.
1001635452cSGreg Roach     *
1011635452cSGreg Roach     * @return void
1021635452cSGreg Roach     */
1031635452cSGreg Roach    public function extractNames(): void
1041635452cSGreg Roach    {
1051635452cSGreg Roach        $this->getAllNames[] = [
1061635452cSGreg Roach            'type'   => self::RECORD_TYPE,
1071635452cSGreg Roach            'sort'   => I18N::translate('Submission'),
1081635452cSGreg Roach            'full'   => I18N::translate('Submission'),
1091635452cSGreg Roach            'fullNN' => I18N::translate('Submission'),
1101635452cSGreg Roach        ];
1111635452cSGreg Roach    }
1121635452cSGreg Roach}
113