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

ActionFeed::feed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 31
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Apps\Controller\Front\Profile;
4
5
use Apps\ActiveRecord\WallPost;
6
use Ffcms\Core\Arch\View;
7
use Ffcms\Core\Network\Request;
8
use Ffcms\Core\Network\Response;
9
10
/**
11
 * Trait ActionFeed
12
 * @package Apps\Controller\Front\Profile
13
 * @property \Apps\ActiveRecord\App $application
14
 * @property Request $request
15
 * @property View $view
16
 * @property Response $response
17
 */
18
trait ActionFeed
19
{
20
    /**
21
     * Show all users feed activity from wall posts
22
     * @return string
23
     */
24
    public function feed(): ?string
25
    {
26
        /** @var array $cfg */
27
        $cfg = $this->application->configs;
28
        // get pagination page id and calc offset
29
        $page = (int)$this->request->query->get('page');
30
        if ((int)$cfg['wallPostOnFeed'] >= 1) {
31
            $items = (int)$cfg['wallPostOnFeed'];
0 ignored issues
show
Unused Code introduced by zenn
The assignment to $items is dead and can be removed.
Loading history...
32
        }
33
        // calc offset
34
        $offset = $page * static::FEED_PER_PAGE;
0 ignored issues
show
Bug introduced by zenn
The constant Apps\Controller\Front\Pr...tionFeed::FEED_PER_PAGE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
35
36
        // total wall posts count
37
        $query = new WallPost();
38
        // get total items count
39
        $total = $query->count();
40
41
        // get records from database as object related with User, Role, Profile objects
42
        $records = $query->with(['senderUser', 'senderUser.role', 'senderUser.profile'])
43
            ->orderBy('id', 'DESC')
44
            ->skip($offset)
45
            ->take(static::FEED_PER_PAGE)
46
            ->get();
47
48
        // render output view
49
        return $this->view->render('profile/feed', [
50
            'records' => $records,
51
            'pagination' => [
52
                'step' => static::FEED_PER_PAGE,
53
                'total' => $total,
54
                'page' => $page
55
            ],
56
        ]);
57
    }
58
}
59