Passed
Push — Showing-Posts ( 5be296...b55a13 )
by Stone
01:58
created

Post::viewPost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
1
<?php
2
namespace App\Controllers;
3
4
use App\Models\CategoryModel;
5
use App\Models\PostModel;
6
use App\Models\SlugModel;
7
use App\Models\TagsModel;
8
use Core\Controller;
9
use Core\Container;
10
11
class Post extends Controller{
12
13
    protected $siteConfig;
14
15
    public function __construct(Container $container)
16
    {
17
        $this->loadModules[] = 'SiteConfig';
18
        parent::__construct($container);
19
    }
20
21
    /**
22
     * @param $slug
23
     * @throws \ErrorException
24
     * @throws \ReflectionException
25
     * @throws \Twig_Error_Loader
26
     * @throws \Twig_Error_Runtime
27
     * @throws \Twig_Error_Syntax
28
     */
29
    public function viewPost($slug){
30
31
        $tagModel = new TagsModel($this->container);
32
        $postModel = new PostModel($this->container);
33
        $slugModel = new SlugModel($this->container);
34
        $categoryModel = new CategoryModel($this->container);
35
36
        $postId = $slugModel->getIdFromSlug($slug, "posts", "posts_slug", "idposts");
37
38
        $this->data['configs'] = $this->siteConfig->getSiteConfig();
39
        $this->data['post'] = $postModel->getSinglePost($postId);
40
        $this->data['postTags'] = $tagModel->getTagsOnPost($postId);
41
42
        $this->data['navigation'] = $categoryModel->getMenu();
43
        $this->renderView('post');
44
45
    }
46
}