From d64e305b6be64150d89cf661a43f0b5fd9b2631b Mon Sep 17 00:00:00 2001 From: xoy Date: Tue, 16 May 2023 13:40:03 +0200 Subject: [PATCH] ChaosBrunch Termin eingebunden --- events/brunch.md | 15 +++++++++++++++ index.php | 22 ++++++++++++++++++---- pages/events.html.twig | 1 + php/util.php | 32 +++++++++++++++++++++++++++++--- tester.php | 2 +- 5 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 events/brunch.md diff --git a/events/brunch.md b/events/brunch.md new file mode 100644 index 0000000..a6da856 --- /dev/null +++ b/events/brunch.md @@ -0,0 +1,15 @@ +ChaosBrunch +Einmal in der Woche treffen wir uns regulär zum quatschen, basteln, frickeln, programmieren, hacken, kochen, essen, … +{{ brunchdatum }} +11:00 - 15:00 +Chaostreff Dortmund e.V. +------------------------ +# Treff + +Alle zwei Wochen an einem Sonntag lädt der CTDO zum **Mitbring-Brunch** in seinen Räume im Kulturzentrum [„Langer August“](/?page=treff) ein! + +Um **ca. 11 Uhr** geht es los, das Ende ist wie immer offen. Die Details dazu gibt es im [ctdo wiki](https://wiki.ctdo.de/events/hackerbrunch)! + +Schaut einfach vorab im [MitbringPad](https://md.ctdo.de/brunch) rein und kündigt an was ihr auf den Tisch werft, alles kann, nichts muss! + +Es sind sowohl alte als auch neue Menschen gerne gesehen! Bringt was zu futtern, euer aktuelles Projekt, beides oder einfach nur Neugierde mit! \ No newline at end of file diff --git a/index.php b/index.php index 4c7ea3e..0b753c1 100644 --- a/index.php +++ b/index.php @@ -58,7 +58,7 @@ switch ($topic->days) { $treff = $util->get_next_treff(); $trefflink = 'Treff'; -switch ($topic->days) { +switch ($treff->days) { case 0: $treff_output = '

Der nächste '.$trefflink.' findet heute statt!

'; break; @@ -72,7 +72,7 @@ switch ($topic->days) { $repaircafe = $util->get_next_repaircafe(); $repaircafelink = 'RepairCafe'; -switch ($topic->days) { +switch ($repaircafe->days) { case 0: $repaircafe_output = '

Das nächste '.$repaircafelink.' findet heute statt!

'; break; @@ -84,6 +84,20 @@ switch ($topic->days) { break; } +$brunch = $util->get_next_brunch(); +$brunchlink = 'ChaosBrunch'; +switch ($brunch->days) { + case 0: + $brunch_output = '

Das nächste '.$brunchlink.' findet heute statt!

'; + break; + case 1: + $brunch_output = '

Das nächste '.$brunchlink.' findet morgen statt!

'; + break; + default: + $brunch_output = '

Das nächste '.$brunchlink.' findet in '.$brunch->days.' Tagen ['.$brunch->date.'] statt.

'; + break; +} + if(isset($_GET['page'])) { $page = $_GET['page']; $active_page = $util->str_mass_replace(array('adresse', 'irc', 'mail'), array('kontakt', 'kontakt', 'kontakt'), $page); @@ -112,10 +126,10 @@ if(isset($_GET['page'])) { break; case 'events': if(!isset($_GET['id'])) { - $content = $twig_pages->render('events.html.twig', [ 'topic' => $topic_output, 'treff' => $treff_output, 'repaircafe' => $repaircafe_output, 'events' => $util->generate_event_list() ]); + $content = $twig_pages->render('events.html.twig', [ 'topic' => $topic_output, 'treff' => $treff_output, 'repaircafe' => $repaircafe_output, 'brunch' => $brunch_output, 'events' => $util->generate_event_list() ]); $head = $util->css_link('css/main.css').$util->css_link('css/events.css'); } else { - $content = $util->str_mass_replace(array('{{ topicdatum }}', 'Chaostreff Dortmund e.V.', '{{ treffdatum }}', '{{ repaircafedatum }}'), array($util->get_next_topic()->date, $util->html_link('/?page=treff', '', 'Chaostreff Dortmund e.V.', FALSE), $util->get_next_treff()->date, $util->get_next_repaircafe()->date), $converter->convert($util->get_event_content($_GET['id']))); + $content = $util->str_mass_replace(array('{{ topicdatum }}', 'Chaostreff Dortmund e.V.', '{{ treffdatum }}', '{{ repaircafedatum }}', '{{ brunchdatum }}'), array($util->get_next_topic()->date, $util->html_link('/?page=treff', '', 'Chaostreff Dortmund e.V.', FALSE), $util->get_next_treff()->date, $util->get_next_repaircafe()->date, $util->get_next_brunch()->date), $converter->convert($util->get_event_content($_GET['id']))); $head = $util->css_link('css/main.css').$util->css_link('css/event.css'); } break; diff --git a/pages/events.html.twig b/pages/events.html.twig index 7cdc6e1..11c618c 100644 --- a/pages/events.html.twig +++ b/pages/events.html.twig @@ -2,4 +2,5 @@ {{ topic | raw }} {{ treff | raw }} {{ repaircafe | raw }} + {{ brunch | raw }} {{ events | raw }} \ No newline at end of file diff --git a/php/util.php b/php/util.php index 8eb10b8..69dfdb4 100644 --- a/php/util.php +++ b/php/util.php @@ -90,7 +90,7 @@ class Util { $s = scandir(__DIR__ . '/../events/', SCANDIR_SORT_DESCENDING); $output = array(); foreach ($s as $f) { - if(count(str_split($f)) >= 4 && $f != 'treff.md' && $f != 'topictreff.md' && $f != 'repaircafe.md') + if(count(str_split($f)) >= 4 && $f != 'treff.md' && $f != 'topictreff.md' && $f != 'repaircafe.md' && $f != 'brunch.md') $output[] = $f; } return $output; @@ -162,7 +162,7 @@ class Util { $diff = $now->diff(new DateTime()); $days_until = $diff->format('%a'); - $output->days = $days_until; + $output->days = $days_until+1; $output->date = $now->format('Y-m-d'); // Return an array with the count and date of the next Friday return $output; @@ -181,11 +181,37 @@ class Util { $daysUntilLastThursday = $today->diff($lastThursday)->days; - $output->days = $daysUntilLastThursday + 1; + $output->days = $daysUntilLastThursday; $output->date = $lastThursday->format('Y-m-d'); return $output; } + + function get_next_brunch() { + $now = new DateTime(); + + if ($now->format('w') == 0) { + $nextSunday = clone $now; + } else { + $nextSunday = new DateTime('next Sunday'); + } + + $weekNumber = (int)$nextSunday->format('W'); + $isEvenWeek = ($weekNumber % 2) == 0; + + if ($isEvenWeek) { + $nextSunday->modify('+1 week'); + } + + $differenz = $nextSunday->diff($now); + $days = $differenz->days; + + $output = new stdClass(); + $output->date = $nextSunday->format('Y-m-d'); + $output->days = $days+1; + + return $output; + } } diff --git a/tester.php b/tester.php index b95adab..2861601 100644 --- a/tester.php +++ b/tester.php @@ -4,4 +4,4 @@ require __DIR__ . '/php/util.php'; $u = new Util(); -echo var_dump($u->get_next_repaircafe()); \ No newline at end of file +echo var_dump($u->get_next_brunch()); \ No newline at end of file