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

Apps/Controller/Admin/Content/ActionIndex.php (1 issue)

Checks if used container constants are declared or listed as dependencies.

Bug Major
1
<?php
2
3
namespace Apps\Controller\Admin\Content;
4
5
use Apps\ActiveRecord\Content as ContentEntity;
6
use Ffcms\Core\Arch\View;
7
use Ffcms\Core\Helper\Type\Any;
8
use Ffcms\Core\Network\Request;
9
use Ffcms\Core\Network\Response;
10
11
/**
12
 * Trait ActionIndex
13
 * @package Apps\Controller\Admin\Content
14
 * @property Request $request
15
 * @property Response $response
16
 * @property View $view
17
 */
18
trait ActionIndex
19
{
20
    /**
21
     * List content items
22
     * @return string|null
23
     */
24
    public function index(): ?string
25
    {
26
        // set current page and offset
27
        $page = (int)$this->request->query->get('page');
28
        $offset = $page * self::ITEM_PER_PAGE;
0 ignored issues
show
The constant Apps\Controller\Admin\Co...ionIndex::ITEM_PER_PAGE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
29
30
        $query = null;
31
        // get query type (trash, category, all)
32
        $type = $this->request->query->get('type');
33
        if ($type === 'trash') {
34
            $query = ContentEntity::onlyTrashed();
35
        } elseif ($type === 'moderate') { // only items on moderate
36
            $query = ContentEntity::where('display', '=', 0);
37
        } elseif (Any::isInt($type)) { // sounds like category id ;)
38
            $query = ContentEntity::where('category_id', '=', (int)$type);
39
        } else {
40
            $query = new ContentEntity();
41
            $type = 'all';
42
        }
43
44
        // calculate total items count for pagination
45
        $total = $query->count();
46
47
        // build listing objects
48
        $records = $query->with('category')
49
            ->orderBy('important', 'DESC')
50
            ->orderBy('id', 'desc')
51
            ->skip($offset)
52
            ->take(self::ITEM_PER_PAGE)
53
            ->get();
54
55
        // render output view
56
        return $this->view->render('content/index', [
57
            'records' => $records,
58
            'pagination' => [
59
                'url' => ['content/index', null, null, ['type' => $type]],
60
                'page' => $page,
61
                'step' => self::ITEM_PER_PAGE,
62
                'total' => $total
63
            ],
64
            'type' => $type
65
        ]);
66
    }
67
}
68