Add automatic agenda on front page.
This commit is contained in:
parent
e4e8b0972b
commit
b6970d3f03
|
@ -1,7 +1,7 @@
|
|||
<?php //declare(strict_types=1);
|
||||
namespace pvv\side;
|
||||
|
||||
use \DateTime;
|
||||
use \DateTimeImmutable;
|
||||
|
||||
interface Activity {
|
||||
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
<?php //declare(strict_types=1);
|
||||
namespace pvv\side;
|
||||
|
||||
use \pvv\side\social\NerdepitsaActivity;
|
||||
use \pvv\side\social\AnimekveldActivity;
|
||||
|
||||
use \DateTimeImmutable;
|
||||
use \DateInterval;
|
||||
|
||||
class Agenda {
|
||||
|
||||
const TODAY = 0;
|
||||
const TOMORROW = 1;
|
||||
const THIS_WEEK = 2;
|
||||
const THIS_MONTH = 3;
|
||||
const NEXT_MONTH = 4;
|
||||
|
||||
public function __construct() {
|
||||
$this->activities = [
|
||||
new NerdepitsaActivity,
|
||||
new AnimekveldActivity,
|
||||
];
|
||||
}
|
||||
|
||||
public function getEventsBetween(DateTimeImmutable $from, DateTimeImmutable $to) {
|
||||
$results = [[], []];
|
||||
do {
|
||||
$run = false;
|
||||
for($i = 0; $i < sizeof($this->activities); $i++) {
|
||||
if (sizeof($results[$i])) {
|
||||
$date = end($results[$i])->getStop();
|
||||
} else {
|
||||
$date = $from;
|
||||
}
|
||||
$next = $this->activities[$i]->getNextEventFrom($date);
|
||||
if (isset($next) && $next->getStart() < $to) {
|
||||
$results[$i][] = $this->activities[$i]->getNextEventFrom($date);
|
||||
$run = true;
|
||||
}
|
||||
}
|
||||
} while ($run);
|
||||
$result = [];
|
||||
foreach($results as $a) foreach($a as $b) $result[] = $b;
|
||||
usort($result, function($a, $b) {
|
||||
return ($a->getStart() < $b->getStart()) ? -1 : 1;
|
||||
});
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getNextDays() {
|
||||
$result = [[], [], [], [], []];
|
||||
$events = $this->getEventsBetween(
|
||||
(new DateTimeImmutable)->sub(new DateInterval('PT1H')),
|
||||
(new DateTimeImmutable)->add(new DateInterval('P1M'))
|
||||
);
|
||||
foreach ($events as $event) {
|
||||
$index = self::NEXT_MONTH;
|
||||
if (self::isToday($event->getStart())) $index = self::TODAY;
|
||||
elseif (self::isTomorrow($event->getStart())) $index = self::TOMORROW;
|
||||
elseif (self::isThisWeek($event->getStart())) $index = self::THIS_WEEK;
|
||||
elseif (self::isThisMonth($event->getStart())) $index = self::THIS_MONTH;
|
||||
$result[$index][] = $event;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function isToday(DateTimeImmutable $date) {
|
||||
return $date->format('dmY') == date('dmY');
|
||||
}
|
||||
|
||||
public static function isTomorrow(DateTimeImmutable $date) {
|
||||
return $date->sub(new DateInterval('P1D'))->format('dmY') == date('dmY');
|
||||
}
|
||||
|
||||
public static function isThisWeek(DateTimeImmutable $date) {
|
||||
return $date->format('WY') == date('WY');
|
||||
}
|
||||
|
||||
public static function isThisMonth(DateTimeImmutable $date) {
|
||||
return $date->format('mY') == date('mY');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,20 @@
|
|||
<?php //declare(strict_types=1);
|
||||
namespace pvv\side;
|
||||
|
||||
interface Event extends Activity {
|
||||
use \DateTimeImmutable;
|
||||
|
||||
public function getStart(); /* : DateTime */
|
||||
abstract class Event implements Activity {
|
||||
|
||||
public function getStop(); /* : DateTime */
|
||||
private $start;
|
||||
|
||||
public function __construct(DateTimeImmutable $start) {
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
public function getStart() {
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
public abstract function getStop(); /* : DateTimeImmutable */
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php //declare(strict_types=1);
|
||||
namespace pvv\side\social;
|
||||
|
||||
use \pvv\side\RepeatingActivity;
|
||||
use \DateTimeImmutable;
|
||||
use \DateInterval;
|
||||
|
||||
class AnimekveldActivity {
|
||||
class AnimekveldActivity implements RepeatingActivity {
|
||||
|
||||
public function nextDate(DateTimeImmutable $date) {
|
||||
if ($date->format('H') > 20 || $date->format('H') == 19 && $date->format('i') > 30)
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php //declare(strict_types=1);
|
||||
namespace pvv\side\social;
|
||||
|
||||
use \pvv\side\Event;
|
||||
|
||||
use \DateInterval;
|
||||
|
||||
class AnimekveldEvent extends Event {
|
||||
|
||||
public function getStop() {
|
||||
return $this->getStart()->add(new DateInterval('PT4H1800S'));
|
||||
}
|
||||
|
||||
public function getName() /* : string */ {
|
||||
return "Animekveld";
|
||||
}
|
||||
|
||||
public function getLocation() /* : Location */ {
|
||||
return "Peppes Kjøpmansgata";
|
||||
}
|
||||
|
||||
public function getOrganiser() /* : User */ {
|
||||
return "Anders Christensen";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php //declare(strict_types=1);
|
||||
namespace pvv\side\social;
|
||||
|
||||
use \pvv\side\Event;
|
||||
|
||||
use \DateInterval;
|
||||
|
||||
class NerdepitsaEvent extends Event {
|
||||
|
||||
public function getStop() {
|
||||
return $this->getStart()->add(new DateInterval('PT2H1800S'));
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return "Nerdepitsa";
|
||||
}
|
||||
|
||||
public function getLocation() /* : Location */ {
|
||||
return "Peppes Kjøpmansgata";
|
||||
}
|
||||
|
||||
public function getOrganiser() /* : User */ {
|
||||
return "Anders Christensen";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,9 @@
|
|||
<<<<<<< e4e8b0972bbec3fff581f7a97b34315265104f3a
|
||||
<?php require '../src/_autoload.php'; ?><!DOCTYPE html>
|
||||
=======
|
||||
<?php require "../src/_autoload.php"; ?>
|
||||
<!DOCTYPE html>
|
||||
>>>>>>> Add automatic agenda on front page.
|
||||
<title>Programvareverkstedet</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
||||
|
@ -36,69 +41,21 @@
|
|||
<article>
|
||||
<h2>Kommende arrangement</h2>
|
||||
<ul class="calendar-events">
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
/* include "../../nettsiden/src/_autoload.php"; */
|
||||
/* use \pvv\side\Events; */
|
||||
# TEST START
|
||||
#Class Event {
|
||||
# private $start, $name;
|
||||
# function Event($name,$start){$this->start = $start;$this->name=$name;}
|
||||
# function getName(){return $this->name;}
|
||||
# function getStart(){return $this->start;}
|
||||
#}
|
||||
/* $evs = new Events(); */
|
||||
/* $events = $evs->getAllEvents(); */
|
||||
/* # TEST END */
|
||||
/* <a href="">animekveld</a> */
|
||||
|
||||
/* echo "<li><p>i dag<span>".date("Y-m-d")."</span></p>"; */
|
||||
/* echo "<ul>"; */
|
||||
/* foreach($events as $ev){ */
|
||||
/* echo "<li>"; */
|
||||
/* echo "<a href=\"\">".$ev->getName()."</a>"; */
|
||||
/* echo "<span>".$ev->getStart()."</span>"; */
|
||||
/* echo " <a class=\"icon subscribe\" href=\"\">+</a>"; */
|
||||
/* echo " </li>"; */
|
||||
/* } */
|
||||
?>
|
||||
|
||||
<?php
|
||||
$a = new \pvv\side\social\NerdepitsaActivity;
|
||||
$nextPizzaDate = $a->nextDate(new \DateTimeImmutable);
|
||||
$a = new \pvv\side\social\AnimekveldActivity;
|
||||
$nextAnimeDate = $a->nextDate(new \DateTimeImmutable);
|
||||
?>
|
||||
|
||||
<li><p><?=$nextPizzaDate->format('l')?><span><?=$nextPizzaDate->format('Y-m-d')?></span></p>
|
||||
<?php $translation = ['i dag', 'i morgen', 'denne uka', 'denne måned', 'neste måned'] ?>
|
||||
<?php $counter1 = 0; ?>
|
||||
<?php $counter2 = 0; ?>
|
||||
<?php foreach((new \pvv\side\Agenda())->getNextDays() as $period => $events) if ($events && $counter1 < 2 && $counter2 < 10) { $counter1++ ?>
|
||||
<li><p><?= $translation[$period] ?> <span><?= reset($events)->getStart()->format('Y-m-d'); ?></span></p>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="nerdepitsa/index.html">nerdepitsa</a>
|
||||
<span><?=$nextPizzaDate->format('H.i')?></span>
|
||||
<a class="icon subscribe" href="">+</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="animekveld/index.html">animekveld</a>
|
||||
<span><?=$nextAnimeDate->format('H.i')?></span>
|
||||
<a class="icon subscribe" href="">+</a>
|
||||
</li>
|
||||
</ul>
|
||||
<?php foreach($events as $event) { $counter2++ ?>
|
||||
<li>
|
||||
<a><?= $event->getName(); ?></a>
|
||||
<span><?= $event->getStart()->format('H:i'); ?></span>
|
||||
<a class="icon subscribe" href="">+</a>
|
||||
</li>
|
||||
|
||||
<li><p>noen gang<span>2016-08-XX</span></p>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="">styremøte</a>
|
||||
<span>XX.00</span>
|
||||
<a class="icon subscribe" href="">+</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<p><a class="btn" href="kalender/index.html">Flere aktiviteter</a></p>
|
||||
</article>
|
||||
|
|
Reference in New Issue