1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Controller\Admin\Comments; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Apps\ActiveRecord\CommentAnswer; |
7
|
|
|
use Apps\ActiveRecord\CommentPost; |
8
|
|
|
use Apps\Controller\Admin\Main; |
9
|
|
|
use Apps\Model\Admin\Main\AbstractSearchItem; |
10
|
|
|
use Apps\Model\Admin\Main\CollectionSearchResults; |
11
|
|
|
use Ffcms\Core\App; |
12
|
|
|
use Ffcms\Core\Helper\Text; |
13
|
|
|
use Illuminate\Support\Collection; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Trait Boot |
17
|
|
|
* @package Apps\Controller\Admin\Comments |
18
|
|
|
*/ |
19
|
|
|
trait Boot |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Boot search hook |
23
|
|
|
* @return void |
24
|
|
|
*/ |
25
|
|
|
public static function boot(): void |
26
|
|
|
{ |
27
|
|
|
App::$Event->on(Main::SEARCH_EVENT_NAME, function ($model) { |
28
|
|
|
/** @var CollectionSearchResults $model */ |
29
|
|
|
$records = CommentPost::search($model->getQuery()) |
30
|
|
|
->take($model->getLimit()) |
31
|
|
|
->get(); |
32
|
|
|
|
33
|
|
|
/** @var CommentPost[]|Collection $records */ |
34
|
|
|
$records->each(function($item) use ($model) { |
35
|
|
|
/** @var CommentPost $item */ |
36
|
|
|
$title = App::$Translate->get('Comments', 'Comment #%id%', ['id' => $item->id]); |
37
|
|
|
$text = Text::snippet(App::$Security->strip_tags($item->message)); |
38
|
|
|
|
39
|
|
|
// initialize abstract response pattern |
40
|
|
|
$res = new AbstractSearchItem(); |
41
|
|
|
$res->setTitle($title); |
42
|
|
|
$res->setSnippet($text); |
43
|
|
|
$res->setDate($item->created_at); |
44
|
|
|
$res->setRelevance((int)$item->relevance); |
|
|
|
|
45
|
|
|
$res->setUrl('comments/read', [$item->id]); |
46
|
|
|
$res->setMarker('Comment'); |
47
|
|
|
|
48
|
|
|
$model->add($res); |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
// search comment answers |
52
|
|
|
$records = CommentAnswer::search($model->getQuery()) |
53
|
|
|
->take($model->getLimit()) |
54
|
|
|
->get(); |
55
|
|
|
|
56
|
|
|
/** @var CommentAnswer[]|Collection $records */ |
57
|
|
|
$records->each(function($item) use ($model) { |
58
|
|
|
/** @var CommentAnswer $item */ |
59
|
|
|
$title = App::$Translate->get('Comments', 'Comment answer #%id%', ['id' => $item->id]); |
60
|
|
|
$text = Text::snippet(App::$Security->strip_tags($item->message)); |
61
|
|
|
|
62
|
|
|
// initialize abstract response pattern |
63
|
|
|
$res = new AbstractSearchItem(); |
64
|
|
|
$res->setTitle($title); |
65
|
|
|
$res->setSnippet($text); |
66
|
|
|
$res->setDate($item->created_at); |
67
|
|
|
$res->setRelevance((int)$item->relevance); |
|
|
|
|
68
|
|
|
$res->setUrl('comments/read', [$item->comment_id]); |
69
|
|
|
$res->setMarker('Comment'); |
70
|
|
|
|
71
|
|
|
$model->add($res); |
72
|
|
|
}); |
73
|
|
|
|
74
|
|
|
}); |
75
|
|
|
} |
76
|
|
|
} |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.