xref: /webtrees/app/Module/FrequentlyAskedQuestionsModule.php (revision 9022ab6638958a155b6ee7c99b822adbb3eaa2f6)
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;
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',
98*9022ab66SGreg Roach                'tree'   => $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', [
13883615acfSGreg Roach            'action'          => route('module', ['module' => $this->name(), 'action' => 'Admin']),
139aee13b6dSGreg Roach            'faqs'            => $faqs,
140aee13b6dSGreg Roach            'max_block_order' => $max_block_order,
141aee13b6dSGreg Roach            'min_block_order' => $min_block_order,
14271378461SGreg Roach            'module'          => $this->name(),
143aee13b6dSGreg Roach            'title'           => $title,
144aee13b6dSGreg Roach            'tree'            => $tree,
145aee13b6dSGreg Roach            'tree_names'      => Tree::getNameList(),
146aee13b6dSGreg Roach        ]);
147aee13b6dSGreg Roach    }
148aee13b6dSGreg Roach
149aee13b6dSGreg Roach    /**
1506ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
151aee13b6dSGreg Roach     *
1526ccdf4f0SGreg Roach     * @return ResponseInterface
153aee13b6dSGreg Roach     */
15457ab2231SGreg Roach    public function postAdminDeleteAction(ServerRequestInterface $request): ResponseInterface
155c1010edaSGreg Roach    {
15657ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
157eb235819SGreg Roach        $block_id = (int) $request->getQueryParams()['block_id'];
158aee13b6dSGreg Roach
15977654037SGreg Roach        DB::table('block_setting')->where('block_id', '=', $block_id)->delete();
160aee13b6dSGreg Roach
16177654037SGreg Roach        DB::table('block')->where('block_id', '=', $block_id)->delete();
162aee13b6dSGreg Roach
163c1010edaSGreg Roach        $url = route('module', [
16426684e68SGreg Roach            'module' => $this->name(),
165c1010edaSGreg Roach            'action' => 'Admin',
166*9022ab66SGreg Roach            'tree'   => $tree->name(),
167c1010edaSGreg Roach        ]);
168aee13b6dSGreg Roach
1696ccdf4f0SGreg Roach        return redirect($url);
170aee13b6dSGreg Roach    }
171aee13b6dSGreg Roach
172aee13b6dSGreg Roach    /**
1736ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
174aee13b6dSGreg Roach     *
1756ccdf4f0SGreg Roach     * @return ResponseInterface
176aee13b6dSGreg Roach     */
17757ab2231SGreg Roach    public function postAdminMoveDownAction(ServerRequestInterface $request): ResponseInterface
178c1010edaSGreg Roach    {
17957ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
180eb235819SGreg Roach        $block_id = (int) $request->getQueryParams()['block_id'];
181aee13b6dSGreg Roach
18277654037SGreg Roach        $block_order = DB::table('block')
18377654037SGreg Roach            ->where('block_id', '=', $block_id)
18477654037SGreg Roach            ->value('block_order');
185aee13b6dSGreg Roach
18677654037SGreg Roach        $swap_block = DB::table('block')
18726684e68SGreg Roach            ->where('module_name', '=', $this->name())
188eb235819SGreg Roach            ->where('block_order', '=', function (Builder $query) use ($block_order): void {
18977654037SGreg Roach                $query
19077654037SGreg Roach                    ->from('block')
19126684e68SGreg Roach                    ->where('module_name', '=', $this->name())
19277654037SGreg Roach                    ->where('block_order', '>', $block_order)
193a69f5655SGreg Roach                    ->min('block_order');
19477654037SGreg Roach            })
19577654037SGreg Roach            ->select(['block_order', 'block_id'])
19677654037SGreg Roach            ->first();
197aee13b6dSGreg Roach
198aee13b6dSGreg Roach        if ($swap_block !== null) {
19977654037SGreg Roach            DB::table('block')
20077654037SGreg Roach                ->where('block_id', '=', $block_id)
20177654037SGreg Roach                ->update([
202aee13b6dSGreg Roach                    'block_order' => $swap_block->block_order,
203aee13b6dSGreg Roach                ]);
20477654037SGreg Roach
20577654037SGreg Roach            DB::table('block')
20677654037SGreg Roach                ->where('block_id', '=', $swap_block->block_id)
20777654037SGreg Roach                ->update([
208aee13b6dSGreg Roach                    'block_order' => $block_order,
209aee13b6dSGreg Roach                ]);
210aee13b6dSGreg Roach        }
211aee13b6dSGreg Roach
212c1010edaSGreg Roach        $url = route('module', [
21326684e68SGreg Roach            'module' => $this->name(),
214c1010edaSGreg Roach            'action' => 'Admin',
215*9022ab66SGreg Roach            'tree'   => $tree->name(),
216c1010edaSGreg Roach        ]);
217aee13b6dSGreg Roach
2186ccdf4f0SGreg Roach        return redirect($url);
219aee13b6dSGreg Roach    }
220aee13b6dSGreg Roach
221aee13b6dSGreg Roach    /**
2226ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
223aee13b6dSGreg Roach     *
2246ccdf4f0SGreg Roach     * @return ResponseInterface
225aee13b6dSGreg Roach     */
22657ab2231SGreg Roach    public function postAdminMoveUpAction(ServerRequestInterface $request): ResponseInterface
227c1010edaSGreg Roach    {
22857ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
229eb235819SGreg Roach        $block_id = (int) $request->getQueryParams()['block_id'];
230aee13b6dSGreg Roach
23177654037SGreg Roach        $block_order = DB::table('block')
23277654037SGreg Roach            ->where('block_id', '=', $block_id)
23377654037SGreg Roach            ->value('block_order');
234aee13b6dSGreg Roach
23577654037SGreg Roach        $swap_block = DB::table('block')
23626684e68SGreg Roach            ->where('module_name', '=', $this->name())
237a69f5655SGreg Roach            ->where('block_order', '=', function (Builder $query) use ($block_order): void {
23877654037SGreg Roach                $query
23977654037SGreg Roach                    ->from('block')
24026684e68SGreg Roach                    ->where('module_name', '=', $this->name())
24177654037SGreg Roach                    ->where('block_order', '<', $block_order)
242a69f5655SGreg Roach                    ->max('block_order');
24377654037SGreg Roach            })
24477654037SGreg Roach            ->select(['block_order', 'block_id'])
24577654037SGreg Roach            ->first();
246aee13b6dSGreg Roach
247aee13b6dSGreg Roach        if ($swap_block !== null) {
24877654037SGreg Roach            DB::table('block')
24977654037SGreg Roach                ->where('block_id', '=', $block_id)
25077654037SGreg Roach                ->update([
251aee13b6dSGreg Roach                    'block_order' => $swap_block->block_order,
252aee13b6dSGreg Roach                ]);
25377654037SGreg Roach
25477654037SGreg Roach            DB::table('block')
25577654037SGreg Roach                ->where('block_id', '=', $swap_block->block_id)
25677654037SGreg Roach                ->update([
257aee13b6dSGreg Roach                    'block_order' => $block_order,
258aee13b6dSGreg Roach                ]);
259aee13b6dSGreg Roach        }
260aee13b6dSGreg Roach
261c1010edaSGreg Roach        $url = route('module', [
26226684e68SGreg Roach            'module' => $this->name(),
263c1010edaSGreg Roach            'action' => 'Admin',
264*9022ab66SGreg Roach            'tree'    => $tree->name(),
265c1010edaSGreg Roach        ]);
266aee13b6dSGreg Roach
2676ccdf4f0SGreg Roach        return redirect($url);
268aee13b6dSGreg Roach    }
269aee13b6dSGreg Roach
270aee13b6dSGreg Roach    /**
2716ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
272aee13b6dSGreg Roach     *
2736ccdf4f0SGreg Roach     * @return ResponseInterface
274aee13b6dSGreg Roach     */
27557ab2231SGreg Roach    public function getAdminEditAction(ServerRequestInterface $request): ResponseInterface
276c1010edaSGreg Roach    {
277aee13b6dSGreg Roach        $this->layout = 'layouts/administration';
278aee13b6dSGreg Roach
27957ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
280eb235819SGreg Roach        $block_id = (int) ($request->getQueryParams()['block_id'] ?? 0);
281aee13b6dSGreg Roach
282aee13b6dSGreg Roach        if ($block_id === 0) {
283aee13b6dSGreg Roach            // Creating a new faq
284aee13b6dSGreg Roach            $header  = '';
285aee13b6dSGreg Roach            $faqbody = '';
28677654037SGreg Roach
28777654037SGreg Roach            $block_order = 1 + (int) DB::table('block')
28826684e68SGreg Roach                    ->where('module_name', '=', $this->name())
28977654037SGreg Roach                    ->max('block_order');
29077654037SGreg Roach
291aee13b6dSGreg Roach            $languages = [];
292aee13b6dSGreg Roach
293aee13b6dSGreg Roach            $title = I18N::translate('Add an FAQ');
294aee13b6dSGreg Roach        } else {
295aee13b6dSGreg Roach            // Editing an existing faq
296aee13b6dSGreg Roach            $header  = $this->getBlockSetting($block_id, 'header');
297aee13b6dSGreg Roach            $faqbody = $this->getBlockSetting($block_id, 'faqbody');
29877654037SGreg Roach
29977654037SGreg Roach            $block_order = DB::table('block')
30077654037SGreg Roach                ->where('block_id', '=', $block_id)
30177654037SGreg Roach                ->value('block_order');
30277654037SGreg Roach
303aee13b6dSGreg Roach            $languages = explode(',', $this->getBlockSetting($block_id, 'languages'));
304aee13b6dSGreg Roach
305aee13b6dSGreg Roach            $title = I18N::translate('Edit the FAQ');
306aee13b6dSGreg Roach        }
307aee13b6dSGreg Roach
308b6c326d8SGreg Roach        $tree_names = ['' => I18N::translate('All')] + Tree::getIdList();
309b6c326d8SGreg Roach
310aee13b6dSGreg Roach        return $this->viewResponse('modules/faq/edit', [
311aee13b6dSGreg Roach            'block_id'    => $block_id,
312aee13b6dSGreg Roach            'block_order' => $block_order,
313aee13b6dSGreg Roach            'header'      => $header,
314aee13b6dSGreg Roach            'faqbody'     => $faqbody,
315aee13b6dSGreg Roach            'languages'   => $languages,
316aee13b6dSGreg Roach            'title'       => $title,
317aee13b6dSGreg Roach            'tree'        => $tree,
318b6c326d8SGreg Roach            'tree_names'  => $tree_names,
319aee13b6dSGreg Roach        ]);
320aee13b6dSGreg Roach    }
321aee13b6dSGreg Roach
322aee13b6dSGreg Roach    /**
3236ccdf4f0SGreg Roach     * @param ServerRequestInterface $request
324aee13b6dSGreg Roach     *
3256ccdf4f0SGreg Roach     * @return ResponseInterface
326aee13b6dSGreg Roach     */
32757ab2231SGreg Roach    public function postAdminEditAction(ServerRequestInterface $request): ResponseInterface
328c1010edaSGreg Roach    {
32957ab2231SGreg Roach        $tree     = $request->getAttribute('tree');
330eb235819SGreg Roach        $block_id = (int) ($request->getQueryParams()['block_id'] ?? 0);
331eb235819SGreg Roach
332eb235819SGreg Roach        $params = $request->getParsedBody();
333eb235819SGreg Roach
334eb235819SGreg Roach        $faqbody     = $params['faqbody'];
335eb235819SGreg Roach        $header      = $params['header'];
336eb235819SGreg Roach        $languages   = $params['languages'] ?? [];
337eb235819SGreg Roach        $gedcom_id   = (int) $params['gedcom_id'] ?: null;
338eb235819SGreg Roach        $block_order = (int) $params['block_order'];
339aee13b6dSGreg Roach
34050d6f48cSGreg Roach        $faqbody = $this->html_service->sanitize($faqbody);
34150d6f48cSGreg Roach        $header  = $this->html_service->sanitize($header);
34250d6f48cSGreg Roach
343aee13b6dSGreg Roach        if ($block_id !== 0) {
34477654037SGreg Roach            DB::table('block')
34577654037SGreg Roach                ->where('block_id', '=', $block_id)
34677654037SGreg Roach                ->update([
34777654037SGreg Roach                    'gedcom_id'   => $gedcom_id,
34877654037SGreg Roach                    'block_order' => $block_order,
349aee13b6dSGreg Roach                ]);
350aee13b6dSGreg Roach        } else {
35177654037SGreg Roach            DB::table('block')->insert([
35277654037SGreg Roach                'gedcom_id'   => $gedcom_id,
35326684e68SGreg Roach                'module_name' => $this->name(),
35477654037SGreg Roach                'block_order' => $block_order,
355aee13b6dSGreg Roach            ]);
356aee13b6dSGreg Roach
35777654037SGreg Roach            $block_id = (int) DB::connection()->getPdo()->lastInsertId();
358aee13b6dSGreg Roach        }
359aee13b6dSGreg Roach
360aee13b6dSGreg Roach        $this->setBlockSetting($block_id, 'faqbody', $faqbody);
361aee13b6dSGreg Roach        $this->setBlockSetting($block_id, 'header', $header);
362aee13b6dSGreg Roach        $this->setBlockSetting($block_id, 'languages', implode(',', $languages));
363aee13b6dSGreg Roach
364c1010edaSGreg Roach        $url = route('module', [
36526684e68SGreg Roach            'module' => $this->name(),
366c1010edaSGreg Roach            'action' => 'Admin',
367*9022ab66SGreg Roach            'tree'   => $tree->name(),
368c1010edaSGreg Roach        ]);
369aee13b6dSGreg Roach
3706ccdf4f0SGreg Roach        return redirect($url);
371aee13b6dSGreg Roach    }
372aee13b6dSGreg Roach
373b998dbceSGreg Roach    /**
37457ab2231SGreg Roach     * @param ServerRequestInterface $request
375b998dbceSGreg Roach     *
3766ccdf4f0SGreg Roach     * @return ResponseInterface
377b998dbceSGreg Roach     */
37857ab2231SGreg Roach    public function getShowAction(ServerRequestInterface $request): ResponseInterface
379c1010edaSGreg Roach    {
38057ab2231SGreg Roach        $tree = $request->getAttribute('tree');
38157ab2231SGreg Roach
3828de50a4eSGreg Roach        // Filter foreign languages.
38377654037SGreg Roach        $faqs = $this->faqsForTree($tree)
3840b5fd0a6SGreg Roach            ->filter(static function (stdClass $faq): bool {
38522d65e5aSGreg Roach                return $faq->languages === '' || in_array(WT_LOCALE, explode(',', $faq->languages), true);
3868de50a4eSGreg Roach            });
387aee13b6dSGreg Roach
388aee13b6dSGreg Roach        return $this->viewResponse('modules/faq/show', [
3898de50a4eSGreg Roach            'faqs'  => $faqs,
390aee13b6dSGreg Roach            'title' => I18N::translate('Frequently asked questions'),
3918de50a4eSGreg Roach            'tree'  => $tree,
392aee13b6dSGreg Roach        ]);
393aee13b6dSGreg Roach    }
39477654037SGreg Roach
39577654037SGreg Roach    /**
39677654037SGreg Roach     * @param Tree $tree
39777654037SGreg Roach     *
39877654037SGreg Roach     * @return Collection
39977654037SGreg Roach     */
40077654037SGreg Roach    private function faqsForTree(Tree $tree): Collection
40177654037SGreg Roach    {
40277654037SGreg Roach        return DB::table('block')
40377654037SGreg Roach            ->join('block_setting AS bs1', 'bs1.block_id', '=', 'block.block_id')
40477654037SGreg Roach            ->join('block_setting AS bs2', 'bs2.block_id', '=', 'block.block_id')
40577654037SGreg Roach            ->join('block_setting AS bs3', 'bs3.block_id', '=', 'block.block_id')
40626684e68SGreg Roach            ->where('module_name', '=', $this->name())
40777654037SGreg Roach            ->where('bs1.setting_name', '=', 'header')
40877654037SGreg Roach            ->where('bs2.setting_name', '=', 'faqbody')
40977654037SGreg Roach            ->where('bs3.setting_name', '=', 'languages')
4100b5fd0a6SGreg Roach            ->where(static function (Builder $query) use ($tree): void {
41177654037SGreg Roach                $query
41277654037SGreg Roach                    ->whereNull('gedcom_id')
41377654037SGreg Roach                    ->orWhere('gedcom_id', '=', $tree->id());
41477654037SGreg Roach            })
41577654037SGreg Roach            ->orderBy('block_order')
41677654037SGreg Roach            ->select(['block.block_id', 'block_order', 'gedcom_id', 'bs1.setting_value AS header', 'bs2.setting_value AS faqbody', 'bs3.setting_value AS languages'])
41777654037SGreg Roach            ->get();
41877654037SGreg Roach    }
41977654037SGreg Roach
42077654037SGreg Roach    /**
42177654037SGreg Roach     * @param Tree   $tree
42277654037SGreg Roach     * @param string $language
42377654037SGreg Roach     *
42477654037SGreg Roach     * @return bool
42577654037SGreg Roach     */
42677654037SGreg Roach    private function faqsExist(Tree $tree, string $language): bool
42777654037SGreg Roach    {
42877654037SGreg Roach        return DB::table('block')
42977654037SGreg Roach            ->join('block_setting', 'block_setting.block_id', '=', 'block.block_id')
43026684e68SGreg Roach            ->where('module_name', '=', $this->name())
43177654037SGreg Roach            ->where('setting_name', '=', 'languages')
4320b5fd0a6SGreg Roach            ->where(static function (Builder $query) use ($tree): void {
43377654037SGreg Roach                $query
43477654037SGreg Roach                    ->whereNull('gedcom_id')
43577654037SGreg Roach                    ->orWhere('gedcom_id', '=', $tree->id());
43677654037SGreg Roach            })
43777654037SGreg Roach            ->select(['setting_value AS languages'])
43877654037SGreg Roach            ->get()
4390b5fd0a6SGreg Roach            ->filter(static function (stdClass $faq) use ($language): bool {
4400b5fd0a6SGreg Roach                return $faq->languages === '' || in_array($language, explode(',', $faq->languages), true);
44177654037SGreg Roach            })
44277654037SGreg Roach            ->isNotEmpty();
44377654037SGreg Roach    }
4448c2e8227SGreg Roach}
445