Passed
Push — Showing-Posts ( 7ae013...329372 )
by Stone
02:31
created

Author::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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
}