Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 70 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| OlzMenu | |
0.00% |
0 / 70 |
|
0.00% |
0 / 2 |
272 | |
0.00% |
0 / 1 |
| getHtml | |
0.00% |
0 / 51 |
|
0.00% |
0 / 1 |
90 | |||
| getMenu | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
56 | |||
| 1 | <?php |
| 2 | |
| 3 | // ============================================================================= |
| 4 | // Das Navigationsmenu der Website. |
| 5 | // ============================================================================= |
| 6 | |
| 7 | namespace Olz\Components\Page\OlzMenu; |
| 8 | |
| 9 | use Olz\Components\Common\OlzComponent; |
| 10 | |
| 11 | /** @extends OlzComponent<array<string, mixed>> */ |
| 12 | class OlzMenu extends OlzComponent { |
| 13 | public function getHtml(mixed $args): string { |
| 14 | $out = ''; |
| 15 | |
| 16 | $code_href = $this->envUtils()->getCodeHref(); |
| 17 | $data_path = $this->envUtils()->getDataPath(); |
| 18 | |
| 19 | $news_utils = $this->newsUtils(); |
| 20 | $enc_news_filter = $news_utils->serialize($news_utils->getDefaultFilter()); |
| 21 | $termine_utils = $this->termineUtils(); |
| 22 | $enc_termine_filter = $termine_utils->serialize($termine_utils->getDefaultFilter()); |
| 23 | |
| 24 | $main_menu = [ |
| 25 | ["Startseite", ""], // Menüpunkt ('Name','Link') |
| 26 | ["", "", ''], |
| 27 | ["News", "news?filter={$enc_news_filter}&seite=1"], |
| 28 | ["Termine", "termine?filter={$enc_termine_filter}"], |
| 29 | ["", "", ''], |
| 30 | ["Karten", "karten"], |
| 31 | ["Material & Kleider", "material"], |
| 32 | ["", "", ''], |
| 33 | ["Service", "service"], |
| 34 | ["Verein", "verein"], |
| 35 | ]; |
| 36 | |
| 37 | // BACK-BUTTON |
| 38 | $back_menu_out = ''; |
| 39 | $back_link = $args['back_link'] ?? null; |
| 40 | if ($back_link !== null) { |
| 41 | $back_menu_out = <<<ZZZZZZZZZZ |
| 42 | <a href='{$back_link}' class='menu-link' id='back-link'> |
| 43 | <div class='menutag'> |
| 44 | <img src='{$code_href}assets/icns/back_16.svg' alt='<' class='back-icon'> |
| 45 | Zurück |
| 46 | </div> |
| 47 | </a> |
| 48 | ZZZZZZZZZZ; |
| 49 | } |
| 50 | |
| 51 | // LIVE-RESULTATE |
| 52 | $live_menu_out = ''; |
| 53 | $live_json_path = "{$data_path}results/_live.json"; |
| 54 | if (is_file($live_json_path)) { |
| 55 | $content = file_get_contents($live_json_path); |
| 56 | if ($content) { |
| 57 | $live = json_decode($content, true); |
| 58 | $last_updated_at = strtotime($live['last_updated_at']) ?: 0; |
| 59 | $now = strtotime($this->dateUtils()->getIsoNow()) ?: 0; |
| 60 | if ($live && $last_updated_at > $now - 3600) { |
| 61 | $live_file = $live['file']; |
| 62 | $style = preg_match('/test/', $live_file) ? " style='display:none;'" : ""; |
| 63 | $live_menu_out = <<<ZZZZZZZZZZ |
| 64 | <a href='{$code_href}apps/resultate/?file={$live_file}'{$style} class='menu-link' id='live-results-link'> |
| 65 | <div class='menutag'> |
| 66 | Live-Resultate |
| 67 | </div> |
| 68 | </a> |
| 69 | ZZZZZZZZZZ; |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | $main_menu_out = self::getMenu($main_menu, $code_href); |
| 75 | |
| 76 | $out .= <<<ZZZZZZZZZZ |
| 77 | <div id='menu' class='menu'> |
| 78 | <div class='back-menu'>{$back_menu_out}</div> |
| 79 | <div class='live-menu'>{$live_menu_out}</div> |
| 80 | <div class='main-menu'>{$main_menu_out}</div> |
| 81 | <div class='feedback-mail'> |
| 82 | <script type='text/javascript'> |
| 83 | olz.MailTo("website", "olzimmerberg.ch", "Feedback geben", "Homepage%20OL%20Zimmerberg"); |
| 84 | </script> |
| 85 | </div> |
| 86 | <div class='platform-links'> |
| 87 | <a |
| 88 | href='https://github.com/olzimmerberg/olz-website' |
| 89 | target='_blank' |
| 90 | rel='noreferrer noopener' |
| 91 | title='OL Zimmerberg auf GitHub' |
| 92 | class='platform-link' |
| 93 | > |
| 94 | <img src='{$code_href}assets/icns/github_16.svg' alt='g' class='noborder' /> |
| 95 | </a> |
| 96 | <a |
| 97 | href='https://www.youtube.com/channel/UCMhMdPRJOqdXHlmB9kEpmXQ' |
| 98 | target='_blank' |
| 99 | rel='noreferrer noopener' |
| 100 | title='OL Zimmerberg auf YouTube' |
| 101 | class='platform-link' |
| 102 | > |
| 103 | <img src='{$code_href}assets/icns/youtube_16.svg' alt='Y' class='noborder' /> |
| 104 | </a> |
| 105 | <a |
| 106 | href='https://www.strava.com/clubs/olzimmerberg' |
| 107 | target='_blank' |
| 108 | rel='noreferrer noopener' |
| 109 | title='OL Zimmerberg auf Strava' |
| 110 | class='platform-link' |
| 111 | > |
| 112 | <img src='{$code_href}assets/icns/strava_16.svg' alt='s' class='noborder' /> |
| 113 | </a> |
| 114 | </div> |
| 115 | </div> |
| 116 | ZZZZZZZZZZ; |
| 117 | |
| 118 | return $out; |
| 119 | } |
| 120 | |
| 121 | /** @param array<array<string>> $menu */ |
| 122 | protected static function getMenu(array $menu, string $code_href): string { |
| 123 | $out = ''; |
| 124 | for ($i = 0; $i < count($menu); $i++) { |
| 125 | $menupunkt = $menu[$i]; |
| 126 | $name = $menupunkt[0]; |
| 127 | $href = $menupunkt[1]; |
| 128 | $href_path = substr($href, 0, strpos($href, '?') ?: strlen($href)); |
| 129 | $request_uri = $_SERVER['REQUEST_URI'] ?? ''; |
| 130 | $is_active = ( |
| 131 | preg_match("/^\\/{$href_path}(\\/|\\?|#|$)/", $request_uri) |
| 132 | || ($href === '' && $request_uri === '') |
| 133 | ); |
| 134 | $active_class = $is_active ? ' active' : ''; |
| 135 | if ($name != '') { |
| 136 | $out .= <<<ZZZZZZZZZZ |
| 137 | <a href='{$code_href}{$href}' id='menu_a_page_{$href}' class='menu-link'> |
| 138 | <div class='menutag{$active_class}'> |
| 139 | {$name} |
| 140 | </div> |
| 141 | </a> |
| 142 | ZZZZZZZZZZ; |
| 143 | } else { |
| 144 | $out .= <<<'ZZZZZZZZZZ' |
| 145 | <div class='separator'></div> |
| 146 | ZZZZZZZZZZ; |
| 147 | } |
| 148 | } |
| 149 | return $out; |
| 150 | } |
| 151 | } |