xref: /webtrees/app/Module/FamilyTreeStatisticsModule.php (revision d35568b467207589ea9059739da0bf1f7e785a0d)
18c2e8227SGreg Roach<?php
23976b470SGreg Roach
38c2e8227SGreg Roach/**
48c2e8227SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
68c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
78c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
88c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
98c2e8227SGreg Roach * (at your option) any later version.
108c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
118c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
128c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
138c2e8227SGreg Roach * GNU General Public License for more details.
148c2e8227SGreg 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/>.
168c2e8227SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
2176692c8bSGreg Roach
220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth;
230e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
248fb4e87cSGreg Roachuse Fisharebest\Webtrees\Individual;
25*d35568b4SGreg Roachuse Fisharebest\Webtrees\Registry;
2667992b6aSRichard Cisseeuse Fisharebest\Webtrees\Services\ModuleService;
279219296aSGreg Roachuse Fisharebest\Webtrees\Statistics;
28e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree;
29748dbe15SGreg Roachuse Fisharebest\Webtrees\Validator;
301ae92905SGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
31a69f5655SGreg Roachuse Illuminate\Database\Query\Expression;
321e7a7a28SGreg Roachuse Illuminate\Support\Str;
336ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
348c2e8227SGreg Roach
35b86c018aSGreg Roachuse function array_slice;
36cd1ec0d0SGreg Roachuse function extract;
37b86c018aSGreg Roachuse function var_dump;
38cd1ec0d0SGreg Roachuse function view;
39cd1ec0d0SGreg Roach
40cd1ec0d0SGreg Roachuse const EXTR_OVERWRITE;
41cd1ec0d0SGreg Roach
428c2e8227SGreg Roach/**
438c2e8227SGreg Roach * Class FamilyTreeStatisticsModule
448c2e8227SGreg Roach */
4537eb8894SGreg Roachclass FamilyTreeStatisticsModule extends AbstractModule implements ModuleBlockInterface
46c1010edaSGreg Roach{
4749a243cbSGreg Roach    use ModuleBlockTrait;
4849a243cbSGreg Roach
49f36626dbSGreg Roach    /** Show this number of surnames by default */
5016d6367aSGreg Roach    private const DEFAULT_NUMBER_OF_SURNAMES = '10';
51f36626dbSGreg Roach
52b55cbc6bSGreg Roach    private ModuleService $module_service;
53b55cbc6bSGreg Roach
54b55cbc6bSGreg Roach    /**
55b55cbc6bSGreg Roach     * @param ModuleService $module_service
56b55cbc6bSGreg Roach     */
57b55cbc6bSGreg Roach    public function __construct(ModuleService $module_service)
58b55cbc6bSGreg Roach    {
59b55cbc6bSGreg Roach        $this->module_service = $module_service;
60b55cbc6bSGreg Roach    }
61b55cbc6bSGreg Roach
62961ec755SGreg Roach    /**
630cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
64961ec755SGreg Roach     *
65961ec755SGreg Roach     * @return string
66961ec755SGreg Roach     */
6749a243cbSGreg Roach    public function title(): string
68c1010edaSGreg Roach    {
69bbb76c12SGreg Roach        /* I18N: Name of a module */
70bbb76c12SGreg Roach        return I18N::translate('Statistics');
718c2e8227SGreg Roach    }
728c2e8227SGreg Roach
73961ec755SGreg Roach    /**
74961ec755SGreg Roach     * A sentence describing what this module does.
75961ec755SGreg Roach     *
76961ec755SGreg Roach     * @return string
77961ec755SGreg Roach     */
7849a243cbSGreg Roach    public function description(): string
79c1010edaSGreg Roach    {
80bbb76c12SGreg Roach        /* I18N: Description of “Statistics” module */
81bbb76c12SGreg Roach        return I18N::translate('The size of the family tree, earliest and latest events, common names, etc.');
828c2e8227SGreg Roach    }
838c2e8227SGreg Roach
8476692c8bSGreg Roach    /**
8576692c8bSGreg Roach     * Generate the HTML content of this block.
8676692c8bSGreg Roach     *
87e490cd80SGreg Roach     * @param Tree                 $tree
8876692c8bSGreg Roach     * @param int                  $block_id
893caaa4d2SGreg Roach     * @param string               $context
9076d39c55SGreg Roach     * @param array<string,string> $config
9176692c8bSGreg Roach     *
9276692c8bSGreg Roach     * @return string
9376692c8bSGreg Roach     */
943caaa4d2SGreg Roach    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
95c1010edaSGreg Roach    {
96*d35568b4SGreg Roach        $statistics = Registry::container()->get(Statistics::class);
97bf57b580SGreg Roach
98e2a378d3SGreg Roach        $show_last_update     = $this->getBlockSetting($block_id, 'show_last_update', '1');
99e2a378d3SGreg Roach        $show_common_surnames = $this->getBlockSetting($block_id, 'show_common_surnames', '1');
10080536c2dSGreg Roach        $number_of_surnames   = (int) $this->getBlockSetting($block_id, 'number_of_surnames', self::DEFAULT_NUMBER_OF_SURNAMES);
101e2a378d3SGreg Roach        $stat_indi            = $this->getBlockSetting($block_id, 'stat_indi', '1');
102e2a378d3SGreg Roach        $stat_fam             = $this->getBlockSetting($block_id, 'stat_fam', '1');
103e2a378d3SGreg Roach        $stat_sour            = $this->getBlockSetting($block_id, 'stat_sour', '1');
104e2a378d3SGreg Roach        $stat_media           = $this->getBlockSetting($block_id, 'stat_media', '1');
105e2a378d3SGreg Roach        $stat_repo            = $this->getBlockSetting($block_id, 'stat_repo', '1');
106e2a378d3SGreg Roach        $stat_surname         = $this->getBlockSetting($block_id, 'stat_surname', '1');
107e2a378d3SGreg Roach        $stat_events          = $this->getBlockSetting($block_id, 'stat_events', '1');
108e2a378d3SGreg Roach        $stat_users           = $this->getBlockSetting($block_id, 'stat_users', '1');
109e2a378d3SGreg Roach        $stat_first_birth     = $this->getBlockSetting($block_id, 'stat_first_birth', '1');
110e2a378d3SGreg Roach        $stat_last_birth      = $this->getBlockSetting($block_id, 'stat_last_birth', '1');
111e2a378d3SGreg Roach        $stat_first_death     = $this->getBlockSetting($block_id, 'stat_first_death', '1');
112e2a378d3SGreg Roach        $stat_last_death      = $this->getBlockSetting($block_id, 'stat_last_death', '1');
113e2a378d3SGreg Roach        $stat_long_life       = $this->getBlockSetting($block_id, 'stat_long_life', '1');
114e2a378d3SGreg Roach        $stat_avg_life        = $this->getBlockSetting($block_id, 'stat_avg_life', '1');
115e2a378d3SGreg Roach        $stat_most_chil       = $this->getBlockSetting($block_id, 'stat_most_chil', '1');
116e2a378d3SGreg Roach        $stat_avg_chil        = $this->getBlockSetting($block_id, 'stat_avg_chil', '1');
1178c2e8227SGreg Roach
1183caaa4d2SGreg Roach        extract($config, EXTR_OVERWRITE);
1198c2e8227SGreg Roach
1208c2e8227SGreg Roach        if ($show_common_surnames) {
121b86c018aSGreg Roach            $query = DB::table('name')
1221ae92905SGreg Roach                ->where('n_file', '=', $tree->id())
1231ae92905SGreg Roach                ->where('n_type', '<>', '_MARNM')
124b86c018aSGreg Roach                ->where('n_surn', '<>', '')
125b86c018aSGreg Roach                ->where('n_surn', '<>', Individual::NOMEN_NESCIO)
126b86c018aSGreg Roach                ->select([
127b86c018aSGreg Roach                    $this->binaryColumn('n_surn', 'n_surn'),
128b86c018aSGreg Roach                    $this->binaryColumn('n_surname', 'n_surname'),
129b86c018aSGreg Roach                    new Expression('COUNT(*) AS total'),
130b86c018aSGreg Roach                ])
131b86c018aSGreg Roach                ->groupBy([
132b86c018aSGreg Roach                    $this->binaryColumn('n_surn'),
133b86c018aSGreg Roach                    $this->binaryColumn('n_surname'),
134b86c018aSGreg Roach                ]);
135e0275e5bSGreg Roach
136b86c018aSGreg Roach            /** @var array<array<int>> $top_surnames */
137b86c018aSGreg Roach            $top_surnames = [];
1381ae92905SGreg Roach
139b86c018aSGreg Roach            foreach ($query->get() as $row) {
140b86c018aSGreg Roach                $row->n_surn = $row->n_surn === '' ? $row->n_surname : $row->n_surn;
141b86c018aSGreg Roach                $row->n_surn = I18N::strtoupper(I18N::language()->normalize($row->n_surn));
14280536c2dSGreg Roach
143b86c018aSGreg Roach                $top_surnames[$row->n_surn][$row->n_surname] ??= 0;
144b86c018aSGreg Roach                $top_surnames[$row->n_surn][$row->n_surname] += (int) $row->total;
145f36626dbSGreg Roach            }
14680536c2dSGreg Roach
147b86c018aSGreg Roach            uasort($top_surnames, static fn (array $x, array $y): int => array_sum($y) <=> array_sum($x));
148b86c018aSGreg Roach
149b86c018aSGreg Roach            $top_surnames = array_slice($top_surnames, 0, $number_of_surnames, true);
1501d3c0c1aSGreg Roach
151b55cbc6bSGreg Roach            // Find a module providing individual lists
152b55cbc6bSGreg Roach            $module = $this->module_service
153b55cbc6bSGreg Roach                ->findByComponent(ModuleListInterface::class, $tree, Auth::user())
154b55cbc6bSGreg Roach                ->first(static fn (ModuleInterface $module): bool => $module instanceof IndividualListModule);
15567992b6aSRichard Cissee
156cd1ec0d0SGreg Roach            $surnames = view('lists/surnames-compact-list', [
157cd1ec0d0SGreg Roach                'module'   => $module,
158cd1ec0d0SGreg Roach                'totals'   => false,
159b86c018aSGreg Roach                'surnames' => $top_surnames,
160cd1ec0d0SGreg Roach                'tree'     => $tree,
161cd1ec0d0SGreg Roach            ]);
1621d3c0c1aSGreg Roach        } else {
1631d3c0c1aSGreg Roach            $surnames = '';
1648c2e8227SGreg Roach        }
1651d3c0c1aSGreg Roach
166147e99aaSGreg Roach        $content = view('modules/gedcom_stats/statistics', [
1671d3c0c1aSGreg Roach            'show_last_update'     => $show_last_update,
1681d3c0c1aSGreg Roach            'show_common_surnames' => $show_common_surnames,
1691d3c0c1aSGreg Roach            'number_of_surnames'   => $number_of_surnames,
1701d3c0c1aSGreg Roach            'stat_indi'            => $stat_indi,
1711d3c0c1aSGreg Roach            'stat_fam'             => $stat_fam,
1721d3c0c1aSGreg Roach            'stat_sour'            => $stat_sour,
1731d3c0c1aSGreg Roach            'stat_media'           => $stat_media,
1741d3c0c1aSGreg Roach            'stat_repo'            => $stat_repo,
1751d3c0c1aSGreg Roach            'stat_surname'         => $stat_surname,
1761d3c0c1aSGreg Roach            'stat_events'          => $stat_events,
1771d3c0c1aSGreg Roach            'stat_users'           => $stat_users,
1781d3c0c1aSGreg Roach            'stat_first_birth'     => $stat_first_birth,
1791d3c0c1aSGreg Roach            'stat_last_birth'      => $stat_last_birth,
1801d3c0c1aSGreg Roach            'stat_first_death'     => $stat_first_death,
1811d3c0c1aSGreg Roach            'stat_last_death'      => $stat_last_death,
1821d3c0c1aSGreg Roach            'stat_long_life'       => $stat_long_life,
1831d3c0c1aSGreg Roach            'stat_avg_life'        => $stat_avg_life,
1841d3c0c1aSGreg Roach            'stat_most_chil'       => $stat_most_chil,
1851d3c0c1aSGreg Roach            'stat_avg_chil'        => $stat_avg_chil,
1861d3c0c1aSGreg Roach            'surnames'             => $surnames,
1871d3c0c1aSGreg Roach        ]);
18828941e3cSGreg Roach
189bd055353SGreg Roach        $content = $statistics->embedTags($content);
190bd055353SGreg Roach
1913caaa4d2SGreg Roach        if ($context !== self::CONTEXT_EMBED) {
192147e99aaSGreg Roach            return view('modules/block-template', [
1931e7a7a28SGreg Roach                'block'      => Str::kebab($this->name()),
1949c6524dcSGreg Roach                'id'         => $block_id,
1953caaa4d2SGreg Roach                'config_url' => $this->configUrl($tree, $context, $block_id),
19649a243cbSGreg Roach                'title'      => $this->title(),
1979c6524dcSGreg Roach                'content'    => $content,
1989c6524dcSGreg Roach            ]);
1998c2e8227SGreg Roach        }
200b2ce94c6SRico Sonntag
201b2ce94c6SRico Sonntag        return $content;
2028c2e8227SGreg Roach    }
2038c2e8227SGreg Roach
2043caaa4d2SGreg Roach    /**
2053caaa4d2SGreg Roach     * Should this block load asynchronously using AJAX?
2063caaa4d2SGreg Roach     *
2073caaa4d2SGreg Roach     * Simple blocks are faster in-line, more complex ones can be loaded later.
2083caaa4d2SGreg Roach     *
2093caaa4d2SGreg Roach     * @return bool
2103caaa4d2SGreg Roach     */
211c1010edaSGreg Roach    public function loadAjax(): bool
212c1010edaSGreg Roach    {
2138c2e8227SGreg Roach        return true;
2148c2e8227SGreg Roach    }
2158c2e8227SGreg Roach
2163caaa4d2SGreg Roach    /**
2173caaa4d2SGreg Roach     * Can this block be shown on the user’s home page?
2183caaa4d2SGreg Roach     *
2193caaa4d2SGreg Roach     * @return bool
2203caaa4d2SGreg Roach     */
221c1010edaSGreg Roach    public function isUserBlock(): bool
222c1010edaSGreg Roach    {
2238c2e8227SGreg Roach        return true;
2248c2e8227SGreg Roach    }
2258c2e8227SGreg Roach
2263caaa4d2SGreg Roach    /**
2273caaa4d2SGreg Roach     * Can this block be shown on the tree’s home page?
2283caaa4d2SGreg Roach     *
2293caaa4d2SGreg Roach     * @return bool
2303caaa4d2SGreg Roach     */
23163276d8fSGreg Roach    public function isTreeBlock(): bool
232c1010edaSGreg Roach    {
2338c2e8227SGreg Roach        return true;
2348c2e8227SGreg Roach    }
2358c2e8227SGreg Roach
23676692c8bSGreg Roach    /**
237a45f9889SGreg Roach     * Update the configuration for a block.
238a45f9889SGreg Roach     *
2396ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
240a45f9889SGreg Roach     * @param int     $block_id
241a45f9889SGreg Roach     *
242a45f9889SGreg Roach     * @return void
243a45f9889SGreg Roach     */
2446ccdf4f0SGreg Roach    public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
245a45f9889SGreg Roach    {
246748dbe15SGreg Roach        $show_last_update     = Validator::parsedBody($request)->boolean('show_last_update', false);
247748dbe15SGreg Roach        $show_common_surnames = Validator::parsedBody($request)->boolean('show_common_surnames', false);
248748dbe15SGreg Roach        $number_of_surnames   = Validator::parsedBody($request)->integer('number_of_surnames');
249748dbe15SGreg Roach        $stat_indi            = Validator::parsedBody($request)->boolean('stat_indi', false);
250748dbe15SGreg Roach        $stat_fam             = Validator::parsedBody($request)->boolean('stat_fam', false);
251748dbe15SGreg Roach        $stat_sour            = Validator::parsedBody($request)->boolean('stat_sour', false);
252748dbe15SGreg Roach        $stat_other           = Validator::parsedBody($request)->boolean('stat_other', false);
253748dbe15SGreg Roach        $stat_media           = Validator::parsedBody($request)->boolean('stat_media', false);
254748dbe15SGreg Roach        $stat_repo            = Validator::parsedBody($request)->boolean('stat_repo', false);
255748dbe15SGreg Roach        $stat_surname         = Validator::parsedBody($request)->boolean('stat_surname', false);
256748dbe15SGreg Roach        $stat_events          = Validator::parsedBody($request)->boolean('stat_events', false);
257748dbe15SGreg Roach        $stat_users           = Validator::parsedBody($request)->boolean('stat_users', false);
258748dbe15SGreg Roach        $stat_first_birth     = Validator::parsedBody($request)->boolean('stat_first_birth', false);
259748dbe15SGreg Roach        $stat_last_birth      = Validator::parsedBody($request)->boolean('stat_last_birth', false);
260748dbe15SGreg Roach        $stat_first_death     = Validator::parsedBody($request)->boolean('stat_first_death', false);
261748dbe15SGreg Roach        $stat_last_death      = Validator::parsedBody($request)->boolean('stat_last_death', false);
262748dbe15SGreg Roach        $stat_long_life       = Validator::parsedBody($request)->boolean('stat_long_life', false);
263748dbe15SGreg Roach        $stat_avg_life        = Validator::parsedBody($request)->boolean('stat_avg_life', false);
264748dbe15SGreg Roach        $stat_most_chil       = Validator::parsedBody($request)->boolean('stat_most_chil', false);
265748dbe15SGreg Roach        $stat_avg_chil        = Validator::parsedBody($request)->boolean('stat_avg_chil', false);
266ac5f8ed1SGreg Roach
267748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'show_last_update', (string) $show_last_update);
268748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'show_common_surnames', (string) $show_common_surnames);
269748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'number_of_surnames', (string) $number_of_surnames);
270748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_indi', (string) $stat_indi);
271748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_fam', (string) $stat_fam);
272748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_sour', (string) $stat_sour);
273748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_other', (string) $stat_other);
274748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_media', (string) $stat_media);
275748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_repo', (string) $stat_repo);
276748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_surname', (string) $stat_surname);
277748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_events', (string) $stat_events);
278748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_users', (string) $stat_users);
279748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_first_birth', (string) $stat_first_birth);
280748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_last_birth', (string) $stat_last_birth);
281748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_first_death', (string) $stat_first_death);
282748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_last_death', (string) $stat_last_death);
283748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_long_life', (string) $stat_long_life);
284748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_avg_life', (string) $stat_avg_life);
285748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_most_chil', (string) $stat_most_chil);
286748dbe15SGreg Roach        $this->setBlockSetting($block_id, 'stat_avg_chil', (string) $stat_avg_chil);
287a45f9889SGreg Roach    }
288a45f9889SGreg Roach
289a45f9889SGreg Roach    /**
29076692c8bSGreg Roach     * An HTML form to edit block settings
29176692c8bSGreg Roach     *
292e490cd80SGreg Roach     * @param Tree $tree
29376692c8bSGreg Roach     * @param int  $block_id
294a9430be8SGreg Roach     *
2953caaa4d2SGreg Roach     * @return string
29676692c8bSGreg Roach     */
2973caaa4d2SGreg Roach    public function editBlockConfiguration(Tree $tree, int $block_id): string
298c1010edaSGreg Roach    {
299e2a378d3SGreg Roach        $show_last_update     = $this->getBlockSetting($block_id, 'show_last_update', '1');
300e2a378d3SGreg Roach        $show_common_surnames = $this->getBlockSetting($block_id, 'show_common_surnames', '1');
301f36626dbSGreg Roach        $number_of_surnames   = $this->getBlockSetting($block_id, 'number_of_surnames', self::DEFAULT_NUMBER_OF_SURNAMES);
302e2a378d3SGreg Roach        $stat_indi            = $this->getBlockSetting($block_id, 'stat_indi', '1');
303e2a378d3SGreg Roach        $stat_fam             = $this->getBlockSetting($block_id, 'stat_fam', '1');
304e2a378d3SGreg Roach        $stat_sour            = $this->getBlockSetting($block_id, 'stat_sour', '1');
305e2a378d3SGreg Roach        $stat_media           = $this->getBlockSetting($block_id, 'stat_media', '1');
306e2a378d3SGreg Roach        $stat_repo            = $this->getBlockSetting($block_id, 'stat_repo', '1');
307e2a378d3SGreg Roach        $stat_surname         = $this->getBlockSetting($block_id, 'stat_surname', '1');
308e2a378d3SGreg Roach        $stat_events          = $this->getBlockSetting($block_id, 'stat_events', '1');
309e2a378d3SGreg Roach        $stat_users           = $this->getBlockSetting($block_id, 'stat_users', '1');
310e2a378d3SGreg Roach        $stat_first_birth     = $this->getBlockSetting($block_id, 'stat_first_birth', '1');
311e2a378d3SGreg Roach        $stat_last_birth      = $this->getBlockSetting($block_id, 'stat_last_birth', '1');
312e2a378d3SGreg Roach        $stat_first_death     = $this->getBlockSetting($block_id, 'stat_first_death', '1');
313e2a378d3SGreg Roach        $stat_last_death      = $this->getBlockSetting($block_id, 'stat_last_death', '1');
314e2a378d3SGreg Roach        $stat_long_life       = $this->getBlockSetting($block_id, 'stat_long_life', '1');
315e2a378d3SGreg Roach        $stat_avg_life        = $this->getBlockSetting($block_id, 'stat_avg_life', '1');
316e2a378d3SGreg Roach        $stat_most_chil       = $this->getBlockSetting($block_id, 'stat_most_chil', '1');
317e2a378d3SGreg Roach        $stat_avg_chil        = $this->getBlockSetting($block_id, 'stat_avg_chil', '1');
3188c2e8227SGreg Roach
3193caaa4d2SGreg Roach        return view('modules/gedcom_stats/config', [
320c385536dSGreg Roach            'show_last_update'     => $show_last_update,
321c385536dSGreg Roach            'show_common_surnames' => $show_common_surnames,
322c385536dSGreg Roach            'number_of_surnames'   => $number_of_surnames,
323c385536dSGreg Roach            'stat_indi'            => $stat_indi,
324c385536dSGreg Roach            'stat_fam'             => $stat_fam,
325c385536dSGreg Roach            'stat_sour'            => $stat_sour,
326c385536dSGreg Roach            'stat_media'           => $stat_media,
327c385536dSGreg Roach            'stat_repo'            => $stat_repo,
328c385536dSGreg Roach            'stat_surname'         => $stat_surname,
329c385536dSGreg Roach            'stat_events'          => $stat_events,
330c385536dSGreg Roach            'stat_users'           => $stat_users,
331c385536dSGreg Roach            'stat_first_birth'     => $stat_first_birth,
332c385536dSGreg Roach            'stat_last_birth'      => $stat_last_birth,
333c385536dSGreg Roach            'stat_first_death'     => $stat_first_death,
334c385536dSGreg Roach            'stat_last_death'      => $stat_last_death,
335c385536dSGreg Roach            'stat_long_life'       => $stat_long_life,
336c385536dSGreg Roach            'stat_avg_life'        => $stat_avg_life,
337c385536dSGreg Roach            'stat_most_chil'       => $stat_most_chil,
338c385536dSGreg Roach            'stat_avg_chil'        => $stat_avg_chil,
339c385536dSGreg Roach        ]);
3408c2e8227SGreg Roach    }
341b86c018aSGreg Roach
342b86c018aSGreg Roach    /**
343b86c018aSGreg Roach     * This module assumes the database will use binary collation on the name columns.
344b86c018aSGreg Roach     * Until we convert MySQL databases to use utf8_bin, we need to do this at run-time.
345b86c018aSGreg Roach     *
346b86c018aSGreg Roach     * @param string      $column
347b86c018aSGreg Roach     * @param string|null $alias
348b86c018aSGreg Roach     *
349b86c018aSGreg Roach     * @return Expression
350b86c018aSGreg Roach     */
351b86c018aSGreg Roach    private function binaryColumn(string $column, string $alias = null): Expression
352b86c018aSGreg Roach    {
353b86c018aSGreg Roach        if (DB::connection()->getDriverName() === 'mysql') {
354b86c018aSGreg Roach            $sql = 'CAST(' . $column . ' AS binary)';
355b86c018aSGreg Roach        } else {
356b86c018aSGreg Roach            $sql = $column;
357b86c018aSGreg Roach        }
358b86c018aSGreg Roach
359b86c018aSGreg Roach        if ($alias !== null) {
360b86c018aSGreg Roach            $sql .= ' AS ' . $alias;
361b86c018aSGreg Roach        }
362b86c018aSGreg Roach
363b86c018aSGreg Roach        return new Expression($sql);
364b86c018aSGreg Roach    }
3658c2e8227SGreg Roach}
366