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