Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 61
0.00% covered (danger)
0.00%
0 / 5
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 / 61
0.00% covered (danger)
0.00%
0 / 5
72
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 / 7
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 / 51
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 (new Metadata())->isAccessibleToUser($this->authUtils()->getCurrentUser());
22    }
23
24    public function searchSqlWhenHasAccess(array $terms): string|array|null {
25        $metadata = new Metadata();
26        return $this->searchUtils()->getStaticResultQuery([
27            'link' => $metadata->getHref(),
28            'icon' => $metadata->getIconHref(),
29            'title' => "Apps: {$this->getPageTitle()}",
30            'text' => $this->getPageDescription(),
31        ], $terms);
32    }
33
34    public function getPageTitle(): string {
35        return "Panini '24";
36    }
37
38    public function getPageDescription(): string {
39        return "Erstelle dein Panini-Bildli für das Mitgliederalbum 2024.";
40    }
41
42    public function getHtmlWhenHasAccess(mixed $args): string {
43        $this->httpUtils()->validateGetParams(OlzPanini2024Params::class);
44        $current_user = $this->authUtils()->getCurrentUser();
45        $code_href = $this->envUtils()->getCodeHref();
46        $entity_manager = $this->dbUtils()->getEntityManager();
47        $data_path = $this->envUtils()->getDataPath();
48        $metadata = new Metadata();
49        $now_datetime = new \DateTime($this->dateUtils()->getIsoNow());
50        $deadline_datetime = new \DateTime(Panini2024Constants::UPDATE_DEADLINE);
51
52        $has_admin_access = $this->authUtils()->hasPermission('all');
53        $is_read_only = ($now_datetime > $deadline_datetime && !$has_admin_access);
54
55        $out = OlzHeader::render([
56            'back_link' => "{$code_href}service/",
57            'title' => $this->getPageTitle(),
58            'description' => $this->getPageDescription(),
59            'norobots' => true,
60        ]);
61
62        $out .= "<div class='content-full'>";
63
64        if ($current_user) {
65            $esc_first_name = json_encode($current_user->getFirstName());
66            $esc_last_name = json_encode($current_user->getLastName());
67            $esc_panini_2024_picture = json_encode(null);
68            $esc_is_read_only = json_encode($is_read_only);
69            $panini_repo = $entity_manager->getRepository(Panini2024Picture::class);
70            $picture = $panini_repo->findOneBy(['owner_user' => $current_user]);
71            if ($picture) {
72                $esc_panini_2024_picture = json_encode([
73                    'id' => intval($picture->getId()),
74                    'line1' => $picture->getLine1(),
75                    'line2' => $picture->getLine2(),
76                    'association' => $picture->getAssociation(),
77                    'imgSrc' => $picture->getImgSrc(),
78                    'infos' => $picture->getInfos(),
79                ]);
80                $portraits_path = "{$data_path}panini_data/portraits/";
81                $portrait_path = "{$portraits_path}{$picture->getId()}/{$picture->getImgSrc()}";
82                $temp_path = "{$data_path}temp/{$picture->getImgSrc()}";
83                copy($portrait_path, $temp_path);
84            }
85            $out .= <<<ZZZZZZZZZZ
86                <script>
87                    window.olzPanini2024FirstName = {$esc_first_name};
88                    window.olzPanini2024LastName = {$esc_last_name};
89                    window.olzPanini2024Picture = {$esc_panini_2024_picture};
90                    window.olzPanini2024IsReadOnly = {$esc_is_read_only};
91                </script>
92                <div id='panini-react-root'>
93                    Lädt...
94                </div>
95                ZZZZZZZZZZ;
96        } else {
97            $out .= OlzNoAppAccess::render([
98                'app' => $metadata,
99            ]);
100        }
101
102        $out .= "</div>";
103
104        $out .= $metadata->getJsCssImports();
105        $out .= OlzFooter::render();
106
107        return $out;
108    }
109}