Passed
Pull Request — master (#58)
by Stone
04:29 queued 02:04
created

Author   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A posts() 0 17 1
A __construct() 0 4 1
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
}