16fd01894SGreg Roach<?php 26fd01894SGreg Roach 36fd01894SGreg Roach/** 46fd01894SGreg Roach * webtrees: online genealogy 589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team 66fd01894SGreg Roach * This program is free software: you can redistribute it and/or modify 76fd01894SGreg Roach * it under the terms of the GNU General Public License as published by 86fd01894SGreg Roach * the Free Software Foundation, either version 3 of the License, or 96fd01894SGreg Roach * (at your option) any later version. 106fd01894SGreg Roach * This program is distributed in the hope that it will be useful, 116fd01894SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 126fd01894SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 136fd01894SGreg Roach * GNU General Public License for more details. 146fd01894SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 166fd01894SGreg Roach */ 176fd01894SGreg Roach 186fd01894SGreg Roachdeclare(strict_types=1); 196fd01894SGreg Roach 206fd01894SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 216fd01894SGreg Roach 226fd01894SGreg Roachuse Fisharebest\Webtrees\Auth; 236fd01894SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 246fd01894SGreg Roachuse Fisharebest\Webtrees\Date; 256fd01894SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 266fd01894SGreg Roachuse Fisharebest\Webtrees\I18N; 276fd01894SGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface; 286b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 296fd01894SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 306fd01894SGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 316fd01894SGreg Roachuse Fisharebest\Webtrees\Services\UserService; 326fd01894SGreg Roachuse Fisharebest\Webtrees\SurnameTradition; 336fd01894SGreg Roachuse Fisharebest\Webtrees\Tree; 34*37646143SGreg Roachuse Illuminate\Support\Collection; 356fd01894SGreg Roachuse Psr\Http\Message\ResponseInterface; 366fd01894SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 376fd01894SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 386fd01894SGreg Roach 396fd01894SGreg Roachuse function app; 406fd01894SGreg Roachuse function array_merge; 416fd01894SGreg Roachuse function array_unique; 426fd01894SGreg Roachuse function assert; 436fd01894SGreg Roachuse function e; 446fd01894SGreg Roachuse function explode; 456fd01894SGreg Roachuse function uasort; 466fd01894SGreg Roach 476fd01894SGreg Roach/** 486fd01894SGreg Roach * Edit the tree preferences. 496fd01894SGreg Roach */ 506fd01894SGreg Roachclass TreePreferencesPage implements RequestHandlerInterface 516fd01894SGreg Roach{ 526fd01894SGreg Roach use ViewResponseTrait; 536fd01894SGreg Roach 54*37646143SGreg Roach private const ALL_FAM_FACTS = [ 55*37646143SGreg Roach 'RESN', 'ANUL', 'CENS', 'DIV', 'DIVF', 'ENGA', 'MARB', 'MARC', 'MARR', 'MARL', 'MARS', 'RESI', 'EVEN', 56*37646143SGreg Roach 'NCHI', 'SUBM', 'SLGS', 'REFN', 'RIN', 'CHAN', 'NOTE', 'SHARED_NOTE', 'SOUR', 'OBJE', 57*37646143SGreg Roach '_NMR', '_COML', '_MBON', '_MARI', '_SEPR', '_TODO', 58*37646143SGreg Roach ]; 59*37646143SGreg Roach 60*37646143SGreg Roach private const ALL_INDI_FACTS = [ 61*37646143SGreg Roach 'RESN', 'NAME', 'SEX', 'BIRT', 'CHR', 'DEAT', 'BURI', 'CREM', 'ADOP', 'BAPM', 'BARM', 'BASM', 62*37646143SGreg Roach 'BLES', 'CHRA', 'CONF', 'FCOM', 'ORDN', 'NATU', 'EMIG', 'IMMI', 'CENS', 'PROB', 'WILL', 63*37646143SGreg Roach 'GRAD', 'RETI', 'EVEN', 'CAST', 'DSCR', 'EDUC', 'IDNO', 'NATI', 'NCHI', 'NMR', 'OCCU', 'PROP', 64*37646143SGreg Roach 'RELI', 'RESI', 'SSN', 'TITL', 'FACT', 'BAPL', 'CONL', 'ENDL', 'SLGC', 'SUBM', 'ASSO', 65*37646143SGreg Roach 'ALIA', 'ANCI', 'DESI', 'RFN', 'AFN', 'REFN', 'RIN', 'CHAN', 'NOTE', 'SHARED_NOTE', 'SOUR', 'OBJE', 66*37646143SGreg Roach '_BRTM', '_DEG', '_DNA', '_EYEC', '_FNRL', '_HAIR', '_HEIG', '_HNM', '_HOL', '_INTE', '_MDCL', 67*37646143SGreg Roach '_MEDC', '_MILI', '_MILT', '_NAME', '_NAMS', '_NLIV', '_NMAR', '_PRMN', '_TODO', '_UID', '_WEIG', '_YART', 68*37646143SGreg Roach ]; 69*37646143SGreg Roach 70*37646143SGreg Roach private const ALL_NAME_FACTS = [ 71*37646143SGreg Roach 'FONE', 'ROMN', '_HEB', '_AKA', '_MARNM', 72*37646143SGreg Roach ]; 73*37646143SGreg Roach 74*37646143SGreg Roach private const ALL_PLAC_FACTS = [ 75*37646143SGreg Roach 'FONE', 'ROMN', '_GOV', '_HEB', 76*37646143SGreg Roach ]; 77*37646143SGreg Roach 78*37646143SGreg Roach private const ALL_REPO_FACTS = [ 79*37646143SGreg Roach 'NAME', 'ADDR', 'PHON', 'EMAIL', 'FAX', 'WWW', 'NOTE', 'SHARED_NOTE', 'REFN', 'RIN', 'CHAN', 'RESN', 80*37646143SGreg Roach ]; 81*37646143SGreg Roach 82*37646143SGreg Roach private const ALL_SOUR_FACTS = [ 83*37646143SGreg Roach 'DATA', 'AUTH', 'TITL', 'ABBR', 'PUBL', 'TEXT', 'REPO', 'REFN', 'RIN', 84*37646143SGreg Roach 'CHAN', 'NOTE', 'SHARED_NOTE', 'OBJE', 'RESN', 85*37646143SGreg Roach ]; 86*37646143SGreg Roach 876fd01894SGreg Roach /** @var ModuleService */ 886fd01894SGreg Roach private $module_service; 896fd01894SGreg Roach 906fd01894SGreg Roach /** @var TreeService */ 916fd01894SGreg Roach private $tree_service; 926fd01894SGreg Roach 936fd01894SGreg Roach /** @var UserService */ 946fd01894SGreg Roach private $user_service; 956fd01894SGreg Roach 966fd01894SGreg Roach public function __construct( 976fd01894SGreg Roach ModuleService $module_service, 986fd01894SGreg Roach TreeService $tree_service, 996fd01894SGreg Roach UserService $user_service 1006fd01894SGreg Roach ) { 1016fd01894SGreg Roach $this->module_service = $module_service; 1026fd01894SGreg Roach $this->tree_service = $tree_service; 1036fd01894SGreg Roach $this->user_service = $user_service; 1046fd01894SGreg Roach } 1056fd01894SGreg Roach 1066fd01894SGreg Roach /** 1076fd01894SGreg Roach * @param ServerRequestInterface $request 1086fd01894SGreg Roach * 1096fd01894SGreg Roach * @return ResponseInterface 1106fd01894SGreg Roach */ 1116fd01894SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 1126fd01894SGreg Roach { 1136fd01894SGreg Roach $this->layout = 'layouts/administration'; 1146fd01894SGreg Roach 1156fd01894SGreg Roach $tree = $request->getAttribute('tree'); 1166fd01894SGreg Roach assert($tree instanceof Tree); 1176fd01894SGreg Roach 1186b9cb339SGreg Roach $data_folder = Registry::filesystem()->dataName(); 1196fd01894SGreg Roach 1206fd01894SGreg Roach $french_calendar_start = new Date('22 SEP 1792'); 1216fd01894SGreg Roach $french_calendar_end = new Date('31 DEC 1805'); 1226fd01894SGreg Roach $gregorian_calendar_start = new Date('15 OCT 1582'); 1236fd01894SGreg Roach 1246fd01894SGreg Roach $surname_list_styles = [ 1256fd01894SGreg Roach /* I18N: Layout option for lists of names */ 1266fd01894SGreg Roach 'style1' => I18N::translate('list'), 1276fd01894SGreg Roach /* I18N: Layout option for lists of names */ 1286fd01894SGreg Roach 'style2' => I18N::translate('table'), 1296fd01894SGreg Roach /* I18N: Layout option for lists of names */ 1306fd01894SGreg Roach 'style3' => I18N::translate('tag cloud'), 1316fd01894SGreg Roach ]; 1326fd01894SGreg Roach 1336fd01894SGreg Roach $page_layouts = [ 1346fd01894SGreg Roach /* I18N: page orientation */ 1356fd01894SGreg Roach 0 => I18N::translate('Portrait'), 1366fd01894SGreg Roach /* I18N: page orientation */ 1376fd01894SGreg Roach 1 => I18N::translate('Landscape'), 1386fd01894SGreg Roach ]; 1396fd01894SGreg Roach 1406fd01894SGreg Roach $formats = [ 1416fd01894SGreg Roach /* I18N: None of the other options */ 1426fd01894SGreg Roach '' => I18N::translate('none'), 1436fd01894SGreg Roach /* I18N: https://en.wikipedia.org/wiki/Markdown */ 1446fd01894SGreg Roach 'markdown' => I18N::translate('markdown'), 1456fd01894SGreg Roach ]; 1466fd01894SGreg Roach 1476fd01894SGreg Roach $source_types = [ 1486fd01894SGreg Roach 0 => I18N::translate('none'), 1496fd01894SGreg Roach 1 => I18N::translate('facts'), 1506fd01894SGreg Roach 2 => I18N::translate('records'), 1516fd01894SGreg Roach ]; 1526fd01894SGreg Roach 1536fd01894SGreg Roach $theme_options = $this->module_service 1546fd01894SGreg Roach ->findByInterface(ModuleThemeInterface::class) 1556fd01894SGreg Roach ->map($this->module_service->titleMapper()) 1566fd01894SGreg Roach ->prepend(I18N::translate('<default theme>'), ''); 1576fd01894SGreg Roach 1586fd01894SGreg Roach $privacy_options = [ 1596fd01894SGreg Roach Auth::PRIV_USER => I18N::translate('Show to members'), 1606fd01894SGreg Roach Auth::PRIV_NONE => I18N::translate('Show to managers'), 1616fd01894SGreg Roach Auth::PRIV_HIDE => I18N::translate('Hide from everyone'), 1626fd01894SGreg Roach ]; 1636fd01894SGreg Roach 1646fd01894SGreg Roach $tags = array_unique(array_merge( 1656fd01894SGreg Roach explode(',', $tree->getPreference('INDI_FACTS_ADD')), 1666fd01894SGreg Roach explode(',', $tree->getPreference('INDI_FACTS_UNIQUE')), 1676fd01894SGreg Roach explode(',', $tree->getPreference('FAM_FACTS_ADD')), 1686fd01894SGreg Roach explode(',', $tree->getPreference('FAM_FACTS_UNIQUE')), 1696fd01894SGreg Roach explode(',', $tree->getPreference('NOTE_FACTS_ADD')), 1706fd01894SGreg Roach explode(',', $tree->getPreference('NOTE_FACTS_UNIQUE')), 1716fd01894SGreg Roach explode(',', $tree->getPreference('SOUR_FACTS_ADD')), 1726fd01894SGreg Roach explode(',', $tree->getPreference('SOUR_FACTS_UNIQUE')), 1736fd01894SGreg Roach explode(',', $tree->getPreference('REPO_FACTS_ADD')), 1746fd01894SGreg Roach explode(',', $tree->getPreference('REPO_FACTS_UNIQUE')), 1756fd01894SGreg Roach ['SOUR', 'REPO', 'OBJE', '_PRIM', 'NOTE', 'SUBM', 'SUBN', '_UID', 'CHAN'] 1766fd01894SGreg Roach )); 1776fd01894SGreg Roach 1786fd01894SGreg Roach $all_tags = []; 1796fd01894SGreg Roach foreach ($tags as $tag) { 1806fd01894SGreg Roach if ($tag) { 1816fd01894SGreg Roach $all_tags[$tag] = GedcomTag::getLabel($tag); 1826fd01894SGreg Roach } 1836fd01894SGreg Roach } 1846fd01894SGreg Roach 1856fd01894SGreg Roach uasort($all_tags, '\Fisharebest\Webtrees\I18N::strcasecmp'); 1866fd01894SGreg Roach 1876fd01894SGreg Roach // For historical reasons, we have two fields in one 1886fd01894SGreg Roach $calendar_formats = explode('_and_', $tree->getPreference('CALENDAR_FORMAT') . '_and_'); 1896fd01894SGreg Roach 1906fd01894SGreg Roach // Split into separate fields 1916fd01894SGreg Roach $relatives_events = explode(',', $tree->getPreference('SHOW_RELATIVES_EVENTS')); 1926fd01894SGreg Roach 1936b9cb339SGreg Roach $pedigree_individual = Registry::individualFactory()->make($tree->getPreference('PEDIGREE_ROOT_ID'), $tree); 1946fd01894SGreg Roach 1956fd01894SGreg Roach $members = $this->user_service->all()->filter(static function (UserInterface $user) use ($tree): bool { 1966fd01894SGreg Roach return Auth::isMember($tree, $user); 1976fd01894SGreg Roach }); 1986fd01894SGreg Roach 199*37646143SGreg Roach $all_fam_facts = Collection::make(self::ALL_FAM_FACTS) 200*37646143SGreg Roach ->mapWithKeys(static function (string $tag): array { 201*37646143SGreg Roach return [$tag => Registry::elementFactory()->make('FAM:' . $tag)->label()]; 202*37646143SGreg Roach }) 203*37646143SGreg Roach ->sort(I18N::comparator()); 204*37646143SGreg Roach 205*37646143SGreg Roach $all_indi_facts = Collection::make(self::ALL_INDI_FACTS) 206*37646143SGreg Roach ->mapWithKeys(static function (string $tag): array { 207*37646143SGreg Roach return [$tag => Registry::elementFactory()->make('INDI:' . $tag)->label()]; 208*37646143SGreg Roach }) 209*37646143SGreg Roach ->sort(I18N::comparator()); 210*37646143SGreg Roach 211*37646143SGreg Roach $all_name_facts = Collection::make(self::ALL_NAME_FACTS) 212*37646143SGreg Roach ->mapWithKeys(static function (string $tag): array { 213*37646143SGreg Roach return [$tag => Registry::elementFactory()->make('INDI:NAME:' . $tag)->label()]; 214*37646143SGreg Roach }) 215*37646143SGreg Roach ->sort(I18N::comparator()); 216*37646143SGreg Roach 217*37646143SGreg Roach $all_plac_facts = Collection::make(self::ALL_PLAC_FACTS) 218*37646143SGreg Roach ->mapWithKeys(static function (string $tag): array { 219*37646143SGreg Roach return [$tag => Registry::elementFactory()->make('INDI:FACT:PLAC:' . $tag)->label()]; 220*37646143SGreg Roach }) 221*37646143SGreg Roach ->sort(I18N::comparator()); 222*37646143SGreg Roach 223*37646143SGreg Roach $all_repo_facts = Collection::make(self::ALL_REPO_FACTS) 224*37646143SGreg Roach ->mapWithKeys(static function (string $tag): array { 225*37646143SGreg Roach return [$tag => Registry::elementFactory()->make('SOUR:' . $tag)->label()]; 226*37646143SGreg Roach }) 227*37646143SGreg Roach ->sort(I18N::comparator()); 228*37646143SGreg Roach 229*37646143SGreg Roach $all_sour_facts = Collection::make(self::ALL_SOUR_FACTS) 230*37646143SGreg Roach ->mapWithKeys(static function (string $tag): array { 231*37646143SGreg Roach return [$tag => Registry::elementFactory()->make('SOUR:' . $tag)->label()]; 232*37646143SGreg Roach }) 233*37646143SGreg Roach ->sort(I18N::comparator()); 2346fd01894SGreg Roach 2356fd01894SGreg Roach $all_surname_traditions = SurnameTradition::allDescriptions(); 2366fd01894SGreg Roach 2376fd01894SGreg Roach $tree_count = $this->tree_service->all()->count(); 2386fd01894SGreg Roach 2396fd01894SGreg Roach $title = I18N::translate('Preferences') . ' — ' . e($tree->title()); 2406fd01894SGreg Roach 2416fd01894SGreg Roach $base_url = app(ServerRequestInterface::class)->getAttribute('base_url'); 2426fd01894SGreg Roach 2436fd01894SGreg Roach return $this->viewResponse('admin/trees-preferences', [ 2446fd01894SGreg Roach 'all_fam_facts' => $all_fam_facts, 2456fd01894SGreg Roach 'all_indi_facts' => $all_indi_facts, 2466fd01894SGreg Roach 'all_name_facts' => $all_name_facts, 2476fd01894SGreg Roach 'all_plac_facts' => $all_plac_facts, 2486fd01894SGreg Roach 'all_repo_facts' => $all_repo_facts, 2496fd01894SGreg Roach 'all_sour_facts' => $all_sour_facts, 2506fd01894SGreg Roach 'all_surname_traditions' => $all_surname_traditions, 2516fd01894SGreg Roach 'base_url' => $base_url, 2526fd01894SGreg Roach 'calendar_formats' => $calendar_formats, 2536fd01894SGreg Roach 'data_folder' => $data_folder, 2546fd01894SGreg Roach 'formats' => $formats, 2556fd01894SGreg Roach 'french_calendar_end' => $french_calendar_end, 2566fd01894SGreg Roach 'french_calendar_start' => $french_calendar_start, 2576fd01894SGreg Roach 'gregorian_calendar_start' => $gregorian_calendar_start, 2586fd01894SGreg Roach 'members' => $members, 2596fd01894SGreg Roach 'page_layouts' => $page_layouts, 2606fd01894SGreg Roach 'pedigree_individual' => $pedigree_individual, 2616fd01894SGreg Roach 'privacy_options' => $privacy_options, 2626fd01894SGreg Roach 'relatives_events' => $relatives_events, 2636fd01894SGreg Roach 'source_types' => $source_types, 2646fd01894SGreg Roach 'surname_list_styles' => $surname_list_styles, 2656fd01894SGreg Roach 'theme_options' => $theme_options, 2666fd01894SGreg Roach 'title' => $title, 2676fd01894SGreg Roach 'tree' => $tree, 2686fd01894SGreg Roach 'tree_count' => $tree_count, 2696fd01894SGreg Roach ]); 2706fd01894SGreg Roach } 2716fd01894SGreg Roach} 272