xref: /webtrees/app/Module/ModuleBlockInterface.php (revision d11be7027e34e3121be11cc025421873364403f9)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify
7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by
8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9a25f0a04SGreg Roach * (at your option) any later version.
10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful,
11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13a25f0a04SGreg Roach * GNU General Public License for more details.
14a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16a25f0a04SGreg Roach */
17fcfa147eSGreg Roach
18a9430be8SGreg Roachdeclare(strict_types=1);
19a9430be8SGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
21a25f0a04SGreg Roach
22e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree;
236ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
24e490cd80SGreg Roach
25a25f0a04SGreg Roach/**
26a25f0a04SGreg Roach * Interface ModuleBlockInterface - Classes and libraries for module system
27a25f0a04SGreg Roach */
2837eb8894SGreg Roachinterface ModuleBlockInterface extends ModuleInterface
29c1010edaSGreg Roach{
303caaa4d2SGreg Roach    // Places we can display blocks
313caaa4d2SGreg Roach    public const CONTEXT_EMBED     = 'embed';
323caaa4d2SGreg Roach    public const CONTEXT_TREE_PAGE = 'tree';
333caaa4d2SGreg Roach    public const CONTEXT_USER_PAGE = 'user';
343caaa4d2SGreg Roach
358e0e1b25SGreg Roach    // We show blocks in two columns on the tree/user pages.
368e0e1b25SGreg Roach    public const MAIN_BLOCKS = 'main';
378e0e1b25SGreg Roach    public const SIDE_BLOCKS = 'side';
388e0e1b25SGreg Roach
398e0e1b25SGreg Roach    public const DEFAULT_TREE_PAGE_BLOCKS = [
408e0e1b25SGreg Roach        self::MAIN_BLOCKS => [
418e0e1b25SGreg Roach            1 => FamilyTreeStatisticsModule::class,
428e0e1b25SGreg Roach            2 => FamilyTreeNewsModule::class,
438e0e1b25SGreg Roach            3 => FamilyTreeFavoritesModule::class,
448e0e1b25SGreg Roach            4 => ReviewChangesModule::class,
458e0e1b25SGreg Roach        ],
468e0e1b25SGreg Roach        self::SIDE_BLOCKS => [
478e0e1b25SGreg Roach            1 => WelcomeBlockModule::class,
488e0e1b25SGreg Roach            2 => SlideShowModule::class,
498e0e1b25SGreg Roach            3 => OnThisDayModule::class,
508e0e1b25SGreg Roach            4 => LoggedInUsersModule::class,
518e0e1b25SGreg Roach        ],
528e0e1b25SGreg Roach    ];
538e0e1b25SGreg Roach
548e0e1b25SGreg Roach    public const DEFAULT_USER_PAGE_BLOCKS = [
558e0e1b25SGreg Roach        self::MAIN_BLOCKS => [
568e0e1b25SGreg Roach            1 => OnThisDayModule::class,
578e0e1b25SGreg Roach            2 => UserMessagesModule::class,
588e0e1b25SGreg Roach            3 => UserFavoritesModule::class,
598e0e1b25SGreg Roach        ],
608e0e1b25SGreg Roach        self::SIDE_BLOCKS => [
618e0e1b25SGreg Roach            1 => UserWelcomeModule::class,
628e0e1b25SGreg Roach            2 => SlideShowModule::class,
638e0e1b25SGreg Roach            3 => UpcomingAnniversariesModule::class,
648e0e1b25SGreg Roach            4 => LoggedInUsersModule::class,
658e0e1b25SGreg Roach        ],
668e0e1b25SGreg Roach    ];
678e0e1b25SGreg Roach
68a25f0a04SGreg Roach    /**
69a25f0a04SGreg Roach     * Generate the HTML content of this block.
70a25f0a04SGreg Roach     *
71e490cd80SGreg Roach     * @param Tree                 $tree
72cbc1590aSGreg Roach     * @param int                  $block_id
733caaa4d2SGreg Roach     * @param string               $context
7476d39c55SGreg Roach     * @param array<string,string> $config
75a25f0a04SGreg Roach     *
76a25f0a04SGreg Roach     * @return string
77a25f0a04SGreg Roach     */
783caaa4d2SGreg Roach    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string;
79a25f0a04SGreg Roach
80a25f0a04SGreg Roach    /**
81a25f0a04SGreg Roach     * Should this block load asynchronously using AJAX?
8276692c8bSGreg Roach     *
833caaa4d2SGreg Roach     * Simple blocks are faster in-line, more complex ones can be loaded later.
84a25f0a04SGreg Roach     *
85cbc1590aSGreg Roach     * @return bool
86a25f0a04SGreg Roach     */
87a9430be8SGreg Roach    public function loadAjax(): bool;
88a25f0a04SGreg Roach
89a25f0a04SGreg Roach    /**
90a25f0a04SGreg Roach     * Can this block be shown on the user’s home page?
91a25f0a04SGreg Roach     *
92cbc1590aSGreg Roach     * @return bool
93a25f0a04SGreg Roach     */
94a9430be8SGreg Roach    public function isUserBlock(): bool;
95a25f0a04SGreg Roach
96a25f0a04SGreg Roach    /**
97a25f0a04SGreg Roach     * Can this block be shown on the tree’s home page?
98a25f0a04SGreg Roach     *
99cbc1590aSGreg Roach     * @return bool
100a25f0a04SGreg Roach     */
10163276d8fSGreg Roach    public function isTreeBlock(): bool;
102a25f0a04SGreg Roach
103a25f0a04SGreg Roach    /**
104a25f0a04SGreg Roach     * An HTML form to edit block settings
105a25f0a04SGreg Roach     *
106e490cd80SGreg Roach     * @param Tree $tree
107cbc1590aSGreg Roach     * @param int  $block_id
108a9430be8SGreg Roach     *
1093caaa4d2SGreg Roach     * @return string
110a25f0a04SGreg Roach     */
1113caaa4d2SGreg Roach    public function editBlockConfiguration(Tree $tree, int $block_id): string;
112a45f9889SGreg Roach
113a45f9889SGreg Roach    /**
114a45f9889SGreg Roach     * Update the configuration for a block.
115a45f9889SGreg Roach     *
1166ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
117a45f9889SGreg Roach     * @param int     $block_id
118a45f9889SGreg Roach     *
119a45f9889SGreg Roach     * @return void
120a45f9889SGreg Roach     */
1216ccdf4f0SGreg Roach    public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void;
122a25f0a04SGreg Roach}
123