-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MVP bugfix SUBM/SUBN is not exported in HEAD. Fixes #9
- Loading branch information
1 parent
6957e8e
commit 40d7406
Showing
3 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/** | ||
* webtrees: online genealogy | ||
* Copyright (C) 2023 webtrees development team | ||
* <http://webtrees.net> | ||
* DownloadGedcomWithURL (webtrees custom module): | ||
* Copyright (C) 2023 Markus Hemprich | ||
* <http://www.familienforschung-hemprich.de> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jefferson49\Webtrees\Module\DownloadGedcomWithURL; | ||
|
||
use Fisharebest\Webtrees\Auth; | ||
use Fisharebest\Webtrees\Header; | ||
use Fisharebest\Webtrees\Registry; | ||
use Fisharebest\Webtrees\Services\GedcomExportService; | ||
use Fisharebest\Webtrees\Tree; | ||
|
||
|
||
/** | ||
* Export data in GEDCOM format | ||
*/ | ||
class RemoteGedcomExportService extends GedcomExportService | ||
{ | ||
/** | ||
* Create a header record for a GEDCOM file, which exports SUBM/SUBN even if no user is logged in | ||
* | ||
* @param Tree $tree | ||
* @param string $encoding | ||
* @param bool $include_sub | ||
* | ||
* @return string | ||
*/ | ||
public function createHeader(Tree $tree, string $encoding, bool $include_sub, int $access_level = null): string | ||
{ | ||
//Take GEDCOM from parent method as a base | ||
$gedcom = parent::createHeader($tree, $encoding, $include_sub); | ||
|
||
$header = Registry::headerFactory()->make('HEAD', $tree) ?? Registry::headerFactory()->new('HEAD', '0 HEAD', null, $tree); | ||
|
||
if ($header instanceof Header) { | ||
|
||
if ($include_sub) { | ||
|
||
//Apply access level of 'none', because the GEDCOM standard requires to include a submitter and export needs to be consistent if a submitter/submission exists | ||
//Privacy of the submitter/submission is handled in the submitter/submission object itself | ||
foreach ($header->facts(['SUBM', 'SUBN'], false, Auth::PRIV_HIDE) as $fact) { | ||
|
||
//Add submitter/submission if the parent method did not find it, because of access rights | ||
if (!str_contains($gedcom, "\n1 " . substr($fact->tag(), -4, 4))) { | ||
$gedcom .= "\n" . $fact->gedcom(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return $gedcom; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters