Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 53
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
OlzPanini2024Params
n/a
0 / 0
n/a
0 / 0
0
n/a
0 / 0
OlzPanini2024
0.00% covered (danger)
0.00%
0 / 53
0.00% covered (danger)
0.00%
0 / 4
56
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
 getSearchTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSearchResultsWhenHasAccess
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 / 50
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace Olz\Apps\Panini2024\Components\OlzPanini2024;
4
5use Olz\Apps\Panini2024\Metadata;
6use Olz\Apps\Panini2024\Panini2024Constants;
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\Utils\HttpParams;
13
14/** @extends HttpParams<array{}> */
15class OlzPanini2024Params extends HttpParams {
16}
17
18/** @extends OlzRootComponent<array<string, mixed>> */
19class OlzPanini2024 extends OlzRootComponent {
20    public function hasAccess(): bool {
21        return true;
22    }
23
24    public function getSearchTitle(): string {
25        return 'TODO';
26    }
27
28    public function getSearchResultsWhenHasAccess(array $terms): array {
29        return [];
30    }
31
32    public function getHtmlWhenHasAccess(mixed $args): string {
33        $this->httpUtils()->validateGetParams(OlzPanini2024Params::class);
34        $current_user = $this->authUtils()->getCurrentUser();
35        $code_href = $this->envUtils()->getCodeHref();
36        $entity_manager = $this->dbUtils()->getEntityManager();
37        $data_path = $this->envUtils()->getDataPath();
38        $metadata = new Metadata();
39        $now_datetime = new \DateTime($this->dateUtils()->getIsoNow());
40        $deadline_datetime = new \DateTime(Panini2024Constants::UPDATE_DEADLINE);
41
42        $has_admin_access = $this->authUtils()->hasPermission('all');
43        $is_read_only = ($now_datetime > $deadline_datetime && !$has_admin_access);
44
45        $out = OlzHeader::render([
46            'back_link' => "{$code_href}service/",
47            'title' => "Panini '24",
48            'norobots' => true,
49        ]);
50
51        $out .= "<div class='content-full'>";
52
53        if ($current_user) {
54            $esc_first_name = json_encode($current_user->getFirstName());
55            $esc_last_name = json_encode($current_user->getLastName());
56            $esc_panini_2024_picture = json_encode(null);
57            $esc_is_read_only = json_encode($is_read_only);
58            $panini_repo = $entity_manager->getRepository(Panini2024Picture::class);
59            $picture = $panini_repo->findOneBy(['owner_user' => $current_user]);
60            if ($picture) {
61                $esc_panini_2024_picture = json_encode([
62                    'id' => intval($picture->getId()),
63                    'line1' => $picture->getLine1(),
64                    'line2' => $picture->getLine2(),
65                    'association' => $picture->getAssociation(),
66                    'imgSrc' => $picture->getImgSrc(),
67                    'infos' => $picture->getInfos(),
68                ]);
69                $portraits_path = "{$data_path}panini_data/portraits/";
70                $portrait_path = "{$portraits_path}{$picture->getId()}/{$picture->getImgSrc()}";
71                $temp_path = "{$data_path}temp/{$picture->getImgSrc()}";
72                copy($portrait_path, $temp_path);
73            }
74            $out .= <<<ZZZZZZZZZZ
75                <script>
76                    window.olzPanini2024FirstName = {$esc_first_name};
77                    window.olzPanini2024LastName = {$esc_last_name};
78                    window.olzPanini2024Picture = {$esc_panini_2024_picture};
79                    window.olzPanini2024IsReadOnly = {$esc_is_read_only};
80                </script>
81                <div id='panini-react-root'>
82                    Lädt...
83                </div>
84                ZZZZZZZZZZ;
85        } else {
86            $out .= OlzNoAppAccess::render([
87                'app' => $metadata,
88            ]);
89        }
90
91        $out .= "</div>";
92
93        $out .= $metadata->getJsCssImports();
94        $out .= OlzFooter::render();
95
96        return $out;
97    }
98}