1*6fd01894SGreg Roach<?php 2*6fd01894SGreg Roach 3*6fd01894SGreg Roach/** 4*6fd01894SGreg Roach * webtrees: online genealogy 5*6fd01894SGreg Roach * Copyright (C) 2020 webtrees development team 6*6fd01894SGreg Roach * This program is free software: you can redistribute it and/or modify 7*6fd01894SGreg Roach * it under the terms of the GNU General Public License as published by 8*6fd01894SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9*6fd01894SGreg Roach * (at your option) any later version. 10*6fd01894SGreg Roach * This program is distributed in the hope that it will be useful, 11*6fd01894SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*6fd01894SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*6fd01894SGreg Roach * GNU General Public License for more details. 14*6fd01894SGreg Roach * You should have received a copy of the GNU General Public License 15*6fd01894SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16*6fd01894SGreg Roach */ 17*6fd01894SGreg Roach 18*6fd01894SGreg Roachdeclare(strict_types=1); 19*6fd01894SGreg Roach 20*6fd01894SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21*6fd01894SGreg Roach 22*6fd01894SGreg Roachuse Fisharebest\Webtrees\Auth; 23*6fd01894SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 24*6fd01894SGreg Roachuse Fisharebest\Webtrees\Date; 25*6fd01894SGreg Roachuse Fisharebest\Webtrees\Factory; 26*6fd01894SGreg Roachuse Fisharebest\Webtrees\GedcomTag; 27*6fd01894SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 28*6fd01894SGreg Roachuse Fisharebest\Webtrees\I18N; 29*6fd01894SGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface; 30*6fd01894SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 31*6fd01894SGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 32*6fd01894SGreg Roachuse Fisharebest\Webtrees\Services\UserService; 33*6fd01894SGreg Roachuse Fisharebest\Webtrees\SurnameTradition; 34*6fd01894SGreg Roachuse Fisharebest\Webtrees\Tree; 35*6fd01894SGreg Roachuse Psr\Http\Message\ResponseInterface; 36*6fd01894SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 37*6fd01894SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 38*6fd01894SGreg Roach 39*6fd01894SGreg Roachuse function app; 40*6fd01894SGreg Roachuse function array_merge; 41*6fd01894SGreg Roachuse function array_unique; 42*6fd01894SGreg Roachuse function assert; 43*6fd01894SGreg Roachuse function e; 44*6fd01894SGreg Roachuse function explode; 45*6fd01894SGreg Roachuse function uasort; 46*6fd01894SGreg Roach 47*6fd01894SGreg Roach/** 48*6fd01894SGreg Roach * Edit the tree preferences. 49*6fd01894SGreg Roach */ 50*6fd01894SGreg Roachclass TreePreferencesPage implements RequestHandlerInterface 51*6fd01894SGreg Roach{ 52*6fd01894SGreg Roach use ViewResponseTrait; 53*6fd01894SGreg Roach 54*6fd01894SGreg Roach /** @var ModuleService */ 55*6fd01894SGreg Roach private $module_service; 56*6fd01894SGreg Roach 57*6fd01894SGreg Roach /** @var TreeService */ 58*6fd01894SGreg Roach private $tree_service; 59*6fd01894SGreg Roach 60*6fd01894SGreg Roach /** @var UserService */ 61*6fd01894SGreg Roach private $user_service; 62*6fd01894SGreg Roach 63*6fd01894SGreg Roach public function __construct( 64*6fd01894SGreg Roach ModuleService $module_service, 65*6fd01894SGreg Roach TreeService $tree_service, 66*6fd01894SGreg Roach UserService $user_service 67*6fd01894SGreg Roach ) { 68*6fd01894SGreg Roach $this->module_service = $module_service; 69*6fd01894SGreg Roach $this->tree_service = $tree_service; 70*6fd01894SGreg Roach $this->user_service = $user_service; 71*6fd01894SGreg Roach } 72*6fd01894SGreg Roach 73*6fd01894SGreg Roach /** 74*6fd01894SGreg Roach * @param ServerRequestInterface $request 75*6fd01894SGreg Roach * 76*6fd01894SGreg Roach * @return ResponseInterface 77*6fd01894SGreg Roach */ 78*6fd01894SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 79*6fd01894SGreg Roach { 80*6fd01894SGreg Roach $this->layout = 'layouts/administration'; 81*6fd01894SGreg Roach 82*6fd01894SGreg Roach $tree = $request->getAttribute('tree'); 83*6fd01894SGreg Roach assert($tree instanceof Tree); 84*6fd01894SGreg Roach 85*6fd01894SGreg Roach $data_folder = Factory::filesystem()->dataName(); 86*6fd01894SGreg Roach 87*6fd01894SGreg Roach $french_calendar_start = new Date('22 SEP 1792'); 88*6fd01894SGreg Roach $french_calendar_end = new Date('31 DEC 1805'); 89*6fd01894SGreg Roach $gregorian_calendar_start = new Date('15 OCT 1582'); 90*6fd01894SGreg Roach 91*6fd01894SGreg Roach $surname_list_styles = [ 92*6fd01894SGreg Roach /* I18N: Layout option for lists of names */ 93*6fd01894SGreg Roach 'style1' => I18N::translate('list'), 94*6fd01894SGreg Roach /* I18N: Layout option for lists of names */ 95*6fd01894SGreg Roach 'style2' => I18N::translate('table'), 96*6fd01894SGreg Roach /* I18N: Layout option for lists of names */ 97*6fd01894SGreg Roach 'style3' => I18N::translate('tag cloud'), 98*6fd01894SGreg Roach ]; 99*6fd01894SGreg Roach 100*6fd01894SGreg Roach $page_layouts = [ 101*6fd01894SGreg Roach /* I18N: page orientation */ 102*6fd01894SGreg Roach 0 => I18N::translate('Portrait'), 103*6fd01894SGreg Roach /* I18N: page orientation */ 104*6fd01894SGreg Roach 1 => I18N::translate('Landscape'), 105*6fd01894SGreg Roach ]; 106*6fd01894SGreg Roach 107*6fd01894SGreg Roach $formats = [ 108*6fd01894SGreg Roach /* I18N: None of the other options */ 109*6fd01894SGreg Roach '' => I18N::translate('none'), 110*6fd01894SGreg Roach /* I18N: https://en.wikipedia.org/wiki/Markdown */ 111*6fd01894SGreg Roach 'markdown' => I18N::translate('markdown'), 112*6fd01894SGreg Roach ]; 113*6fd01894SGreg Roach 114*6fd01894SGreg Roach $source_types = [ 115*6fd01894SGreg Roach 0 => I18N::translate('none'), 116*6fd01894SGreg Roach 1 => I18N::translate('facts'), 117*6fd01894SGreg Roach 2 => I18N::translate('records'), 118*6fd01894SGreg Roach ]; 119*6fd01894SGreg Roach 120*6fd01894SGreg Roach $theme_options = $this->module_service 121*6fd01894SGreg Roach ->findByInterface(ModuleThemeInterface::class) 122*6fd01894SGreg Roach ->map($this->module_service->titleMapper()) 123*6fd01894SGreg Roach ->prepend(I18N::translate('<default theme>'), ''); 124*6fd01894SGreg Roach 125*6fd01894SGreg Roach $privacy_options = [ 126*6fd01894SGreg Roach Auth::PRIV_USER => I18N::translate('Show to members'), 127*6fd01894SGreg Roach Auth::PRIV_NONE => I18N::translate('Show to managers'), 128*6fd01894SGreg Roach Auth::PRIV_HIDE => I18N::translate('Hide from everyone'), 129*6fd01894SGreg Roach ]; 130*6fd01894SGreg Roach 131*6fd01894SGreg Roach $tags = array_unique(array_merge( 132*6fd01894SGreg Roach explode(',', $tree->getPreference('INDI_FACTS_ADD')), 133*6fd01894SGreg Roach explode(',', $tree->getPreference('INDI_FACTS_UNIQUE')), 134*6fd01894SGreg Roach explode(',', $tree->getPreference('FAM_FACTS_ADD')), 135*6fd01894SGreg Roach explode(',', $tree->getPreference('FAM_FACTS_UNIQUE')), 136*6fd01894SGreg Roach explode(',', $tree->getPreference('NOTE_FACTS_ADD')), 137*6fd01894SGreg Roach explode(',', $tree->getPreference('NOTE_FACTS_UNIQUE')), 138*6fd01894SGreg Roach explode(',', $tree->getPreference('SOUR_FACTS_ADD')), 139*6fd01894SGreg Roach explode(',', $tree->getPreference('SOUR_FACTS_UNIQUE')), 140*6fd01894SGreg Roach explode(',', $tree->getPreference('REPO_FACTS_ADD')), 141*6fd01894SGreg Roach explode(',', $tree->getPreference('REPO_FACTS_UNIQUE')), 142*6fd01894SGreg Roach ['SOUR', 'REPO', 'OBJE', '_PRIM', 'NOTE', 'SUBM', 'SUBN', '_UID', 'CHAN'] 143*6fd01894SGreg Roach )); 144*6fd01894SGreg Roach 145*6fd01894SGreg Roach $all_tags = []; 146*6fd01894SGreg Roach foreach ($tags as $tag) { 147*6fd01894SGreg Roach if ($tag) { 148*6fd01894SGreg Roach $all_tags[$tag] = GedcomTag::getLabel($tag); 149*6fd01894SGreg Roach } 150*6fd01894SGreg Roach } 151*6fd01894SGreg Roach 152*6fd01894SGreg Roach uasort($all_tags, '\Fisharebest\Webtrees\I18N::strcasecmp'); 153*6fd01894SGreg Roach 154*6fd01894SGreg Roach // For historical reasons, we have two fields in one 155*6fd01894SGreg Roach $calendar_formats = explode('_and_', $tree->getPreference('CALENDAR_FORMAT') . '_and_'); 156*6fd01894SGreg Roach 157*6fd01894SGreg Roach // Split into separate fields 158*6fd01894SGreg Roach $relatives_events = explode(',', $tree->getPreference('SHOW_RELATIVES_EVENTS')); 159*6fd01894SGreg Roach 160*6fd01894SGreg Roach $pedigree_individual = Factory::individual()->make($tree->getPreference('PEDIGREE_ROOT_ID'), $tree); 161*6fd01894SGreg Roach 162*6fd01894SGreg Roach $members = $this->user_service->all()->filter(static function (UserInterface $user) use ($tree): bool { 163*6fd01894SGreg Roach return Auth::isMember($tree, $user); 164*6fd01894SGreg Roach }); 165*6fd01894SGreg Roach 166*6fd01894SGreg Roach $all_fam_facts = GedcomTag::getPicklistFacts('FAM'); 167*6fd01894SGreg Roach $all_indi_facts = GedcomTag::getPicklistFacts('INDI'); 168*6fd01894SGreg Roach $all_name_facts = GedcomTag::getPicklistFacts('NAME'); 169*6fd01894SGreg Roach $all_plac_facts = GedcomTag::getPicklistFacts('PLAC'); 170*6fd01894SGreg Roach $all_repo_facts = GedcomTag::getPicklistFacts('REPO'); 171*6fd01894SGreg Roach $all_sour_facts = GedcomTag::getPicklistFacts('SOUR'); 172*6fd01894SGreg Roach 173*6fd01894SGreg Roach $all_surname_traditions = SurnameTradition::allDescriptions(); 174*6fd01894SGreg Roach 175*6fd01894SGreg Roach $tree_count = $this->tree_service->all()->count(); 176*6fd01894SGreg Roach 177*6fd01894SGreg Roach $title = I18N::translate('Preferences') . ' — ' . e($tree->title()); 178*6fd01894SGreg Roach 179*6fd01894SGreg Roach $base_url = app(ServerRequestInterface::class)->getAttribute('base_url'); 180*6fd01894SGreg Roach 181*6fd01894SGreg Roach return $this->viewResponse('admin/trees-preferences', [ 182*6fd01894SGreg Roach 'all_fam_facts' => $all_fam_facts, 183*6fd01894SGreg Roach 'all_indi_facts' => $all_indi_facts, 184*6fd01894SGreg Roach 'all_name_facts' => $all_name_facts, 185*6fd01894SGreg Roach 'all_plac_facts' => $all_plac_facts, 186*6fd01894SGreg Roach 'all_repo_facts' => $all_repo_facts, 187*6fd01894SGreg Roach 'all_sour_facts' => $all_sour_facts, 188*6fd01894SGreg Roach 'all_surname_traditions' => $all_surname_traditions, 189*6fd01894SGreg Roach 'base_url' => $base_url, 190*6fd01894SGreg Roach 'calendar_formats' => $calendar_formats, 191*6fd01894SGreg Roach 'data_folder' => $data_folder, 192*6fd01894SGreg Roach 'formats' => $formats, 193*6fd01894SGreg Roach 'french_calendar_end' => $french_calendar_end, 194*6fd01894SGreg Roach 'french_calendar_start' => $french_calendar_start, 195*6fd01894SGreg Roach 'gregorian_calendar_start' => $gregorian_calendar_start, 196*6fd01894SGreg Roach 'members' => $members, 197*6fd01894SGreg Roach 'page_layouts' => $page_layouts, 198*6fd01894SGreg Roach 'pedigree_individual' => $pedigree_individual, 199*6fd01894SGreg Roach 'privacy_options' => $privacy_options, 200*6fd01894SGreg Roach 'relatives_events' => $relatives_events, 201*6fd01894SGreg Roach 'source_types' => $source_types, 202*6fd01894SGreg Roach 'surname_list_styles' => $surname_list_styles, 203*6fd01894SGreg Roach 'theme_options' => $theme_options, 204*6fd01894SGreg Roach 'title' => $title, 205*6fd01894SGreg Roach 'tree' => $tree, 206*6fd01894SGreg Roach 'tree_count' => $tree_count, 207*6fd01894SGreg Roach ]); 208*6fd01894SGreg Roach } 209*6fd01894SGreg Roach} 210