1 | <?php |
||
2 | |||
3 | namespace Apps\Controller\Admin\Main; |
||
4 | |||
5 | |||
6 | use Apps\Model\Admin\Main\CollectionSearchResults; |
||
7 | use Ffcms\Core\App; |
||
8 | use Ffcms\Core\Arch\View; |
||
9 | use Ffcms\Core\Exception\ForbiddenException; |
||
10 | use Ffcms\Core\Helper\Type\Any; |
||
11 | use Ffcms\Core\Helper\Type\Str; |
||
12 | use Ffcms\Core\Network\Request; |
||
13 | use Ffcms\Core\Network\Response; |
||
14 | |||
15 | /** |
||
16 | * Trait ActionSearch |
||
17 | * @package Apps\Controller\Admin\Main |
||
18 | * @property Request $request |
||
19 | * @property Response $response |
||
20 | * @property View $view |
||
21 | */ |
||
22 | trait ActionSearch |
||
23 | { |
||
24 | /** |
||
25 | * Process search action |
||
26 | * @return string|null |
||
27 | * @throws ForbiddenException |
||
28 | */ |
||
29 | public function search(): ?string |
||
30 | { |
||
31 | $query = App::$Security->strip_tags($this->request->query->get('search'), null); |
||
32 | if (!Any::isStr($query) || Str::likeEmpty($query) || Str::length($query) > static::SEARCH_QUERY_MAX_LENGTH) { |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
33 | throw new ForbiddenException(__('Wrong query format')); |
||
34 | } |
||
35 | |||
36 | $model = new CollectionSearchResults($query, 10); |
||
37 | App::$Event->run(static::SEARCH_EVENT_NAME, [ |
||
0 ignored issues
–
show
|
|||
38 | 'model' => $model |
||
39 | ]); |
||
40 | |||
41 | return $this->view->render('main/search', [ |
||
42 | 'model' => $model |
||
43 | ]); |
||
44 | } |
||
45 | } |