xref: /webtrees/app/Module/UserWelcomeModule.php (revision c88a5019dff7bc89d58039dfe7af14f8446e6384)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Module;
19
20use Fisharebest\Webtrees\Auth;
21use Fisharebest\Webtrees\I18N;
22use Fisharebest\Webtrees\Individual;
23use Fisharebest\Webtrees\Module;
24use Fisharebest\Webtrees\Tree;
25use Symfony\Component\HttpFoundation\Request;
26
27/**
28 * Class UserWelcomeModule
29 */
30class UserWelcomeModule extends AbstractModule implements ModuleBlockInterface
31{
32    /** {@inheritdoc} */
33    public function getTitle(): string
34    {
35        /* I18N: Name of a module */
36        return I18N::translate('My page');
37    }
38
39    /** {@inheritdoc} */
40    public function getDescription(): string
41    {
42        /* I18N: Description of the “My page” module */
43        return I18N::translate('A greeting message and useful links for a user.');
44    }
45
46    /**
47     * Generate the HTML content of this block.
48     *
49     * @param Tree     $tree
50     * @param int      $block_id
51     * @param string   $ctype
52     * @param string[] $cfg
53     *
54     * @return string
55     */
56    public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string
57    {
58        $gedcomid   = $tree->getUserPreference(Auth::user(), 'gedcomid');
59        $individual = Individual::getInstance($gedcomid, $tree);
60        $links      = [];
61
62        if ($individual) {
63            if (Module::isActiveChart($tree, 'pedigree_chart')) {
64                $links[] = [
65                    'url'   => route('pedigree', [
66                        'xref' => $individual->xref(),
67                        'ged'  => $individual->tree()->name(),
68                    ]),
69                    'title' => I18N::translate('Default chart'),
70                    'icon'  => 'icon-pedigree',
71                ];
72            }
73
74            $links[] = [
75                'url'   => $individual->url(),
76                'title' => I18N::translate('My individual record'),
77                'icon'  => 'icon-indis',
78            ];
79        }
80
81        $links[] = [
82            'url'   => route('my-account', []),
83            'title' => I18N::translate('My account'),
84            'icon'  => 'icon-mypage',
85        ];
86        $content = view('modules/user_welcome/welcome', ['links' => $links]);
87
88        $real_name = '<span dir="auto">' . e(Auth::user()->getRealName()) . '</span>';
89
90        /* I18N: A %s is the user’s name */
91        $title = I18N::translate('Welcome %s', $real_name);
92
93        if ($ctype !== '') {
94            return view('modules/block-template', [
95                'block'      => str_replace('_', '-', $this->getName()),
96                'id'         => $block_id,
97                'config_url' => '',
98                'title'      => $title,
99                'content'    => $content,
100            ]);
101        }
102
103        return $content;
104    }
105
106    /** {@inheritdoc} */
107    public function loadAjax(): bool
108    {
109        return false;
110    }
111
112    /** {@inheritdoc} */
113    public function isUserBlock(): bool
114    {
115        return true;
116    }
117
118    /** {@inheritdoc} */
119    public function isGedcomBlock(): bool
120    {
121        return false;
122    }
123
124    /**
125     * Update the configuration for a block.
126     *
127     * @param Request $request
128     * @param int     $block_id
129     *
130     * @return void
131     */
132    public function saveBlockConfiguration(Request $request, int $block_id)
133    {
134    }
135
136    /**
137     * An HTML form to edit block settings
138     *
139     * @param Tree $tree
140     * @param int  $block_id
141     *
142     * @return void
143     */
144    public function editBlockConfiguration(Tree $tree, int $block_id)
145    {
146    }
147}
148