Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

Apps/Controller/Front/Content/ActionList.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Apps\Controller\Front\Content;
4
5
use Apps\Model\Front\Content\EntityCategoryList;
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\View;
8
use Ffcms\Core\Helper\Type\Arr;
9
use Ffcms\Core\Network\Request;
10
use Ffcms\Core\Network\Response;
11
12
/**
13
 * Trait ActionList
14
 * @package Apps\Controller\Front\Content
15
 * @property View $view
16
 * @property Request $request
17
 * @property Response $response
18
 * @method array getConfigs
19
 */
20
trait ActionList
21
{
22
    /**
23
     * List category content
24
     * @return string
25
     */
26
    public function listing(): ?string
27
    {
28
        $path = $this->request->getPathWithoutControllerAction();
29
        $configs = $this->getConfigs();
30
        $page = (int)$this->request->query->get('page', 0);
31
        $sort = (string)$this->request->query->get('sort', 'newest');
32
        $itemCount = (int)$configs['itemPerCategory'];
33
34
        // build special model with content list and category list information
35
        $model = new EntityCategoryList($path, $configs, $page, $sort);
36
37
        // prepare query string (?a=b) for pagination if sort is defined
38
        $sortQuery = null;
39
        if (Arr::in($sort, ['rating', 'views'])) {
40
            $sortQuery = ['sort' => $sort];
41
        }
42
        // calculate total row count
43
        $totalCount = $model->getContentCount();
44
45
        // define list event
46
        App::$Event->run(static::EVENT_CONTENT_LIST, [
0 ignored issues
show
The constant Apps\Controller\Front\Co...ist::EVENT_CONTENT_LIST was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
47
            'model' => $model
48
        ]);
49
50
        // draw response view
51
        return $this->view->render('content/list', [
52
            'model' => $model,
53
            'pagination' => [
54
                'page' => $page,
55
                'total' => $totalCount,
56
                'step' => $itemCount,
57
                'url' => ['content/list', [$path], [$sortQuery]]
58
            ],
59
            'configs' => $configs,
60
        ]);
61
    }
62
}
63