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