From 66114f36f997d2c1304cd3cf821e2ecf4d753f12 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B8rn=20=C3=85ne?= <git@jornane.no>
Date: Fri, 26 Aug 2016 17:04:20 +0200
Subject: [PATCH 1/4] Simplify class structure.

---
 src/pvv/side/activity.php                  |  6 ++--
 src/pvv/side/dbactivity.php                | 16 +---------
 src/pvv/side/event.php                     |  2 +-
 src/pvv/side/events.php                    | 21 -------------
 src/pvv/side/onceevent.php                 | 30 ------------------
 src/pvv/side/repeatingactivity.php         | 12 --------
 src/pvv/side/simpleevent.php               | 36 ++++++++++++++++++++++
 src/pvv/side/social/animekveldactivity.php | 16 ++--------
 src/pvv/side/social/brettspillactivity.php | 16 ++--------
 src/pvv/side/social/nerdepitsaactivity.php | 16 ++--------
 src/pvv/side/sql_config_example.php        |  6 ----
 11 files changed, 46 insertions(+), 131 deletions(-)
 delete mode 100644 src/pvv/side/events.php
 delete mode 100644 src/pvv/side/onceevent.php
 delete mode 100644 src/pvv/side/repeatingactivity.php
 create mode 100644 src/pvv/side/simpleevent.php
 delete mode 100644 src/pvv/side/sql_config_example.php

diff --git a/src/pvv/side/activity.php b/src/pvv/side/activity.php
index b860fdd..9fd6a46 100644
--- a/src/pvv/side/activity.php
+++ b/src/pvv/side/activity.php
@@ -5,10 +5,8 @@ use \DateTimeImmutable;
 
 interface Activity {
 
-	public function getName(); /* : string */
+	public function getNextEventFrom(DateTimeImmutable $date) /* : Event */;
 
-	public function getLocation(); /* : Location */
-
-	public function getOrganiser(); /* : User */
+	public function getPreviousEventFrom(DateTimeImmutable $date) /* : Event */;
 
 }
diff --git a/src/pvv/side/dbactivity.php b/src/pvv/side/dbactivity.php
index 8b4929f..5362e06 100644
--- a/src/pvv/side/dbactivity.php
+++ b/src/pvv/side/dbactivity.php
@@ -4,7 +4,7 @@ namespace pvv\side;
 use \DateTimeImmutable;
 use \PDO;
 
