xref: /webtrees/app/Module/FrequentlyAskedQuestionsModule.php (revision f3874e197f9762d298de9838533175b6115261e9)
18c2e8227SGreg Roach<?php
23976b470SGreg Roach
38c2e8227SGreg Roach/**
48c2e8227SGreg Roach * webtrees: online genealogy
58fcd0d32SGreg Roach * Copyright (C) 2019 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
158c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
168c2e8227SGreg Roach */
17e7f56f2aSGreg Roachdeclare(strict_types=1);
18e7f56f2aSGreg Roach
1976692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
2076692c8bSGreg Roach
210e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Menu;
2350d6f48cSGreg Roachuse Fisharebest\Webtrees\Services\HtmlService;
240e62c4b8SGreg Roachuse Fisharebest\Webtrees\Tree;
2577654037SGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
2677654037SGreg Roachuse Illuminate\Database\Query\Builder;
2777654037SGreg Roachuse Illuminate\Support\Collection;
285229eadeSGreg Roachuse InvalidArgumentException;
296ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface;
306ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
318de50a4eSGreg Roachuse stdClass;
32*f3874e19SGreg Roach
335229eadeSGreg Roachuse function assert;
348c2e8227SGreg Roach
358c2e8227SGreg Roach/**
368c2e8227SGreg Roach * Class FrequentlyAskedQuestionsModule
378c2e8227SGreg Roach */
3837eb8894SGreg Roachclass FrequentlyAskedQuestionsModule extends AbstractModule implements ModuleConfigInterface, ModuleMenuInterface
39c1010edaSGreg Roach{
4049a243cbSGreg Roach    use ModuleConfigTrait;
4149a243cbSGreg Roach    use ModuleMenuTrait;
4249a243cbSGreg Roach
4350d6f48cSGreg Roach    /** @var HtmlService */
4450d6f48cSGreg Roach    private $html_service;
4550d6f48cSGreg Roach
4650d6f48cSGreg Roach    /**
4750d6f48cSGreg Roach     * HtmlBlockModule bootstrap.
4850d6f48cSGreg Roach     *
4950d6f48cSGreg Roach     * @param HtmlService $html_service
5050d6f48cSGreg Roach     */
5150d6f48cSGreg Roach    public function boot(HtmlService $html_service)
5250d6f48cSGreg Roach    {
5350d6f48cSGreg Roach        $this->html_service = $html_service;
5450d6f48cSGreg Roach    }
5550d6f48cSGreg Roach
56961ec755SGreg Roach    /**
570cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
58961ec755SGreg Roach     *
59961ec755SGreg Roach     * @return string
60961ec755SGreg Roach     */
6149a243cbSGreg Roach    public function title(): string
62c1010edaSGreg Roach    {
63bbb76c12SGreg Roach        /* I18N: Name of a module. Abbreviation for “Frequently Asked Questions” */
64bbb76c12SGreg Roach        return I18N::translate('FAQ');
658c2e8227SGreg Roach    }
668c2e8227SGreg Roach
67961ec755SGreg Roach    /**
68961ec755SGreg Roach     * A sentence describing what this module does.
69961ec755SGreg Roach     *
70961ec755SGreg Roach     * @return string
71961ec755SGreg Roach     */
7249a243cbSGreg Roach    public function description(): string
73c1010edaSGreg Roach    {
74bbb76c12SGreg Roach        /* I18N: Description of the “FAQ” module */
75bbb76c12SGreg Roach        return I18N::translate('A list of frequently asked questions and answers.');
768c2e8227SGreg Roach    }
778c2e8227SGreg Roach
7876692c8bSGreg Roach    /**
7949a243cbSGreg Roach     * The default position for this menu.  It can be changed in the control panel.
800ee13198SGreg Roach     *
810ee13198SGreg Roach     * @return int
820ee13198SGreg Roach     */
838f53f488SRico Sonntag    public function defaultMenuOrder(): int
84c1010edaSGreg Roach    {
85353b36abSGreg Roach        return 8;
868c2e8227SGreg Roach    }
878c2e8227SGreg Roach
880ee13198SGreg Roach    /**
890ee13198SGreg Roach     * A menu, to be added to the main application menu.
900ee13198SGreg Roach     *
91aee13b6dSGreg Roach     * @param Tree $tree
92aee13b6dSGreg Roach     *
930ee13198SGreg Roach     * @return Menu|null
940ee13198SGreg Roach     */
9546295629SGreg Roach    public function getMenu(Tree $tree): ?Menu
96c1010edaSGreg Roach    {
9777654037SGreg Roach        if ($this->faqsExist($tree, WT_LOCALE)) {
9849a243cbSGreg Roach            return new Menu($this->title(), route('module', [
9926684e68SGreg Roach                'module' => $this->name(),
100c1010edaSGreg Roach                'action' => 'Show',
1019022ab66SGreg Roach                'tree'   => $tree->name(),
102c1010edaSGreg Roach            ]), 'menu-help');
1038c2e8227SGreg Roach        }
104b2ce94c6SRico Sonntag
105b2ce94c6SRico Sonntag        return null;
1068c2e8227SGreg Roach    }
107aee13b6dSGreg Roach
108aee13b6dSGreg Roach    /**
10957ab2231SGreg Roach     * @param ServerRequestInterface $request
110aee13b6dSGreg Roach     *
1116ccdf4f0SGreg Roach     * @return ResponseInterface
112aee13b6dSGreg Roach     */
11357ab2231SGreg Roach    public function getAdminAction(ServerRequestInterface $request): ResponseInterface
114c1010edaSGreg Roach    {
115aee13b6dSGreg Roach        $this->layout = 'layouts/administration';
116aee13b6dSGreg Roach
11757ab2231SGreg Roach        $tree = $request->getAttribute('tree');
1185229eadeSGreg Roach        assert($tree instanceof Tree, new InvalidArgumentException());
1195229eadeSGreg Roach
12026348dcdSGreg Roach        $faqs = $this->faqsForTree($tree);
121aee13b6dSGreg Roach
12277654037SGreg Roach        $min_block_order = DB::table('block')
12326684e68SGreg Roach            ->where('module_name', '=', $this->name())
1240b5fd0a6SGreg Roach            ->where(static function (Builder $query) use ($tree): void {
12577654037SGreg Roach                $query
12677654037SGreg Roach                    ->whereNull('gedcom_id')
12777654037SGreg Roach                    ->orWhere('gedcom_id', '=', $tree->id());
12877654037SGreg Roach            })
12977654037SGreg Roach            ->min('block_order');
130aee13b6dSGreg Roach
13177654037SGreg Roach        $max_block_order = DB::table('block')
13226684e68SGreg Roach            ->where('module_name', '=', $this->name())
1330b5fd0a6SGreg Roach            ->where(static function (Builder $query) use ($tree): void {
13477654037SGreg Roach                $query
13577654037SGreg Roach                    ->whereNull('gedcom_id')
13677654037SGreg Roach                    ->orWhere('gedcom_id', '=', $tree->id());
13777654037SGreg Roach            })
13877654037SGreg Roach            ->max('block_order');
139aee13b6dSGreg Roach
140cc13d6d8SGreg Roach        $title = I18N::translate('Frequently asked questions') . ' — ' . $tree->title();
141aee13b6dSGreg Roach
142aee13b6dSGreg Roach        return $this->viewResponse('modules/faq/config', [
14383615acfSGreg Roach            'action'          => route('module', ['module' => $this->name(), 'action' => 'Admin']),
144aee13b6dSGreg Roach            'faqs'            => $faqs,
145aee13b6dSGreg Roach            'max_block_order' => $max_block_order,
146aee13b6dSGreg Roach            'min_block_order' => $min_block_order,
14771378461SGreg Roach            'module'          => $this->name(),
148aee13b6dSGreg Roach            'title'           => $title,
149aee13b6dSGreg Roach            'tree'            => $tree,
150aee13b6dSGreg Roach            'tree_names'      => Tree::getNameList(),
151aee13b6dSGreg Roach        ]);
152aee13b6dSGreg Roach    }
153aee13b6dSGreg Roach
154aee13b6dSGreg Roach    /**
1556ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
156aee13b6dSGreg Roach     *
1576ccdf4f0SGreg Roach     * @return ResponseInterface
158aee13b6dSGreg Roach     */
15957ab2231SGreg Roach    public function postAdminDeleteAction(ServerRequestInterface $request): ResponseInterface
160c1010edaSGreg Roach    {
16157ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
162eb235819SGreg Roach        $block_id = (int) $request->getQueryParams()['block_id'];
163aee13b6dSGreg Roach
16477654037SGreg Roach        DB::table('block_setting')->where('block_id', '=', $block_id)->delete();
165aee13b6dSGreg Roach
16677654037SGreg Roach        DB::table('block')->where('block_id', '=', $block_id)->delete();
167aee13b6dSGreg Roach
168c1010edaSGreg Roach        $url = route('module', [
16926684e68SGreg Roach            'module' => $this->name(),
170c1010edaSGreg Roach            'action' => 'Admin',
1719022ab66SGreg Roach            'tree'   => $tree->name(),
172c1010edaSGreg Roach        ]);
173aee13b6dSGreg Roach
1746ccdf4f0SGreg Roach        return redirect($url);
175aee13b6dSGreg Roach    }
176aee13b6dSGreg Roach
177aee13b6dSGreg Roach    /**
1786ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
179aee13b6dSGreg Roach     *
1806ccdf4f0SGreg Roach     * @return ResponseInterface
181aee13b6dSGreg Roach     */
18257ab2231SGreg Roach    public function postAdminMoveDownAction(ServerRequestInterface $request): ResponseInterface
183c1010edaSGreg Roach    {
18457ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
185eb235819SGreg Roach        $block_id = (int) $request->getQueryParams()['block_id'];
186aee13b6dSGreg Roach
18777654037SGreg Roach        $block_order = DB::table('block')
18877654037SGreg Roach            ->where('block_id', '=', $block_id)
18977654037SGreg Roach            ->value('block_order');
190aee13b6dSGreg Roach
19177654037SGreg Roach        $swap_block = DB::table('block')
19226684e68SGreg Roach            ->where('module_name', '=', $this->name())
193eb235819SGreg Roach            ->where('block_order', '=', function (Builder $query) use ($block_order): void {
19477654037SGreg Roach                $query
19577654037SGreg Roach                    ->from('block')
19626684e68SGreg Roach                    ->where('module_name', '=', $this->name())
19777654037SGreg Roach                    ->where('block_order', '>', $block_order)
198a69f5655SGreg Roach                    ->min('block_order');
19977654037SGreg Roach            })
20077654037SGreg Roach            ->select(['block_order', 'block_id'])
20177654037SGreg Roach            ->first();
202aee13b6dSGreg Roach
203aee13b6dSGreg Roach        if ($swap_block !== null) {
20477654037SGreg Roach            DB::table('block')
20577654037SGreg Roach                ->where('block_id', '=', $block_id)
20677654037SGreg Roach                ->update([
207aee13b6dSGreg Roach                    'block_order' => $swap_block->block_order,
208aee13b6dSGreg Roach                ]);
20977654037SGreg Roach
21077654037SGreg Roach            DB::table('block')
21177654037SGreg Roach                ->where('block_id', '=', $swap_block->block_id)
21277654037SGreg Roach                ->update([
213aee13b6dSGreg Roach                    'block_order' => $block_order,
214aee13b6dSGreg Roach                ]);
215aee13b6dSGreg Roach        }
216aee13b6dSGreg Roach
217c1010edaSGreg Roach        $url = route('module', [
21826684e68SGreg Roach            'module' => $this->name(),
219c1010edaSGreg Roach            'action' => 'Admin',
2209022ab66SGreg Roach            'tree'   => $tree->name(),
221c1010edaSGreg Roach        ]);
222aee13b6dSGreg Roach
2236ccdf4f0SGreg Roach        return redirect($url);
224aee13b6dSGreg Roach    }
225aee13b6dSGreg Roach
226aee13b6dSGreg Roach    /**
2276ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
228aee13b6dSGreg Roach     *
2296ccdf4f0SGreg Roach     * @return ResponseInterface
230aee13b6dSGreg Roach     */
23157ab2231SGreg Roach    public function postAdminMoveUpAction(ServerRequestInterface $request): ResponseInterface
232c1010edaSGreg Roach    {
23357ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
234eb235819SGreg Roach        $block_id = (int) $request->getQueryParams()['block_id'];
235aee13b6dSGreg Roach
23677654037SGreg Roach        $block_order = DB::table('block')
23777654037SGreg Roach            ->where('block_id', '=', $block_id)
23877654037SGreg Roach            ->value('block_order');
239aee13b6dSGreg Roach
24077654037SGreg Roach        $swap_block = DB::table('block')
24126684e68SGreg Roach            ->where('module_name', '=', $this->name())
242a69f5655SGreg Roach            ->where('block_order', '=', function (Builder $query) use ($block_order): void {
24377654037SGreg Roach                $query
24477654037SGreg Roach                    ->from('block')
24526684e68SGreg Roach                    ->where('module_name', '=', $this->name())
24677654037SGreg Roach                    ->where('block_order', '<', $block_order)
247a69f5655SGreg Roach                    ->max('block_order');
24877654037SGreg Roach            })
24977654037SGreg Roach            ->select(['block_order', 'block_id'])
25077654037SGreg Roach            ->first();
251aee13b6dSGreg Roach
252aee13b6dSGreg Roach        if ($swap_block !== null) {
25377654037SGreg Roach            DB::table('block')
25477654037SGreg Roach                ->where('block_id', '=', $block_id)
25577654037SGreg Roach                ->update([
256aee13b6dSGreg Roach                    'block_order' => $swap_block->block_order,
257aee13b6dSGreg Roach                ]);
25877654037SGreg Roach
25977654037SGreg Roach            DB::table('block')
26077654037SGreg Roach                ->where('block_id', '=', $swap_block->block_id)
26177654037SGreg Roach                ->update([
262aee13b6dSGreg Roach                    'block_order' => $block_order,
263aee13b6dSGreg Roach                ]);
264aee13b6dSGreg Roach        }
265aee13b6dSGreg Roach
266c1010edaSGreg Roach        $url = route('module', [
26726684e68SGreg Roach            'module' => $this->name(),
268c1010edaSGreg Roach            'action' => 'Admin',
2699022ab66SGreg Roach            'tree'    => $tree->name(),
270c1010edaSGreg Roach        ]);
271aee13b6dSGreg Roach
2726ccdf4f0SGreg Roach        return redirect($url);
273aee13b6dSGreg Roach    }
274aee13b6dSGreg Roach
275aee13b6dSGreg Roach    /**
2766ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
277aee13b6dSGreg Roach     *
2786ccdf4f0SGreg Roach     * @return ResponseInterface
279aee13b6dSGreg Roach     */
28057ab2231SGreg Roach    public function getAdminEditAction(ServerRequestInterface $request): ResponseInterface
281c1010edaSGreg Roach    {
282aee13b6dSGreg Roach        $this->layout = 'layouts/administration';
283aee13b6dSGreg Roach
28457ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
285eb235819SGreg Roach        $block_id = (int) ($request->getQueryParams()['block_id'] ?? 0);
286aee13b6dSGreg Roach
287aee13b6dSGreg Roach        if ($block_id === 0) {
288aee13b6dSGreg Roach            // Creating a new faq
289aee13b6dSGreg Roach            $header  = '';
290aee13b6dSGreg Roach            $faqbody = '';
29177654037SGreg Roach
29277654037SGreg Roach            $block_order = 1 + (int) DB::table('block')
29326684e68SGreg Roach                    ->where('module_name', '=', $this->name())
29477654037SGreg Roach                    ->max('block_order');
29577654037SGreg Roach
296aee13b6dSGreg Roach            $languages = [];
297aee13b6dSGreg Roach
298aee13b6dSGreg Roach            $title = I18N::translate('Add an FAQ');
299aee13b6dSGreg Roach        } else {
300aee13b6dSGreg Roach            // Editing an existing faq
301aee13b6dSGreg Roach            $header  = $this->getBlockSetting($block_id, 'header');
302aee13b6dSGreg Roach            $faqbody = $this->getBlockSetting($block_id, 'faqbody');
30377654037SGreg Roach
30477654037SGreg Roach            $block_order = DB::table('block')
30577654037SGreg Roach                ->where('block_id', '=', $block_id)
30677654037SGreg Roach                ->value('block_order');
30777654037SGreg Roach
308aee13b6dSGreg Roach            $languages = explode(',', $this->getBlockSetting($block_id, 'languages'));
309aee13b6dSGreg Roach
310aee13b6dSGreg Roach            $title = I18N::translate('Edit the FAQ');
311aee13b6dSGreg Roach        }
312aee13b6dSGreg Roach
313b6c326d8SGreg Roach        $tree_names = ['' => I18N::translate('All')] + Tree::getIdList();
314b6c326d8SGreg Roach
315aee13b6dSGreg Roach        return $this->viewResponse('modules/faq/edit', [
316aee13b6dSGreg Roach            'block_id'    => $block_id,
317aee13b6dSGreg Roach            'block_order' => $block_order,
318aee13b6dSGreg Roach            'header'      => $header,
319aee13b6dSGreg Roach            'faqbody'     => $faqbody,
320aee13b6dSGreg Roach            'languages'   => $languages,
321aee13b6dSGreg Roach            'title'       => $title,
322aee13b6dSGreg Roach            'tree'        => $tree,
323b6c326d8SGreg Roach            'tree_names'  => $tree_names,
324aee13b6dSGreg Roach        ]);
325aee13b6dSGreg Roach    }
326aee13b6dSGreg Roach
327aee13b6dSGreg Roach    /**
3286ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
329aee13b6dSGreg Roach     *
3306ccdf4f0SGreg Roach     * @return ResponseInterface
331aee13b6dSGreg Roach     */
33257ab2231SGreg Roach    public function postAdminEditAction(ServerRequestInterface $request): ResponseInterface
333c1010edaSGreg Roach    {
33457ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
335eb235819SGreg Roach        $block_id = (int) ($request->getQueryParams()['block_id'] ?? 0);
336eb235819SGreg Roach
337eb235819SGreg Roach        $params = $request->getParsedBody();
338eb235819SGreg Roach
339eb235819SGreg Roach        $faqbody     = $params['faqbody'];
340eb235819SGreg Roach        $header      = $params['header'];
341eb235819SGreg Roach        $languages   = $params['languages'] ?? [];
342eb235819SGreg Roach        $gedcom_id   = (int) $params['gedcom_id'] ?: null;
343eb235819SGreg Roach        $block_order = (int) $params['block_order'];
344aee13b6dSGreg Roach
34550d6f48cSGreg Roach        $faqbody = $this->html_service->sanitize($faqbody);
34650d6f48cSGreg Roach        $header  = $this->html_service->sanitize($header);
34750d6f48cSGreg Roach
348aee13b6dSGreg Roach        if ($block_id !== 0) {
34977654037SGreg Roach            DB::table('block')
35077654037SGreg Roach                ->where('block_id', '=', $block_id)
35177654037SGreg Roach                ->update([
35277654037SGreg Roach                    'gedcom_id'   => $gedcom_id,
35377654037SGreg Roach                    'block_order' => $block_order,
354aee13b6dSGreg Roach                ]);
355aee13b6dSGreg Roach        } else {
35677654037SGreg Roach            DB::table('block')->insert([
35777654037SGreg Roach                'gedcom_id'   => $gedcom_id,
35826684e68SGreg Roach                'module_name' => $this->name(),
35977654037SGreg Roach                'block_order' => $block_order,
360aee13b6dSGreg Roach            ]);
361aee13b6dSGreg Roach
36277654037SGreg Roach            $block_id = (int) DB::connection()->getPdo()->lastInsertId();
363aee13b6dSGreg Roach        }
364aee13b6dSGreg Roach
365aee13b6dSGreg Roach        $this->setBlockSetting($block_id, 'faqbody', $faqbody);
366aee13b6dSGreg Roach        $this->setBlockSetting($block_id, 'header', $header);
367aee13b6dSGreg Roach        $this->setBlockSetting($block_id, 'languages', implode(',', $languages));
368aee13b6dSGreg Roach
369c1010edaSGreg Roach        $url = route('module', [
37026684e68SGreg Roach            'module' => $this->name(),
371c1010edaSGreg Roach            'action' => 'Admin',
3729022ab66SGreg Roach            'tree'   => $tree->name(),
373c1010edaSGreg Roach        ]);
374aee13b6dSGreg Roach
3756ccdf4f0SGreg Roach        return redirect($url);
376aee13b6dSGreg Roach    }
377aee13b6dSGreg Roach
378b998dbceSGreg Roach    /**
37957ab2231SGreg Roach     * @param ServerRequestInterface $request
380b998dbceSGreg Roach     *
3816ccdf4f0SGreg Roach     * @return ResponseInterface
382b998dbceSGreg Roach     */
38357ab2231SGreg Roach    public function getShowAction(ServerRequestInterface $request): ResponseInterface
384c1010edaSGreg Roach    {
38557ab2231SGreg Roach        $tree = $request->getAttribute('tree');
3865229eadeSGreg Roach        assert($tree instanceof Tree, new InvalidArgumentException());
38757ab2231SGreg Roach
3888de50a4eSGreg Roach        // Filter foreign languages.
38977654037SGreg Roach        $faqs = $this->faqsForTree($tree)
3900b5fd0a6SGreg Roach            ->filter(static function (stdClass $faq): bool {
39122d65e5aSGreg Roach                return $faq->languages === '' || in_array(WT_LOCALE, explode(',', $faq->languages), true);
3928de50a4eSGreg Roach            });
393aee13b6dSGreg Roach
394aee13b6dSGreg Roach        return $this->viewResponse('modules/faq/show', [
3958de50a4eSGreg Roach            'faqs'  => $faqs,
396aee13b6dSGreg Roach            'title' => I18N::translate('Frequently asked questions'),
3978de50a4eSGreg Roach            'tree'  => $tree,
398aee13b6dSGreg Roach        ]);
399aee13b6dSGreg Roach    }
40077654037SGreg Roach
40177654037SGreg Roach    /**
40277654037SGreg Roach     * @param Tree $tree
40377654037SGreg Roach     *
40477654037SGreg Roach     * @return Collection
40577654037SGreg Roach     */
40677654037SGreg Roach    private function faqsForTree(Tree $tree): Collection
40777654037SGreg Roach    {
40877654037SGreg Roach        return DB::table('block')
40977654037SGreg Roach            ->join('block_setting AS bs1', 'bs1.block_id', '=', 'block.block_id')
41077654037SGreg Roach            ->join('block_setting AS bs2', 'bs2.block_id', '=', 'block.block_id')
41177654037SGreg Roach            ->join('block_setting AS bs3', 'bs3.block_id', '=', 'block.block_id')
41226684e68SGreg Roach            ->where('module_name', '=', $this->name())
41377654037SGreg Roach            ->where('bs1.setting_name', '=', 'header')
41477654037SGreg Roach            ->where('bs2.setting_name', '=', 'faqbody')
41577654037SGreg Roach            ->where('bs3.setting_name', '=', 'languages')
4160b5fd0a6SGreg Roach            ->where(static function (Builder $query) use ($tree): void {
41777654037SGreg Roach                $query
41877654037SGreg Roach                    ->whereNull('gedcom_id')
41977654037SGreg Roach                    ->orWhere('gedcom_id', '=', $tree->id());
42077654037SGreg Roach            })
42177654037SGreg Roach            ->orderBy('block_order')
42277654037SGreg Roach            ->select(['block.block_id', 'block_order', 'gedcom_id', 'bs1.setting_value AS header', 'bs2.setting_value AS faqbody', 'bs3.setting_value AS languages'])
42377654037SGreg Roach            ->get();
42477654037SGreg Roach    }
42577654037SGreg Roach
42677654037SGreg Roach    /**
42777654037SGreg Roach     * @param Tree   $tree
42877654037SGreg Roach     * @param string $language
42977654037SGreg Roach     *
43077654037SGreg Roach     * @return bool
43177654037SGreg Roach     */
43277654037SGreg Roach    private function faqsExist(Tree $tree, string $language): bool
43377654037SGreg Roach    {
43477654037SGreg Roach        return DB::table('block')
43577654037SGreg Roach            ->join('block_setting', 'block_setting.block_id', '=', 'block.block_id')
43626684e68SGreg Roach            ->where('module_name', '=', $this->name())
43777654037SGreg Roach            ->where('setting_name', '=', 'languages')
4380b5fd0a6SGreg Roach            ->where(static function (Builder $query) use ($tree): void {
43977654037SGreg Roach                $query
44077654037SGreg Roach                    ->whereNull('gedcom_id')
44177654037SGreg Roach                    ->orWhere('gedcom_id', '=', $tree->id());
44277654037SGreg Roach            })
44377654037SGreg Roach            ->select(['setting_value AS languages'])
44477654037SGreg Roach            ->get()
4450b5fd0a6SGreg Roach            ->filter(static function (stdClass $faq) use ($language): bool {
4460b5fd0a6SGreg Roach                return $faq->languages === '' || in_array($language, explode(',', $faq->languages), true);
44777654037SGreg Roach            })
44877654037SGreg Roach            ->isNotEmpty();
44977654037SGreg Roach    }
4508c2e8227SGreg Roach}
451