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