Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 52 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
OlzLinks | |
0.00% |
0 / 52 |
|
0.00% |
0 / 1 |
110 | |
0.00% |
0 / 1 |
getHtml | |
0.00% |
0 / 52 |
|
0.00% |
0 / 1 |
110 |
1 | <?php |
2 | |
3 | namespace Olz\Service\Components\OlzLinks; |
4 | |
5 | use Doctrine\Common\Collections\Criteria; |
6 | use Doctrine\Common\Collections\Order; |
7 | use Olz\Components\Common\OlzComponent; |
8 | use Olz\Entity\Service\Link; |
9 | |
10 | /** @extends OlzComponent<array<string, mixed>> */ |
11 | class OlzLinks extends OlzComponent { |
12 | public function getHtml(mixed $args): string { |
13 | $has_permission = $this->authUtils()->hasPermission('links'); |
14 | $code_href = $this->envUtils()->getCodeHref(); |
15 | |
16 | $out = ''; |
17 | |
18 | $out .= "<h2>Links</h2>"; |
19 | |
20 | if ($has_permission) { |
21 | $out .= <<<ZZZZZZZZZZ |
22 | <button |
23 | id='create-link-button' |
24 | class='btn btn-secondary' |
25 | onclick='return olz.initOlzEditLinkModal()' |
26 | > |
27 | <img src='{$code_href}assets/icns/new_white_16.svg' class='noborder' /> |
28 | Neuer Link |
29 | </button> |
30 | ZZZZZZZZZZ; |
31 | } |
32 | |
33 | $link_repo = $this->entityManager()->getRepository(Link::class); |
34 | $criteria = Criteria::create()->where(Criteria::expr()->andX( |
35 | Criteria::expr()->eq('on_off', 1) |
36 | )); |
37 | $criteria = $criteria |
38 | ->orderBy(['position' => Order::Ascending]) |
39 | ->setFirstResult(0) |
40 | ->setMaxResults(100) |
41 | ; |
42 | $links = $link_repo->matching($criteria); |
43 | |
44 | $out .= "<ul class='no-style olz-links'>"; |
45 | foreach ($links as $link) { |
46 | $id = $link->getId(); |
47 | $name = $link->getName(); |
48 | $on_off = $link->getOnOff(); |
49 | $url = $link->getUrl(); |
50 | |
51 | $user = $this->authUtils()->getCurrentUser(); |
52 | $owner_user = $link->getOwnerUser(); |
53 | $is_owner = $user && $owner_user && intval($owner_user->getId() ?? 0) === intval($user->getId()); |
54 | $can_edit = $is_owner || $has_permission; |
55 | $edit_admin = ''; |
56 | if ($can_edit) { |
57 | $json_id = json_encode($id); |
58 | $edit_admin = <<<ZZZZZZZZZZ |
59 | <button |
60 | id='edit-link-{$id}-button' |
61 | class='btn btn-secondary-outline btn-sm edit-link-list-button' |
62 | onclick='return olz.olzLinksEditLink({$json_id})' |
63 | > |
64 | <img src='{$code_href}assets/icns/edit_16.svg' class='noborder' /> |
65 | </button> |
66 | ZZZZZZZZZZ; |
67 | } |
68 | |
69 | $class = ''; |
70 | if ($on_off == 0) { |
71 | $class .= " error"; |
72 | } |
73 | if ($can_edit) { |
74 | $class .= " edit-flex"; |
75 | } |
76 | |
77 | if ($name === '---') { |
78 | $out .= "{$edit_admin}<br />"; |
79 | } else { |
80 | $out .= <<<ZZZZZZZZZZ |
81 | <li class='{$class}'> |
82 | {$edit_admin} |
83 | <a href='{$url}' class='linkext' target='_blank'>{$name}</a> |
84 | </li> |
85 | ZZZZZZZZZZ; |
86 | } |
87 | } |
88 | $out .= "</ul>"; |
89 | |
90 | return $out; |
91 | } |
92 | } |