xref: /webtrees/app/Module/LoggedInUsersModule.php (revision 87cca37c8b5ee0f07397179f377cdfde768951bb)
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 Symfony\Component\HttpFoundation\Request;
25
26/**
27 * Class LoggedInUsersModule
28 */
29class LoggedInUsersModule extends AbstractModule implements ModuleBlockInterface
30{
31    use ModuleBlockTrait;
32
33    /**
34     * @var UserService
35     */
36    private $user_service;
37
38    /**
39     * LoggedInUsersModule constructor.
40     *
41     * @param UserService $user_service
42     */
43    public function __construct(UserService $user_service)
44    {
45        $this->user_service = $user_service;
46    }
47
48    /**
49     * How should this module be labelled on tabs, menus, etc.?
50     *
51     * @return string
52     */
53    public function title(): string
54    {
55        /* I18N: Name of a module. (A list of users who are online now) */
56        return I18N::translate('Who is online');
57    }
58
59    /**
60     * A sentence describing what this module does.
61     *
62     * @return string
63     */
64    public function description(): string
65    {
66        /* I18N: Description of the “Who is online” module */
67        return I18N::translate('A list of users and visitors who are currently online.');
68    }
69
70    /**
71     * Generate the HTML content of this block.
72     *
73     * @param Tree     $tree
74     * @param int      $block_id
75     * @param string   $ctype
76     * @param string[] $cfg
77     *
78     * @return string
79     */
80    public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string
81    {
82        /** @var Statistics $statistics */
83        $statistics = app()->make(Statistics::class);
84
85        $content = '<div class="logged_in_count">' . $statistics->usersLoggedInList() . '</div>';
86
87        if ($ctype !== '') {
88            return view('modules/block-template', [
89                'block'      => str_replace('_', '-', $this->name()),
90                'id'         => $block_id,
91                'config_url' => '',
92                'title'      => $this->title(),
93                'content'    => $content,
94            ]);
95        }
96
97        return $content;
98    }
99
100    /** {@inheritdoc} */
101    public function loadAjax(): bool
102    {
103        return false;
104    }
105
106    /** {@inheritdoc} */
107    public function isUserBlock(): bool
108    {
109        return true;
110    }
111
112    /** {@inheritdoc} */
113    public function isTreeBlock(): bool
114    {
115        return true;
116    }
117
118    /**
119     * Update the configuration for a block.
120     *
121     * @param Request $request
122     * @param int     $block_id
123     *
124     * @return void
125     */
126    public function saveBlockConfiguration(Request $request, int $block_id)
127    {
128    }
129
130    /**
131     * An HTML form to edit block settings
132     *
133     * @param Tree $tree
134     * @param int  $block_id
135     *
136     * @return void
137     */
138    public function editBlockConfiguration(Tree $tree, int $block_id)
139    {
140    }
141}
142