From 0edb438872796902d3e4d3c2eea791f6af1956aa Mon Sep 17 00:00:00 2001
From: horus
Date: Thu, 20 Feb 2020 15:35:53 +0100
Subject: Supports iCal-Feed and styled website with bootstrap.css.
---
app/Http/Controllers/HomeController.php | 28 ++++++++++++++++++++++++++
app/Http/Controllers/iCalController.php | 34 +++++++++++++++++++++-----------
app/Http/Middleware/TrustProxies.php | 2 +-
app/Libraries/.Zeitumstellung.php.swp | Bin 12288 -> 0 bytes
app/Libraries/Zeitumstellung.php | 26 +++++++++++++++++-------
5 files changed, 70 insertions(+), 20 deletions(-)
create mode 100644 app/Http/Controllers/HomeController.php
delete mode 100644 app/Libraries/.Zeitumstellung.php.swp
(limited to 'app')
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php
new file mode 100644
index 0000000..7cbc2c3
--- /dev/null
+++ b/app/Http/Controllers/HomeController.php
@@ -0,0 +1,28 @@
+middleware('auth');
+ }
+
+ /**
+ * Show the application dashboard.
+ *
+ * @return \Illuminate\Contracts\Support\Renderable
+ */
+ public function index()
+ {
+ return view('home');
+ }
+}
diff --git a/app/Http/Controllers/iCalController.php b/app/Http/Controllers/iCalController.php
index 928976e..f41f322 100644
--- a/app/Http/Controllers/iCalController.php
+++ b/app/Http/Controllers/iCalController.php
@@ -15,25 +15,31 @@ class iCalController extends Controller {
*
* @return Response
*/
- public function showPage(Request $request) {
+ public function icalFeed(Request $request) {
- $tc = new Zeitumstellung();
- $data = $tc->getData();
$vCalendar = new Calendar('zeitumstellung.iamfabulous.de');
$vCalendar->setName('Zeitumstellung');
$vCalendar->setTimezone('Europe/Berlin');
- $vEvent = new Event();
- $vEvent
- ->setDtStart(new \DateTime($tc->dateText))
- ->setDtEnd(new \DateTime($tc->dateText))
- ->setNoTime(true)
- ->setSummary('Zeitumstellung')
- ->setDescription($tc->description)
- ->setDescriptionHTML($tc->descriptionHTML);
+ $tc = new Zeitumstellung();
+
+ for ( $i= 0; $i<3; $i++ ) {
+
+ $vEvent = new Event();
+ $vEvent
+ ->setDtStart(new \DateTime($tc->dateText))
+ ->setDtEnd(new \DateTime($tc->dateText))
+ ->setNoTime(true)
+ ->setSummary('Zeitumstellung')
+ ->setUrl( env("APP_URL") )
+ ->setDescription($tc->description)
+ ->setDescriptionHTML($tc->descriptionHTML);
- $vCalendar->addComponent($vEvent);
+ $vCalendar->addComponent($vEvent);
+
+ $tc = $tc->next();
+ }
header('Content-Type: text/calendar; charset=utf-8');
@@ -43,4 +49,8 @@ class iCalController extends Controller {
echo $vCalendar->render();
}
+
+ public function showPage(Request $request) {
+ return view('index');
+ }
}
diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php
index ee5b595..3625f37 100644
--- a/app/Http/Middleware/TrustProxies.php
+++ b/app/Http/Middleware/TrustProxies.php
@@ -12,7 +12,7 @@ class TrustProxies extends Middleware
*
* @var array|string
*/
- protected $proxies;
+ protected $proxies = [ '192.168.122.1' ];
/**
* The headers that should be used to detect proxies.
diff --git a/app/Libraries/.Zeitumstellung.php.swp b/app/Libraries/.Zeitumstellung.php.swp
deleted file mode 100644
index 5eacf1c..0000000
Binary files a/app/Libraries/.Zeitumstellung.php.swp and /dev/null differ
diff --git a/app/Libraries/Zeitumstellung.php b/app/Libraries/Zeitumstellung.php
index 17daa08..42b8415 100644
--- a/app/Libraries/Zeitumstellung.php
+++ b/app/Libraries/Zeitumstellung.php
@@ -27,12 +27,16 @@ class Zeitumstellung {
private $tc_march;
private $tc_oct;
- function __construct() {
+ function __construct($setNow = null) {
# debug
#Carbon::setTestNow( Carbon::create(2018, 10, 28, 2) );
#Carbon::setTestNow( Carbon::create(2020, 03, 30, 5) );
- $this->now = Carbon::now()->startOfDay();
+ if ( is_null($setNow) ) {
+ $this->now = Carbon::now()->startOfDay();
+ } else {
+ $this->now = $setNow;
+ }
$this->year = $this->now->year;
@@ -45,16 +49,17 @@ class Zeitumstellung {
$this->tc_oct = Carbon::parse('last sunday of october ' . $this->year)->startOfDay();
if ( $this->now->lte($this->tc_march) ){
- # next time change is in march this year, (last sunday in october)
+ # next time change is in march this year, (last sunday in march)
$this->date = $this->tc_march;
$this->description = 'Die Uhr wird von 2 Uhr auf 3 Uhr vorgestellt, sodass wir 1 Stunde weniger schlafen.';
- $this->descriptionHTML = 'Die Uhr wird von 2 Uhr auf 3 Uhr vorgestellt, sodass wir 1 Stunde weniger schlafen.';
+ $this->descriptionHTML = 'Die Uhr wird von 2 Uhr auf 3 Uhr vorgestellt, sodass wir 1 Stunde weniger schlafen.';
# detect if last time change was last year
if ( $this->now->lt( Carbon::parse('last sunday of march ') ) ) {
- $this->year = $this->now->year - 1;
- $this->daysago = Carbon::parse('last sunday of october' . $this->year)->diffInDays( $this->now );
+ #$this->year = $this->now->year - 1;
+ $year = $this->now->year - 1;
+ $this->daysago = Carbon::parse('last sunday of october' . $year)->diffInDays( $this->now );
} else {
$this->daysago = $this->tc_oct->diffInDays( $this->now );
}
@@ -64,7 +69,7 @@ class Zeitumstellung {
$this->date = $this->tc_oct;
$this->description = 'Die Uhr wird von 3 Uhr auf 2 Uhr zurückgestellt, sodass wir 1 Stunde länger schlafen.';
- $this->descriptionHTML = 'Die Uhr wird von 3 Uhr auf 2 Uhr zurückgestellt, sodass wir 1 Stunde länger schlafen.';
+ $this->descriptionHTML = 'Die Uhr wird von 3 Uhr auf 2 Uhr zurückgestellt, sodass wir 1 Stunde länger schlafen.';
$this->daysago = $this->tc_march->diffInDays( $this->now );
}
@@ -84,6 +89,13 @@ class Zeitumstellung {
}
}
+ /**
+ * Returns an instance of the object with the next time change after the current one.
+ */
+ function next(){
+ return new Zeitumstellung( $this->date->add(1, 'day') );
+ }
+
public function getData(){
$result = array();
--
cgit v1.2.3