Issues (2560)

app/Module/UserWelcomeModule.php (7 issues)

1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2025 webtrees development team
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\Module;
21
22
use Fisharebest\Webtrees\Auth;
0 ignored issues
show
The type Fisharebest\Webtrees\Auth was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use Fisharebest\Webtrees\Contracts\UserInterface;
0 ignored issues
show
The type Fisharebest\Webtrees\Contracts\UserInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use Fisharebest\Webtrees\Http\RequestHandlers\AccountEdit;
25
use Fisharebest\Webtrees\I18N;
0 ignored issues
show
The type Fisharebest\Webtrees\I18N was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use Fisharebest\Webtrees\Individual;
0 ignored issues
show
The type Fisharebest\Webtrees\Individual was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
use Fisharebest\Webtrees\Registry;
28
use Fisharebest\Webtrees\Services\ModuleService;
0 ignored issues
show
The type Fisharebest\Webtrees\Services\ModuleService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use Fisharebest\Webtrees\Tree;
30
use Illuminate\Support\Str;
31
32
use function view;
33
34
class UserWelcomeModule extends AbstractModule implements ModuleBlockInterface
0 ignored issues
show
The type Fisharebest\Webtrees\Module\ModuleBlockInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
{
36
    use ModuleBlockTrait;
37
38
    private ModuleService $module_service;
39
40
    /**
41
     * @param ModuleService $module_service
42
     */
43
    public function __construct(ModuleService $module_service)
44
    {
45
        $this->module_service = $module_service;
46
    }
47
48
    public function title(): string
49
    {
50
        /* I18N: Name of a module */
51
        return I18N::translate('My page');
52
    }
53
54
    public function description(): string
55
    {
56
        /* I18N: Description of the “My page” module */
57
        return I18N::translate('A greeting message and useful links for a user.');
58
    }
59
60
    /**
61
     * Generate the HTML content of this block.
62
     *
63
     * @param Tree                 $tree
64
     * @param int                  $block_id
65
     * @param string               $context
66
     * @param array<string,string> $config
67
     *
68
     * @return string
69
     */
70
    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
71
    {
72
        $gedcomid   = $tree->getUserPreference(Auth::user(), UserInterface::PREF_TREE_ACCOUNT_XREF);
73
        $individual = Registry::individualFactory()->make($gedcomid, $tree);
74
        $links      = [];
75
76
        $pedigree_chart = $this->module_service
77
            ->findByComponent(ModuleChartInterface::class, $tree, Auth::user())
78
            ->first(static fn (ModuleInterface $module): bool => $module instanceof PedigreeChartModule);
0 ignored issues
show
The type Fisharebest\Webtrees\Module\PedigreeChartModule was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
79
80
        if ($individual instanceof Individual) {
81
            if ($pedigree_chart instanceof PedigreeChartModule) {
82
                $links[] = [
83
                    'url'   => $pedigree_chart->chartUrl($individual),
84
                    'title' => I18N::translate('Default chart'),
85
                    'class' => 'icon-pedigree',
86
                    'icon'  => view('icons/pedigree-right'),
87
                ];
88
            }
89
90
            $links[] = [
91
                'url'   => $individual->url(),
92
                'title' => I18N::translate('My individual record'),
93
                'class' => 'icon-indis',
94
                'icon'  => view('icons/user'),
95
            ];
96
        }
97
98
        $links[] = [
99
            'url'   => route(AccountEdit::class, ['tree' => $tree->name()]),
100
            'title' => I18N::translate('My account'),
101
            'class' => 'icon-mypage',
102
            'icon'  => view('icons/account'),
103
        ];
104
105
        $content = view('modules/user_welcome/welcome', ['links' => $links]);
106
107
        $real_name = "\u{2068}" . e(Auth::user()->realName()) . "\u{2069}";
108
109
        /* I18N: A %s is the user’s name */
110
        $title = I18N::translate('Welcome %s', $real_name);
111
112
        if ($context !== self::CONTEXT_EMBED) {
113
            return view('modules/block-template', [
114
                'block'      => Str::kebab($this->name()),
115
                'id'         => $block_id,
116
                'config_url' => '',
117
                'title'      => $title,
118
                'content'    => $content,
119
            ]);
120
        }
121
122
        return $content;
123
    }
124
125
    /**
126
     * Should this block load asynchronously using AJAX?
127
     *
128
     * Simple blocks are faster in-line, more complex ones can be loaded later.
129
     *
130
     * @return bool
131
     */
132
    public function loadAjax(): bool
133
    {
134
        return false;
135
    }
136
137
    /**
138
     * Can this block be shown on the user’s home page?
139
     *
140
     * @return bool
141
     */
142
    public function isUserBlock(): bool
143
    {
144
        return true;
145
    }
146
147
    /**
148
     * Can this block be shown on the tree’s home page?
149
     *
150
     * @return bool
151
     */
152
    public function isTreeBlock(): bool
153
    {
154
        return false;
155
    }
156
}
157