Completed
Push — master ( 0d0ae6...7c7732 )
by Stone
19s
created

Tag   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A posts() 0 16 1
A __construct() 0 4 1
1
<?php
2
3
namespace App\Controllers;
4
5
use App\Models\CategoryModel;
6
use App\Models\PostModel;
7
use App\Models\TagModel;
8
use Core\Controller;
9
use Core\Container;
10
11
class Tag extends Controller
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
     * @param int $tagId
24
     * @param string $page
25
     * @throws \ErrorException
26
     * @throws \ReflectionException
27
     * @throws \Twig_Error_Loader
28
     * @throws \Twig_Error_Runtime
29
     * @throws \Twig_Error_Syntax
30
     */
31
    public function posts(int $tagId, string $page = "page-1")
32
    {
33
        $postModel = new PostModel($this->container);
34
        $tagModel = new TagModel($this->container);
35
36
        $totalPosts = $postModel->totalNumberPostsByTag($tagId);
37
        $pagination = $this->pagination->getPagination($page, $totalPosts);
38
39
        $this->sendSessionVars();
40
        $this->data['posts'] = $postModel->getPostsWithTag($tagId, $pagination["offset"]);
41
        $this->data['configs'] = $this->siteConfig->getSiteConfig();
42
        $this->data['navigation'] = $this->siteConfig->getMenu();
43
        $this->data['pagination'] = $pagination;
44
        $this->data['tagId'] = $tagId;
45
        $this->data['tag'] = $tagModel->getTagDetails($tagId);
46
        $this->renderView('Tag');
47
    }
48
}