18c2e8227SGreg Roach<?php 28c2e8227SGreg Roach/** 38c2e8227SGreg Roach * webtrees: online genealogy 48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team 58c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 68c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 78c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 88c2e8227SGreg Roach * (at your option) any later version. 98c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 108c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 118c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 128c2e8227SGreg Roach * GNU General Public License for more details. 138c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 148c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 158c2e8227SGreg Roach */ 16e7f56f2aSGreg Roachdeclare(strict_types=1); 17e7f56f2aSGreg Roach 1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 1976692c8bSGreg Roach 200e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 21e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Services\UserService; 22c0112ce8SGreg Roachuse Fisharebest\Webtrees\Statistics; 23e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree; 24a45f9889SGreg Roachuse Symfony\Component\HttpFoundation\Request; 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 /** 34e5a6b4d4SGreg Roach * @var UserService 35e5a6b4d4SGreg Roach */ 36e5a6b4d4SGreg Roach private $user_service; 37e5a6b4d4SGreg Roach 38e5a6b4d4SGreg Roach /** 39e5a6b4d4SGreg Roach * LoggedInUsersModule constructor. 40e5a6b4d4SGreg Roach * 41e5a6b4d4SGreg Roach * @param UserService $user_service 42e5a6b4d4SGreg Roach */ 43e2cbf57aSGreg Roach public function __construct(UserService $user_service) 44e2cbf57aSGreg Roach { 45e5a6b4d4SGreg Roach $this->user_service = $user_service; 46e5a6b4d4SGreg Roach } 47e5a6b4d4SGreg Roach 48e5a6b4d4SGreg Roach /** 49961ec755SGreg Roach * How should this module be labelled on tabs, menus, etc.? 50961ec755SGreg Roach * 51961ec755SGreg Roach * @return string 52961ec755SGreg Roach */ 5349a243cbSGreg Roach public function title(): string 54c1010edaSGreg Roach { 55bbb76c12SGreg Roach /* I18N: Name of a module. (A list of users who are online now) */ 56bbb76c12SGreg Roach return I18N::translate('Who is online'); 578c2e8227SGreg Roach } 588c2e8227SGreg Roach 59961ec755SGreg Roach /** 60961ec755SGreg Roach * A sentence describing what this module does. 61961ec755SGreg Roach * 62961ec755SGreg Roach * @return string 63961ec755SGreg Roach */ 6449a243cbSGreg Roach public function description(): string 65c1010edaSGreg Roach { 66bbb76c12SGreg Roach /* I18N: Description of the “Who is online” module */ 67bbb76c12SGreg Roach return I18N::translate('A list of users and visitors who are currently online.'); 688c2e8227SGreg Roach } 698c2e8227SGreg Roach 7076692c8bSGreg Roach /** 7176692c8bSGreg Roach * Generate the HTML content of this block. 7276692c8bSGreg Roach * 73e490cd80SGreg Roach * @param Tree $tree 7476692c8bSGreg Roach * @param int $block_id 755f2ae573SGreg Roach * @param string $ctype 76727f238cSGreg Roach * @param string[] $cfg 7776692c8bSGreg Roach * 7876692c8bSGreg Roach * @return string 7976692c8bSGreg Roach */ 805f2ae573SGreg Roach public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string 81c1010edaSGreg Roach { 82c0112ce8SGreg Roach /** @var Statistics $statistics */ 83c0112ce8SGreg Roach $statistics = app()->make(Statistics::class); 84e3fb86dfSGreg Roach 85*35358640SGreg Roach $content = '<div class="logged_in_count">' . $statistics->usersLoggedInList() . '</div>'; 868c2e8227SGreg Roach 876a8879feSGreg Roach if ($ctype !== '') { 88147e99aaSGreg Roach return view('modules/block-template', [ 8926684e68SGreg Roach 'block' => str_replace('_', '-', $this->name()), 909c6524dcSGreg Roach 'id' => $block_id, 919c6524dcSGreg Roach 'config_url' => '', 9249a243cbSGreg Roach 'title' => $this->title(), 939c6524dcSGreg Roach 'content' => $content, 949c6524dcSGreg Roach ]); 958c2e8227SGreg Roach } 96b2ce94c6SRico Sonntag 97b2ce94c6SRico Sonntag return $content; 988c2e8227SGreg Roach } 998c2e8227SGreg Roach 1008c2e8227SGreg Roach /** {@inheritdoc} */ 101c1010edaSGreg Roach public function loadAjax(): bool 102c1010edaSGreg Roach { 1038c2e8227SGreg Roach return false; 1048c2e8227SGreg Roach } 1058c2e8227SGreg Roach 1068c2e8227SGreg Roach /** {@inheritdoc} */ 107c1010edaSGreg Roach public function isUserBlock(): bool 108c1010edaSGreg Roach { 1098c2e8227SGreg Roach return true; 1108c2e8227SGreg Roach } 1118c2e8227SGreg Roach 1128c2e8227SGreg Roach /** {@inheritdoc} */ 11363276d8fSGreg Roach public function isTreeBlock(): bool 114c1010edaSGreg Roach { 1158c2e8227SGreg Roach return true; 1168c2e8227SGreg Roach } 1178c2e8227SGreg Roach 11876692c8bSGreg Roach /** 119a45f9889SGreg Roach * Update the configuration for a block. 120a45f9889SGreg Roach * 121a45f9889SGreg Roach * @param Request $request 122a45f9889SGreg Roach * @param int $block_id 123a45f9889SGreg Roach * 124a45f9889SGreg Roach * @return void 125a45f9889SGreg Roach */ 126a45f9889SGreg Roach public function saveBlockConfiguration(Request $request, int $block_id) 127a45f9889SGreg Roach { 128a45f9889SGreg Roach } 129a45f9889SGreg Roach 130a45f9889SGreg Roach /** 13176692c8bSGreg Roach * An HTML form to edit block settings 13276692c8bSGreg Roach * 133e490cd80SGreg Roach * @param Tree $tree 13476692c8bSGreg Roach * @param int $block_id 135a9430be8SGreg Roach * 136a9430be8SGreg Roach * @return void 13776692c8bSGreg Roach */ 138a45f9889SGreg Roach public function editBlockConfiguration(Tree $tree, int $block_id) 139c1010edaSGreg Roach { 1408c2e8227SGreg Roach } 1418c2e8227SGreg Roach} 142