1 | <?php |
||
2 | |||
3 | namespace Apps\Controller\Front\Content; |
||
4 | |||
5 | |||
6 | use Apps\ActiveRecord\Content; |
||
7 | use Apps\Controller\Front\Search; |
||
8 | use Apps\Model\Front\Search\AbstractSearchResult; |
||
9 | use Apps\Model\Front\Search\EntitySearchMain; |
||
10 | use Ffcms\Core\App; |
||
11 | use Apps\ActiveRecord\App as AppRecord; |
||
12 | use Ffcms\Core\Helper\Text; |
||
13 | use Ffcms\Core\Helper\Type\Str; |
||
14 | use Ffcms\Templex\Helper\Html\Dom; |
||
15 | use Illuminate\Support\Collection; |
||
16 | |||
17 | /** |
||
18 | * Trait Boot |
||
19 | * @package Apps\Controller\Front\Content |
||
20 | */ |
||
21 | trait Boot |
||
22 | { |
||
23 | /** |
||
24 | * Implement boot features |
||
25 | */ |
||
26 | public static function boot(): void |
||
27 | { |
||
28 | App::$Event->on(Search::EVENT_SEARCH_RUN, function ($model) { |
||
29 | /** @var EntitySearchMain $model */ |
||
30 | $limit = (int)$model->getConfigs()['itemPerApp']; |
||
31 | if ($limit < 1) { |
||
32 | $limit = 1; |
||
33 | } |
||
34 | |||
35 | // relevant search by string query |
||
36 | $records = Content::search($model->query) |
||
37 | ->where('display', true) |
||
38 | ->take($limit) |
||
39 | ->get(); |
||
40 | |||
41 | /** @var Content[]|Collection $records */ |
||
42 | $records->each(function($item) use ($model) { |
||
43 | /** @var Content $item */ |
||
44 | $title = $item->getLocaled('title'); |
||
45 | $text = App::$Security->strip_tags($item->getLocaled('text')); |
||
46 | $snippet = Text::snippet($text); |
||
47 | // prevent empty items |
||
48 | if (Str::likeEmpty($title)) { |
||
49 | return; |
||
50 | } |
||
51 | |||
52 | // initialize abstract response pattern |
||
53 | $res = new AbstractSearchResult(); |
||
54 | $res->setTitle($title); |
||
55 | $res->setSnippet($snippet); |
||
56 | $res->setDate($item->created_at); |
||
57 | $res->setRelevance((int)$item->relevance); |
||
0 ignored issues
–
show
|
|||
58 | $res->setUri('/content/read/' . $item->getPath()); |
||
59 | |||
60 | $model->add($res); |
||
61 | }); |
||
62 | }); |
||
63 | } |
||
64 | } |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.