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