Passed
Pull Request — 1.11.x (#4900)
by Angel Fernando Quiroz
10:17
created

BaseController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 4
1
<?php
2
3
namespace Chamilo\PluginBundle\ExerciseFocused\Controller;
4
5
use Chamilo\PluginBundle\ExerciseFocused\Repository\LogRepository;
6
use Doctrine\ORM\EntityManager;
7
use Exception;
8
use ExerciseFocusedPlugin;
9
use Symfony\Component\HttpFoundation\Request as HttpRequest;
10
use Symfony\Component\HttpFoundation\Response as HttpResponse;
11
use Template;
12
13
abstract class BaseController
14
{
15
    /**
16
     * @var ExerciseFocusedPlugin
17
     */
18
    protected $plugin;
19
20
    /**
21
     * @var HttpRequest
22
     */
23
    protected $request;
24
25
    /**
26
     * @var EntityManager
27
     */
28
    protected $em;
29
30
    /**
31
     * @var LogRepository
32
     */
33
    protected $logRepository;
34
35
    /**
36
     * @var Template
37
     */
38
    protected $template;
39
40
    public function __construct(
41
        ExerciseFocusedPlugin $plugin,
42
        HttpRequest $request,
43
        EntityManager $em,
44
        LogRepository $logRepository
45
    ) {
46
        $this->plugin = $plugin;
47
        $this->request = $request;
48
        $this->em = $em;
49
        $this->logRepository = $logRepository;
50
    }
51
52
    /**
53
     * @throws Exception
54
     */
55
    public function __invoke(): HttpResponse
56
    {
57
        if (!$this->plugin->isEnabled(true)) {
58
            throw new Exception();
59
        }
60
61
        return HttpResponse::create();
62
    }
63
64
    protected function renderView(
65
        string $title,
66
        string $content,
67
        ?string $header = null,
68
        array $actions = []
69
    ): HttpResponse {
70
        if (!$header) {
71
            $header = $title;
72
        }
73
74
        $this->template = new Template($title);
75
        $this->template->assign('header', $header);
76
        $this->template->assign('actions', implode(PHP_EOL, $actions));
77
        $this->template->assign('content', $content);
78
79
        ob_start();
80
        $this->template->display_one_col_template();
81
        $html = ob_get_contents();
82
        ob_end_clean();
83
84
        return HttpResponse::create($html);
85
    }
86
}
87