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