1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Models\PostModel; |
6
|
|
|
use App\Models\UserModel; |
7
|
|
|
use Core\Controller; |
8
|
|
|
use Core\Container; |
9
|
|
|
|
10
|
|
|
class Author extends Controller |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
protected $siteConfig; |
15
|
|
|
|
16
|
|
|
public function __construct(Container $container) |
17
|
|
|
{ |
18
|
|
|
$this->loadModules[] = 'SiteConfig'; |
19
|
|
|
parent::__construct($container); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* get all posts from author |
24
|
|
|
* @param $authorId |
25
|
|
|
* @param string $page |
26
|
|
|
* @throws \ErrorException |
27
|
|
|
* @throws \ReflectionException |
28
|
|
|
* @throws \Twig_Error_Loader |
29
|
|
|
* @throws \Twig_Error_Runtime |
30
|
|
|
* @throws \Twig_Error_Syntax |
31
|
|
|
*/ |
32
|
|
|
public function posts(int $authorId, string $page = "page-1") |
33
|
|
|
{ |
34
|
|
|
$postModel = new PostModel($this->container); |
35
|
|
|
$userModel = new UserModel($this->container); |
36
|
|
|
|
37
|
|
|
$totalPosts = $postModel->totalNumberPostsByAuthor($authorId); |
38
|
|
|
$pagination = $this->pagination->getPagination($page, $totalPosts); |
39
|
|
|
|
40
|
|
|
$this->sendSessionVars(); |
41
|
|
|
$this->data['posts'] = $postModel->getPostsWithAuthor($authorId, $pagination["offset"]); |
42
|
|
|
$this->data['configs'] = $this->siteConfig->getSiteConfig(); |
43
|
|
|
$this->data['navigation'] = $this->siteConfig->getMenu(); |
44
|
|
|
$this->data['pagination'] = $pagination; |
45
|
|
|
$this->data['authorId'] = $authorId; |
46
|
|
|
$this->data['user'] = $userModel->getUserDetailsById($authorId); |
47
|
|
|
|
48
|
|
|
$this->renderView('Author'); |
49
|
|
|
} |
50
|
|
|
} |