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; 24*1e7a7a28SGreg Roachuse Illuminate\Support\Str; 25a45f9889SGreg Roachuse Symfony\Component\HttpFoundation\Request; 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 615f2ae573SGreg Roach * @param string $ctype 62727f238cSGreg Roach * @param string[] $cfg 6376692c8bSGreg Roach * 6476692c8bSGreg Roach * @return string 6576692c8bSGreg Roach */ 665f2ae573SGreg Roach public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string 67c1010edaSGreg Roach { 68c0112ce8SGreg Roach /** @var Statistics $statistics */ 69cab242e7SGreg Roach $statistics = app(Statistics::class); 70e3fb86dfSGreg Roach 7135358640SGreg Roach $content = '<div class="logged_in_count">' . $statistics->usersLoggedInList() . '</div>'; 728c2e8227SGreg Roach 736a8879feSGreg Roach if ($ctype !== '') { 74147e99aaSGreg Roach return view('modules/block-template', [ 75*1e7a7a28SGreg 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 868c2e8227SGreg Roach /** {@inheritdoc} */ 87c1010edaSGreg Roach public function loadAjax(): bool 88c1010edaSGreg Roach { 898c2e8227SGreg Roach return false; 908c2e8227SGreg Roach } 918c2e8227SGreg Roach 928c2e8227SGreg Roach /** {@inheritdoc} */ 93c1010edaSGreg Roach public function isUserBlock(): bool 94c1010edaSGreg Roach { 958c2e8227SGreg Roach return true; 968c2e8227SGreg Roach } 978c2e8227SGreg Roach 988c2e8227SGreg Roach /** {@inheritdoc} */ 9963276d8fSGreg Roach public function isTreeBlock(): bool 100c1010edaSGreg Roach { 1018c2e8227SGreg Roach return true; 1028c2e8227SGreg Roach } 1038c2e8227SGreg Roach 10476692c8bSGreg Roach /** 105a45f9889SGreg Roach * Update the configuration for a block. 106a45f9889SGreg Roach * 107a45f9889SGreg Roach * @param Request $request 108a45f9889SGreg Roach * @param int $block_id 109a45f9889SGreg Roach * 110a45f9889SGreg Roach * @return void 111a45f9889SGreg Roach */ 112e364afe4SGreg Roach public function saveBlockConfiguration(Request $request, int $block_id): void 113a45f9889SGreg Roach { 114a45f9889SGreg Roach } 115a45f9889SGreg Roach 116a45f9889SGreg Roach /** 11776692c8bSGreg Roach * An HTML form to edit block settings 11876692c8bSGreg Roach * 119e490cd80SGreg Roach * @param Tree $tree 12076692c8bSGreg Roach * @param int $block_id 121a9430be8SGreg Roach * 122a9430be8SGreg Roach * @return void 12376692c8bSGreg Roach */ 124e364afe4SGreg Roach public function editBlockConfiguration(Tree $tree, int $block_id): void 125c1010edaSGreg Roach { 1268c2e8227SGreg Roach } 1278c2e8227SGreg Roach} 128