xref: /webtrees/app/Http/RequestHandlers/ControlPanel.php (revision c9c6f2ec6e88594e58f14a6418e0de5aaa1484bd)
10c0910bfSGreg Roach<?php
20c0910bfSGreg Roach
30c0910bfSGreg Roach/**
40c0910bfSGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team
60c0910bfSGreg Roach * This program is free software: you can redistribute it and/or modify
70c0910bfSGreg Roach * it under the terms of the GNU General Public License as published by
80c0910bfSGreg Roach * the Free Software Foundation, either version 3 of the License, or
90c0910bfSGreg Roach * (at your option) any later version.
100c0910bfSGreg Roach * This program is distributed in the hope that it will be useful,
110c0910bfSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
120c0910bfSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
130c0910bfSGreg Roach * GNU General Public License for more details.
140c0910bfSGreg 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/>.
160c0910bfSGreg Roach */
17fcfa147eSGreg Roach
180c0910bfSGreg Roachdeclare(strict_types=1);
190c0910bfSGreg Roach
200c0910bfSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
210c0910bfSGreg Roach
220c0910bfSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait;
230c0910bfSGreg Roachuse Fisharebest\Webtrees\I18N;
240c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\FamilyListModule;
250c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\IndividualListModule;
260c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\MediaListModule;
270c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\ModuleAnalyticsInterface;
280c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface;
290c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface;
3064d12f7bSGreg Roachuse Fisharebest\Webtrees\Module\ModuleCustomInterface;
31ce42304aSGreg Roachuse Fisharebest\Webtrees\Module\ModuleDataFixInterface;
320c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\ModuleFooterInterface;
330c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\ModuleHistoricEventsInterface;
340c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\ModuleLanguageInterface;
350c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\ModuleListInterface;
36*c9c6f2ecSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMapAutocompleteInterface;
37*c9c6f2ecSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMapGeoLocationInterface;
38e3544cb2SGreg Roachuse Fisharebest\Webtrees\Module\ModuleMapLinkInterface;
39*c9c6f2ecSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMapProviderInterface;
400c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMenuInterface;
410c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\ModuleReportInterface;
428a1a28d7SGreg Roachuse Fisharebest\Webtrees\Module\ModuleShareInterface;
430c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\ModuleSidebarInterface;
440c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface;
450c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface;
460c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\NoteListModule;
470c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\RepositoryListModule;
480c0910bfSGreg Roachuse Fisharebest\Webtrees\Module\SourceListModule;
49e72c24d6SGreg Roachuse Fisharebest\Webtrees\Module\SubmitterListModule;
50e72c24d6SGreg Roachuse Fisharebest\Webtrees\Note;
516b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry;
52e72c24d6SGreg Roachuse Fisharebest\Webtrees\Repository;
536fd01894SGreg Roachuse Fisharebest\Webtrees\Services\AdminService;
540c0910bfSGreg Roachuse Fisharebest\Webtrees\Services\HousekeepingService;
550c0910bfSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService;
560c0910bfSGreg Roachuse Fisharebest\Webtrees\Services\ServerCheckService;
570c0910bfSGreg Roachuse Fisharebest\Webtrees\Services\TreeService;
580c0910bfSGreg Roachuse Fisharebest\Webtrees\Services\UpgradeService;
590c0910bfSGreg Roachuse Fisharebest\Webtrees\Services\UserService;
60e72c24d6SGreg Roachuse Fisharebest\Webtrees\Submitter;
610c0910bfSGreg Roachuse Fisharebest\Webtrees\Webtrees;
620c0910bfSGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
630c0910bfSGreg Roachuse Illuminate\Database\Query\Expression;
640c0910bfSGreg Roachuse Illuminate\Database\Query\JoinClause;
650c0910bfSGreg Roachuse Illuminate\Support\Collection;
660c0910bfSGreg Roachuse League\Flysystem\Filesystem;
67f7cf8a15SGreg Roachuse League\Flysystem\Local\LocalFilesystemAdapter;
680c0910bfSGreg Roachuse Psr\Http\Message\ResponseInterface;
690c0910bfSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
700c0910bfSGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
710c0910bfSGreg Roach
720c0910bfSGreg Roach/**
730c0910bfSGreg Roach * The control panel shows a summary of the site and links to admin functions.
740c0910bfSGreg Roach */
750c0910bfSGreg Roachclass ControlPanel implements RequestHandlerInterface
760c0910bfSGreg Roach{
770c0910bfSGreg Roach    use ViewResponseTrait;
780c0910bfSGreg Roach
79*c9c6f2ecSGreg Roach    private AdminService $admin_service;
806fd01894SGreg Roach
81*c9c6f2ecSGreg Roach    private ModuleService $module_service;
820c0910bfSGreg Roach
83*c9c6f2ecSGreg Roach    private HousekeepingService $housekeeping_service;
840c0910bfSGreg Roach
85*c9c6f2ecSGreg Roach    private ServerCheckService $server_check_service;
860c0910bfSGreg Roach
87*c9c6f2ecSGreg Roach    private TreeService $tree_service;
880c0910bfSGreg Roach
89*c9c6f2ecSGreg Roach    private UpgradeService $upgrade_service;
900c0910bfSGreg Roach
91*c9c6f2ecSGreg Roach    private UserService $user_service;
920c0910bfSGreg Roach
930c0910bfSGreg Roach    /**
940c0910bfSGreg Roach     * ControlPanel constructor.
950c0910bfSGreg Roach     *
966fd01894SGreg Roach     * @param AdminService        $admin_service
970c0910bfSGreg Roach     * @param HousekeepingService $housekeeping_service
980c0910bfSGreg Roach     * @param ModuleService       $module_service
990c0910bfSGreg Roach     * @param ServerCheckService  $server_check_service
1000c0910bfSGreg Roach     * @param TreeService         $tree_service
1010c0910bfSGreg Roach     * @param UpgradeService      $upgrade_service
1020c0910bfSGreg Roach     * @param UserService         $user_service
1030c0910bfSGreg Roach     */
1040c0910bfSGreg Roach    public function __construct(
1056fd01894SGreg Roach        AdminService $admin_service,
1060c0910bfSGreg Roach        HousekeepingService $housekeeping_service,
1070c0910bfSGreg Roach        ModuleService $module_service,
1080c0910bfSGreg Roach        ServerCheckService $server_check_service,
1090c0910bfSGreg Roach        TreeService $tree_service,
1100c0910bfSGreg Roach        UpgradeService $upgrade_service,
1110c0910bfSGreg Roach        UserService $user_service
112*c9c6f2ecSGreg Roach    )
113*c9c6f2ecSGreg Roach    {
1146fd01894SGreg Roach        $this->admin_service        = $admin_service;
1150c0910bfSGreg Roach        $this->housekeeping_service = $housekeeping_service;
1166fd01894SGreg Roach        $this->module_service       = $module_service;
1170c0910bfSGreg Roach        $this->server_check_service = $server_check_service;
1180c0910bfSGreg Roach        $this->tree_service         = $tree_service;
1190c0910bfSGreg Roach        $this->upgrade_service      = $upgrade_service;
1200c0910bfSGreg Roach        $this->user_service         = $user_service;
1210c0910bfSGreg Roach    }
1220c0910bfSGreg Roach
1230c0910bfSGreg Roach    /**
1240c0910bfSGreg Roach     * @param ServerRequestInterface $request
1250c0910bfSGreg Roach     *
1260c0910bfSGreg Roach     * @return ResponseInterface
1270c0910bfSGreg Roach     */
1280c0910bfSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
1290c0910bfSGreg Roach    {
1300c0910bfSGreg Roach        $this->layout = 'layouts/administration';
1310c0910bfSGreg Roach
132f7cf8a15SGreg Roach        $filesystem      = new Filesystem(new LocalFilesystemAdapter(Webtrees::ROOT_DIR));
1330c0910bfSGreg Roach        $files_to_delete = $this->housekeeping_service->deleteOldWebtreesFiles($filesystem);
1340c0910bfSGreg Roach
13564d12f7bSGreg Roach        $custom_updates = $this->module_service
13664d12f7bSGreg Roach            ->findByInterface(ModuleCustomInterface::class)
13764d12f7bSGreg Roach            ->filter(static function (ModuleCustomInterface $module): bool {
13864d12f7bSGreg Roach                return version_compare($module->customModuleLatestVersion(), $module->customModuleVersion()) > 0;
13964d12f7bSGreg Roach            });
14064d12f7bSGreg Roach
1416fd01894SGreg Roach        $multiple_tree_threshold = $this->admin_service->multipleTreeThreshold();
1426b9cb339SGreg Roach        $gedcom_file_count       = $this->admin_service->gedcomFiles(Registry::filesystem()->data())->count();
1436fd01894SGreg Roach
1440c0910bfSGreg Roach        return $this->viewResponse('admin/control-panel', [
1450c0910bfSGreg Roach            'title'                             => I18N::translate('Control panel'),
1460c0910bfSGreg Roach            'server_errors'                     => $this->server_check_service->serverErrors(),
1470c0910bfSGreg Roach            'server_warnings'                   => $this->server_check_service->serverWarnings(),
1480c0910bfSGreg Roach            'latest_version'                    => $this->upgrade_service->latestVersion(),
1490c0910bfSGreg Roach            'all_users'                         => $this->user_service->all(),
1500c0910bfSGreg Roach            'administrators'                    => $this->user_service->administrators(),
1510c0910bfSGreg Roach            'managers'                          => $this->user_service->managers(),
1520c0910bfSGreg Roach            'moderators'                        => $this->user_service->moderators(),
1530c0910bfSGreg Roach            'unapproved'                        => $this->user_service->unapproved(),
1540c0910bfSGreg Roach            'unverified'                        => $this->user_service->unverified(),
1550c0910bfSGreg Roach            'all_trees'                         => $this->tree_service->all(),
1560c0910bfSGreg Roach            'changes'                           => $this->totalChanges(),
1570c0910bfSGreg Roach            'individuals'                       => $this->totalIndividuals(),
1580c0910bfSGreg Roach            'families'                          => $this->totalFamilies(),
1590c0910bfSGreg Roach            'sources'                           => $this->totalSources(),
1600c0910bfSGreg Roach            'media'                             => $this->totalMediaObjects(),
1610c0910bfSGreg Roach            'repositories'                      => $this->totalRepositories(),
1620c0910bfSGreg Roach            'notes'                             => $this->totalNotes(),
163e72c24d6SGreg Roach            'submitters'                        => $this->totalSubmitters(),
16460ef53afSGreg Roach            'individual_list_module'            => $this->module_service->findByInterface(IndividualListModule::class)->last(),
1650c0910bfSGreg Roach            'family_list_module'                => $this->module_service->findByInterface(FamilyListModule::class)->first(),
1660c0910bfSGreg Roach            'media_list_module'                 => $this->module_service->findByInterface(MediaListModule::class)->first(),
1670c0910bfSGreg Roach            'note_list_module'                  => $this->module_service->findByInterface(NoteListModule::class)->first(),
1680c0910bfSGreg Roach            'repository_list_module'            => $this->module_service->findByInterface(RepositoryListModule::class)->first(),
1690c0910bfSGreg Roach            'source_list_module'                => $this->module_service->findByInterface(SourceListModule::class)->first(),
170e72c24d6SGreg Roach            'submitter_list_module'             => $this->module_service->findByInterface(SubmitterListModule::class)->first(),
1710c0910bfSGreg Roach            'files_to_delete'                   => $files_to_delete,
1720c0910bfSGreg Roach            'all_modules_disabled'              => $this->module_service->all(true),
1730c0910bfSGreg Roach            'all_modules_enabled'               => $this->module_service->all(),
1740c0910bfSGreg Roach            'deleted_modules'                   => $this->module_service->deletedModules(),
1750c0910bfSGreg Roach            'analytics_modules_disabled'        => $this->module_service->findByInterface(ModuleAnalyticsInterface::class, true),
1760c0910bfSGreg Roach            'analytics_modules_enabled'         => $this->module_service->findByInterface(ModuleAnalyticsInterface::class),
1770c0910bfSGreg Roach            'block_modules_disabled'            => $this->module_service->findByInterface(ModuleBlockInterface::class, true),
1780c0910bfSGreg Roach            'block_modules_enabled'             => $this->module_service->findByInterface(ModuleBlockInterface::class),
1790c0910bfSGreg Roach            'chart_modules_disabled'            => $this->module_service->findByInterface(ModuleChartInterface::class, true),
1800c0910bfSGreg Roach            'chart_modules_enabled'             => $this->module_service->findByInterface(ModuleChartInterface::class),
18164d12f7bSGreg Roach            'custom_updates'                    => $custom_updates,
182ce42304aSGreg Roach            'data_fix_modules_disabled'         => $this->module_service->findByInterface(ModuleDataFixInterface::class, true),
183ce42304aSGreg Roach            'data_fix_modules_enabled'          => $this->module_service->findByInterface(ModuleDataFixInterface::class),
1840c0910bfSGreg Roach            'other_modules'                     => $this->module_service->otherModules(true),
1850c0910bfSGreg Roach            'footer_modules_disabled'           => $this->module_service->findByInterface(ModuleFooterInterface::class, true),
1860c0910bfSGreg Roach            'footer_modules_enabled'            => $this->module_service->findByInterface(ModuleFooterInterface::class),
1870c0910bfSGreg Roach            'history_modules_disabled'          => $this->module_service->findByInterface(ModuleHistoricEventsInterface::class, true),
1880c0910bfSGreg Roach            'history_modules_enabled'           => $this->module_service->findByInterface(ModuleHistoricEventsInterface::class),
1890c0910bfSGreg Roach            'language_modules_disabled'         => $this->module_service->findByInterface(ModuleLanguageInterface::class, true),
1900c0910bfSGreg Roach            'language_modules_enabled'          => $this->module_service->findByInterface(ModuleLanguageInterface::class),
1910c0910bfSGreg Roach            'list_modules_disabled'             => $this->module_service->findByInterface(ModuleListInterface::class, true),
1920c0910bfSGreg Roach            'list_modules_enabled'              => $this->module_service->findByInterface(ModuleListInterface::class),
193*c9c6f2ecSGreg Roach            'map_autocomplete_modules_disabled' => $this->module_service->findByInterface(ModuleMapAutocompleteInterface::class, true),
194*c9c6f2ecSGreg Roach            'map_autocomplete_modules_enabled'  => $this->module_service->findByInterface(ModuleMapAutocompleteInterface::class),
195e3544cb2SGreg Roach            'map_link_modules_disabled'         => $this->module_service->findByInterface(ModuleMapLinkInterface::class, true),
196e3544cb2SGreg Roach            'map_link_modules_enabled'          => $this->module_service->findByInterface(ModuleMapLinkInterface::class),
197*c9c6f2ecSGreg Roach            'map_provider_modules_disabled'     => $this->module_service->findByInterface(ModuleMapProviderInterface::class, true),
198*c9c6f2ecSGreg Roach            'map_provider_modules_enabled'      => $this->module_service->findByInterface(ModuleMapProviderInterface::class),
199*c9c6f2ecSGreg Roach            'map_search_modules_disabled'       => $this->module_service->findByInterface(ModuleMapGeoLocationInterface::class, true),
200*c9c6f2ecSGreg Roach            'map_search_modules_enabled'        => $this->module_service->findByInterface(ModuleMapGeoLocationInterface::class),
2010c0910bfSGreg Roach            'menu_modules_disabled'             => $this->module_service->findByInterface(ModuleMenuInterface::class, true),
2020c0910bfSGreg Roach            'menu_modules_enabled'              => $this->module_service->findByInterface(ModuleMenuInterface::class),
2030c0910bfSGreg Roach            'report_modules_disabled'           => $this->module_service->findByInterface(ModuleReportInterface::class, true),
2040c0910bfSGreg Roach            'report_modules_enabled'            => $this->module_service->findByInterface(ModuleReportInterface::class),
2058a1a28d7SGreg Roach            'share_modules_disabled'            => $this->module_service->findByInterface(ModuleShareInterface::class, true),
2068a1a28d7SGreg Roach            'share_modules_enabled'             => $this->module_service->findByInterface(ModuleShareInterface::class),
2070c0910bfSGreg Roach            'sidebar_modules_disabled'          => $this->module_service->findByInterface(ModuleSidebarInterface::class, true),
2080c0910bfSGreg Roach            'sidebar_modules_enabled'           => $this->module_service->findByInterface(ModuleSidebarInterface::class),
2090c0910bfSGreg Roach            'tab_modules_disabled'              => $this->module_service->findByInterface(ModuleTabInterface::class, true),
2100c0910bfSGreg Roach            'tab_modules_enabled'               => $this->module_service->findByInterface(ModuleTabInterface::class),
2110c0910bfSGreg Roach            'theme_modules_disabled'            => $this->module_service->findByInterface(ModuleThemeInterface::class, true),
2120c0910bfSGreg Roach            'theme_modules_enabled'             => $this->module_service->findByInterface(ModuleThemeInterface::class),
2136fd01894SGreg Roach            'show_synchronize'                  => $gedcom_file_count >= $multiple_tree_threshold,
2140c0910bfSGreg Roach        ]);
2150c0910bfSGreg Roach    }
2160c0910bfSGreg Roach
2170c0910bfSGreg Roach    /**
2180c0910bfSGreg Roach     * Count the number of pending changes in each tree.
2190c0910bfSGreg Roach     *
22024f2a3afSGreg Roach     * @return array<string>
2210c0910bfSGreg Roach     */
2220c0910bfSGreg Roach    private function totalChanges(): array
2230c0910bfSGreg Roach    {
2240c0910bfSGreg Roach        return DB::table('gedcom')
2250c0910bfSGreg Roach            ->leftJoin('change', static function (JoinClause $join): void {
2260c0910bfSGreg Roach                $join
2270c0910bfSGreg Roach                    ->on('change.gedcom_id', '=', 'gedcom.gedcom_id')
2280c0910bfSGreg Roach                    ->where('change.status', '=', 'pending');
2290c0910bfSGreg Roach            })
2300c0910bfSGreg Roach            ->groupBy(['gedcom.gedcom_id'])
231eb8ab1e1SGreg Roach            ->pluck(new Expression('COUNT(change_id) AS aggregate'), 'gedcom.gedcom_id')
2320c0910bfSGreg Roach            ->all();
2330c0910bfSGreg Roach    }
2340c0910bfSGreg Roach
2350c0910bfSGreg Roach    /**
2360c0910bfSGreg Roach     * Count the number of individuals in each tree.
2370c0910bfSGreg Roach     *
238e72c24d6SGreg Roach     * @return Collection<string,int>
2390c0910bfSGreg Roach     */
2400c0910bfSGreg Roach    private function totalIndividuals(): Collection
2410c0910bfSGreg Roach    {
2420c0910bfSGreg Roach        return DB::table('gedcom')
2430c0910bfSGreg Roach            ->leftJoin('individuals', 'i_file', '=', 'gedcom_id')
2440c0910bfSGreg Roach            ->groupBy(['gedcom_id'])
245eb8ab1e1SGreg Roach            ->pluck(new Expression('COUNT(i_id) AS aggregate'), 'gedcom_id')
2460c0910bfSGreg Roach            ->map(static function (string $count) {
2470c0910bfSGreg Roach                return (int) $count;
2480c0910bfSGreg Roach            });
2490c0910bfSGreg Roach    }
2500c0910bfSGreg Roach
2510c0910bfSGreg Roach    /**
2520c0910bfSGreg Roach     * Count the number of families in each tree.
2530c0910bfSGreg Roach     *
254e72c24d6SGreg Roach     * @return Collection<string,int>
2550c0910bfSGreg Roach     */
2560c0910bfSGreg Roach    private function totalFamilies(): Collection
2570c0910bfSGreg Roach    {
2580c0910bfSGreg Roach        return DB::table('gedcom')
2590c0910bfSGreg Roach            ->leftJoin('families', 'f_file', '=', 'gedcom_id')
2600c0910bfSGreg Roach            ->groupBy(['gedcom_id'])
261eb8ab1e1SGreg Roach            ->pluck(new Expression('COUNT(f_id) AS aggregate'), 'gedcom_id')
2620c0910bfSGreg Roach            ->map(static function (string $count) {
2630c0910bfSGreg Roach                return (int) $count;
2640c0910bfSGreg Roach            });
2650c0910bfSGreg Roach    }
2660c0910bfSGreg Roach
2670c0910bfSGreg Roach    /**
2680c0910bfSGreg Roach     * Count the number of sources in each tree.
2690c0910bfSGreg Roach     *
270e72c24d6SGreg Roach     * @return Collection<string,int>
2710c0910bfSGreg Roach     */
2720c0910bfSGreg Roach    private function totalSources(): Collection
2730c0910bfSGreg Roach    {
2740c0910bfSGreg Roach        return DB::table('gedcom')
2750c0910bfSGreg Roach            ->leftJoin('sources', 's_file', '=', 'gedcom_id')
2760c0910bfSGreg Roach            ->groupBy(['gedcom_id'])
277eb8ab1e1SGreg Roach            ->pluck(new Expression('COUNT(s_id) AS aggregate'), 'gedcom_id')
2780c0910bfSGreg Roach            ->map(static function (string $count) {
2790c0910bfSGreg Roach                return (int) $count;
2800c0910bfSGreg Roach            });
2810c0910bfSGreg Roach    }
2820c0910bfSGreg Roach
2830c0910bfSGreg Roach    /**
2840c0910bfSGreg Roach     * Count the number of media objects in each tree.
2850c0910bfSGreg Roach     *
286e72c24d6SGreg Roach     * @return Collection<string,int>
2870c0910bfSGreg Roach     */
2880c0910bfSGreg Roach    private function totalMediaObjects(): Collection
2890c0910bfSGreg Roach    {
2900c0910bfSGreg Roach        return DB::table('gedcom')
2910c0910bfSGreg Roach            ->leftJoin('media', 'm_file', '=', 'gedcom_id')
2920c0910bfSGreg Roach            ->groupBy(['gedcom_id'])
293eb8ab1e1SGreg Roach            ->pluck(new Expression('COUNT(m_id) AS aggregate'), 'gedcom_id')
2940c0910bfSGreg Roach            ->map(static function (string $count) {
2950c0910bfSGreg Roach                return (int) $count;
2960c0910bfSGreg Roach            });
2970c0910bfSGreg Roach    }
2980c0910bfSGreg Roach
2990c0910bfSGreg Roach    /**
3000c0910bfSGreg Roach     * Count the number of repositorie in each tree.
3010c0910bfSGreg Roach     *
302e72c24d6SGreg Roach     * @return Collection<string,int>
3030c0910bfSGreg Roach     */
3040c0910bfSGreg Roach    private function totalRepositories(): Collection
3050c0910bfSGreg Roach    {
3060c0910bfSGreg Roach        return DB::table('gedcom')
3070c0910bfSGreg Roach            ->leftJoin('other', static function (JoinClause $join): void {
3080c0910bfSGreg Roach                $join
3090c0910bfSGreg Roach                    ->on('o_file', '=', 'gedcom_id')
310e72c24d6SGreg Roach                    ->where('o_type', '=', Repository::RECORD_TYPE);
3110c0910bfSGreg Roach            })
3120c0910bfSGreg Roach            ->groupBy(['gedcom_id'])
313eb8ab1e1SGreg Roach            ->pluck(new Expression('COUNT(o_id) AS aggregate'), 'gedcom_id')
3140c0910bfSGreg Roach            ->map(static function (string $count) {
3150c0910bfSGreg Roach                return (int) $count;
3160c0910bfSGreg Roach            });
3170c0910bfSGreg Roach    }
3180c0910bfSGreg Roach
3190c0910bfSGreg Roach    /**
3200c0910bfSGreg Roach     * Count the number of notes in each tree.
3210c0910bfSGreg Roach     *
322e72c24d6SGreg Roach     * @return Collection<string,int>
3230c0910bfSGreg Roach     */
3240c0910bfSGreg Roach    private function totalNotes(): Collection
3250c0910bfSGreg Roach    {
3260c0910bfSGreg Roach        return DB::table('gedcom')
3270c0910bfSGreg Roach            ->leftJoin('other', static function (JoinClause $join): void {
3280c0910bfSGreg Roach                $join
3290c0910bfSGreg Roach                    ->on('o_file', '=', 'gedcom_id')
330e72c24d6SGreg Roach                    ->where('o_type', '=', Note::RECORD_TYPE);
331e72c24d6SGreg Roach            })
332e72c24d6SGreg Roach            ->groupBy(['gedcom_id'])
333eb8ab1e1SGreg Roach            ->pluck(new Expression('COUNT(o_id) AS aggregate'), 'gedcom_id')
334e72c24d6SGreg Roach            ->map(static function (string $count) {
335e72c24d6SGreg Roach                return (int) $count;
336e72c24d6SGreg Roach            });
337e72c24d6SGreg Roach    }
338e72c24d6SGreg Roach
339e72c24d6SGreg Roach    /**
340e72c24d6SGreg Roach     * Count the number of submitters in each tree.
341e72c24d6SGreg Roach     *
342e72c24d6SGreg Roach     * @return Collection<string,int>
343e72c24d6SGreg Roach     */
344e72c24d6SGreg Roach    private function totalSubmitters(): Collection
345e72c24d6SGreg Roach    {
346e72c24d6SGreg Roach        return DB::table('gedcom')
347e72c24d6SGreg Roach            ->leftJoin('other', static function (JoinClause $join): void {
348e72c24d6SGreg Roach                $join
349e72c24d6SGreg Roach                    ->on('o_file', '=', 'gedcom_id')
350e72c24d6SGreg Roach                    ->where('o_type', '=', Submitter::RECORD_TYPE);
3510c0910bfSGreg Roach            })
3520c0910bfSGreg Roach            ->groupBy(['gedcom_id'])
353eb8ab1e1SGreg Roach            ->pluck(new Expression('COUNT(o_id) AS aggregate'), 'gedcom_id')
3540c0910bfSGreg Roach            ->map(static function (string $count) {
3550c0910bfSGreg Roach                return (int) $count;
3560c0910bfSGreg Roach            });
3570c0910bfSGreg Roach    }
3580c0910bfSGreg Roach}
359