1
|
|
|
<?php |
2
|
|
|
namespace App\Controllers; |
3
|
|
|
|
4
|
|
|
use App\Models\CategoryModel; |
5
|
|
|
use App\Models\PaginationModel; |
6
|
|
|
use App\Models\PostModel; |
7
|
|
|
use Core\Controller; |
8
|
|
|
use Core\Container; |
9
|
|
|
|
10
|
|
|
class Author extends Controller{ |
11
|
|
|
|
12
|
|
|
protected $siteConfig; |
13
|
|
|
protected $pagination; |
14
|
|
|
|
15
|
|
|
public function __construct(Container $container) |
16
|
|
|
{ |
17
|
|
|
$this->loadModules[] = 'SiteConfig'; |
18
|
|
|
$this->loadModules[] = 'pagination'; |
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($authorId, string $page = "page-1") |
33
|
|
|
{ |
34
|
|
|
$categoryModel = new CategoryModel($this->container); |
35
|
|
|
$postModel = new PostModel($this->container); |
36
|
|
|
$paginationModel = new PaginationModel($this->container); |
37
|
|
|
|
38
|
|
|
$totalPosts = $paginationModel->totalNumberPostsByAuthor($authorId); |
39
|
|
|
$pagination = $this->pagination->getPagination($page, $totalPosts); |
40
|
|
|
|
41
|
|
|
$this->sendSessionVars(); |
42
|
|
|
$this->data['posts'] = $postModel->getPostsWithAuthor($authorId, $pagination["offset"]); |
43
|
|
|
$this->data['configs'] = $this->siteConfig->getSiteConfig(); |
44
|
|
|
$this->data['navigation'] = $categoryModel->getMenu(); |
45
|
|
|
$this->data['pagination'] = $pagination; |
46
|
|
|
$this->data['authorId'] = $authorId; |
47
|
|
|
$this->renderView('Author'); |
48
|
|
|
} |
49
|
|
|
} |