This commit is contained in:
Peder Bergebakken Sundt 2016-08-26 17:49:53 +02:00
commit e0fcf5f265
15 changed files with 80 additions and 142 deletions

View File

@ -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 */;
}

View File

@ -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;
}
*/
}

View File

@ -3,7 +3,7 @@ namespace pvv\side;
use \DateTimeImmutable;
abstract class Event implements Activity {
abstract class Event {
private $start;
@ -17,4 +17,6 @@ abstract class Event implements Activity {
public abstract function getStop(); /* : DateTimeImmutable */
public abstract function getURL(); /* : string */
}

View File

@ -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;
}
}
?>

View File

@ -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;
}
}

View File

@ -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 */;
}

View File

@ -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;
}
}

View File

@ -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";
}
}

View File

@ -23,4 +23,8 @@ class AnimekveldEvent extends Event {
return "Liang Zhu";
}
public function getURL() /* : string */ {
return '/anime/';
}
}

View File

@ -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";
}
}

View File

@ -23,4 +23,8 @@ class BrettspillEvent extends Event {
return "PVV";
}
public function getURL() /* : string */ {
return '/brettspill/';
}
}

View File

@ -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";
}
}

View File

@ -23,4 +23,8 @@ class NerdepitsaEvent extends Event {
return "Anders Christensen";
}
public function getURL() /* : string */ {
return '/nerdepitsa/';
}
}

View File

@ -1,6 +0,0 @@
<?php
$url = "127.0.0.1";
$user = "user";
$pass = "password";
$db = "events";
?>

View File

@ -1,8 +1,9 @@
<?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';
$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,25 +57,27 @@ $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 < 3 && $counter2 < 10) { $counter1++ ?>
<?php foreach($agenda->getNextDays() as $period => $events) if ($events && $counter1 < 2 && $counter2 < 10) { $counter1++ ?>
<li>
<p><?= $translation[$period] ?></p>
<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="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>