-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
212 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/6.0/fileDelete.xsd"> | ||
<delete> | ||
<file>lib/action/FaqSearchAction</file> | ||
</delete> | ||
</data> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
files/lib/system/endpoint/controller/faq/questions/search/GetSearch.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace wcf\system\endpoint\controller\faq\questions\search; | ||
|
||
use Laminas\Diactoros\Response\JsonResponse; | ||
use Override; | ||
use PDO; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use wcf\data\faq\Question; | ||
use wcf\data\faq\QuestionList; | ||
use wcf\http\Helper; | ||
use wcf\system\endpoint\GetRequest; | ||
use wcf\system\endpoint\IController; | ||
use wcf\system\exception\UserInputException; | ||
use wcf\system\WCF; | ||
|
||
#[GetRequest('/faq/questions/search')] | ||
final class GetSearch implements IController | ||
{ | ||
#[Override] | ||
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface | ||
{ | ||
$parameters = Helper::mapApiParameters($request, GetSearchParameters::class); | ||
if (\mb_strlen($parameters->query) < 3) { | ||
throw new UserInputException('query', 'tooShort'); | ||
} | ||
|
||
$questionIDs = $this->getQuestionsIDs($parameters->query); | ||
|
||
return new JsonResponse([ | ||
'template' => WCF::getTPL()->fetch('faqQuestionSearchResult', 'wcf', [ | ||
'questions' => $this->getQuestions($questionIDs), | ||
]), | ||
]); | ||
} | ||
|
||
/** | ||
* @return list<int> | ||
*/ | ||
private function getQuestionsIDs(string $query): array | ||
{ | ||
$sql = " | ||
SELECT faq_questions.questionID | ||
FROM wcf1_faq_questions faq_questions | ||
LEFT JOIN wcf1_language_item language_item | ||
ON language_item.languageItem = faq_questions.question | ||
WHERE faq_questions.question LIKE ? | ||
OR ( | ||
language_item.languageItemValue LIKE ? | ||
AND language_item.languageID = ? | ||
) | ||
ORDER BY faq_questions.question | ||
"; | ||
$statement = WCF::getDB()->prepare($sql, 5); | ||
$statement->execute([ | ||
'%' . WCF::getDB()->escapeLikeValue($query) . '%', | ||
'%' . WCF::getDB()->escapeLikeValue($query) . '%', | ||
WCF::getLanguage()->languageID, | ||
]); | ||
|
||
return $statement->fetchAll(PDO::FETCH_COLUMN, 0); | ||
} | ||
|
||
/** | ||
* @return list<Question> | ||
*/ | ||
private function getQuestions(array $questionIDs): array | ||
{ | ||
if ($questionIDs === []) { | ||
return []; | ||
} | ||
|
||
$questionList = new QuestionList(); | ||
$questionList->setObjectIDs($questionIDs); | ||
$questionList->readObjects(); | ||
|
||
return $questionList->getObjects(); | ||
} | ||
} | ||
|
||
/** @internal */ | ||
final class GetSearchParameters // phpcs:ignore | ||
{ | ||
public function __construct( | ||
/** @var non-empty-string */ | ||
public readonly string $query, | ||
) { | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
files/lib/system/endpoint/controller/faq/questions/search/RenderSearch.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace wcf\system\endpoint\controller\faq\questions\search; | ||
|
||
use Laminas\Diactoros\Response\JsonResponse; | ||
use Override; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use wcf\system\endpoint\GetRequest; | ||
use wcf\system\endpoint\IController; | ||
use wcf\system\WCF; | ||
|
||
#[GetRequest('/faq/questions/search/render')] | ||
final class RenderSearch implements IController | ||
{ | ||
#[Override] | ||
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface | ||
{ | ||
return new JsonResponse([ | ||
'template' => WCF::getTPL()->fetch('faqQuestionSearchDialog', 'wcf'), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend"; | ||
import { ApiResult, apiResultFromError, apiResultFromValue } from "WoltLabSuite/Core/Api/Result"; | ||
|
||
type Response = { | ||
template: string; | ||
}; | ||
|
||
export async function renderSearch(): Promise<ApiResult<Response>> { | ||
const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/faq/questions/search/render`); | ||
|
||
let response: Response; | ||
try { | ||
response = (await prepareRequest(url).get().fetchAsJson()) as Response; | ||
} catch (e) { | ||
return apiResultFromError(e); | ||
} | ||
|
||
return apiResultFromValue(response); | ||
} | ||
|
||
export async function searchQuestions(query: string): Promise<ApiResult<Response>> { | ||
const url = new URL(`${window.WSC_API_URL}index.php?api/rpc/faq/questions/search`); | ||
url.searchParams.set("query", query); | ||
|
||
let response: Response; | ||
try { | ||
response = (await prepareRequest(url).get().fetchAsJson()) as Response; | ||
} catch (e) { | ||
return apiResultFromError(e); | ||
} | ||
|
||
return apiResultFromValue(response); | ||
} |
Oops, something went wrong.