Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 70 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
OlzFaqListParams | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | n/a |
0 / 0 |
|||
OlzFaqList | |
0.00% |
0 / 70 |
|
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 1 |
getHtml | |
0.00% |
0 / 70 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | |
3 | namespace Olz\Faq\Components\OlzFaqList; |
4 | |
5 | use Olz\Components\Common\OlzComponent; |
6 | use Olz\Components\Common\OlzPostingListItem\OlzPostingListItem; |
7 | use Olz\Components\Page\OlzFooter\OlzFooter; |
8 | use Olz\Components\Page\OlzHeader\OlzHeader; |
9 | use Olz\Entity\Faq\Question; |
10 | use Olz\Entity\Faq\QuestionCategory; |
11 | use Olz\Entity\Roles\Role; |
12 | use Olz\Repository\Roles\PredefinedRole; |
13 | use Olz\Users\Components\OlzUserInfoModal\OlzUserInfoModal; |
14 | use Olz\Utils\HttpParams; |
15 | |
16 | /** @extends HttpParams<array{von?: ?string}> */ |
17 | class OlzFaqListParams extends HttpParams { |
18 | } |
19 | |
20 | /** @extends OlzComponent<array<string, mixed>> */ |
21 | class OlzFaqList extends OlzComponent { |
22 | public static string $title = "Fragen & Antworten"; |
23 | public static string $description = "Antworten auf die wichtigsten Fragen rund um den OL, die OL Zimmerberg und diese Website."; |
24 | |
25 | public function getHtml(mixed $args): string { |
26 | $this->httpUtils()->validateGetParams(OlzFaqListParams::class); |
27 | $code_href = $this->envUtils()->getCodeHref(); |
28 | $entityManager = $this->dbUtils()->getEntityManager(); |
29 | $question_repo = $entityManager->getRepository(Question::class); |
30 | $category_repo = $entityManager->getRepository(QuestionCategory::class); |
31 | |
32 | $out = OlzHeader::render([ |
33 | 'title' => self::$title, |
34 | 'description' => self::$description, |
35 | 'canonical_url' => "{$code_href}fragen_und_antworten", |
36 | ]); |
37 | |
38 | $role_repo = $entityManager->getRepository(Role::class); |
39 | $nachwuchs_role = $role_repo->getPredefinedRole(PredefinedRole::Nachwuchs); |
40 | $nachwuchs_out = ''; |
41 | $nachwuchs_assignees = $nachwuchs_role?->getUsers() ?? []; |
42 | foreach ($nachwuchs_assignees as $nachwuchs_assignee) { |
43 | $nachwuchs_out .= OlzUserInfoModal::render([ |
44 | 'user' => $nachwuchs_assignee, |
45 | 'mode' => 'name_picture', |
46 | ]); |
47 | } |
48 | |
49 | $out .= <<<ZZZZZZZZZZ |
50 | <div class='content-right'> |
51 | <h3>Ansprechperson</h3> |
52 | <div style='padding:0px 10px 0px 10px; text-align:center;'> |
53 | {$nachwuchs_out} |
54 | </div> |
55 | </div> |
56 | <div class='content-middle olz-faq-list'> |
57 | <h1>Fragen & Antworten (FAQ)</h1> |
58 | ZZZZZZZZZZ; |
59 | |
60 | $has_access = $this->authUtils()->hasPermission('faq'); |
61 | if ($has_access) { |
62 | $out .= <<<ZZZZZZZZZZ |
63 | <button |
64 | id='create-question-category-button' |
65 | class='btn btn-secondary' |
66 | onclick='return olz.initOlzEditQuestionCategoryModal()' |
67 | > |
68 | <img src='{$code_href}assets/icns/new_white_16.svg' class='noborder' /> |
69 | Neue Frage-Kategorie |
70 | </button> |
71 | ZZZZZZZZZZ; |
72 | } |
73 | |
74 | $categories = $category_repo->findBy(['on_off' => 1], ['position' => 'ASC']); |
75 | foreach ($categories as $category) { |
76 | $create_admin = ''; |
77 | $edit_admin = ''; |
78 | if ($has_access) { |
79 | $json_id = json_encode($category->getId()); |
80 | $create_admin = <<<ZZZZZZZZZZ |
81 | <button |
82 | id='create-question-button' |
83 | class='btn btn-secondary' |
84 | onclick='return olz.initOlzEditQuestionModal(undefined, undefined, {categoryId: {$json_id}})' |
85 | > |
86 | <img src='{$code_href}assets/icns/new_white_16.svg' class='noborder' /> |
87 | Neue Frage |
88 | </button> |
89 | ZZZZZZZZZZ; |
90 | $edit_admin = <<<ZZZZZZZZZZ |
91 | <button |
92 | class='btn btn-secondary-outline btn-sm edit-question-category-list-button' |
93 | onclick='return olz.faqListEditQuestionCategory({$json_id})' |
94 | > |
95 | <img src='{$code_href}assets/icns/edit_16.svg' class='noborder' /> |
96 | </button> |
97 | ZZZZZZZZZZ; |
98 | } |
99 | |
100 | $out .= "<h2 class='category'>{$category->getName()}{$edit_admin}</h2>"; |
101 | $out .= $create_admin; |
102 | $questions = $question_repo->findBy( |
103 | ['category' => $category, 'on_off' => 1], |
104 | ['position_within_category' => 'ASC'], |
105 | ); |
106 | foreach ($questions as $question) { |
107 | $icon = "{$code_href}assets/icns/question_mark_20.svg"; |
108 | $link = "fragen_und_antworten/{$question->getIdent()}"; |
109 | $edit_admin = ''; |
110 | if ($has_access) { |
111 | $json_id = json_encode($question->getId()); |
112 | $edit_admin = <<<ZZZZZZZZZZ |
113 | <button |
114 | class='btn btn-secondary-outline btn-sm edit-question-list-button' |
115 | onclick='return olz.faqListEditQuestion({$json_id})' |
116 | > |
117 | <img src='{$code_href}assets/icns/edit_16.svg' class='noborder' /> |
118 | </button> |
119 | ZZZZZZZZZZ; |
120 | } |
121 | |
122 | $out .= OlzPostingListItem::render([ |
123 | 'icon' => $icon, |
124 | 'title' => $question->getQuestion().$edit_admin, |
125 | 'link' => $link, |
126 | ]); |
127 | } |
128 | } |
129 | |
130 | $out .= "</div>"; |
131 | |
132 | $out .= OlzFooter::render(); |
133 | return $out; |
134 | } |
135 | } |