xref: /webtrees/app/Module/NoteListModule.php (revision 4db4b4a9fa882f4515ff0c373eac4f3f86a0db52)
167992b6aSRichard Cissee<?php
267992b6aSRichard Cissee/**
367992b6aSRichard Cissee * webtrees: online genealogy
467992b6aSRichard Cissee * Copyright (C) 2019 webtrees development team
567992b6aSRichard Cissee * This program is free software: you can redistribute it and/or modify
667992b6aSRichard Cissee * it under the terms of the GNU General Public License as published by
767992b6aSRichard Cissee * the Free Software Foundation, either version 3 of the License, or
867992b6aSRichard Cissee * (at your option) any later version.
967992b6aSRichard Cissee * This program is distributed in the hope that it will be useful,
1067992b6aSRichard Cissee * but WITHOUT ANY WARRANTY; without even the implied warranty of
1167992b6aSRichard Cissee * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1267992b6aSRichard Cissee * GNU General Public License for more details.
1367992b6aSRichard Cissee * You should have received a copy of the GNU General Public License
1467992b6aSRichard Cissee * along with this program. If not, see <http://www.gnu.org/licenses/>.
1567992b6aSRichard Cissee */
1667992b6aSRichard Cisseedeclare(strict_types=1);
1767992b6aSRichard Cissee
1867992b6aSRichard Cisseenamespace Fisharebest\Webtrees\Module;
1967992b6aSRichard Cissee
2067992b6aSRichard Cisseeuse Fisharebest\Webtrees\Contracts\UserInterface;
2167992b6aSRichard Cisseeuse Fisharebest\Webtrees\Http\Controllers\ListController;
2267992b6aSRichard Cisseeuse Fisharebest\Webtrees\I18N;
2367992b6aSRichard Cisseeuse Fisharebest\Webtrees\Services\IndividualListService;
2467992b6aSRichard Cisseeuse Fisharebest\Webtrees\Services\LocalizationService;
2567992b6aSRichard Cisseeuse Fisharebest\Webtrees\Tree;
2667992b6aSRichard Cisseeuse Fisharebest\Webtrees\Auth;
2767992b6aSRichard Cisseeuse Symfony\Component\HttpFoundation\Response;
2867992b6aSRichard Cisseeuse Illuminate\Database\Capsule\Manager as DB;
2967992b6aSRichard Cissee
3067992b6aSRichard Cissee/**
3167992b6aSRichard Cissee * Class IndividualListModule
3267992b6aSRichard Cissee */
3367992b6aSRichard Cisseeclass NoteListModule extends AbstractModule implements ModuleListInterface
3467992b6aSRichard Cissee{
3567992b6aSRichard Cissee    use ModuleListTrait;
3667992b6aSRichard Cissee
3767992b6aSRichard Cissee    /**
3867992b6aSRichard Cissee     * How should this module be labelled on tabs, menus, etc.?
3967992b6aSRichard Cissee     *
4067992b6aSRichard Cissee     * @return string
4167992b6aSRichard Cissee     */
4267992b6aSRichard Cissee    public function title(): string
4367992b6aSRichard Cissee    {
4467992b6aSRichard Cissee        /* I18N: Name of a module/list */
4567992b6aSRichard Cissee        return I18N::translate('Shared notes');
4667992b6aSRichard Cissee    }
4767992b6aSRichard Cissee
4867992b6aSRichard Cissee    /**
4967992b6aSRichard Cissee     * A sentence describing what this module does.
5067992b6aSRichard Cissee     *
5167992b6aSRichard Cissee     * @return string
5267992b6aSRichard Cissee     */
5367992b6aSRichard Cissee    public function description(): string
5467992b6aSRichard Cissee    {
5567992b6aSRichard Cissee        /* I18N: Description of the “NoteListModule” module */
5667992b6aSRichard Cissee        return I18N::translate('A list of shared notes.');
5767992b6aSRichard Cissee    }
5867992b6aSRichard Cissee
5967992b6aSRichard Cissee    /**
6067992b6aSRichard Cissee     * CSS class for the URL.
6167992b6aSRichard Cissee     *
6267992b6aSRichard Cissee     * @return string
6367992b6aSRichard Cissee     */
6467992b6aSRichard Cissee    public function listMenuClass(): string
6567992b6aSRichard Cissee    {
6667992b6aSRichard Cissee        return 'menu-list-note';
6767992b6aSRichard Cissee    }
6867992b6aSRichard Cissee
69*4db4b4a9SGreg Roach    /**
70*4db4b4a9SGreg Roach     * @param Tree          $tree
71*4db4b4a9SGreg Roach     * @param UserInterface $user
72*4db4b4a9SGreg Roach     *
73*4db4b4a9SGreg Roach     * @return Response
74*4db4b4a9SGreg Roach     */
7567992b6aSRichard Cissee    public function getListAction(Tree $tree, UserInterface $user): Response
7667992b6aSRichard Cissee    {
7767992b6aSRichard Cissee        Auth::checkComponentAccess($this, 'list', $tree, $user);
7867992b6aSRichard Cissee
7967992b6aSRichard Cissee        $listController = new ListController(app(IndividualListService::class), app(LocalizationService::class));
8067992b6aSRichard Cissee        return $listController->noteList($tree);
8167992b6aSRichard Cissee    }
8267992b6aSRichard Cissee
83*4db4b4a9SGreg Roach    /**
84*4db4b4a9SGreg Roach     * @return string[]
85*4db4b4a9SGreg Roach     */
8667992b6aSRichard Cissee    public function listUrlAttributes(): array
8767992b6aSRichard Cissee    {
8867992b6aSRichard Cissee        return [];
8967992b6aSRichard Cissee    }
9067992b6aSRichard Cissee
91*4db4b4a9SGreg Roach    /**
92*4db4b4a9SGreg Roach     * @param Tree $tree
93*4db4b4a9SGreg Roach     *
94*4db4b4a9SGreg Roach     * @return bool
95*4db4b4a9SGreg Roach     */
9667992b6aSRichard Cissee    public function listIsEmpty(Tree $tree): bool
9767992b6aSRichard Cissee    {
9867992b6aSRichard Cissee        return !DB::table('other')
9967992b6aSRichard Cissee            ->where('o_file', '=', $tree->id())
10067992b6aSRichard Cissee            ->where('o_type', '=', 'NOTE')
10167992b6aSRichard Cissee            ->exists();
10267992b6aSRichard Cissee    }
10367992b6aSRichard Cissee}
104