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']; |
||
32 | } |
||
33 | // calc offset |
||
34 | $offset = $page * static::FEED_PER_PAGE; |
||
0 ignored issues
–
show
Bug
introduced
by
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 |