xref: /webtrees/app/Module/LoggedInUsersModule.php (revision b6017f990d38d8c56e04c0096ce9a7e8745ad4ba)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Module;
21
22use Fisharebest\Webtrees\I18N;
23use Fisharebest\Webtrees\Statistics;
24use Fisharebest\Webtrees\Tree;
25use Illuminate\Support\Str;
26
27/**
28 * Class LoggedInUsersModule
29 */
30class LoggedInUsersModule extends AbstractModule implements ModuleBlockInterface
31{
32    use ModuleBlockTrait;
33
34    /**
35     * How should this module be identified in the control panel, etc.?
36     *
37     * @return string
38     */
39    public function title(): string
40    {
41        /* I18N: Name of a module. (A list of users who are online now) */
42        return I18N::translate('Who is online');
43    }
44
45    /**
46     * A sentence describing what this module does.
47     *
48     * @return string
49     */
50    public function description(): string
51    {
52        /* I18N: Description of the “Who is online” module */
53        return I18N::translate('A list of users and visitors who are currently online.');
54    }
55
56    /**
57     * Generate the HTML content of this block.
58     *
59     * @param Tree     $tree
60     * @param int      $block_id
61     * @param string   $context
62     * @param string[] $config
63     *
64     * @return string
65     */
66    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
67    {
68        /** @var Statistics $statistics */
69        $statistics = app(Statistics::class);
70
71        $content = $statistics->usersLoggedInList();
72
73        if ($context !== self::CONTEXT_EMBED) {
74            return view('modules/block-template', [
75                'block'      => Str::kebab($this->name()),
76                'id'         => $block_id,
77                'config_url' => '',
78                'title'      => $this->title(),
79                'content'    => $content,
80            ]);
81        }
82
83        return $content;
84    }
85
86    /**
87     * Should this block load asynchronously using AJAX?
88     *
89     * Simple blocks are faster in-line, more complex ones can be loaded later.
90     *
91     * @return bool
92     */
93    public function loadAjax(): bool
94    {
95        return false;
96    }
97
98    /**
99     * Can this block be shown on the user’s home page?
100     *
101     * @return bool
102     */
103    public function isUserBlock(): bool
104    {
105        return true;
106    }
107
108    /**
109     * Can this block be shown on the tree’s home page?
110     *
111     * @return bool
112     */
113    public function isTreeBlock(): bool
114    {
115        return true;
116    }
117}
118