1 | <?php |
||
2 | |||
3 | namespace Apps\Controller\Front\Content; |
||
4 | |||
5 | use Apps\ActiveRecord\Content as ContentRecord; |
||
6 | use Ffcms\Core\App; |
||
7 | use Ffcms\Core\Arch\View; |
||
8 | use Ffcms\Core\Exception\NotFoundException; |
||
9 | use Ffcms\Core\Helper\Type\Any; |
||
10 | use Ffcms\Core\Helper\Type\Str; |
||
11 | use Ffcms\Core\Network\Request; |
||
12 | use Ffcms\Core\Network\Response; |
||
13 | |||
14 | /** |
||
15 | * Trait ActionTag |
||
16 | * @package Apps\Controller\Front\Content |
||
17 | * @property View $view |
||
18 | * @property Request $request |
||
19 | * @property Response $response |
||
20 | * @method array getConfigs |
||
21 | */ |
||
22 | trait ActionTag |
||
23 | { |
||
24 | /** |
||
25 | * List latest by created_at content items contains tag name |
||
26 | * @param string $name |
||
27 | * @return null|string |
||
28 | * @throws NotFoundException |
||
29 | */ |
||
30 | public function tag($name): ?string |
||
31 | { |
||
32 | // remove spaces and other sh@ts |
||
33 | $name = App::$Security->strip_tags(trim($name)); |
||
34 | |||
35 | // check if tag is not empty |
||
36 | if (!Any::isStr($name) || Str::length($name) < 2) { |
||
37 | throw new NotFoundException(__('Tag is empty or is too short!')); |
||
38 | } |
||
39 | |||
40 | // get equal rows order by creation date |
||
41 | $records = ContentRecord::where('meta_keywords', 'like', '%' . $name . '%') |
||
42 | ->orderBy('created_at', 'DESC') |
||
43 | ->take(self::TAG_PER_PAGE); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
44 | // check if result is not empty |
||
45 | if ($records->count() < 1) { |
||
46 | throw new NotFoundException(__('Nothing found')); |
||
47 | } |
||
48 | |||
49 | // define tag list event |
||
50 | App::$Event->run(static::EVENT_TAG_LIST, [ |
||
0 ignored issues
–
show
|
|||
51 | 'records' => $records |
||
52 | ]); |
||
53 | |||
54 | // render response |
||
55 | return $this->view->render('content/tag', [ |
||
56 | 'records' => $records->get(), |
||
57 | 'tag' => $name |
||
58 | ]); |
||
59 | } |
||
60 | } |
||
61 |