Passed
Push — master ( 466fee...8256f4 )
by Greg
06:43 queued 01:19
created

SubmitterListModule::listUrlAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\Module;
21
22
use Fisharebest\Webtrees\Http\Controllers\ListController;
23
use Fisharebest\Webtrees\I18N;
24
use Fisharebest\Webtrees\Services\IndividualListService;
25
use Fisharebest\Webtrees\Services\LocalizationService;
26
use Fisharebest\Webtrees\Submitter;
27
use Fisharebest\Webtrees\Tree;
28
use Fisharebest\Webtrees\Auth;
29
use Illuminate\Database\Capsule\Manager as DB;
30
use Psr\Http\Message\ResponseInterface;
31
use Psr\Http\Message\ServerRequestInterface;
32
33
use function assert;
34
35
/**
36
 * Class SubmitterListModule
37
 */
38
class 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