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 */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 2176692c8bSGreg Roach 221d1f373cSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel; 230e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 240e62c4b8SGreg Roachuse Fisharebest\Webtrees\Menu; 2550d6f48cSGreg Roachuse Fisharebest\Webtrees\Services\HtmlService; 261d1f373cSGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 270e62c4b8SGreg Roachuse Fisharebest\Webtrees\Tree; 2877654037SGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 2977654037SGreg Roachuse Illuminate\Database\Query\Builder; 3077654037SGreg Roachuse Illuminate\Support\Collection; 315229eadeSGreg Roachuse InvalidArgumentException; 326ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface; 336ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 348de50a4eSGreg Roachuse stdClass; 35f3874e19SGreg Roach 365229eadeSGreg Roachuse function assert; 371d1f373cSGreg Roachuse function redirect; 381d1f373cSGreg Roachuse function route; 398c2e8227SGreg Roach 408c2e8227SGreg Roach/** 418c2e8227SGreg Roach * Class FrequentlyAskedQuestionsModule 428c2e8227SGreg Roach */ 4337eb8894SGreg Roachclass FrequentlyAskedQuestionsModule extends AbstractModule implements ModuleConfigInterface, ModuleMenuInterface 44c1010edaSGreg Roach{ 4549a243cbSGreg Roach use ModuleConfigTrait; 4649a243cbSGreg Roach use ModuleMenuTrait; 4749a243cbSGreg Roach 4850d6f48cSGreg Roach /** @var HtmlService */ 4950d6f48cSGreg Roach private $html_service; 5050d6f48cSGreg Roach 511d1f373cSGreg Roach /** @var TreeService */ 521d1f373cSGreg Roach private $tree_service; 531d1f373cSGreg Roach 5450d6f48cSGreg Roach /** 551d1f373cSGreg Roach * BatchUpdateModule constructor. 5650d6f48cSGreg Roach * 5750d6f48cSGreg Roach * @param HtmlService $html_service 581d1f373cSGreg Roach * @param TreeService $tree_service 5950d6f48cSGreg Roach */ 601d1f373cSGreg Roach public function __construct(HtmlService $html_service, TreeService $tree_service) 6150d6f48cSGreg Roach { 6250d6f48cSGreg Roach $this->html_service = $html_service; 631d1f373cSGreg Roach $this->tree_service = $tree_service; 6450d6f48cSGreg Roach } 6550d6f48cSGreg Roach 66961ec755SGreg Roach /** 670cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 68961ec755SGreg Roach * 69961ec755SGreg Roach * @return string 70961ec755SGreg Roach */ 7149a243cbSGreg Roach public function title(): string 72c1010edaSGreg Roach { 73bbb76c12SGreg Roach /* I18N: Name of a module. Abbreviation for “Frequently Asked Questions” */ 74bbb76c12SGreg Roach return I18N::translate('FAQ'); 758c2e8227SGreg Roach } 768c2e8227SGreg Roach 77961ec755SGreg Roach /** 78961ec755SGreg Roach * A sentence describing what this module does. 79961ec755SGreg Roach * 80961ec755SGreg Roach * @return string 81961ec755SGreg Roach */ 8249a243cbSGreg Roach public function description(): string 83c1010edaSGreg Roach { 84bbb76c12SGreg Roach /* I18N: Description of the “FAQ” module */ 85bbb76c12SGreg Roach return I18N::translate('A list of frequently asked questions and answers.'); 868c2e8227SGreg Roach } 878c2e8227SGreg Roach 8876692c8bSGreg Roach /** 8949a243cbSGreg Roach * The default position for this menu. It can be changed in the control panel. 900ee13198SGreg Roach * 910ee13198SGreg Roach * @return int 920ee13198SGreg Roach */ 938f53f488SRico Sonntag public function defaultMenuOrder(): int 94c1010edaSGreg Roach { 95353b36abSGreg Roach return 8; 968c2e8227SGreg Roach } 978c2e8227SGreg Roach 980ee13198SGreg Roach /** 990ee13198SGreg Roach * A menu, to be added to the main application menu. 1000ee13198SGreg Roach * 101aee13b6dSGreg Roach * @param Tree $tree 102aee13b6dSGreg Roach * 1030ee13198SGreg Roach * @return Menu|null 1040ee13198SGreg Roach */ 10546295629SGreg Roach public function getMenu(Tree $tree): ?Menu 106c1010edaSGreg Roach { 10777654037SGreg Roach if ($this->faqsExist($tree, WT_LOCALE)) { 10849a243cbSGreg Roach return new Menu($this->title(), route('module', [ 10926684e68SGreg Roach 'module' => $this->name(), 110c1010edaSGreg Roach 'action' => 'Show', 1119022ab66SGreg Roach 'tree' => $tree->name(), 112c1010edaSGreg Roach ]), 'menu-help'); 1138c2e8227SGreg Roach } 114b2ce94c6SRico Sonntag 115b2ce94c6SRico Sonntag return null; 1168c2e8227SGreg Roach } 117aee13b6dSGreg Roach 118aee13b6dSGreg Roach /** 11957ab2231SGreg Roach * @param ServerRequestInterface $request 120aee13b6dSGreg Roach * 1216ccdf4f0SGreg Roach * @return ResponseInterface 122aee13b6dSGreg Roach */ 12357ab2231SGreg Roach public function getAdminAction(ServerRequestInterface $request): ResponseInterface 124c1010edaSGreg Roach { 125aee13b6dSGreg Roach $this->layout = 'layouts/administration'; 126aee13b6dSGreg Roach 1271d1f373cSGreg Roach // This module can't run without a tree 128e218f363SGreg Roach $tree = $request->getAttribute('tree'); 129e218f363SGreg Roach 1301d1f373cSGreg Roach if (!$tree instanceof Tree) { 131e218f363SGreg Roach $tree = $this->tree_service->all()->first(); 132e218f363SGreg Roach if ($tree instanceof Tree) { 133e218f363SGreg Roach return redirect(route('module', ['module' => $this->name(), 'action' => 'Admin', 'tree' => $tree->name()])); 134e218f363SGreg Roach } 135e218f363SGreg Roach 1361d1f373cSGreg Roach return redirect(route(ControlPanel::class)); 1371d1f373cSGreg Roach } 1385229eadeSGreg Roach 13926348dcdSGreg Roach $faqs = $this->faqsForTree($tree); 140aee13b6dSGreg Roach 14177654037SGreg Roach $min_block_order = DB::table('block') 14226684e68SGreg Roach ->where('module_name', '=', $this->name()) 1430b5fd0a6SGreg Roach ->where(static function (Builder $query) use ($tree): void { 14477654037SGreg Roach $query 14577654037SGreg Roach ->whereNull('gedcom_id') 14677654037SGreg Roach ->orWhere('gedcom_id', '=', $tree->id()); 14777654037SGreg Roach }) 14877654037SGreg Roach ->min('block_order'); 149aee13b6dSGreg Roach 15077654037SGreg Roach $max_block_order = DB::table('block') 15126684e68SGreg Roach ->where('module_name', '=', $this->name()) 1520b5fd0a6SGreg Roach ->where(static function (Builder $query) use ($tree): void { 15377654037SGreg Roach $query 15477654037SGreg Roach ->whereNull('gedcom_id') 15577654037SGreg Roach ->orWhere('gedcom_id', '=', $tree->id()); 15677654037SGreg Roach }) 15777654037SGreg Roach ->max('block_order'); 158aee13b6dSGreg Roach 159cc13d6d8SGreg Roach $title = I18N::translate('Frequently asked questions') . ' — ' . $tree->title(); 160aee13b6dSGreg Roach 161aee13b6dSGreg Roach return $this->viewResponse('modules/faq/config', [ 16283615acfSGreg Roach 'action' => route('module', ['module' => $this->name(), 'action' => 'Admin']), 163aee13b6dSGreg Roach 'faqs' => $faqs, 164aee13b6dSGreg Roach 'max_block_order' => $max_block_order, 165aee13b6dSGreg Roach 'min_block_order' => $min_block_order, 16671378461SGreg Roach 'module' => $this->name(), 167aee13b6dSGreg Roach 'title' => $title, 168aee13b6dSGreg Roach 'tree' => $tree, 169*1e653452SGreg Roach 'tree_names' => $this->tree_service->titles(), 170aee13b6dSGreg Roach ]); 171aee13b6dSGreg Roach } 172aee13b6dSGreg Roach 173aee13b6dSGreg Roach /** 1746ccdf4f0SGreg Roach * @param ServerRequestInterface $request 175aee13b6dSGreg Roach * 1766ccdf4f0SGreg Roach * @return ResponseInterface 177aee13b6dSGreg Roach */ 178e218f363SGreg Roach public function postAdminAction(ServerRequestInterface $request): ResponseInterface 179e218f363SGreg Roach { 180e218f363SGreg Roach return redirect(route('module', [ 181e218f363SGreg Roach 'module' => $this->name(), 182e218f363SGreg Roach 'action' => 'Admin', 183e218f363SGreg Roach 'tree' => $request->getParsedBody()['tree'] ?? '', 184e218f363SGreg Roach ])); 185e218f363SGreg Roach } 186e218f363SGreg Roach 187e218f363SGreg Roach /** 188e218f363SGreg Roach * @param ServerRequestInterface $request 189e218f363SGreg Roach * 190e218f363SGreg Roach * @return ResponseInterface 191e218f363SGreg Roach */ 19257ab2231SGreg Roach public function postAdminDeleteAction(ServerRequestInterface $request): ResponseInterface 193c1010edaSGreg Roach { 194eb235819SGreg Roach $block_id = (int) $request->getQueryParams()['block_id']; 195aee13b6dSGreg Roach 19677654037SGreg Roach DB::table('block_setting')->where('block_id', '=', $block_id)->delete(); 197aee13b6dSGreg Roach 19877654037SGreg Roach DB::table('block')->where('block_id', '=', $block_id)->delete(); 199aee13b6dSGreg Roach 200c1010edaSGreg Roach $url = route('module', [ 20126684e68SGreg Roach 'module' => $this->name(), 202c1010edaSGreg Roach 'action' => 'Admin', 203c1010edaSGreg Roach ]); 204aee13b6dSGreg Roach 2056ccdf4f0SGreg Roach return redirect($url); 206aee13b6dSGreg Roach } 207aee13b6dSGreg Roach 208aee13b6dSGreg Roach /** 2096ccdf4f0SGreg Roach * @param ServerRequestInterface $request 210aee13b6dSGreg Roach * 2116ccdf4f0SGreg Roach * @return ResponseInterface 212aee13b6dSGreg Roach */ 21357ab2231SGreg Roach public function postAdminMoveDownAction(ServerRequestInterface $request): ResponseInterface 214c1010edaSGreg Roach { 215eb235819SGreg Roach $block_id = (int) $request->getQueryParams()['block_id']; 216aee13b6dSGreg Roach 21777654037SGreg Roach $block_order = DB::table('block') 21877654037SGreg Roach ->where('block_id', '=', $block_id) 21977654037SGreg Roach ->value('block_order'); 220aee13b6dSGreg Roach 22177654037SGreg Roach $swap_block = DB::table('block') 22226684e68SGreg Roach ->where('module_name', '=', $this->name()) 22377654037SGreg Roach ->where('block_order', '>', $block_order) 2241d1f373cSGreg Roach ->orderBy('block_order', 'asc') 22577654037SGreg Roach ->first(); 226aee13b6dSGreg Roach 2271d1f373cSGreg Roach if ($block_order !== null && $swap_block !== null) { 22877654037SGreg Roach DB::table('block') 22977654037SGreg Roach ->where('block_id', '=', $block_id) 23077654037SGreg Roach ->update([ 231aee13b6dSGreg Roach 'block_order' => $swap_block->block_order, 232aee13b6dSGreg Roach ]); 23377654037SGreg Roach 23477654037SGreg Roach DB::table('block') 23577654037SGreg Roach ->where('block_id', '=', $swap_block->block_id) 23677654037SGreg Roach ->update([ 237aee13b6dSGreg Roach 'block_order' => $block_order, 238aee13b6dSGreg Roach ]); 239aee13b6dSGreg Roach } 240aee13b6dSGreg Roach 2411d1f373cSGreg Roach return response(); 242aee13b6dSGreg Roach } 243aee13b6dSGreg Roach 244aee13b6dSGreg Roach /** 2456ccdf4f0SGreg Roach * @param ServerRequestInterface $request 246aee13b6dSGreg Roach * 2476ccdf4f0SGreg Roach * @return ResponseInterface 248aee13b6dSGreg Roach */ 24957ab2231SGreg Roach public function postAdminMoveUpAction(ServerRequestInterface $request): ResponseInterface 250c1010edaSGreg Roach { 251eb235819SGreg Roach $block_id = (int) $request->getQueryParams()['block_id']; 252aee13b6dSGreg Roach 25377654037SGreg Roach $block_order = DB::table('block') 25477654037SGreg Roach ->where('block_id', '=', $block_id) 25577654037SGreg Roach ->value('block_order'); 256aee13b6dSGreg Roach 25777654037SGreg Roach $swap_block = DB::table('block') 25826684e68SGreg Roach ->where('module_name', '=', $this->name()) 25977654037SGreg Roach ->where('block_order', '<', $block_order) 2601d1f373cSGreg Roach ->orderBy('block_order', 'desc') 26177654037SGreg Roach ->first(); 262aee13b6dSGreg Roach 2631d1f373cSGreg Roach if ($block_order !== null && $swap_block !== null) { 26477654037SGreg Roach DB::table('block') 26577654037SGreg Roach ->where('block_id', '=', $block_id) 26677654037SGreg Roach ->update([ 267aee13b6dSGreg Roach 'block_order' => $swap_block->block_order, 268aee13b6dSGreg Roach ]); 26977654037SGreg Roach 27077654037SGreg Roach DB::table('block') 27177654037SGreg Roach ->where('block_id', '=', $swap_block->block_id) 27277654037SGreg Roach ->update([ 273aee13b6dSGreg Roach 'block_order' => $block_order, 274aee13b6dSGreg Roach ]); 275aee13b6dSGreg Roach } 276aee13b6dSGreg Roach 2771d1f373cSGreg Roach return response(); 278aee13b6dSGreg Roach } 279aee13b6dSGreg Roach 280aee13b6dSGreg Roach /** 2816ccdf4f0SGreg Roach * @param ServerRequestInterface $request 282aee13b6dSGreg Roach * 2836ccdf4f0SGreg Roach * @return ResponseInterface 284aee13b6dSGreg Roach */ 28557ab2231SGreg Roach public function getAdminEditAction(ServerRequestInterface $request): ResponseInterface 286c1010edaSGreg Roach { 287aee13b6dSGreg Roach $this->layout = 'layouts/administration'; 288aee13b6dSGreg Roach 289eb235819SGreg Roach $block_id = (int) ($request->getQueryParams()['block_id'] ?? 0); 290aee13b6dSGreg Roach 291aee13b6dSGreg Roach if ($block_id === 0) { 292aee13b6dSGreg Roach // Creating a new faq 293aee13b6dSGreg Roach $header = ''; 294*1e653452SGreg Roach $body = ''; 295*1e653452SGreg Roach $gedcom_id = null; 296*1e653452SGreg Roach $block_order = 1 + (int) DB::table('block')->where('module_name', '=', $this->name())->max('block_order'); 29777654037SGreg Roach 298aee13b6dSGreg Roach $languages = []; 299aee13b6dSGreg Roach 300aee13b6dSGreg Roach $title = I18N::translate('Add an FAQ'); 301aee13b6dSGreg Roach } else { 302aee13b6dSGreg Roach // Editing an existing faq 303aee13b6dSGreg Roach $header = $this->getBlockSetting($block_id, 'header'); 304*1e653452SGreg Roach $body = $this->getBlockSetting($block_id, 'faqbody'); 305*1e653452SGreg Roach $gedcom_id = DB::table('block')->where('block_id', '=', $block_id)->value('gedcom_id'); 306*1e653452SGreg Roach $block_order = DB::table('block')->where('block_id', '=', $block_id)->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 313*1e653452SGreg Roach $gedcom_ids = $this->tree_service->all() 314*1e653452SGreg Roach ->mapWithKeys(static function (Tree $tree): array { 315*1e653452SGreg Roach return [$tree->id() => $tree->title()]; 316*1e653452SGreg Roach }) 317*1e653452SGreg Roach ->all(); 318*1e653452SGreg Roach 319*1e653452SGreg Roach $gedcom_ids = ['' => I18N::translate('All')] + $gedcom_ids; 320b6c326d8SGreg Roach 321aee13b6dSGreg Roach return $this->viewResponse('modules/faq/edit', [ 322aee13b6dSGreg Roach 'block_id' => $block_id, 323aee13b6dSGreg Roach 'block_order' => $block_order, 324aee13b6dSGreg Roach 'header' => $header, 325*1e653452SGreg Roach 'body' => $body, 326aee13b6dSGreg Roach 'languages' => $languages, 327aee13b6dSGreg Roach 'title' => $title, 328*1e653452SGreg Roach 'gedcom_id' => $gedcom_id, 329*1e653452SGreg Roach 'gedcom_ids' => $gedcom_ids, 330aee13b6dSGreg Roach ]); 331aee13b6dSGreg Roach } 332aee13b6dSGreg Roach 333aee13b6dSGreg Roach /** 3346ccdf4f0SGreg Roach * @param ServerRequestInterface $request 335aee13b6dSGreg Roach * 3366ccdf4f0SGreg Roach * @return ResponseInterface 337aee13b6dSGreg Roach */ 33857ab2231SGreg Roach public function postAdminEditAction(ServerRequestInterface $request): ResponseInterface 339c1010edaSGreg Roach { 340eb235819SGreg Roach $block_id = (int) ($request->getQueryParams()['block_id'] ?? 0); 341eb235819SGreg Roach 342eb235819SGreg Roach $params = $request->getParsedBody(); 343eb235819SGreg Roach 344*1e653452SGreg Roach $body = $params['body']; 345eb235819SGreg Roach $header = $params['header']; 346eb235819SGreg Roach $languages = $params['languages'] ?? []; 347*1e653452SGreg Roach $gedcom_id = $params['gedcom_id']; 348*1e653452SGreg Roach $block_order = $params['block_order']; 349aee13b6dSGreg Roach 350*1e653452SGreg Roach if ($gedcom_id === '') { 351*1e653452SGreg Roach $gedcom_id = null; 352*1e653452SGreg Roach } 353*1e653452SGreg Roach 354*1e653452SGreg Roach $body = $this->html_service->sanitize($body); 35550d6f48cSGreg Roach $header = $this->html_service->sanitize($header); 35650d6f48cSGreg Roach 357aee13b6dSGreg Roach if ($block_id !== 0) { 35877654037SGreg Roach DB::table('block') 35977654037SGreg Roach ->where('block_id', '=', $block_id) 36077654037SGreg Roach ->update([ 36177654037SGreg Roach 'gedcom_id' => $gedcom_id, 36277654037SGreg Roach 'block_order' => $block_order, 363aee13b6dSGreg Roach ]); 364aee13b6dSGreg Roach } else { 36577654037SGreg Roach DB::table('block')->insert([ 36677654037SGreg Roach 'gedcom_id' => $gedcom_id, 36726684e68SGreg Roach 'module_name' => $this->name(), 36877654037SGreg Roach 'block_order' => $block_order, 369aee13b6dSGreg Roach ]); 370aee13b6dSGreg Roach 37177654037SGreg Roach $block_id = (int) DB::connection()->getPdo()->lastInsertId(); 372aee13b6dSGreg Roach } 373aee13b6dSGreg Roach 374*1e653452SGreg Roach $this->setBlockSetting($block_id, 'faqbody', $body); 375aee13b6dSGreg Roach $this->setBlockSetting($block_id, 'header', $header); 376aee13b6dSGreg Roach $this->setBlockSetting($block_id, 'languages', implode(',', $languages)); 377aee13b6dSGreg Roach 378c1010edaSGreg Roach $url = route('module', [ 37926684e68SGreg Roach 'module' => $this->name(), 380c1010edaSGreg Roach 'action' => 'Admin', 381c1010edaSGreg Roach ]); 382aee13b6dSGreg Roach 3836ccdf4f0SGreg Roach return redirect($url); 384aee13b6dSGreg Roach } 385aee13b6dSGreg Roach 386b998dbceSGreg Roach /** 38757ab2231SGreg Roach * @param ServerRequestInterface $request 388b998dbceSGreg Roach * 3896ccdf4f0SGreg Roach * @return ResponseInterface 390b998dbceSGreg Roach */ 39157ab2231SGreg Roach public function getShowAction(ServerRequestInterface $request): ResponseInterface 392c1010edaSGreg Roach { 39357ab2231SGreg Roach $tree = $request->getAttribute('tree'); 3945229eadeSGreg Roach assert($tree instanceof Tree, new InvalidArgumentException()); 39557ab2231SGreg Roach 3968de50a4eSGreg Roach // Filter foreign languages. 39777654037SGreg Roach $faqs = $this->faqsForTree($tree) 3980b5fd0a6SGreg Roach ->filter(static function (stdClass $faq): bool { 39922d65e5aSGreg Roach return $faq->languages === '' || in_array(WT_LOCALE, explode(',', $faq->languages), true); 4008de50a4eSGreg Roach }); 401aee13b6dSGreg Roach 402aee13b6dSGreg Roach return $this->viewResponse('modules/faq/show', [ 4038de50a4eSGreg Roach 'faqs' => $faqs, 404aee13b6dSGreg Roach 'title' => I18N::translate('Frequently asked questions'), 4058de50a4eSGreg Roach 'tree' => $tree, 406aee13b6dSGreg Roach ]); 407aee13b6dSGreg Roach } 40877654037SGreg Roach 40977654037SGreg Roach /** 41077654037SGreg Roach * @param Tree $tree 41177654037SGreg Roach * 41277654037SGreg Roach * @return Collection 41377654037SGreg Roach */ 41477654037SGreg Roach private function faqsForTree(Tree $tree): Collection 41577654037SGreg Roach { 41677654037SGreg Roach return DB::table('block') 41777654037SGreg Roach ->join('block_setting AS bs1', 'bs1.block_id', '=', 'block.block_id') 41877654037SGreg Roach ->join('block_setting AS bs2', 'bs2.block_id', '=', 'block.block_id') 41977654037SGreg Roach ->join('block_setting AS bs3', 'bs3.block_id', '=', 'block.block_id') 42026684e68SGreg Roach ->where('module_name', '=', $this->name()) 42177654037SGreg Roach ->where('bs1.setting_name', '=', 'header') 42277654037SGreg Roach ->where('bs2.setting_name', '=', 'faqbody') 42377654037SGreg Roach ->where('bs3.setting_name', '=', 'languages') 4240b5fd0a6SGreg Roach ->where(static function (Builder $query) use ($tree): void { 42577654037SGreg Roach $query 42677654037SGreg Roach ->whereNull('gedcom_id') 42777654037SGreg Roach ->orWhere('gedcom_id', '=', $tree->id()); 42877654037SGreg Roach }) 42977654037SGreg Roach ->orderBy('block_order') 43077654037SGreg Roach ->select(['block.block_id', 'block_order', 'gedcom_id', 'bs1.setting_value AS header', 'bs2.setting_value AS faqbody', 'bs3.setting_value AS languages']) 43177654037SGreg Roach ->get(); 43277654037SGreg Roach } 43377654037SGreg Roach 43477654037SGreg Roach /** 43577654037SGreg Roach * @param Tree $tree 43677654037SGreg Roach * @param string $language 43777654037SGreg Roach * 43877654037SGreg Roach * @return bool 43977654037SGreg Roach */ 44077654037SGreg Roach private function faqsExist(Tree $tree, string $language): bool 44177654037SGreg Roach { 44277654037SGreg Roach return DB::table('block') 44377654037SGreg Roach ->join('block_setting', 'block_setting.block_id', '=', 'block.block_id') 44426684e68SGreg Roach ->where('module_name', '=', $this->name()) 44577654037SGreg Roach ->where('setting_name', '=', 'languages') 4460b5fd0a6SGreg Roach ->where(static function (Builder $query) use ($tree): void { 44777654037SGreg Roach $query 44877654037SGreg Roach ->whereNull('gedcom_id') 44977654037SGreg Roach ->orWhere('gedcom_id', '=', $tree->id()); 45077654037SGreg Roach }) 45177654037SGreg Roach ->select(['setting_value AS languages']) 45277654037SGreg Roach ->get() 4530b5fd0a6SGreg Roach ->filter(static function (stdClass $faq) use ($language): bool { 4540b5fd0a6SGreg Roach return $faq->languages === '' || in_array($language, explode(',', $faq->languages), true); 45577654037SGreg Roach }) 45677654037SGreg Roach ->isNotEmpty(); 45777654037SGreg Roach } 4588c2e8227SGreg Roach} 459