-class DBActivity implements RepeatingActivity {
+class DBActivity implements Activity {
 
 	public function __construct(PDO $pdo) {
 		$this->pdo = $pdo;
@@ -48,18 +48,4 @@ class DBActivity implements RepeatingActivity {
 		return "User";
 	}
 
-	/*
-    public function getAllEvents(){
-	global $url, $user,$pass,$db;
-	$events = array();
-	$mysqli = new mysqli($url,$user,$pass,$db);
-	$result = $mysqli->query("SELECT name,start,stop,organiser,location FROM events");
-	while($row = $result->fetch_assoc()){
-	$ev = new OnceEvent($row['name'],$row['start'],$row['stop'],$row['organiser'],$row['location']);
-	array_push($events,$ev);
-	}
-	#array_sort($events);
-	return $events;
-    }
-    */
 }
diff --git a/src/pvv/side/event.php b/src/pvv/side/event.php
index 0affb9d..08f365f 100644
--- a/src/pvv/side/event.php
+++ b/src/pvv/side/event.php
@@ -3,7 +3,7 @@ namespace pvv\side;
 
 use \DateTimeImmutable;
 
-abstract class Event implements Activity {
+abstract class Event {
 
 	private $start;
 
diff --git a/src/pvv/side/events.php b/src/pvv/side/events.php
deleted file mode 100644
index 68e8320..0000000
--- a/src/pvv/side/events.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-namespace pvv\side;
-use \mysqli;
-require __DIR__.'/sql_config.php';
-
-Class Events {
-    public function getAllEvents(){
-	global $url, $user,$pass,$db;
-	$events = array();
-	$mysqli = new mysqli($url,$user,$pass,$db);
-	$result = $mysqli->query("SELECT name,start,stop,organiser,location FROM events");
-	while($row = $result->fetch_assoc()){
-	$ev = new OnceEvent($row['name'],$row['start'],$row['stop'],$row['organiser'],$row['location']);
-	array_push($events,$ev);
-	}
-	#array_sort($events);
-	return $events;
-    }
-}
-
-?>
diff --git a/src/pvv/side/onceevent.php b/src/pvv/side/onceevent.php
deleted file mode 100644
index 3b41413..0000000
--- a/src/pvv/side/onceevent.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-namespace pvv\side;
-
-Class OnceEvent extends Event {
-    private $name, $start, $end, $org, $loc;
-    public function __construct($name,\DateTimeImmutable $start,\DateTimeImmutable $end,$org, $loc){
-    $this->name = $name;
-    $this->start = $start;
-    $this->end = $end;
-    $this->org = $org;
-    $this->log = $loc;
-    }
-    public function getStart(){
-	return $this->start;
-    }
-    public function getStop(){
-	return $this->end;
-    }
-    public function getOrganiser(){
-	return $this->org;
-    }
-    public function getLocation(){
-	return $this->loc;
-    }
-    public function getName(){
-	return $this->name;
-    }
-
-}
-
diff --git a/src/pvv/side/repeatingactivity.php b/src/pvv/side/repeatingactivity.php
deleted file mode 100644
index 9bcda82..0000000
--- a/src/pvv/side/repeatingactivity.php
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php //declare(strict_types=1);
-namespace pvv\side;
-
-use \DateTimeImmutable;
-
-interface RepeatingActivity extends Activity {
-
-	public function getNextEventFrom(DateTimeImmutable $date) /* : Event */;
-
-	public function getPreviousEventFrom(DateTimeImmutable $date) /* : Event */;
-
-}
diff --git a/src/pvv/side/simpleevent.php b/src/pvv/side/simpleevent.php
new file mode 100644
index 0000000..f9a40fb
--- /dev/null
+++ b/src/pvv/side/simpleevent.php
@@ -0,0 +1,36 @@
+<?php
+namespace pvv\side;
+
+Class SimpleEvent extends Event {
+
+	private $name, $start, $end, $org, $loc;
+
+	public function __construct($name,\DateTimeImmutable $start,\DateTimeImmutable $end,$org, $loc){
+		$this->name = $name;
+		$this->start = $start;
+		$this->end = $end;
+		$this->org = $org;
+		$this->log = $loc;
+	}
+
+	public function getStart(){
+		return $this->start;
+	}
+
+	public function getStop(){
+		return $this->end;
+	}
+
+	public function getOrganiser(){
+		return $this->org;
+	}
+
+	public function getLocation(){
+		return $this->loc;
+	}
+
+	public function getName(){
+		return $this->name;
+	}
+
+}
diff --git a/src/pvv/side/social/animekveldactivity.php b/src/pvv/side/social/animekveldactivity.php
index 3f2f590..11a0e37 100644
--- a/src/pvv/side/social/animekveldactivity.php
+++ b/src/pvv/side/social/animekveldactivity.php
@@ -1,11 +1,11 @@
 <?php //declare(strict_types=1);
 namespace pvv\side\social;
 
-use \pvv\side\RepeatingActivity;
+use \pvv\side\Activity;
 use \DateTimeImmutable;
 use \DateInterval;
 
-class AnimekveldActivity implements RepeatingActivity {
+class AnimekveldActivity implements Activity {
 
 	public function nextDate(DateTimeImmutable $date) {
 		if ($date->format('H') > 20 || $date->format('H') == 19 && $date->format('i') > 30)
@@ -33,16 +33,4 @@ class AnimekveldActivity implements RepeatingActivity {
 		return new AnimekveldEvent($this->prevDate($date));
 	}
 
-	public function getName() /* : string */ {
-		return "Animekveld";
-	}
-
-	public function getLocation() /* : Location */ {
-		return "Koserommet";
-	}
-
-	public function getOrganiser() /* : User */ {
-		return "Liang Zhu";
-	}
-
 }
diff --git a/src/pvv/side/social/brettspillactivity.php b/src/pvv/side/social/brettspillactivity.php
index 19a31f3..7242f36 100644
--- a/src/pvv/side/social/brettspillactivity.php
+++ b/src/pvv/side/social/brettspillactivity.php
@@ -1,11 +1,11 @@
 <?php //declare(strict_types=1);
 namespace pvv\side\social;
 
-use \pvv\side\RepeatingActivity;
+use \pvv\side\Activity;
 use \DateTimeImmutable;
 use \DateInterval;
 
-class BrettspillActivity implements RepeatingActivity {
+class BrettspillActivity implements Activity {
 
 	public function nextDate(DateTimeImmutable $date) {
 		if ($date->format('H') > 20 || $date->format('H') == 19 && $date->format('i') > 30)
@@ -33,16 +33,4 @@ class BrettspillActivity implements RepeatingActivity {
 		return new BrettspillEvent($this->prevDate($date));
 	}
 
-	public function getName() /* : string */ {
-		return "Brettspillkveld";
-	}
-
-	public function getLocation() /* : Location */ {
-		return "Koserommet";
-	}
-
-	public function getOrganiser() /* : User */ {
-		return "PVV";
-	}
-
 }
diff --git a/src/pvv/side/social/nerdepitsaactivity.php b/src/pvv/side/social/nerdepitsaactivity.php
index 4984d96..d320a51 100644
--- a/src/pvv/side/social/nerdepitsaactivity.php
+++ b/src/pvv/side/social/nerdepitsaactivity.php
@@ -1,11 +1,11 @@
 <?php //declare(strict_types=1);
 namespace pvv\side\social;
 
-use \pvv\side\RepeatingActivity;
+use \pvv\side\Activity;
 use \DateTimeImmutable;
 use \DateInterval;
 
-class NerdepitsaActivity implements RepeatingActivity {
+class NerdepitsaActivity implements Activity {
 
 	public function nextDate(DateTimeImmutable $date) {
 		if ($date->format('H') > 19)
@@ -37,16 +37,4 @@ class NerdepitsaActivity implements RepeatingActivity {
 		return new NerdepitsaEvent($this->prevDate($date));
 	}
 
-	public function getName() /* : string */ {
-		return "Nerdepitsa";
-	}
-
-	public function getLocation() /* : Location */ {
-		return "Peppes Kjøpmansgata";
-	}
-
-	public function getOrganiser() /* : User */ {
-		return "Anders Christensen";
-	}
-
 }
diff --git a/src/pvv/side/sql_config_example.php b/src/pvv/side/sql_config_example.php
deleted file mode 100644
index ea7c6a6..0000000
--- a/src/pvv/side/sql_config_example.php
+++ /dev/null
@@ -1,6 +0,0 @@
-<?php
-$url = "127.0.0.1";
-$user = "user";
-$pass = "password";
-$db = "events";
-?>

From 8519c00a575f05f61366d7ad97ce8de2294fb7d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B8rn=20=C3=85ne?= <git@jornane.no>
Date: Fri, 26 Aug 2016 17:04:49 +0200
Subject: [PATCH 2/4] Show more relevant times in upcoming activities.

---
 www/index.php | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/www/index.php b/www/index.php
index 370bc3b..767f886 100644
--- a/www/index.php
+++ b/www/index.php
@@ -53,7 +53,7 @@ $agenda = new \pvv\side\Agenda([
 <?php $translation = ['i dag', 'i morgen', 'denne uka', 'neste uke', 'denne måneden', 'neste måned'] ?>
 <?php $counter1 = 0; ?>
 <?php $counter2 = 0; ?>
-<?php foreach($agenda->getNextDays() as $period => $events) if ($events && $counter1 < 3 && $counter2 < 10) { $counter1++ ?>
+<?php foreach($agenda->getNextDays() as $period => $events) if ($events && $counter1 < 2 && $counter2 < 10) { $counter1++ ?>
 <li>
 <p><?= $translation[$period] ?></p>
 <ul>
@@ -63,12 +63,15 @@ $agenda = new \pvv\side\Agenda([
 <a class="icon subscribe" href="">+</a>
 <?php if ($period) {
 	if (\pvv\side\Agenda::isThisWeek($event->getStart()) || $event->getStart()->sub(new DateInterval('P3D'))->getTimestamp() < time()) {
-		echo '<span class="date">' . strftime('%A', $event->getStart()->getTimestamp()) . '</span>';
+		echo '<span class="time">' . strftime('%a', $event->getStart()->getTimestamp()) . '</span>';
 	} else {
-		echo '<span class="date">' . strftime('%e. %b', $event->getStart()->getTimestamp()) . '</span>';
+		echo '<span class="time">' . strftime('%e. %b', $event->getStart()->getTimestamp()) . '</span>';
 	}
-} ?>
-<span class="time"><?= $event->getStart()->format('H:i'); ?></span>
+	echo '<span class="date">' . $event->getStart()->format('H:i') . '</span>';
+} else {
+	echo '<span class="time">' . $event->getStart()->format('H:i') . '</span>';
+}
+?>
 </li>
 <?php } ?>
 </ul>

From 328a2a31e6786d9515ba28ae3ab65f1c95b4b905 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B8rn=20=C3=85ne?= <git@jornane.no>
Date: Fri, 26 Aug 2016 17:22:11 +0200
Subject: [PATCH 3/4] Add URL property to events.

---
 src/pvv/side/event.php                  | 2 ++
 src/pvv/side/social/animekveldevent.php | 4 ++++
 src/pvv/side/social/brettspillevent.php | 4 ++++
 src/pvv/side/social/nerdepitsaevent.php | 4 ++++
 www/index.php                           | 8 ++++----
 5 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/pvv/side/event.php b/src/pvv/side/event.php
index 08f365f..76eab76 100644
--- a/src/pvv/side/event.php
+++ b/src/pvv/side/event.php
@@ -17,4 +17,6 @@ abstract class Event {
 
 	public abstract function getStop(); /* : DateTimeImmutable */
 
+	public abstract function getURL(); /* : string */
+
 }
diff --git a/src/pvv/side/social/animekveldevent.php b/src/pvv/side/social/animekveldevent.php
index f9dd0ba..cabbb37 100644
--- a/src/pvv/side/social/animekveldevent.php
+++ b/src/pvv/side/social/animekveldevent.php
@@ -23,4 +23,8 @@ class AnimekveldEvent extends Event {
 		return "Liang Zhu";
 	}
 
+	public function getURL() /* : string */ {
+		return '/anime/';
+	}
+
 }
diff --git a/src/pvv/side/social/brettspillevent.php b/src/pvv/side/social/brettspillevent.php
index a9bd58d..d9d49f3 100644
--- a/src/pvv/side/social/brettspillevent.php
+++ b/src/pvv/side/social/brettspillevent.php
@@ -23,4 +23,8 @@ class BrettspillEvent extends Event {
 		return "PVV";
 	}
 
+	public function getURL() /* : string */ {
+		return '/brettspill/';
+	}
+
 }
diff --git a/src/pvv/side/social/nerdepitsaevent.php b/src/pvv/side/social/nerdepitsaevent.php
index 83b764c..9614de4 100644
--- a/src/pvv/side/social/nerdepitsaevent.php
+++ b/src/pvv/side/social/nerdepitsaevent.php
@@ -23,4 +23,8 @@ class NerdepitsaEvent extends Event {
 		return "Anders Christensen";
 	}
 
+	public function getURL() /* : string */ {
+		return '/nerdepitsa/';
+	}
+
 }
diff --git a/www/index.php b/www/index.php
index 767f886..f70b0a8 100644
--- a/www/index.php
+++ b/www/index.php
@@ -1,8 +1,8 @@
 <?php
-require '../src/_autoload.php';
 date_default_timezone_set('Europe/Oslo');
-require __DIR__ . '/../sql_config.php';
 setlocale(LC_ALL, 'no_NO');
+require __DIR__ . '/../src/_autoload.php';
+require __DIR__ . '/../sql_config.php';
 $pdo = new \PDO($dbDsn, $dbUser, $dbPass);
 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 $agenda = new \pvv\side\Agenda([
@@ -59,8 +59,8 @@ $agenda = new \pvv\side\Agenda([
 <ul>
 <?php foreach($events as $event) { $counter2++ ?>
 <li>
-<a><?= $event->getName(); ?></a>
-<a class="icon subscribe" href="">+</a>
+<a href="<?= htmlspecialchars($event->getURL()) ?>"><?= $event->getName(); ?></a>
+<?php /* <a class="icon subscribe">+</a> */ ?>
 <?php if ($period) {
 	if (\pvv\side\Agenda::isThisWeek($event->getStart()) || $event->getStart()->sub(new DateInterval('P3D'))->getTimestamp() < time()) {
 		echo '<span class="time">' . strftime('%a', $event->getStart()->getTimestamp()) . '</span>';

From 963973bc6bafe343293b60f941f7bc7fa34a907c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B8rn=20=C3=85ne?= <git@jornane.no>
Date: Fri, 26 Aug 2016 17:29:09 +0200
Subject: [PATCH 4/4] Show upcoming activity in the header on the main page.

---
 www/index.php | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/www/index.php b/www/index.php
index f70b0a8..e4f8536 100644
--- a/www/index.php
+++ b/www/index.php
@@ -3,6 +3,7 @@ date_default_timezone_set('Europe/Oslo');
 setlocale(LC_ALL, 'no_NO');
 require __DIR__ . '/../src/_autoload.php';
 require __DIR__ . '/../sql_config.php';
+$translation = ['i dag', 'i morgen', 'denne uka', 'neste uke', 'denne måneden', 'neste måned'];
 $pdo = new \PDO($dbDsn, $dbUser, $dbPass);
 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 $agenda = new \pvv\side\Agenda([
@@ -31,7 +32,13 @@ $agenda = new \pvv\side\Agenda([
 <header>Program&shy;vare&shy;verk&shy;stedet</header>
 
 <ul id="ticker">
-	<li>I DAG: <a href="">nerdepitsa</a>
+<?php
+foreach($agenda->getNextDays() as $period => $events) {
+	$event = reset($events);
+	echo '<li>' . strtoupper($translation[$period]) . ': <a href="' . $event->getURL() . '">' . $event->getName() . '</a>';
+	break;
+}
+?>
 </ul>
 
 <main>
@@ -50,7 +57,6 @@ $agenda = new \pvv\side\Agenda([
 <article>
 <h2>Kommende arrangement</h2>
 <ul class="calendar-events">
-<?php $translation = ['i dag', 'i morgen', 'denne uka', 'neste uke', 'denne måneden', 'neste måned'] ?>
 <?php $counter1 = 0; ?>
 <?php $counter2 = 0; ?>
 <?php foreach($agenda->getNextDays() as $period => $events) if ($events && $counter1 < 2 && $counter2 < 10) { $counter1++ ?>