xref: /webtrees/app/Module/SubmitterListModule.php (revision 37f4d1f0a7a5610284a8bb3182a07ec4441c9fc7)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Module;
21
22use Fisharebest\Webtrees\Http\Controllers\ListController;
23use Fisharebest\Webtrees\I18N;
24use Fisharebest\Webtrees\Services\IndividualListService;
25use Fisharebest\Webtrees\Services\LocalizationService;
26use Fisharebest\Webtrees\Submitter;
27use Fisharebest\Webtrees\Tree;
28use Fisharebest\Webtrees\Auth;
29use Illuminate\Database\Capsule\Manager as DB;
30use Psr\Http\Message\ResponseInterface;
31use Psr\Http\Message\ServerRequestInterface;
32
33use function assert;
34
35/**
36 * Class SubmitterListModule
37 */
38class SubmitterListModule extends AbstractModule implements ModuleListInterface
39{
40    use ModuleListTrait;
41
42    /** @var int The default access level for this module.  It can be changed in the control panel. */
43    protected $access_level = Auth::PRIV_NONE;
44
45    /**
46     * How should this module be identified in the control panel, etc.?
47     *
48     * @return string
49     */
50    public function title(): string
51    {
52        /* I18N: Name of a module/list */
53        return I18N::translate('Submitters');
54    }
55
56    /**
57     * A sentence describing what this module does.
58     *
59     * @return string
60     */
61    public function description(): string
62    {
63        /* I18N: Description of the “Shared submitters” module */
64        return I18N::translate('A list of submitters.');
65    }
66
67    /**
68     * Should this module be enabled when it is first installed?
69     *
70     * @return bool
71     */
72    public function isEnabledByDefault(): bool
73    {
74        return false;
75    }
76
77    /**
78     * CSS class for the URL.
79     *
80     * @return string
81     */
82    public function listMenuClass(): string
83    {
84        return 'menu-list-subm';
85    }
86
87    /**
88     * @param ServerRequestInterface $request
89     *
90     * @return ResponseInterface
91     */
92    public function getListAction(ServerRequestInterface $request): ResponseInterface
93    {
94        $tree = $request->getAttribute('tree');
95        assert($tree instanceof Tree);
96
97        $user = $request->getAttribute('user');
98
99        Auth::checkComponentAccess($this, ModuleListInterface::class, $tree, $user);
100
101        $listController = new ListController(app(IndividualListService::class), app(LocalizationService::class));
102        return $listController->submitterList($request);
103    }
104
105    /**
106     * @return string[]
107     */
108    public function listUrlAttributes(): array
109    {
110        return [];
111    }
112
113    /**
114     * @param Tree $tree
115     *
116     * @return bool
117     */
118    public function listIsEmpty(Tree $tree): bool
119    {
120        return !DB::table('other')
121            ->where('o_file', '=', $tree->id())
122            ->where('o_type', '=', Submitter::RECORD_TYPE)
123            ->exists();
124    }
125}
126