xref: /webtrees/app/Module/ModuleThemeTrait.php (revision e6bcfa02ed9fcf5302d732668830a57cc49f94e2)
149a243cbSGreg Roach<?php
249a243cbSGreg Roach/**
349a243cbSGreg Roach * webtrees: online genealogy
449a243cbSGreg Roach * Copyright (C) 2019 webtrees development team
549a243cbSGreg Roach * This program is free software: you can redistribute it and/or modify
649a243cbSGreg Roach * it under the terms of the GNU General Public License as published by
749a243cbSGreg Roach * the Free Software Foundation, either version 3 of the License, or
849a243cbSGreg Roach * (at your option) any later version.
949a243cbSGreg Roach * This program is distributed in the hope that it will be useful,
1049a243cbSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1149a243cbSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1249a243cbSGreg Roach * GNU General Public License for more details.
1349a243cbSGreg Roach * You should have received a copy of the GNU General Public License
1449a243cbSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1549a243cbSGreg Roach */
1649a243cbSGreg Roachdeclare(strict_types=1);
1749a243cbSGreg Roach
1849a243cbSGreg Roachnamespace Fisharebest\Webtrees\Module;
1949a243cbSGreg Roach
20ade503dfSGreg Roachuse Fisharebest\Webtrees\Auth;
21ade503dfSGreg Roachuse Fisharebest\Webtrees\Fact;
22ade503dfSGreg Roachuse Fisharebest\Webtrees\Gedcom;
23ade503dfSGreg Roachuse Fisharebest\Webtrees\GedcomTag;
24ade503dfSGreg Roachuse Fisharebest\Webtrees\I18N;
25ade503dfSGreg Roachuse Fisharebest\Webtrees\Individual;
26ade503dfSGreg Roachuse Fisharebest\Webtrees\Menu;
274ca7e03cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService;
28ade503dfSGreg Roachuse Fisharebest\Webtrees\Tree;
29ade503dfSGreg Roachuse Symfony\Component\HttpFoundation\Request;
30ade503dfSGreg Roach
3149a243cbSGreg Roach/**
3249a243cbSGreg Roach * Trait ModuleThemeTrait - default implementation of ModuleThemeInterface
3349a243cbSGreg Roach */
3449a243cbSGreg Roachtrait ModuleThemeTrait
3549a243cbSGreg Roach{
36ade503dfSGreg Roach    /**
37ade503dfSGreg Roach     * Add markup to the secondary menu.
38ade503dfSGreg Roach     *
390c8c69d4SGreg Roach     * @param Tree|null $tree
400c8c69d4SGreg Roach     *
41ade503dfSGreg Roach     * @return string
42ade503dfSGreg Roach     */
430c8c69d4SGreg Roach    public function formatUserMenu(?Tree $tree): string
44ade503dfSGreg Roach    {
45ade503dfSGreg Roach        return
460c8c69d4SGreg Roach            '<ul class="nav wt-user-menu">' .
47f79c9408SGreg Roach            implode('', array_map(function (Menu $menu): string {
480c8c69d4SGreg Roach                return $this->formatUserMenuItem($menu);
490c8c69d4SGreg Roach            }, $this->userMenu($tree))) .
50ade503dfSGreg Roach            '</ul>';
51ade503dfSGreg Roach    }
52ade503dfSGreg Roach
53ade503dfSGreg Roach    /**
54ade503dfSGreg Roach     * Add markup to an item in the secondary menu.
55ade503dfSGreg Roach     *
56ade503dfSGreg Roach     * @param Menu $menu
57ade503dfSGreg Roach     *
58ade503dfSGreg Roach     * @return string
59ade503dfSGreg Roach     */
600c8c69d4SGreg Roach    public function formatUserMenuItem(Menu $menu): string
61ade503dfSGreg Roach    {
62ade503dfSGreg Roach        return $menu->bootstrap4();
63ade503dfSGreg Roach    }
64ade503dfSGreg Roach
65ade503dfSGreg Roach    /**
66ade503dfSGreg Roach     * Display an icon for this fact.
67ade503dfSGreg Roach     *
68e837ff07SGreg Roach     * @TODO use CSS for this
69e837ff07SGreg Roach     *
70ade503dfSGreg Roach     * @param Fact $fact
71ade503dfSGreg Roach     *
72ade503dfSGreg Roach     * @return string
73ade503dfSGreg Roach     */
74ade503dfSGreg Roach    public function icon(Fact $fact): string
75ade503dfSGreg Roach    {
76e837ff07SGreg Roach        $asset = 'public/css/' . $this->name() . '/images/facts/' . $fact->getTag() . '.png';
77e837ff07SGreg Roach        if (file_exists(WT_ROOT . 'public' . $asset)) {
78e837ff07SGreg Roach            return '<img src="' . e(asset($asset)) . '" title="' . GedcomTag::getLabel($fact->getTag()) . '">';
79ade503dfSGreg Roach        }
80ade503dfSGreg Roach
81ade503dfSGreg Roach        // Spacer image - for alignment - until we move to a sprite.
82e837ff07SGreg Roach        $asset = 'public/css/' . $this->name() . '/images/facts/NULL.png';
83e837ff07SGreg Roach        if (file_exists(WT_ROOT . 'public' . $asset)) {
84e837ff07SGreg Roach            return '<img src="' . e(asset($asset)) . '">';
85ade503dfSGreg Roach        }
86ade503dfSGreg Roach
87ade503dfSGreg Roach        return '';
88ade503dfSGreg Roach    }
89ade503dfSGreg Roach
90ade503dfSGreg Roach    /**
91ade503dfSGreg Roach     * Display an individual in a box - for charts, etc.
92ade503dfSGreg Roach     *
93ade503dfSGreg Roach     * @param Individual $individual
94ade503dfSGreg Roach     *
95ade503dfSGreg Roach     * @return string
96ade503dfSGreg Roach     */
97ade503dfSGreg Roach    public function individualBox(Individual $individual): string
98ade503dfSGreg Roach    {
99242a7862SGreg Roach        return view('chart-box', ['individual' => $individual]);
100ade503dfSGreg Roach    }
101ade503dfSGreg Roach
102ade503dfSGreg Roach    /**
103ade503dfSGreg Roach     * Display an empty box - for a missing individual in a chart.
104ade503dfSGreg Roach     *
105ade503dfSGreg Roach     * @return string
106ade503dfSGreg Roach     */
107ade503dfSGreg Roach    public function individualBoxEmpty(): string
108ade503dfSGreg Roach    {
109242a7862SGreg Roach        return '<div class="wt-chart-box"></div>';
110ade503dfSGreg Roach    }
111ade503dfSGreg Roach
112ade503dfSGreg Roach    /**
113ade503dfSGreg Roach     * Display an individual in a box - for charts, etc.
114ade503dfSGreg Roach     *
115ade503dfSGreg Roach     * @param Individual $individual
116ade503dfSGreg Roach     *
117ade503dfSGreg Roach     * @return string
118ade503dfSGreg Roach     */
119ade503dfSGreg Roach    public function individualBoxLarge(Individual $individual): string
120ade503dfSGreg Roach    {
121242a7862SGreg Roach        return $this->individualBox($individual);
122ade503dfSGreg Roach    }
123ade503dfSGreg Roach
124ade503dfSGreg Roach    /**
125ade503dfSGreg Roach     * Display an individual in a box - for charts, etc.
126ade503dfSGreg Roach     *
127ade503dfSGreg Roach     * @param Individual $individual
128ade503dfSGreg Roach     *
129ade503dfSGreg Roach     * @return string
130ade503dfSGreg Roach     */
131ade503dfSGreg Roach    public function individualBoxSmall(Individual $individual): string
132ade503dfSGreg Roach    {
133242a7862SGreg Roach        return $this->individualBox($individual);
134ade503dfSGreg Roach    }
135ade503dfSGreg Roach
136ade503dfSGreg Roach    /**
137ade503dfSGreg Roach     * Display an individual in a box - for charts, etc.
138ade503dfSGreg Roach     *
139ade503dfSGreg Roach     * @return string
140ade503dfSGreg Roach     */
141ade503dfSGreg Roach    public function individualBoxSmallEmpty(): string
142ade503dfSGreg Roach    {
143242a7862SGreg Roach        return '<div class="wt-chart-box"></div>';
144ade503dfSGreg Roach    }
145ade503dfSGreg Roach
146ade503dfSGreg Roach    /**
147ade503dfSGreg Roach     * Generate the facts, for display in charts.
148ade503dfSGreg Roach     *
149ade503dfSGreg Roach     * @param Individual $individual
150ade503dfSGreg Roach     *
151ade503dfSGreg Roach     * @return string
152ade503dfSGreg Roach     */
153ade503dfSGreg Roach    public function individualBoxFacts(Individual $individual): string
154ade503dfSGreg Roach    {
155ade503dfSGreg Roach        $html = '';
156ade503dfSGreg Roach
157ade503dfSGreg Roach        $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY);
158ade503dfSGreg Roach        // Show BIRT or equivalent event
159ade503dfSGreg Roach        foreach (Gedcom::BIRTH_EVENTS as $birttag) {
160ade503dfSGreg Roach            if (!in_array($birttag, $opt_tags)) {
161820b62dfSGreg Roach                $event = $individual->facts([$birttag])->first();
162820b62dfSGreg Roach                if ($event instanceof Fact) {
163ade503dfSGreg Roach                    $html .= $event->summary();
164ade503dfSGreg Roach                    break;
165ade503dfSGreg Roach                }
166ade503dfSGreg Roach            }
167ade503dfSGreg Roach        }
168ade503dfSGreg Roach        // Show optional events (before death)
169ade503dfSGreg Roach        foreach ($opt_tags as $key => $tag) {
170ade503dfSGreg Roach            if (!in_array($tag, Gedcom::DEATH_EVENTS)) {
171820b62dfSGreg Roach                $event = $individual->facts([$tag])->first();
172820b62dfSGreg Roach                if ($event instanceof Fact) {
173ade503dfSGreg Roach                    $html .= $event->summary();
174ade503dfSGreg Roach                    unset($opt_tags[$key]);
175ade503dfSGreg Roach                }
176ade503dfSGreg Roach            }
177ade503dfSGreg Roach        }
178ade503dfSGreg Roach        // Show DEAT or equivalent event
179ade503dfSGreg Roach        foreach (Gedcom::DEATH_EVENTS as $deattag) {
180820b62dfSGreg Roach            $event = $individual->facts([$deattag])->first();
181820b62dfSGreg Roach            if ($event instanceof Fact) {
182ade503dfSGreg Roach                $html .= $event->summary();
183ade503dfSGreg Roach                if (in_array($deattag, $opt_tags)) {
184ade503dfSGreg Roach                    unset($opt_tags[array_search($deattag, $opt_tags)]);
185ade503dfSGreg Roach                }
186ade503dfSGreg Roach                break;
187ade503dfSGreg Roach            }
188ade503dfSGreg Roach        }
189ade503dfSGreg Roach        // Show remaining optional events (after death)
190ade503dfSGreg Roach        foreach ($opt_tags as $tag) {
191820b62dfSGreg Roach            $event = $individual->facts([$tag])->first();
192820b62dfSGreg Roach            if ($event instanceof Fact) {
193ade503dfSGreg Roach                $html .= $event->summary();
194ade503dfSGreg Roach            }
195ade503dfSGreg Roach        }
196ade503dfSGreg Roach
197ade503dfSGreg Roach        return $html;
198ade503dfSGreg Roach    }
199ade503dfSGreg Roach
200ade503dfSGreg Roach    /**
201ade503dfSGreg Roach     * Links, to show in chart boxes;
202ade503dfSGreg Roach     *
203ade503dfSGreg Roach     * @param Individual $individual
204ade503dfSGreg Roach     *
205ade503dfSGreg Roach     * @return Menu[]
206ade503dfSGreg Roach     */
207ade503dfSGreg Roach    public function individualBoxMenu(Individual $individual): array
208ade503dfSGreg Roach    {
209ade503dfSGreg Roach        $menus = array_merge(
210ade503dfSGreg Roach            $this->individualBoxMenuCharts($individual),
211ade503dfSGreg Roach            $this->individualBoxMenuFamilyLinks($individual)
212ade503dfSGreg Roach        );
213ade503dfSGreg Roach
214ade503dfSGreg Roach        return $menus;
215ade503dfSGreg Roach    }
216ade503dfSGreg Roach
217ade503dfSGreg Roach    /**
218ade503dfSGreg Roach     * Chart links, to show in chart boxes;
219ade503dfSGreg Roach     *
220ade503dfSGreg Roach     * @param Individual $individual
221ade503dfSGreg Roach     *
222ade503dfSGreg Roach     * @return Menu[]
223ade503dfSGreg Roach     */
224ade503dfSGreg Roach    public function individualBoxMenuCharts(Individual $individual): array
225ade503dfSGreg Roach    {
226ade503dfSGreg Roach        $menus = [];
227f39638cfSGreg Roach        foreach (app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user()) as $chart) {
228ade503dfSGreg Roach            $menu = $chart->chartBoxMenu($individual);
229ade503dfSGreg Roach            if ($menu) {
230ade503dfSGreg Roach                $menus[] = $menu;
231ade503dfSGreg Roach            }
232ade503dfSGreg Roach        }
233ade503dfSGreg Roach
234ade503dfSGreg Roach        usort($menus, function (Menu $x, Menu $y) {
235ade503dfSGreg Roach            return I18N::strcasecmp($x->getLabel(), $y->getLabel());
236ade503dfSGreg Roach        });
237ade503dfSGreg Roach
238ade503dfSGreg Roach        return $menus;
239ade503dfSGreg Roach    }
240ade503dfSGreg Roach
241ade503dfSGreg Roach    /**
242ade503dfSGreg Roach     * Family links, to show in chart boxes.
243ade503dfSGreg Roach     *
244ade503dfSGreg Roach     * @param Individual $individual
245ade503dfSGreg Roach     *
246ade503dfSGreg Roach     * @return Menu[]
247ade503dfSGreg Roach     */
248ade503dfSGreg Roach    public function individualBoxMenuFamilyLinks(Individual $individual): array
249ade503dfSGreg Roach    {
250ade503dfSGreg Roach        $menus = [];
251ade503dfSGreg Roach
25239ca88baSGreg Roach        foreach ($individual->spouseFamilies() as $family) {
253ade503dfSGreg Roach            $menus[] = new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url());
25439ca88baSGreg Roach            $spouse  = $family->spouse($individual);
255ade503dfSGreg Roach            if ($spouse && $spouse->canShowName()) {
25639ca88baSGreg Roach                $menus[] = new Menu($spouse->fullName(), $spouse->url());
257ade503dfSGreg Roach            }
25839ca88baSGreg Roach            foreach ($family->children() as $child) {
259ade503dfSGreg Roach                if ($child->canShowName()) {
26039ca88baSGreg Roach                    $menus[] = new Menu($child->fullName(), $child->url());
261ade503dfSGreg Roach                }
262ade503dfSGreg Roach            }
263ade503dfSGreg Roach        }
264ade503dfSGreg Roach
265ade503dfSGreg Roach        return $menus;
266ade503dfSGreg Roach    }
267ade503dfSGreg Roach
268ade503dfSGreg Roach    /**
269ade503dfSGreg Roach     * Generate a menu item to change the blocks on the current (index.php) page.
270ade503dfSGreg Roach     *
2710c8c69d4SGreg Roach     * @param Tree $tree
2720c8c69d4SGreg Roach     *
273ade503dfSGreg Roach     * @return Menu|null
274ade503dfSGreg Roach     */
275e364afe4SGreg Roach    public function menuChangeBlocks(Tree $tree): ?Menu
276ade503dfSGreg Roach    {
277*e6bcfa02SGreg Roach        $request = app(Request::class);
278*e6bcfa02SGreg Roach
279*e6bcfa02SGreg Roach        if (Auth::check() && $request->get('route') === 'user-page') {
2800c8c69d4SGreg Roach            return new Menu(I18N::translate('Customize this page'), route('user-page-edit', ['ged' => $tree->name()]), 'menu-change-blocks');
281ade503dfSGreg Roach        }
282ade503dfSGreg Roach
283*e6bcfa02SGreg Roach        if (Auth::isManager($tree) && $request->get('route') === 'tree-page') {
2840c8c69d4SGreg Roach            return new Menu(I18N::translate('Customize this page'), route('tree-page-edit', ['ged' => $tree->name()]), 'menu-change-blocks');
285ade503dfSGreg Roach        }
286ade503dfSGreg Roach
287ade503dfSGreg Roach        return null;
288ade503dfSGreg Roach    }
289ade503dfSGreg Roach
290ade503dfSGreg Roach    /**
291ade503dfSGreg Roach     * Generate a menu item for the control panel.
292ade503dfSGreg Roach     *
2930c8c69d4SGreg Roach     * @param Tree $tree
2940c8c69d4SGreg Roach     *
295ade503dfSGreg Roach     * @return Menu|null
296ade503dfSGreg Roach     */
297e364afe4SGreg Roach    public function menuControlPanel(Tree $tree): ?Menu
298ade503dfSGreg Roach    {
299ade503dfSGreg Roach        if (Auth::isAdmin()) {
300ade503dfSGreg Roach            return new Menu(I18N::translate('Control panel'), route('admin-control-panel'), 'menu-admin');
301ade503dfSGreg Roach        }
302ade503dfSGreg Roach
3030c8c69d4SGreg Roach        if (Auth::isManager($tree)) {
304ade503dfSGreg Roach            return new Menu(I18N::translate('Control panel'), route('admin-control-panel-manager'), 'menu-admin');
305ade503dfSGreg Roach        }
306ade503dfSGreg Roach
307ade503dfSGreg Roach        return null;
308ade503dfSGreg Roach    }
309ade503dfSGreg Roach
310ade503dfSGreg Roach    /**
311ade503dfSGreg Roach     * A menu to show a list of available languages.
312ade503dfSGreg Roach     *
313ade503dfSGreg Roach     * @return Menu|null
314ade503dfSGreg Roach     */
315e364afe4SGreg Roach    public function menuLanguages(): ?Menu
316ade503dfSGreg Roach    {
317ade503dfSGreg Roach        $menu = new Menu(I18N::translate('Language'), '#', 'menu-language');
318ade503dfSGreg Roach
319ade503dfSGreg Roach        foreach (I18N::activeLocales() as $locale) {
320ade503dfSGreg Roach            $language_tag = $locale->languageTag();
321ade503dfSGreg Roach            $class        = 'menu-language-' . $language_tag . (WT_LOCALE === $language_tag ? ' active' : '');
322ade503dfSGreg Roach            $menu->addSubmenu(new Menu($locale->endonym(), '#', $class, [
323ade503dfSGreg Roach                'onclick'       => 'return false;',
324ade503dfSGreg Roach                'data-language' => $language_tag,
325ade503dfSGreg Roach            ]));
326ade503dfSGreg Roach        }
327ade503dfSGreg Roach
328ade503dfSGreg Roach        if (count($menu->getSubmenus()) > 1) {
329ade503dfSGreg Roach            return $menu;
330ade503dfSGreg Roach        }
331ade503dfSGreg Roach
332ade503dfSGreg Roach        return null;
333ade503dfSGreg Roach    }
334ade503dfSGreg Roach
335ade503dfSGreg Roach    /**
336ade503dfSGreg Roach     * A login menu option (or null if we are already logged in).
337ade503dfSGreg Roach     *
338ade503dfSGreg Roach     * @return Menu|null
339ade503dfSGreg Roach     */
340e364afe4SGreg Roach    public function menuLogin(): ?Menu
341ade503dfSGreg Roach    {
342ade503dfSGreg Roach        if (Auth::check()) {
343ade503dfSGreg Roach            return null;
344ade503dfSGreg Roach        }
345ade503dfSGreg Roach
346ade503dfSGreg Roach        // Return to this page after login...
347*e6bcfa02SGreg Roach        $url = app(Request::class)->getRequestUri();
348ade503dfSGreg Roach
349ade503dfSGreg Roach        // ...but switch from the tree-page to the user-page
350ade503dfSGreg Roach        $url = str_replace('route=tree-page', 'route=user-page', $url);
351ade503dfSGreg Roach
352ade503dfSGreg Roach        return new Menu(I18N::translate('Sign in'), route('login', ['url' => $url]), 'menu-login', ['rel' => 'nofollow']);
353ade503dfSGreg Roach    }
354ade503dfSGreg Roach
355ade503dfSGreg Roach    /**
356ade503dfSGreg Roach     * A logout menu option (or null if we are already logged out).
357ade503dfSGreg Roach     *
358ade503dfSGreg Roach     * @return Menu|null
359ade503dfSGreg Roach     */
360e364afe4SGreg Roach    public function menuLogout(): ?Menu
361ade503dfSGreg Roach    {
362ade503dfSGreg Roach        if (Auth::check()) {
363ade503dfSGreg Roach            return new Menu(I18N::translate('Sign out'), route('logout'), 'menu-logout');
364ade503dfSGreg Roach        }
365ade503dfSGreg Roach
366ade503dfSGreg Roach        return null;
367ade503dfSGreg Roach    }
368ade503dfSGreg Roach
369ade503dfSGreg Roach    /**
370ade503dfSGreg Roach     * A link to allow users to edit their account settings.
371ade503dfSGreg Roach     *
372ade503dfSGreg Roach     * @return Menu|null
373ade503dfSGreg Roach     */
374e364afe4SGreg Roach    public function menuMyAccount(): ?Menu
375ade503dfSGreg Roach    {
376ade503dfSGreg Roach        if (Auth::check()) {
377ade503dfSGreg Roach            return new Menu(I18N::translate('My account'), route('my-account'));
378ade503dfSGreg Roach        }
379ade503dfSGreg Roach
380ade503dfSGreg Roach        return null;
381ade503dfSGreg Roach    }
382ade503dfSGreg Roach
383ade503dfSGreg Roach    /**
384ade503dfSGreg Roach     * A link to the user's individual record (individual.php).
385ade503dfSGreg Roach     *
3860c8c69d4SGreg Roach     * @param Tree $tree
3870c8c69d4SGreg Roach     *
388ade503dfSGreg Roach     * @return Menu|null
389ade503dfSGreg Roach     */
390e364afe4SGreg Roach    public function menuMyIndividualRecord(Tree $tree): ?Menu
391ade503dfSGreg Roach    {
3920c8c69d4SGreg Roach        $record = Individual::getInstance($tree->getUserPreference(Auth::user(), 'gedcomid'), $tree);
393ade503dfSGreg Roach
394ade503dfSGreg Roach        if ($record) {
395ade503dfSGreg Roach            return new Menu(I18N::translate('My individual record'), $record->url(), 'menu-myrecord');
396ade503dfSGreg Roach        }
397ade503dfSGreg Roach
398ade503dfSGreg Roach        return null;
399ade503dfSGreg Roach    }
400ade503dfSGreg Roach
401ade503dfSGreg Roach    /**
402ade503dfSGreg Roach     * A link to the user's personal home page.
403ade503dfSGreg Roach     *
4040c8c69d4SGreg Roach     * @param Tree $tree
4050c8c69d4SGreg Roach     *
406ade503dfSGreg Roach     * @return Menu
407ade503dfSGreg Roach     */
4080c8c69d4SGreg Roach    public function menuMyPage(Tree $tree): Menu
409ade503dfSGreg Roach    {
4100c8c69d4SGreg Roach        return new Menu(I18N::translate('My page'), route('user-page', ['ged' => $tree->name()]), 'menu-mypage');
411ade503dfSGreg Roach    }
412ade503dfSGreg Roach
413ade503dfSGreg Roach    /**
414ade503dfSGreg Roach     * A menu for the user's personal pages.
415ade503dfSGreg Roach     *
4160c8c69d4SGreg Roach     * @param Tree|null $tree
4170c8c69d4SGreg Roach     *
418ade503dfSGreg Roach     * @return Menu|null
419ade503dfSGreg Roach     */
420e364afe4SGreg Roach    public function menuMyPages(?Tree $tree): ?Menu
421ade503dfSGreg Roach    {
4220c8c69d4SGreg Roach        if ($tree instanceof Tree && Auth::id()) {
423ade503dfSGreg Roach            return new Menu(I18N::translate('My pages'), '#', 'menu-mymenu', [], array_filter([
4240c8c69d4SGreg Roach                $this->menuMyPage($tree),
4250c8c69d4SGreg Roach                $this->menuMyIndividualRecord($tree),
4260c8c69d4SGreg Roach                $this->menuMyPedigree($tree),
427ade503dfSGreg Roach                $this->menuMyAccount(),
4280c8c69d4SGreg Roach                $this->menuControlPanel($tree),
4290c8c69d4SGreg Roach                $this->menuChangeBlocks($tree),
430ade503dfSGreg Roach            ]));
431ade503dfSGreg Roach        }
432ade503dfSGreg Roach
433ade503dfSGreg Roach        return null;
434ade503dfSGreg Roach    }
435ade503dfSGreg Roach
436ade503dfSGreg Roach    /**
437ade503dfSGreg Roach     * A link to the user's individual record.
438ade503dfSGreg Roach     *
4390c8c69d4SGreg Roach     * @param Tree $tree
4400c8c69d4SGreg Roach     *
441ade503dfSGreg Roach     * @return Menu|null
442ade503dfSGreg Roach     */
443e364afe4SGreg Roach    public function menuMyPedigree(Tree $tree): ?Menu
444ade503dfSGreg Roach    {
4450c8c69d4SGreg Roach        $gedcomid = $tree->getUserPreference(Auth::user(), 'gedcomid');
446ade503dfSGreg Roach
4470c8c69d4SGreg Roach        $pedigree_chart = app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $tree, Auth::user())
448ade503dfSGreg Roach            ->filter(function (ModuleInterface $module): bool {
449ade503dfSGreg Roach                return $module instanceof PedigreeChartModule;
450ade503dfSGreg Roach            });
451ade503dfSGreg Roach
452ade503dfSGreg Roach        if ($gedcomid !== '' && $pedigree_chart instanceof PedigreeChartModule) {
453ade503dfSGreg Roach            return new Menu(
454ade503dfSGreg Roach                I18N::translate('My pedigree'),
455ade503dfSGreg Roach                route('pedigree', [
456ade503dfSGreg Roach                    'xref' => $gedcomid,
4570c8c69d4SGreg Roach                    'ged'  => $tree->name(),
458ade503dfSGreg Roach                ]),
459ade503dfSGreg Roach                'menu-mypedigree'
460ade503dfSGreg Roach            );
461ade503dfSGreg Roach        }
462ade503dfSGreg Roach
463ade503dfSGreg Roach        return null;
464ade503dfSGreg Roach    }
465ade503dfSGreg Roach
466ade503dfSGreg Roach    /**
467ade503dfSGreg Roach     * Create a pending changes menu.
468ade503dfSGreg Roach     *
4690c8c69d4SGreg Roach     * @param Tree|null $tree
4700c8c69d4SGreg Roach     *
471ade503dfSGreg Roach     * @return Menu|null
472ade503dfSGreg Roach     */
473e364afe4SGreg Roach    public function menuPendingChanges(?Tree $tree): ?Menu
474ade503dfSGreg Roach    {
4750c8c69d4SGreg Roach        if ($tree instanceof Tree && $tree->hasPendingEdit() && Auth::isModerator($tree)) {
476ade503dfSGreg Roach            $url = route('show-pending', [
4770c8c69d4SGreg Roach                'ged' => $tree->name(),
478*e6bcfa02SGreg Roach                'url' => app(Request::class)->getRequestUri(),
479ade503dfSGreg Roach            ]);
480ade503dfSGreg Roach
481ade503dfSGreg Roach            return new Menu(I18N::translate('Pending changes'), $url, 'menu-pending');
482ade503dfSGreg Roach        }
483ade503dfSGreg Roach
484ade503dfSGreg Roach        return null;
485ade503dfSGreg Roach    }
486ade503dfSGreg Roach
487ade503dfSGreg Roach    /**
488ade503dfSGreg Roach     * Themes menu.
489ade503dfSGreg Roach     *
490ade503dfSGreg Roach     * @return Menu|null
491ade503dfSGreg Roach     */
492e364afe4SGreg Roach    public function menuThemes(): ?Menu
493ade503dfSGreg Roach    {
4944ca7e03cSGreg Roach        $themes = app(ModuleService::class)->findByInterface(ModuleThemeInterface::class);
495df8baf00SGreg Roach
496cab242e7SGreg Roach        $current_theme = app(ModuleThemeInterface::class);
4978136679eSGreg Roach
4988136679eSGreg Roach        if ($themes->count() > 1) {
4998136679eSGreg Roach            $submenus = $themes->map(function (ModuleThemeInterface $theme) use ($current_theme): Menu {
5008136679eSGreg Roach                $active     = $theme->name() === $current_theme->name();
5018136679eSGreg Roach                $class      = 'menu-theme-' . $theme->name() . ($active ? ' active' : '');
5028136679eSGreg Roach
5038136679eSGreg Roach                return new Menu($theme->title(), '#', $class, [
504ade503dfSGreg Roach                    'onclick'    => 'return false;',
505ade503dfSGreg Roach                    'data-theme' => $theme->name(),
506ade503dfSGreg Roach                ]);
507ade503dfSGreg Roach            });
508ade503dfSGreg Roach
5098136679eSGreg Roach            return  new Menu(I18N::translate('Theme'), '#', 'menu-theme', [], $submenus->all());
510ade503dfSGreg Roach        }
511ade503dfSGreg Roach
512ade503dfSGreg Roach        return null;
513ade503dfSGreg Roach    }
514ade503dfSGreg Roach
515ade503dfSGreg Roach    /**
516ade503dfSGreg Roach     * Misecellaneous dimensions, fonts, styles, etc.
517ade503dfSGreg Roach     *
518ade503dfSGreg Roach     * @param string $parameter_name
519ade503dfSGreg Roach     *
520ade503dfSGreg Roach     * @return string|int|float
521ade503dfSGreg Roach     */
522ade503dfSGreg Roach    public function parameter($parameter_name)
523ade503dfSGreg Roach    {
524ade503dfSGreg Roach        return '';
525ade503dfSGreg Roach    }
526ade503dfSGreg Roach
527ade503dfSGreg Roach    /**
528ade503dfSGreg Roach     * Generate a list of items for the main menu.
529ade503dfSGreg Roach     *
5300c8c69d4SGreg Roach     * @param Tree|null $tree
5310c8c69d4SGreg Roach     *
532ade503dfSGreg Roach     * @return Menu[]
533ade503dfSGreg Roach     */
5340c8c69d4SGreg Roach    public function genealogyMenu(?Tree $tree): array
535ade503dfSGreg Roach    {
5360c8c69d4SGreg Roach        if ($tree === null) {
5370c8c69d4SGreg Roach            return [];
5380c8c69d4SGreg Roach        }
5390c8c69d4SGreg Roach
5400c8c69d4SGreg Roach        return app(ModuleService::class)->findByComponent(ModuleMenuInterface::class, $tree, Auth::user())
5410c8c69d4SGreg Roach            ->map(function (ModuleMenuInterface $menu) use ($tree): ?Menu {
5420c8c69d4SGreg Roach                return $menu->getMenu($tree);
543ade503dfSGreg Roach            })
544ade503dfSGreg Roach            ->filter()
545ade503dfSGreg Roach            ->all();
546ade503dfSGreg Roach    }
547ade503dfSGreg Roach
548ade503dfSGreg Roach    /**
5490c8c69d4SGreg Roach     * Create the genealogy menu.
550ade503dfSGreg Roach     *
551ade503dfSGreg Roach     * @param Menu[] $menus
552ade503dfSGreg Roach     *
553ade503dfSGreg Roach     * @return string
554ade503dfSGreg Roach     */
5550c8c69d4SGreg Roach    public function genealogyMenuContent(array $menus): string
556ade503dfSGreg Roach    {
557ade503dfSGreg Roach        return implode('', array_map(function (Menu $menu): string {
558ade503dfSGreg Roach            return $menu->bootstrap4();
559ade503dfSGreg Roach        }, $menus));
560ade503dfSGreg Roach    }
561ade503dfSGreg Roach
562ade503dfSGreg Roach    /**
563ade503dfSGreg Roach     * Generate a list of items for the user menu.
564ade503dfSGreg Roach     *
5650c8c69d4SGreg Roach     * @param Tree|null $tree
5660c8c69d4SGreg Roach     *
567ade503dfSGreg Roach     * @return Menu[]
568ade503dfSGreg Roach     */
5690c8c69d4SGreg Roach    public function userMenu(?Tree $tree): array
570ade503dfSGreg Roach    {
571ade503dfSGreg Roach        return array_filter([
5720c8c69d4SGreg Roach            $this->menuPendingChanges($tree),
5730c8c69d4SGreg Roach            $this->menuMyPages($tree),
574ade503dfSGreg Roach            $this->menuThemes(),
575ade503dfSGreg Roach            $this->menuLanguages(),
576ade503dfSGreg Roach            $this->menuLogin(),
577ade503dfSGreg Roach            $this->menuLogout(),
578ade503dfSGreg Roach        ]);
579ade503dfSGreg Roach    }
580ade503dfSGreg Roach
581ade503dfSGreg Roach    /**
582ade503dfSGreg Roach     * A list of CSS files to include for this page.
583ade503dfSGreg Roach     *
584ade503dfSGreg Roach     * @return string[]
585ade503dfSGreg Roach     */
586ade503dfSGreg Roach    public function stylesheets(): array
587ade503dfSGreg Roach    {
588ade503dfSGreg Roach        return [];
589ade503dfSGreg Roach    }
59049a243cbSGreg Roach}
591