xref: /webtrees/app/Module/LoggedInUsersModule.php (revision 7413816e6dd2d50e569034fb804f3dce7471bb94)
18c2e8227SGreg Roach<?php
23976b470SGreg Roach
38c2e8227SGreg Roach/**
48c2e8227SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
68c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
78c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
88c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
98c2e8227SGreg Roach * (at your option) any later version.
108c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
118c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
128c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
138c2e8227SGreg Roach * GNU General Public License for more details.
148c2e8227SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
168c2e8227SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
2176692c8bSGreg Roach
220e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
23*d35568b4SGreg Roachuse Fisharebest\Webtrees\Registry;
24c0112ce8SGreg Roachuse Fisharebest\Webtrees\Statistics;
25e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree;
261e7a7a28SGreg Roachuse Illuminate\Support\Str;
278c2e8227SGreg Roach
288c2e8227SGreg Roach/**
298c2e8227SGreg Roach * Class LoggedInUsersModule
308c2e8227SGreg Roach */
3137eb8894SGreg Roachclass LoggedInUsersModule extends AbstractModule implements ModuleBlockInterface
32c1010edaSGreg Roach{
3349a243cbSGreg Roach    use ModuleBlockTrait;
3449a243cbSGreg Roach
35961ec755SGreg Roach    /**
360cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
37961ec755SGreg Roach     *
38961ec755SGreg Roach     * @return string
39961ec755SGreg Roach     */
4049a243cbSGreg Roach    public function title(): string
41c1010edaSGreg Roach    {
42bbb76c12SGreg Roach        /* I18N: Name of a module. (A list of users who are online now) */
43bbb76c12SGreg Roach        return I18N::translate('Who is online');
448c2e8227SGreg Roach    }
458c2e8227SGreg Roach
4649a243cbSGreg Roach    public function description(): string
47c1010edaSGreg Roach    {
48bbb76c12SGreg Roach        /* I18N: Description of the “Who is online” module */
49bbb76c12SGreg Roach        return I18N::translate('A list of users and visitors who are currently online.');
508c2e8227SGreg Roach    }
518c2e8227SGreg Roach
5276692c8bSGreg Roach    /**
5376692c8bSGreg Roach     * Generate the HTML content of this block.
5476692c8bSGreg Roach     *
55e490cd80SGreg Roach     * @param Tree                 $tree
5676692c8bSGreg Roach     * @param int                  $block_id
573caaa4d2SGreg Roach     * @param string               $context
5876d39c55SGreg Roach     * @param array<string,string> $config
5976692c8bSGreg Roach     *
6076692c8bSGreg Roach     * @return string
6176692c8bSGreg Roach     */
623caaa4d2SGreg Roach    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
63c1010edaSGreg Roach    {
64*d35568b4SGreg Roach        $statistics = Registry::container()->get(Statistics::class);
6569e217d1SGreg Roach        $content    = $statistics->usersLoggedInList();
668c2e8227SGreg Roach
673caaa4d2SGreg Roach        if ($context !== self::CONTEXT_EMBED) {
68147e99aaSGreg Roach            return view('modules/block-template', [
691e7a7a28SGreg Roach                'block'      => Str::kebab($this->name()),
709c6524dcSGreg Roach                'id'         => $block_id,
719c6524dcSGreg Roach                'config_url' => '',
7249a243cbSGreg Roach                'title'      => $this->title(),
739c6524dcSGreg Roach                'content'    => $content,
749c6524dcSGreg Roach            ]);
758c2e8227SGreg Roach        }
76b2ce94c6SRico Sonntag
77b2ce94c6SRico Sonntag        return $content;
788c2e8227SGreg Roach    }
798c2e8227SGreg Roach
803caaa4d2SGreg Roach    /**
813caaa4d2SGreg Roach     * Should this block load asynchronously using AJAX?
823caaa4d2SGreg Roach     *
833caaa4d2SGreg Roach     * Simple blocks are faster in-line, more complex ones can be loaded later.
843caaa4d2SGreg Roach     *
853caaa4d2SGreg Roach     * @return bool
863caaa4d2SGreg Roach     */
87c1010edaSGreg Roach    public function loadAjax(): bool
88c1010edaSGreg Roach    {
898c2e8227SGreg Roach        return false;
908c2e8227SGreg Roach    }
918c2e8227SGreg Roach
923caaa4d2SGreg Roach    /**
933caaa4d2SGreg Roach     * Can this block be shown on the user’s home page?
943caaa4d2SGreg Roach     *
953caaa4d2SGreg Roach     * @return bool
963caaa4d2SGreg Roach     */
97c1010edaSGreg Roach    public function isUserBlock(): bool
98c1010edaSGreg Roach    {
998c2e8227SGreg Roach        return true;
1008c2e8227SGreg Roach    }
1018c2e8227SGreg Roach
1023caaa4d2SGreg Roach    /**
1033caaa4d2SGreg Roach     * Can this block be shown on the tree’s home page?
1043caaa4d2SGreg Roach     *
1053caaa4d2SGreg Roach     * @return bool
1063caaa4d2SGreg Roach     */
10763276d8fSGreg Roach    public function isTreeBlock(): bool
108c1010edaSGreg Roach    {
1098c2e8227SGreg Roach        return true;
1108c2e8227SGreg Roach    }
1118c2e8227SGreg Roach}
112