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

Tag::posts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 2
dl 0
loc 16
rs 9.8666
c 0
b 0
f 0
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
}