xref: /webtrees/app/Module/FrequentlyAskedQuestionsModule.php (revision 3976b4703df669696105ed6b024b96d433c8fbdb)
18c2e8227SGreg Roach<?php
2*3976b470SGreg 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;
286ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface;
296ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
308de50a4eSGreg Roachuse stdClass;
318c2e8227SGreg Roach
328c2e8227SGreg Roach/**
338c2e8227SGreg Roach * Class FrequentlyAskedQuestionsModule
348c2e8227SGreg Roach */
3537eb8894SGreg Roachclass FrequentlyAskedQuestionsModule extends AbstractModule implements ModuleConfigInterface, ModuleMenuInterface
36c1010edaSGreg Roach{
3749a243cbSGreg Roach    use ModuleConfigTrait;
3849a243cbSGreg Roach    use ModuleMenuTrait;
3949a243cbSGreg Roach
4050d6f48cSGreg Roach    /** @var HtmlService */
4150d6f48cSGreg Roach    private $html_service;
4250d6f48cSGreg Roach
4350d6f48cSGreg Roach    /**
4450d6f48cSGreg Roach     * HtmlBlockModule bootstrap.
4550d6f48cSGreg Roach     *
4650d6f48cSGreg Roach     * @param HtmlService $html_service
4750d6f48cSGreg Roach     */
4850d6f48cSGreg Roach    public function boot(HtmlService $html_service)
4950d6f48cSGreg Roach    {
5050d6f48cSGreg Roach        $this->html_service = $html_service;
5150d6f48cSGreg Roach    }
5250d6f48cSGreg Roach
53961ec755SGreg Roach    /**
540cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
55961ec755SGreg Roach     *
56961ec755SGreg Roach     * @return string
57961ec755SGreg Roach     */
5849a243cbSGreg Roach    public function title(): string
59c1010edaSGreg Roach    {
60bbb76c12SGreg Roach        /* I18N: Name of a module. Abbreviation for “Frequently Asked Questions” */
61bbb76c12SGreg Roach        return I18N::translate('FAQ');
628c2e8227SGreg Roach    }
638c2e8227SGreg Roach
64961ec755SGreg Roach    /**
65961ec755SGreg Roach     * A sentence describing what this module does.
66961ec755SGreg Roach     *
67961ec755SGreg Roach     * @return string
68961ec755SGreg Roach     */
6949a243cbSGreg Roach    public function description(): string
70c1010edaSGreg Roach    {
71bbb76c12SGreg Roach        /* I18N: Description of the “FAQ” module */
72bbb76c12SGreg Roach        return I18N::translate('A list of frequently asked questions and answers.');
738c2e8227SGreg Roach    }
748c2e8227SGreg Roach
7576692c8bSGreg Roach    /**
7649a243cbSGreg Roach     * The default position for this menu.  It can be changed in the control panel.
770ee13198SGreg Roach     *
780ee13198SGreg Roach     * @return int
790ee13198SGreg Roach     */
808f53f488SRico Sonntag    public function defaultMenuOrder(): int
81c1010edaSGreg Roach    {
82353b36abSGreg Roach        return 8;
838c2e8227SGreg Roach    }
848c2e8227SGreg Roach
850ee13198SGreg Roach    /**
860ee13198SGreg Roach     * A menu, to be added to the main application menu.
870ee13198SGreg Roach     *
88aee13b6dSGreg Roach     * @param Tree $tree
89aee13b6dSGreg Roach     *
900ee13198SGreg Roach     * @return Menu|null
910ee13198SGreg Roach     */
9246295629SGreg Roach    public function getMenu(Tree $tree): ?Menu
93c1010edaSGreg Roach    {
9477654037SGreg Roach        if ($this->faqsExist($tree, WT_LOCALE)) {
9549a243cbSGreg Roach            return new Menu($this->title(), route('module', [
9626684e68SGreg Roach                'module' => $this->name(),
97c1010edaSGreg Roach                'action' => 'Show',
98aa6f03bbSGreg Roach                'ged'    => $tree->name(),
99c1010edaSGreg Roach            ]), 'menu-help');
1008c2e8227SGreg Roach        }
101b2ce94c6SRico Sonntag
102b2ce94c6SRico Sonntag        return null;
1038c2e8227SGreg Roach    }
104aee13b6dSGreg Roach
105aee13b6dSGreg Roach    /**
10657ab2231SGreg Roach     * @param ServerRequestInterface $request
107aee13b6dSGreg Roach     *
1086ccdf4f0SGreg Roach     * @return ResponseInterface
109aee13b6dSGreg Roach     */
11057ab2231SGreg Roach    public function getAdminAction(ServerRequestInterface $request): ResponseInterface
111c1010edaSGreg Roach    {
112aee13b6dSGreg Roach        $this->layout = 'layouts/administration';
113aee13b6dSGreg Roach
11457ab2231SGreg Roach        $tree = $request->getAttribute('tree');
11526348dcdSGreg Roach        $faqs = $this->faqsForTree($tree);
116aee13b6dSGreg Roach
11777654037SGreg Roach        $min_block_order = DB::table('block')
11826684e68SGreg Roach            ->where('module_name', '=', $this->name())
1190b5fd0a6SGreg Roach            ->where(static function (Builder $query) use ($tree): void {
12077654037SGreg Roach                $query
12177654037SGreg Roach                    ->whereNull('gedcom_id')
12277654037SGreg Roach                    ->orWhere('gedcom_id', '=', $tree->id());
12377654037SGreg Roach            })
12477654037SGreg Roach            ->min('block_order');
125aee13b6dSGreg Roach
12677654037SGreg Roach        $max_block_order = DB::table('block')
12726684e68SGreg Roach            ->where('module_name', '=', $this->name())
1280b5fd0a6SGreg Roach            ->where(static function (Builder $query) use ($tree): void {
12977654037SGreg Roach                $query
13077654037SGreg Roach                    ->whereNull('gedcom_id')
13177654037SGreg Roach                    ->orWhere('gedcom_id', '=', $tree->id());
13277654037SGreg Roach            })
13377654037SGreg Roach            ->max('block_order');
134aee13b6dSGreg Roach
135cc13d6d8SGreg Roach        $title = I18N::translate('Frequently asked questions') . ' — ' . $tree->title();
136aee13b6dSGreg Roach
137aee13b6dSGreg Roach        return $this->viewResponse('modules/faq/config', [
138aee13b6dSGreg Roach            'faqs'            => $faqs,
139aee13b6dSGreg Roach            'max_block_order' => $max_block_order,
140aee13b6dSGreg Roach            'min_block_order' => $min_block_order,
141aee13b6dSGreg Roach            'title'           => $title,
142aee13b6dSGreg Roach            'tree'            => $tree,
143aee13b6dSGreg Roach            'tree_names'      => Tree::getNameList(),
144aee13b6dSGreg Roach        ]);
145aee13b6dSGreg Roach    }
146aee13b6dSGreg Roach
147aee13b6dSGreg Roach    /**
1486ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
149aee13b6dSGreg Roach     *
1506ccdf4f0SGreg Roach     * @return ResponseInterface
151aee13b6dSGreg Roach     */
15257ab2231SGreg Roach    public function postAdminDeleteAction(ServerRequestInterface $request): ResponseInterface
153c1010edaSGreg Roach    {
15457ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
155eb235819SGreg Roach        $block_id = (int) $request->getQueryParams()['block_id'];
156aee13b6dSGreg Roach
15777654037SGreg Roach        DB::table('block_setting')->where('block_id', '=', $block_id)->delete();
158aee13b6dSGreg Roach
15977654037SGreg Roach        DB::table('block')->where('block_id', '=', $block_id)->delete();
160aee13b6dSGreg Roach
161c1010edaSGreg Roach        $url = route('module', [
16226684e68SGreg Roach            'module' => $this->name(),
163c1010edaSGreg Roach            'action' => 'Admin',
164aa6f03bbSGreg Roach            'ged'    => $tree->name(),
165c1010edaSGreg Roach        ]);
166aee13b6dSGreg Roach
1676ccdf4f0SGreg Roach        return redirect($url);
168aee13b6dSGreg Roach    }
169aee13b6dSGreg Roach
170aee13b6dSGreg Roach    /**
1716ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
172aee13b6dSGreg Roach     *
1736ccdf4f0SGreg Roach     * @return ResponseInterface
174aee13b6dSGreg Roach     */
17557ab2231SGreg Roach    public function postAdminMoveDownAction(ServerRequestInterface $request): ResponseInterface
176c1010edaSGreg Roach    {
17757ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
178eb235819SGreg Roach        $block_id = (int) $request->getQueryParams()['block_id'];
179aee13b6dSGreg Roach
18077654037SGreg Roach        $block_order = DB::table('block')
18177654037SGreg Roach            ->where('block_id', '=', $block_id)
18277654037SGreg Roach            ->value('block_order');
183aee13b6dSGreg Roach
18477654037SGreg Roach        $swap_block = DB::table('block')
18526684e68SGreg Roach            ->where('module_name', '=', $this->name())
186eb235819SGreg Roach            ->where('block_order', '=', function (Builder $query) use ($block_order): void {
18777654037SGreg Roach                $query
18877654037SGreg Roach                    ->from('block')
18926684e68SGreg Roach                    ->where('module_name', '=', $this->name())
19077654037SGreg Roach                    ->where('block_order', '>', $block_order)
191a69f5655SGreg Roach                    ->min('block_order');
19277654037SGreg Roach            })
19377654037SGreg Roach            ->select(['block_order', 'block_id'])
19477654037SGreg Roach            ->first();
195aee13b6dSGreg Roach
196aee13b6dSGreg Roach        if ($swap_block !== null) {
19777654037SGreg Roach            DB::table('block')
19877654037SGreg Roach                ->where('block_id', '=', $block_id)
19977654037SGreg Roach                ->update([
200aee13b6dSGreg Roach                    'block_order' => $swap_block->block_order,
201aee13b6dSGreg Roach                ]);
20277654037SGreg Roach
20377654037SGreg Roach            DB::table('block')
20477654037SGreg Roach                ->where('block_id', '=', $swap_block->block_id)
20577654037SGreg Roach                ->update([
206aee13b6dSGreg Roach                    'block_order' => $block_order,
207aee13b6dSGreg Roach                ]);
208aee13b6dSGreg Roach        }
209aee13b6dSGreg Roach
210c1010edaSGreg Roach        $url = route('module', [
21126684e68SGreg Roach            'module' => $this->name(),
212c1010edaSGreg Roach            'action' => 'Admin',
213aa6f03bbSGreg Roach            'ged'    => $tree->name(),
214c1010edaSGreg Roach        ]);
215aee13b6dSGreg Roach
2166ccdf4f0SGreg Roach        return redirect($url);
217aee13b6dSGreg Roach    }
218aee13b6dSGreg Roach
219aee13b6dSGreg Roach    /**
2206ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
221aee13b6dSGreg Roach     *
2226ccdf4f0SGreg Roach     * @return ResponseInterface
223aee13b6dSGreg Roach     */
22457ab2231SGreg Roach    public function postAdminMoveUpAction(ServerRequestInterface $request): ResponseInterface
225c1010edaSGreg Roach    {
22657ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
227eb235819SGreg Roach        $block_id = (int) $request->getQueryParams()['block_id'];
228aee13b6dSGreg Roach
22977654037SGreg Roach        $block_order = DB::table('block')
23077654037SGreg Roach            ->where('block_id', '=', $block_id)
23177654037SGreg Roach            ->value('block_order');
232aee13b6dSGreg Roach
23377654037SGreg Roach        $swap_block = DB::table('block')
23426684e68SGreg Roach            ->where('module_name', '=', $this->name())
235a69f5655SGreg Roach            ->where('block_order', '=', function (Builder $query) use ($block_order): void {
23677654037SGreg Roach                $query
23777654037SGreg Roach                    ->from('block')
23826684e68SGreg Roach                    ->where('module_name', '=', $this->name())
23977654037SGreg Roach                    ->where('block_order', '<', $block_order)
240a69f5655SGreg Roach                    ->max('block_order');
24177654037SGreg Roach            })
24277654037SGreg Roach            ->select(['block_order', 'block_id'])
24377654037SGreg Roach            ->first();
244aee13b6dSGreg Roach
245aee13b6dSGreg Roach        if ($swap_block !== null) {
24677654037SGreg Roach            DB::table('block')
24777654037SGreg Roach                ->where('block_id', '=', $block_id)
24877654037SGreg Roach                ->update([
249aee13b6dSGreg Roach                    'block_order' => $swap_block->block_order,
250aee13b6dSGreg Roach                ]);
25177654037SGreg Roach
25277654037SGreg Roach            DB::table('block')
25377654037SGreg Roach                ->where('block_id', '=', $swap_block->block_id)
25477654037SGreg Roach                ->update([
255aee13b6dSGreg Roach                    'block_order' => $block_order,
256aee13b6dSGreg Roach                ]);
257aee13b6dSGreg Roach        }
258aee13b6dSGreg Roach
259c1010edaSGreg Roach        $url = route('module', [
26026684e68SGreg Roach            'module' => $this->name(),
261c1010edaSGreg Roach            'action' => 'Admin',
262aa6f03bbSGreg Roach            'ged'    => $tree->name(),
263c1010edaSGreg Roach        ]);
264aee13b6dSGreg Roach
2656ccdf4f0SGreg Roach        return redirect($url);
266aee13b6dSGreg Roach    }
267aee13b6dSGreg Roach
268aee13b6dSGreg Roach    /**
2696ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
270aee13b6dSGreg Roach     *
2716ccdf4f0SGreg Roach     * @return ResponseInterface
272aee13b6dSGreg Roach     */
27357ab2231SGreg Roach    public function getAdminEditAction(ServerRequestInterface $request): ResponseInterface
274c1010edaSGreg Roach    {
275aee13b6dSGreg Roach        $this->layout = 'layouts/administration';
276aee13b6dSGreg Roach
27757ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
278eb235819SGreg Roach        $block_id = (int) ($request->getQueryParams()['block_id'] ?? 0);
279aee13b6dSGreg Roach
280aee13b6dSGreg Roach        if ($block_id === 0) {
281aee13b6dSGreg Roach            // Creating a new faq
282aee13b6dSGreg Roach            $header  = '';
283aee13b6dSGreg Roach            $faqbody = '';
28477654037SGreg Roach
28577654037SGreg Roach            $block_order = 1 + (int) DB::table('block')
28626684e68SGreg Roach                    ->where('module_name', '=', $this->name())
28777654037SGreg Roach                    ->max('block_order');
28877654037SGreg Roach
289aee13b6dSGreg Roach            $languages = [];
290aee13b6dSGreg Roach
291aee13b6dSGreg Roach            $title = I18N::translate('Add an FAQ');
292aee13b6dSGreg Roach        } else {
293aee13b6dSGreg Roach            // Editing an existing faq
294aee13b6dSGreg Roach            $header  = $this->getBlockSetting($block_id, 'header');
295aee13b6dSGreg Roach            $faqbody = $this->getBlockSetting($block_id, 'faqbody');
29677654037SGreg Roach
29777654037SGreg Roach            $block_order = DB::table('block')
29877654037SGreg Roach                ->where('block_id', '=', $block_id)
29977654037SGreg Roach                ->value('block_order');
30077654037SGreg Roach
301aee13b6dSGreg Roach            $languages = explode(',', $this->getBlockSetting($block_id, 'languages'));
302aee13b6dSGreg Roach
303aee13b6dSGreg Roach            $title = I18N::translate('Edit the FAQ');
304aee13b6dSGreg Roach        }
305aee13b6dSGreg Roach
306b6c326d8SGreg Roach        $tree_names = ['' => I18N::translate('All')] + Tree::getIdList();
307b6c326d8SGreg Roach
308aee13b6dSGreg Roach        return $this->viewResponse('modules/faq/edit', [
309aee13b6dSGreg Roach            'block_id'    => $block_id,
310aee13b6dSGreg Roach            'block_order' => $block_order,
311aee13b6dSGreg Roach            'header'      => $header,
312aee13b6dSGreg Roach            'faqbody'     => $faqbody,
313aee13b6dSGreg Roach            'languages'   => $languages,
314aee13b6dSGreg Roach            'title'       => $title,
315aee13b6dSGreg Roach            'tree'        => $tree,
316b6c326d8SGreg Roach            'tree_names'  => $tree_names,
317aee13b6dSGreg Roach        ]);
318aee13b6dSGreg Roach    }
319aee13b6dSGreg Roach
320aee13b6dSGreg Roach    /**
3216ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
322aee13b6dSGreg Roach     *
3236ccdf4f0SGreg Roach     * @return ResponseInterface
324aee13b6dSGreg Roach     */
32557ab2231SGreg Roach    public function postAdminEditAction(ServerRequestInterface $request): ResponseInterface
326c1010edaSGreg Roach    {
32757ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
328eb235819SGreg Roach        $block_id = (int) ($request->getQueryParams()['block_id'] ?? 0);
329eb235819SGreg Roach
330eb235819SGreg Roach        $params = $request->getParsedBody();
331eb235819SGreg Roach
332eb235819SGreg Roach        $faqbody     = $params['faqbody'];
333eb235819SGreg Roach        $header      = $params['header'];
334eb235819SGreg Roach        $languages   = $params['languages'] ?? [];
335eb235819SGreg Roach        $gedcom_id   = (int) $params['gedcom_id'] ?: null;
336eb235819SGreg Roach        $block_order = (int) $params['block_order'];
337aee13b6dSGreg Roach
33850d6f48cSGreg Roach        $faqbody = $this->html_service->sanitize($faqbody);
33950d6f48cSGreg Roach        $header  = $this->html_service->sanitize($header);
34050d6f48cSGreg Roach
341aee13b6dSGreg Roach        if ($block_id !== 0) {
34277654037SGreg Roach            DB::table('block')
34377654037SGreg Roach                ->where('block_id', '=', $block_id)
34477654037SGreg Roach                ->update([
34577654037SGreg Roach                    'gedcom_id'   => $gedcom_id,
34677654037SGreg Roach                    'block_order' => $block_order,
347aee13b6dSGreg Roach                ]);
348aee13b6dSGreg Roach        } else {
34977654037SGreg Roach            DB::table('block')->insert([
35077654037SGreg Roach                'gedcom_id'   => $gedcom_id,
35126684e68SGreg Roach                'module_name' => $this->name(),
35277654037SGreg Roach                'block_order' => $block_order,
353aee13b6dSGreg Roach            ]);
354aee13b6dSGreg Roach
35577654037SGreg Roach            $block_id = (int) DB::connection()->getPdo()->lastInsertId();
356aee13b6dSGreg Roach        }
357aee13b6dSGreg Roach
358aee13b6dSGreg Roach        $this->setBlockSetting($block_id, 'faqbody', $faqbody);
359aee13b6dSGreg Roach        $this->setBlockSetting($block_id, 'header', $header);
360aee13b6dSGreg Roach        $this->setBlockSetting($block_id, 'languages', implode(',', $languages));
361aee13b6dSGreg Roach
362c1010edaSGreg Roach        $url = route('module', [
36326684e68SGreg Roach            'module' => $this->name(),
364c1010edaSGreg Roach            'action' => 'Admin',
365aa6f03bbSGreg Roach            'ged'    => $tree->name(),
366c1010edaSGreg Roach        ]);
367aee13b6dSGreg Roach
3686ccdf4f0SGreg Roach        return redirect($url);
369aee13b6dSGreg Roach    }
370aee13b6dSGreg Roach
371b998dbceSGreg Roach    /**
37257ab2231SGreg Roach     * @param ServerRequestInterface $request
373b998dbceSGreg Roach     *
3746ccdf4f0SGreg Roach     * @return ResponseInterface
375b998dbceSGreg Roach     */
37657ab2231SGreg Roach    public function getShowAction(ServerRequestInterface $request): ResponseInterface
377c1010edaSGreg Roach    {
37857ab2231SGreg Roach        $tree = $request->getAttribute('tree');
37957ab2231SGreg Roach
3808de50a4eSGreg Roach        // Filter foreign languages.
38177654037SGreg Roach        $faqs = $this->faqsForTree($tree)
3820b5fd0a6SGreg Roach            ->filter(static function (stdClass $faq): bool {
38322d65e5aSGreg Roach                return $faq->languages === '' || in_array(WT_LOCALE, explode(',', $faq->languages), true);
3848de50a4eSGreg Roach            });
385aee13b6dSGreg Roach
386aee13b6dSGreg Roach        return $this->viewResponse('modules/faq/show', [
3878de50a4eSGreg Roach            'faqs'  => $faqs,
388aee13b6dSGreg Roach            'title' => I18N::translate('Frequently asked questions'),
3898de50a4eSGreg Roach            'tree'  => $tree,
390aee13b6dSGreg Roach        ]);
391aee13b6dSGreg Roach    }
39277654037SGreg Roach
39377654037SGreg Roach    /**
39477654037SGreg Roach     * @param Tree $tree
39577654037SGreg Roach     *
39677654037SGreg Roach     * @return Collection
39777654037SGreg Roach     */
39877654037SGreg Roach    private function faqsForTree(Tree $tree): Collection
39977654037SGreg Roach    {
40077654037SGreg Roach        return DB::table('block')
40177654037SGreg Roach            ->join('block_setting AS bs1', 'bs1.block_id', '=', 'block.block_id')
40277654037SGreg Roach            ->join('block_setting AS bs2', 'bs2.block_id', '=', 'block.block_id')
40377654037SGreg Roach            ->join('block_setting AS bs3', 'bs3.block_id', '=', 'block.block_id')
40426684e68SGreg Roach            ->where('module_name', '=', $this->name())
40577654037SGreg Roach            ->where('bs1.setting_name', '=', 'header')
40677654037SGreg Roach            ->where('bs2.setting_name', '=', 'faqbody')
40777654037SGreg Roach            ->where('bs3.setting_name', '=', 'languages')
4080b5fd0a6SGreg Roach            ->where(static function (Builder $query) use ($tree): void {
40977654037SGreg Roach                $query
41077654037SGreg Roach                    ->whereNull('gedcom_id')
41177654037SGreg Roach                    ->orWhere('gedcom_id', '=', $tree->id());
41277654037SGreg Roach            })
41377654037SGreg Roach            ->orderBy('block_order')
41477654037SGreg Roach            ->select(['block.block_id', 'block_order', 'gedcom_id', 'bs1.setting_value AS header', 'bs2.setting_value AS faqbody', 'bs3.setting_value AS languages'])
41577654037SGreg Roach            ->get();
41677654037SGreg Roach    }
41777654037SGreg Roach
41877654037SGreg Roach    /**
41977654037SGreg Roach     * @param Tree   $tree
42077654037SGreg Roach     * @param string $language
42177654037SGreg Roach     *
42277654037SGreg Roach     * @return bool
42377654037SGreg Roach     */
42477654037SGreg Roach    private function faqsExist(Tree $tree, string $language): bool
42577654037SGreg Roach    {
42677654037SGreg Roach        return DB::table('block')
42777654037SGreg Roach            ->join('block_setting', 'block_setting.block_id', '=', 'block.block_id')
42826684e68SGreg Roach            ->where('module_name', '=', $this->name())
42977654037SGreg Roach            ->where('setting_name', '=', 'languages')
4300b5fd0a6SGreg Roach            ->where(static function (Builder $query) use ($tree): void {
43177654037SGreg Roach                $query
43277654037SGreg Roach                    ->whereNull('gedcom_id')
43377654037SGreg Roach                    ->orWhere('gedcom_id', '=', $tree->id());
43477654037SGreg Roach            })
43577654037SGreg Roach            ->select(['setting_value AS languages'])
43677654037SGreg Roach            ->get()
4370b5fd0a6SGreg Roach            ->filter(static function (stdClass $faq) use ($language): bool {
4380b5fd0a6SGreg Roach                return $faq->languages === '' || in_array($language, explode(',', $faq->languages), true);
43977654037SGreg Roach            })
44077654037SGreg Roach            ->isNotEmpty();
44177654037SGreg Roach    }
4428c2e8227SGreg Roach}
443