. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Contracts\UserInterface; use Fisharebest\Webtrees\Date; use Fisharebest\Webtrees\Factory; use Fisharebest\Webtrees\GedcomTag; use Fisharebest\Webtrees\Http\ViewResponseTrait; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Module\ModuleThemeInterface; use Fisharebest\Webtrees\Services\ModuleService; use Fisharebest\Webtrees\Services\TreeService; use Fisharebest\Webtrees\Services\UserService; use Fisharebest\Webtrees\SurnameTradition; use Fisharebest\Webtrees\Tree; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use function app; use function array_merge; use function array_unique; use function assert; use function e; use function explode; use function uasort; /** * Edit the tree preferences. */ class TreePreferencesPage implements RequestHandlerInterface { use ViewResponseTrait; /** @var ModuleService */ private $module_service; /** @var TreeService */ private $tree_service; /** @var UserService */ private $user_service; public function __construct( ModuleService $module_service, TreeService $tree_service, UserService $user_service ) { $this->module_service = $module_service; $this->tree_service = $tree_service; $this->user_service = $user_service; } /** * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $this->layout = 'layouts/administration'; $tree = $request->getAttribute('tree'); assert($tree instanceof Tree); $data_folder = Factory::filesystem()->dataName(); $french_calendar_start = new Date('22 SEP 1792'); $french_calendar_end = new Date('31 DEC 1805'); $gregorian_calendar_start = new Date('15 OCT 1582'); $surname_list_styles = [ /* I18N: Layout option for lists of names */ 'style1' => I18N::translate('list'), /* I18N: Layout option for lists of names */ 'style2' => I18N::translate('table'), /* I18N: Layout option for lists of names */ 'style3' => I18N::translate('tag cloud'), ]; $page_layouts = [ /* I18N: page orientation */ 0 => I18N::translate('Portrait'), /* I18N: page orientation */ 1 => I18N::translate('Landscape'), ]; $formats = [ /* I18N: None of the other options */ '' => I18N::translate('none'), /* I18N: https://en.wikipedia.org/wiki/Markdown */ 'markdown' => I18N::translate('markdown'), ]; $source_types = [ 0 => I18N::translate('none'), 1 => I18N::translate('facts'), 2 => I18N::translate('records'), ]; $theme_options = $this->module_service ->findByInterface(ModuleThemeInterface::class) ->map($this->module_service->titleMapper()) ->prepend(I18N::translate(''), ''); $privacy_options = [ Auth::PRIV_USER => I18N::translate('Show to members'), Auth::PRIV_NONE => I18N::translate('Show to managers'), Auth::PRIV_HIDE => I18N::translate('Hide from everyone'), ]; $tags = array_unique(array_merge( explode(',', $tree->getPreference('INDI_FACTS_ADD')), explode(',', $tree->getPreference('INDI_FACTS_UNIQUE')), explode(',', $tree->getPreference('FAM_FACTS_ADD')), explode(',', $tree->getPreference('FAM_FACTS_UNIQUE')), explode(',', $tree->getPreference('NOTE_FACTS_ADD')), explode(',', $tree->getPreference('NOTE_FACTS_UNIQUE')), explode(',', $tree->getPreference('SOUR_FACTS_ADD')), explode(',', $tree->getPreference('SOUR_FACTS_UNIQUE')), explode(',', $tree->getPreference('REPO_FACTS_ADD')), explode(',', $tree->getPreference('REPO_FACTS_UNIQUE')), ['SOUR', 'REPO', 'OBJE', '_PRIM', 'NOTE', 'SUBM', 'SUBN', '_UID', 'CHAN'] )); $all_tags = []; foreach ($tags as $tag) { if ($tag) { $all_tags[$tag] = GedcomTag::getLabel($tag); } } uasort($all_tags, '\Fisharebest\Webtrees\I18N::strcasecmp'); // For historical reasons, we have two fields in one $calendar_formats = explode('_and_', $tree->getPreference('CALENDAR_FORMAT') . '_and_'); // Split into separate fields $relatives_events = explode(',', $tree->getPreference('SHOW_RELATIVES_EVENTS')); $pedigree_individual = Factory::individual()->make($tree->getPreference('PEDIGREE_ROOT_ID'), $tree); $members = $this->user_service->all()->filter(static function (UserInterface $user) use ($tree): bool { return Auth::isMember($tree, $user); }); $all_fam_facts = GedcomTag::getPicklistFacts('FAM'); $all_indi_facts = GedcomTag::getPicklistFacts('INDI'); $all_name_facts = GedcomTag::getPicklistFacts('NAME'); $all_plac_facts = GedcomTag::getPicklistFacts('PLAC'); $all_repo_facts = GedcomTag::getPicklistFacts('REPO'); $all_sour_facts = GedcomTag::getPicklistFacts('SOUR'); $all_surname_traditions = SurnameTradition::allDescriptions(); $tree_count = $this->tree_service->all()->count(); $title = I18N::translate('Preferences') . ' — ' . e($tree->title()); $base_url = app(ServerRequestInterface::class)->getAttribute('base_url'); return $this->viewResponse('admin/trees-preferences', [ 'all_fam_facts' => $all_fam_facts, 'all_indi_facts' => $all_indi_facts, 'all_name_facts' => $all_name_facts, 'all_plac_facts' => $all_plac_facts, 'all_repo_facts' => $all_repo_facts, 'all_sour_facts' => $all_sour_facts, 'all_surname_traditions' => $all_surname_traditions, 'base_url' => $base_url, 'calendar_formats' => $calendar_formats, 'data_folder' => $data_folder, 'formats' => $formats, 'french_calendar_end' => $french_calendar_end, 'french_calendar_start' => $french_calendar_start, 'gregorian_calendar_start' => $gregorian_calendar_start, 'members' => $members, 'page_layouts' => $page_layouts, 'pedigree_individual' => $pedigree_individual, 'privacy_options' => $privacy_options, 'relatives_events' => $relatives_events, 'source_types' => $source_types, 'surname_list_styles' => $surname_list_styles, 'theme_options' => $theme_options, 'title' => $title, 'tree' => $tree, 'tree_count' => $tree_count, ]); } }