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