xref: /webtrees/app/Module/LoggedInUsersModule.php (revision d11be7027e34e3121be11cc025421873364403f9)
18c2e8227SGreg Roach<?php
23976b470SGreg Roach
38c2e8227SGreg Roach/**
48c2e8227SGreg Roach * webtrees: online genealogy
5*d11be702SGreg 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;
23c0112ce8SGreg Roachuse Fisharebest\Webtrees\Statistics;
24e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree;
251e7a7a28SGreg Roachuse Illuminate\Support\Str;
268c2e8227SGreg Roach
278c2e8227SGreg Roach/**
288c2e8227SGreg Roach * Class LoggedInUsersModule
298c2e8227SGreg Roach */
3037eb8894SGreg Roachclass LoggedInUsersModule extends AbstractModule implements ModuleBlockInterface
31c1010edaSGreg Roach{
3249a243cbSGreg Roach    use ModuleBlockTrait;
3349a243cbSGreg Roach
34961ec755SGreg Roach    /**
350cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
36961ec755SGreg Roach     *
37961ec755SGreg Roach     * @return string
38961ec755SGreg Roach     */
3949a243cbSGreg Roach    public function title(): string
40c1010edaSGreg Roach    {
41bbb76c12SGreg Roach        /* I18N: Name of a module. (A list of users who are online now) */
42bbb76c12SGreg Roach        return I18N::translate('Who is online');
438c2e8227SGreg Roach    }
448c2e8227SGreg Roach
45961ec755SGreg Roach    /**
46961ec755SGreg Roach     * A sentence describing what this module does.
47961ec755SGreg Roach     *
48961ec755SGreg Roach     * @return string
49961ec755SGreg Roach     */
5049a243cbSGreg Roach    public function description(): string
51c1010edaSGreg Roach    {
52bbb76c12SGreg Roach        /* I18N: Description of the “Who is online” module */
53bbb76c12SGreg Roach        return I18N::translate('A list of users and visitors who are currently online.');
548c2e8227SGreg Roach    }
558c2e8227SGreg Roach
5676692c8bSGreg Roach    /**
5776692c8bSGreg Roach     * Generate the HTML content of this block.
5876692c8bSGreg Roach     *
59e490cd80SGreg Roach     * @param Tree                 $tree
6076692c8bSGreg Roach     * @param int                  $block_id
613caaa4d2SGreg Roach     * @param string               $context
6276d39c55SGreg Roach     * @param array<string,string> $config
6376692c8bSGreg Roach     *
6476692c8bSGreg Roach     * @return string
6576692c8bSGreg Roach     */
663caaa4d2SGreg Roach    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
67c1010edaSGreg Roach    {
68c0112ce8SGreg Roach        /** @var Statistics $statistics */
69cab242e7SGreg Roach        $statistics = app(Statistics::class);
70e3fb86dfSGreg Roach
7169e217d1SGreg Roach        $content = $statistics->usersLoggedInList();
728c2e8227SGreg Roach
733caaa4d2SGreg Roach        if ($context !== self::CONTEXT_EMBED) {
74147e99aaSGreg Roach            return view('modules/block-template', [
751e7a7a28SGreg Roach                'block'      => Str::kebab($this->name()),
769c6524dcSGreg Roach                'id'         => $block_id,
779c6524dcSGreg Roach                'config_url' => '',
7849a243cbSGreg Roach                'title'      => $this->title(),
799c6524dcSGreg Roach                'content'    => $content,
809c6524dcSGreg Roach            ]);
818c2e8227SGreg Roach        }
82b2ce94c6SRico Sonntag
83b2ce94c6SRico Sonntag        return $content;
848c2e8227SGreg Roach    }
858c2e8227SGreg Roach
863caaa4d2SGreg Roach    /**
873caaa4d2SGreg Roach     * Should this block load asynchronously using AJAX?
883caaa4d2SGreg Roach     *
893caaa4d2SGreg Roach     * Simple blocks are faster in-line, more complex ones can be loaded later.
903caaa4d2SGreg Roach     *
913caaa4d2SGreg Roach     * @return bool
923caaa4d2SGreg Roach     */
93c1010edaSGreg Roach    public function loadAjax(): bool
94c1010edaSGreg Roach    {
958c2e8227SGreg Roach        return false;
968c2e8227SGreg Roach    }
978c2e8227SGreg Roach
983caaa4d2SGreg Roach    /**
993caaa4d2SGreg Roach     * Can this block be shown on the user’s home page?
1003caaa4d2SGreg Roach     *
1013caaa4d2SGreg Roach     * @return bool
1023caaa4d2SGreg Roach     */
103c1010edaSGreg Roach    public function isUserBlock(): bool
104c1010edaSGreg Roach    {
1058c2e8227SGreg Roach        return true;
1068c2e8227SGreg Roach    }
1078c2e8227SGreg Roach
1083caaa4d2SGreg Roach    /**
1093caaa4d2SGreg Roach     * Can this block be shown on the tree’s home page?
1103caaa4d2SGreg Roach     *
1113caaa4d2SGreg Roach     * @return bool
1123caaa4d2SGreg Roach     */
11363276d8fSGreg Roach    public function isTreeBlock(): bool
114c1010edaSGreg Roach    {
1158c2e8227SGreg Roach        return true;
1168c2e8227SGreg Roach    }
1178c2e8227SGreg Roach}
118