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\Helper\HTML\SimplePagination; |
8
|
|
|
use Ffcms\Core\Network\Request; |
9
|
|
|
use Ffcms\Core\Network\Response; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Trait ActionFeed |
14
|
|
|
* @package Apps\Controller\Front\Profile |
15
|
|
|
* @property \Apps\ActiveRecord\App $application |
16
|
|
|
* @property Request $request |
17
|
|
|
* @property View $view |
18
|
|
|
* @property Response $response |
19
|
|
|
*/ |
20
|
|
|
trait ActionFeed |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Show all users feed activity from wall posts |
25
|
|
|
* @return string |
26
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
27
|
|
|
*/ |
28
|
|
|
public function feed() |
29
|
|
|
{ |
30
|
|
|
/** @var array $cfg */ |
31
|
|
|
$cfg = $this->application->configs; |
32
|
|
|
// get pagination page id and calc offset |
33
|
|
|
$page = (int)$this->request->query->get('page'); |
34
|
|
|
$items = 10; |
35
|
|
|
if ((int)$cfg['wallPostOnFeed'] >= 1) { |
36
|
|
|
$items = (int)$cfg['wallPostOnFeed']; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$offset = $page * $items; |
40
|
|
|
|
41
|
|
|
// total wall posts count |
42
|
|
|
$query = new WallPost(); |
43
|
|
|
|
44
|
|
|
// build pagination |
45
|
|
|
$pagination = new SimplePagination([ |
46
|
|
|
'url' => ['profile/feed'], |
47
|
|
|
'page' => $page, |
48
|
|
|
'step' => $items, |
49
|
|
|
'total' => $query->count() |
50
|
|
|
]); |
51
|
|
|
|
52
|
|
|
// get records from database as object related with User, Role, Profile objects |
53
|
|
|
$records = $query->with(['senderUser', 'senderUser.role', 'senderUser.profile']) |
54
|
|
|
->orderBy('id', 'DESC') |
55
|
|
|
->skip($offset) |
56
|
|
|
->take($items) |
57
|
|
|
->get(); |
58
|
|
|
|
59
|
|
|
// render output view |
60
|
|
|
return $this->view->render('feed', [ |
61
|
|
|
'records' => $records, |
62
|
|
|
'pagination' => $pagination |
63
|
|
|
]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |