Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 66
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
OlzPanini2024AllParams
n/a
0 / 0
n/a
0 / 0
0
n/a
0 / 0
OlzPanini2024All
0.00% covered (danger)
0.00%
0 / 66
0.00% covered (danger)
0.00%
0 / 5
210
0.00% covered (danger)
0.00%
0 / 1
 hasAccess
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 searchSqlWhenHasAccess
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPageTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPageDescription
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHtmlWhenHasAccess
0.00% covered (danger)
0.00%
0 / 62
0.00% covered (danger)
0.00%
0 / 1
110
1<?php
2
3namespace Olz\Apps\Panini2024\Components\OlzPanini2024All;
4
5use Olz\Apps\Panini2024\Metadata;
6use Olz\Apps\Panini2024\Utils\Panini2024Utils;
7use Olz\Components\Apps\OlzNoAppAccess\OlzNoAppAccess;
8use Olz\Components\Common\OlzRootComponent;
9use Olz\Components\Page\OlzFooter\OlzFooter;
10use Olz\Components\Page\OlzHeader\OlzHeader;
11use Olz\Entity\Panini2024\Panini2024Picture;
12use Olz\Users\Components\OlzUserInfoModal\OlzUserInfoModal;
13use Olz\Utils\HttpParams;
14
15/** @extends HttpParams<array{}> */
16class OlzPanini2024AllParams extends HttpParams {
17}
18
19/** @extends OlzRootComponent<array<string, mixed>> */
20class OlzPanini2024All extends OlzRootComponent {
21    public function hasAccess(): bool {
22        return (new Metadata())->isAccessibleToUser($this->authUtils()->getCurrentUser());
23    }
24
25    public function searchSqlWhenHasAccess(array $terms): string|array|null {
26        return null;
27    }
28
29    public function getPageTitle(): string {
30        return "";
31    }
32
33    public function getPageDescription(): string {
34        return "";
35    }
36
37    public function getHtmlWhenHasAccess(mixed $args): string {
38        $this->httpUtils()->validateGetParams(OlzPanini2024AllParams::class);
39        $code_href = $this->envUtils()->getCodeHref();
40        $entity_manager = $this->dbUtils()->getEntityManager();
41        $metadata = new Metadata();
42
43        $out = OlzHeader::render([
44            'back_link' => "{$code_href}service/",
45            'title' => "Panini '24 All",
46            'norobots' => true,
47        ]);
48
49        $out .= "<div class='content-full'>";
50        $out .= "<div class='olz-panini-2024-all'>";
51
52        if ($this->authUtils()->hasPermission('panini2024')) {
53            $panini_repo = $entity_manager->getRepository(Panini2024Picture::class);
54            $pictures = $panini_repo->findAll();
55            $out .= "<table>";
56            $ids = json_encode(array_map(function ($picture) {
57                return $picture->getId();
58            }, $pictures));
59            $out .= <<<ZZZZZZZZZZ
60                <tr>
61                    <th class='column id'>ID</th>
62                    <th class='column name'>Name</th>
63                    <th class='column account'>OLZ-Konto</th>
64                    <th class='column association'>Wappen</th>
65                    <th class='column infos'>Infos</th>
66                    <th class='column active'>Aktiv</th>
67                    <th class='column picture'>
68                        Bild
69                        <button onclick='olzPanini2024.showPaniniPictures({$ids})'>
70                            alle anzeigen
71                        </button>
72                    </th>
73                </tr>
74                ZZZZZZZZZZ;
75            foreach ($pictures as $picture) {
76                $id = $picture->getId();
77                $line1 = $picture->getLine1();
78                $line2 = $picture->getLine2();
79                $owner_user = $picture->getOwnerUser();
80                $user_html = $owner_user ? OlzUserInfoModal::render([
81                    'user' => $owner_user,
82                    'mode' => 'name',
83                ]) : '-';
84                $association = $picture->getAssociation();
85                $association_emoji = (Panini2024Utils::ASSOCIATION_MAP[$association] ?? 0) ? '✅' : '❌';
86                $infos = $picture->getInfos();
87                $infos_emojis = '';
88                for ($i = 0; $i < 5; $i++) {
89                    if ($i !== 0) {
90                        $infos_emojis .= ' ';
91                    }
92                    $is_valid = ($infos[$i] ?? false) && strlen($infos[$i]) > 0;
93                    $infos_emojis .= $is_valid ? '✅' : '❌';
94                }
95                $on_off = $picture->getOnOff();
96                $on_off_emoji = $on_off ? '✅' : '❌';
97                $out .= <<<ZZZZZZZZZZ
98                    <tr>
99                        <td class='column id'>{$id}</td>
100                        <td class='column name'>{$line1}<br/>{$line2}</td>
101                        <td class='column account'>{$user_html}</td>
102                        <td class='column association'>{$association_emoji} {$association}</td>
103                        <td class='column infos'>{$infos_emojis}</td>
104                        <td class='column active'>{$on_off_emoji}</td>
105                        <td class='column picture' id='panini-picture-{$id}'>
106                            <button onclick='olzPanini2024.showPaniniPicture(&quot;{$id}&quot;)'>
107                                anzeigen
108                            </button>
109                        </td>
110                    </tr>
111                    ZZZZZZZZZZ;
112            }
113            $out .= "</table>";
114        } else {
115            $out .= OlzNoAppAccess::render([
116                'app' => $metadata,
117            ]);
118        }
119
120        $out .= "</div>";
121        $out .= "</div>";
122
123        $out .= $metadata->getJsCssImports();
124        $out .= OlzFooter::render();
125
126        return $out;
127    }
128}