xref: /webtrees/app/Module/LoggedInUsersModule.php (revision 1e7a7a28dc1ca3b4463e0c60d00ce3163e72010d)
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\I18N;
21use Fisharebest\Webtrees\Services\UserService;
22use Fisharebest\Webtrees\Statistics;
23use Fisharebest\Webtrees\Tree;
24use Illuminate\Support\Str;
25use Symfony\Component\HttpFoundation\Request;
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   $ctype
62     * @param string[] $cfg
63     *
64     * @return string
65     */
66    public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string
67    {
68        /** @var Statistics $statistics */
69        $statistics = app(Statistics::class);
70
71        $content = '<div class="logged_in_count">' . $statistics->usersLoggedInList() . '</div>';
72
73        if ($ctype !== '') {
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    /** {@inheritdoc} */
87    public function loadAjax(): bool
88    {
89        return false;
90    }
91
92    /** {@inheritdoc} */
93    public function isUserBlock(): bool
94    {
95        return true;
96    }
97
98    /** {@inheritdoc} */
99    public function isTreeBlock(): bool
100    {
101        return true;
102    }
103
104    /**
105     * Update the configuration for a block.
106     *
107     * @param Request $request
108     * @param int     $block_id
109     *
110     * @return void
111     */
112    public function saveBlockConfiguration(Request $request, int $block_id): void
113    {
114    }
115
116    /**
117     * An HTML form to edit block settings
118     *
119     * @param Tree $tree
120     * @param int  $block_id
121     *
122     * @return void
123     */
124    public function editBlockConfiguration(Tree $tree, int $block_id): void
125    {
126    }
127}
128