xref: /webtrees/app/Module/NoteListModule.php (revision 5229eade2a8cdd1381e19f96f67fc1c8b92ca95d)
167992b6aSRichard Cissee<?php
23976b470SGreg Roach
367992b6aSRichard Cissee/**
467992b6aSRichard Cissee * webtrees: online genealogy
567992b6aSRichard Cissee * Copyright (C) 2019 webtrees development team
667992b6aSRichard Cissee * This program is free software: you can redistribute it and/or modify
767992b6aSRichard Cissee * it under the terms of the GNU General Public License as published by
867992b6aSRichard Cissee * the Free Software Foundation, either version 3 of the License, or
967992b6aSRichard Cissee * (at your option) any later version.
1067992b6aSRichard Cissee * This program is distributed in the hope that it will be useful,
1167992b6aSRichard Cissee * but WITHOUT ANY WARRANTY; without even the implied warranty of
1267992b6aSRichard Cissee * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1367992b6aSRichard Cissee * GNU General Public License for more details.
1467992b6aSRichard Cissee * You should have received a copy of the GNU General Public License
1567992b6aSRichard Cissee * along with this program. If not, see <http://www.gnu.org/licenses/>.
1667992b6aSRichard Cissee */
1767992b6aSRichard Cisseedeclare(strict_types=1);
1867992b6aSRichard Cissee
1967992b6aSRichard Cisseenamespace Fisharebest\Webtrees\Module;
2067992b6aSRichard Cissee
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 Illuminate\Database\Capsule\Manager as DB;
28*5229eadeSGreg Roachuse InvalidArgumentException;
296ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface;
3057ab2231SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
31*5229eadeSGreg Roachuse function assert;
3267992b6aSRichard Cissee
3367992b6aSRichard Cissee/**
3467992b6aSRichard Cissee * Class IndividualListModule
3567992b6aSRichard Cissee */
3667992b6aSRichard Cisseeclass NoteListModule extends AbstractModule implements ModuleListInterface
3767992b6aSRichard Cissee{
3867992b6aSRichard Cissee    use ModuleListTrait;
3967992b6aSRichard Cissee
4067992b6aSRichard Cissee    /**
410cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
4267992b6aSRichard Cissee     *
4367992b6aSRichard Cissee     * @return string
4467992b6aSRichard Cissee     */
4567992b6aSRichard Cissee    public function title(): string
4667992b6aSRichard Cissee    {
4767992b6aSRichard Cissee        /* I18N: Name of a module/list */
4867992b6aSRichard Cissee        return I18N::translate('Shared notes');
4967992b6aSRichard Cissee    }
5067992b6aSRichard Cissee
5167992b6aSRichard Cissee    /**
5267992b6aSRichard Cissee     * A sentence describing what this module does.
5367992b6aSRichard Cissee     *
5467992b6aSRichard Cissee     * @return string
5567992b6aSRichard Cissee     */
5667992b6aSRichard Cissee    public function description(): string
5767992b6aSRichard Cissee    {
5867992b6aSRichard Cissee        /* I18N: Description of the “NoteListModule” module */
5967992b6aSRichard Cissee        return I18N::translate('A list of shared notes.');
6067992b6aSRichard Cissee    }
6167992b6aSRichard Cissee
6267992b6aSRichard Cissee    /**
6367992b6aSRichard Cissee     * CSS class for the URL.
6467992b6aSRichard Cissee     *
6567992b6aSRichard Cissee     * @return string
6667992b6aSRichard Cissee     */
6767992b6aSRichard Cissee    public function listMenuClass(): string
6867992b6aSRichard Cissee    {
6967992b6aSRichard Cissee        return 'menu-list-note';
7067992b6aSRichard Cissee    }
7167992b6aSRichard Cissee
724db4b4a9SGreg Roach    /**
7357ab2231SGreg Roach     * @param ServerRequestInterface $request
744db4b4a9SGreg Roach     *
756ccdf4f0SGreg Roach     * @return ResponseInterface
764db4b4a9SGreg Roach     */
7757ab2231SGreg Roach    public function getListAction(ServerRequestInterface $request): ResponseInterface
7867992b6aSRichard Cissee    {
7957ab2231SGreg Roach        $tree = $request->getAttribute('tree');
80*5229eadeSGreg Roach        assert($tree instanceof Tree, new InvalidArgumentException());
81*5229eadeSGreg Roach
8257ab2231SGreg Roach        $user = $request->getAttribute('user');
8357ab2231SGreg Roach
8496d794e7SGreg Roach        Auth::checkComponentAccess($this, ModuleListInterface::class, $tree, $user);
8567992b6aSRichard Cissee
8667992b6aSRichard Cissee        $listController = new ListController(app(IndividualListService::class), app(LocalizationService::class));
872dbf429aSGreg Roach        return $listController->noteList($request);
8867992b6aSRichard Cissee    }
8967992b6aSRichard Cissee
904db4b4a9SGreg Roach    /**
914db4b4a9SGreg Roach     * @return string[]
924db4b4a9SGreg Roach     */
9367992b6aSRichard Cissee    public function listUrlAttributes(): array
9467992b6aSRichard Cissee    {
9567992b6aSRichard Cissee        return [];
9667992b6aSRichard Cissee    }
9767992b6aSRichard Cissee
984db4b4a9SGreg Roach    /**
994db4b4a9SGreg Roach     * @param Tree $tree
1004db4b4a9SGreg Roach     *
1014db4b4a9SGreg Roach     * @return bool
1024db4b4a9SGreg Roach     */
10367992b6aSRichard Cissee    public function listIsEmpty(Tree $tree): bool
10467992b6aSRichard Cissee    {
10567992b6aSRichard Cissee        return !DB::table('other')
10667992b6aSRichard Cissee            ->where('o_file', '=', $tree->id())
10767992b6aSRichard Cissee            ->where('o_type', '=', 'NOTE')
10867992b6aSRichard Cissee            ->exists();
10967992b6aSRichard Cissee    }
11067992b6aSRichard Cissee}
111