Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
OlzEditableText | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
getHtml | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace Olz\Components\Common\OlzEditableText; |
4 | |
5 | use Olz\Components\Common\OlzComponent; |
6 | use Olz\Entity\Snippets\Snippet; |
7 | |
8 | /** @extends OlzComponent<array<string, mixed>> */ |
9 | class OlzEditableText extends OlzComponent { |
10 | public function getHtml(mixed $args): string { |
11 | $code_href = $this->envUtils()->getCodeHref(); |
12 | |
13 | $snippet_id = intval($args['snippet_id'] ?? 0); |
14 | $esc_id = htmlentities(json_encode($snippet_id) ?: '0'); |
15 | $entityManager = $this->dbUtils()->getEntityManager(); |
16 | $snippet_repo = $entityManager->getRepository(Snippet::class); |
17 | $snippet = $snippet_repo->findOneBy(['id' => $snippet_id]); |
18 | |
19 | $snippet_text = $snippet?->getText() ?? ''; |
20 | $snippet_html = $this->htmlUtils()->renderMarkdown($snippet_text); |
21 | if ($snippet) { |
22 | $snippet_html = $snippet->replaceImagePaths($snippet_html); |
23 | $snippet_html = $snippet->replaceFilePaths($snippet_html); |
24 | } |
25 | |
26 | $has_access = $this->authUtils()->hasPermission("snippet_{$snippet_id}"); |
27 | if (!$has_access) { |
28 | return <<<ZZZZZZZZZZ |
29 | <div class='olz-editable-text'> |
30 | {$snippet_html} |
31 | </div> |
32 | ZZZZZZZZZZ; |
33 | } |
34 | |
35 | return <<<ZZZZZZZZZZ |
36 | <div class='olz-editable-text editable'> |
37 | <button |
38 | type='button' |
39 | onclick='olz.olzEditableTextEditSnippet({$esc_id})' |
40 | class='btn btn-link olz-edit-button' |
41 | > |
42 | <img src='{$code_href}assets/icns/edit_16.svg' alt='Bearbeiten' class='noborder' /> |
43 | </button> |
44 | {$snippet_html} |
45 | </div> |
46 | ZZZZZZZZZZ; |
47 | } |
48 | } |