xref: /webtrees/app/Module/LoggedInUsersModule.php (revision 3976b4703df669696105ed6b024b96d433c8fbdb)
18c2e8227SGreg Roach<?php
2*3976b470SGreg Roach
38c2e8227SGreg Roach/**
48c2e8227SGreg Roach * webtrees: online genealogy
58fcd0d32SGreg Roach * Copyright (C) 2019 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
158c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
168c2e8227SGreg Roach */
17e7f56f2aSGreg Roachdeclare(strict_types=1);
18e7f56f2aSGreg Roach
1976692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
2076692c8bSGreg Roach
210e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
22c0112ce8SGreg Roachuse Fisharebest\Webtrees\Statistics;
23e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree;
241e7a7a28SGreg Roachuse Illuminate\Support\Str;
258c2e8227SGreg Roach
268c2e8227SGreg Roach/**
278c2e8227SGreg Roach * Class LoggedInUsersModule
288c2e8227SGreg Roach */
2937eb8894SGreg Roachclass LoggedInUsersModule extends AbstractModule implements ModuleBlockInterface
30c1010edaSGreg Roach{
3149a243cbSGreg Roach    use ModuleBlockTrait;
3249a243cbSGreg Roach
33961ec755SGreg Roach    /**
340cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
35961ec755SGreg Roach     *
36961ec755SGreg Roach     * @return string
37961ec755SGreg Roach     */
3849a243cbSGreg Roach    public function title(): string
39c1010edaSGreg Roach    {
40bbb76c12SGreg Roach        /* I18N: Name of a module. (A list of users who are online now) */
41bbb76c12SGreg Roach        return I18N::translate('Who is online');
428c2e8227SGreg Roach    }
438c2e8227SGreg Roach
44961ec755SGreg Roach    /**
45961ec755SGreg Roach     * A sentence describing what this module does.
46961ec755SGreg Roach     *
47961ec755SGreg Roach     * @return string
48961ec755SGreg Roach     */
4949a243cbSGreg Roach    public function description(): string
50c1010edaSGreg Roach    {
51bbb76c12SGreg Roach        /* I18N: Description of the “Who is online” module */
52bbb76c12SGreg Roach        return I18N::translate('A list of users and visitors who are currently online.');
538c2e8227SGreg Roach    }
548c2e8227SGreg Roach
5576692c8bSGreg Roach    /**
5676692c8bSGreg Roach     * Generate the HTML content of this block.
5776692c8bSGreg Roach     *
58e490cd80SGreg Roach     * @param Tree     $tree
5976692c8bSGreg Roach     * @param int      $block_id
603caaa4d2SGreg Roach     * @param string   $context
613caaa4d2SGreg Roach     * @param string[] $config
6276692c8bSGreg Roach     *
6376692c8bSGreg Roach     * @return string
6476692c8bSGreg Roach     */
653caaa4d2SGreg Roach    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
66c1010edaSGreg Roach    {
67c0112ce8SGreg Roach        /** @var Statistics $statistics */
68cab242e7SGreg Roach        $statistics = app(Statistics::class);
69e3fb86dfSGreg Roach
7035358640SGreg Roach        $content = '<div class="logged_in_count">' . $statistics->usersLoggedInList() . '</div>';
718c2e8227SGreg Roach
723caaa4d2SGreg Roach        if ($context !== self::CONTEXT_EMBED) {
73147e99aaSGreg Roach            return view('modules/block-template', [
741e7a7a28SGreg Roach                'block'      => Str::kebab($this->name()),
759c6524dcSGreg Roach                'id'         => $block_id,
769c6524dcSGreg Roach                'config_url' => '',
7749a243cbSGreg Roach                'title'      => $this->title(),
789c6524dcSGreg Roach                'content'    => $content,
799c6524dcSGreg Roach            ]);
808c2e8227SGreg Roach        }
81b2ce94c6SRico Sonntag
82b2ce94c6SRico Sonntag        return $content;
838c2e8227SGreg Roach    }
848c2e8227SGreg Roach
853caaa4d2SGreg Roach    /**
863caaa4d2SGreg Roach     * Should this block load asynchronously using AJAX?
873caaa4d2SGreg Roach     *
883caaa4d2SGreg Roach     * Simple blocks are faster in-line, more complex ones can be loaded later.
893caaa4d2SGreg Roach     *
903caaa4d2SGreg Roach     * @return bool
913caaa4d2SGreg Roach     */
92c1010edaSGreg Roach    public function loadAjax(): bool
93c1010edaSGreg Roach    {
948c2e8227SGreg Roach        return false;
958c2e8227SGreg Roach    }
968c2e8227SGreg Roach
973caaa4d2SGreg Roach    /**
983caaa4d2SGreg Roach     * Can this block be shown on the user’s home page?
993caaa4d2SGreg Roach     *
1003caaa4d2SGreg Roach     * @return bool
1013caaa4d2SGreg Roach     */
102c1010edaSGreg Roach    public function isUserBlock(): bool
103c1010edaSGreg Roach    {
1048c2e8227SGreg Roach        return true;
1058c2e8227SGreg Roach    }
1068c2e8227SGreg Roach
1073caaa4d2SGreg Roach    /**
1083caaa4d2SGreg Roach     * Can this block be shown on the tree’s home page?
1093caaa4d2SGreg Roach     *
1103caaa4d2SGreg Roach     * @return bool
1113caaa4d2SGreg Roach     */
11263276d8fSGreg Roach    public function isTreeBlock(): bool
113c1010edaSGreg Roach    {
1148c2e8227SGreg Roach        return true;
1158c2e8227SGreg Roach    }
1168c2e8227SGreg Roach}
117