Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
OlzFaqDetailParams
n/a
0 / 0
n/a
0 / 0
0
n/a
0 / 0
OlzFaqDetail
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 1
56
0.00% covered (danger)
0.00%
0 / 1
 getHtml
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2
3namespace Olz\Faq\Components\OlzFaqDetail;
4
5use Olz\Components\Common\OlzComponent;
6use Olz\Components\Page\OlzFooter\OlzFooter;
7use Olz\Components\Page\OlzHeader\OlzHeader;
8use Olz\Entity\Faq\Question;
9use Olz\Entity\Roles\Role;
10use Olz\Repository\Roles\PredefinedRole;
11use Olz\Roles\Components\OlzRoleInfoModal\OlzRoleInfoModal;
12use Olz\Users\Components\OlzUserInfoModal\OlzUserInfoModal;
13use Olz\Utils\HttpParams;
14
15/** @extends HttpParams<array{von?: ?string}> */
16class OlzFaqDetailParams extends HttpParams {
17}
18
19/** @extends OlzComponent<array<string, mixed>> */
20class OlzFaqDetail extends OlzComponent {
21    public function getHtml(mixed $args): string {
22        $this->httpUtils()->validateGetParams(OlzFaqDetailParams::class);
23        $code_href = $this->envUtils()->getCodeHref();
24        $entityManager = $this->dbUtils()->getEntityManager();
25        $ident = $args['ident'] ?? null;
26
27        $question_repo = $entityManager->getRepository(Question::class);
28        $answered_question = $question_repo->findOneBy(['ident' => $ident]);
29        if (!$answered_question) {
30            $this->httpUtils()->dieWithHttpError(404);
31            throw new \Exception('should already have failed');
32        }
33        $is_active = $answered_question->getOnOff();
34        if (!$is_active && !$this->authUtils()->hasPermission('faq')) {
35            $this->httpUtils()->dieWithHttpError(404);
36            throw new \Exception('should already have failed');
37        }
38
39        $question = $answered_question->getQuestion();
40        $out = OlzHeader::render([
41            'back_link' => "{$code_href}fragen_und_antworten",
42            'title' => "{$question} - Fragen & Antworten",
43            'description' => "Antworten auf die wichtigsten Fragen rund um den OL, die OL Zimmerberg und diese Website.",
44            'canonical_url' => "{$code_href}fragen_und_antworten/{$ident}",
45        ]);
46
47        $answer = $answered_question->getAnswer() ?? '';
48        $answer_html = $this->htmlUtils()->renderMarkdown($answer);
49        $answer_html = $answered_question->replaceImagePaths($answer_html);
50        $answer_html = $answered_question->replaceFilePaths($answer_html);
51
52        $edit_admin = '';
53        $can_edit = $this->authUtils()->hasPermission('faq');
54        if ($can_edit) {
55            $id = $answered_question->getId();
56            $json_id = json_encode($id);
57            $edit_admin = <<<ZZZZZZZZZZ
58                <div>
59                    <button
60                        id='edit-question-button'
61                        class='btn btn-primary'
62                        onclick='return olz.editQuestion({$json_id})'
63                    >
64                        <img src='{$code_href}assets/icns/edit_white_16.svg' class='noborder' />
65                        Bearbeiten
66                    </button>
67                </div>
68                ZZZZZZZZZZ;
69        }
70
71        $owner_role = $answered_question->getOwnerRole();
72        $role_repo = $entityManager->getRepository(Role::class);
73        $responsible_role = $owner_role ?? $role_repo->getPredefinedRole(PredefinedRole::Nachwuchs);
74        $responsible_title = 'Ansprechperson';
75        if ($owner_role) {
76            $responsible_title = OlzRoleInfoModal::render(['role' => $owner_role]);
77        }
78        $responsible_assignees = $responsible_role?->getUsers() ?? [];
79        $responsible_out = '';
80        foreach ($responsible_assignees as $responsible_assignee) {
81            $responsible_out .= OlzUserInfoModal::render([
82                'user' => $responsible_assignee,
83                'mode' => 'name_picture',
84            ]);
85        }
86
87        $out .= <<<ZZZZZZZZZZ
88            <div class='content-right optional'>
89                <h3>{$responsible_title}</h3>
90                <div style='padding:0px 10px 0px 10px; text-align:center;'>
91                    {$responsible_out}
92                </div>
93            </div>
94            <div class='content-middle'>
95                {$edit_admin}
96                <h1>{$question}</h1>
97                <div>{$answer_html}</div>
98            </div>
99            ZZZZZZZZZZ;
100
101        $out .= OlzFooter::render();
102        return $out;
103    }
104}