2016-08-18 22:43:32 +02:00
|
|
|
<?php
|
|
|
|
namespace pvv\side;
|
|
|
|
|
|
|
|
use \DateTimeImmutable;
|
|
|
|
use \PDO;
|
|
|
|
|
2016-08-26 17:04:20 +02:00
|
|
|
class DBActivity implements Activity {
|
2016-08-18 22:43:32 +02:00
|
|
|
|
2016-08-18 23:17:24 +02:00
|
|
|
public function __construct(PDO $pdo) {
|
|
|
|
$this->pdo = $pdo;
|
2016-08-18 22:43:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getNextEventFrom(DateTimeImmutable $date) {
|
|
|
|
$query = 'SELECT name,start,stop,organiser,location FROM events WHERE start > :date ORDER BY start ASC LIMIT 1';
|
|
|
|
return $this->retrieve($date, $query);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPreviousEventFrom(DateTimeImmutable $date) {
|
|
|
|
$query = 'SELECT name,start,stop,organiser,location FROM events WHERE start < :date ORDER BY start DESC LIMIT 1';
|
|
|
|
return $this->retrieve($date, $query);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function retrieve($date, $query) {
|
|
|
|
$stmt = $this->pdo->prepare($query);
|
|
|
|
$stmt->execute(['date' => $date->format('Y-m-d H:i:s')]);
|
|
|
|
if ($result = $stmt->fetch(PDO::FETCH_ASSOC)){
|
2016-08-26 17:58:43 +02:00
|
|
|
$ev = new SimpleEvent(
|
2016-08-18 22:43:32 +02:00
|
|
|
$result['name'],
|
|
|
|
DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $result['start']),
|
|
|
|
DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $result['stop']),
|
|
|
|
$result['organiser'],
|
|
|
|
$result['location']
|
|
|
|
);
|
|
|
|
return $ev;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() /* : string */ {
|
|
|
|
return "Database";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLocation() /* : Location */ {
|
|
|
|
return "Location";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOrganiser() /* : User */ {
|
|
|
|
return "User";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|