Simplify class structure.
This commit is contained in:
parent
6c3ac94804
commit
66114f36f9
|
@ -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 */;
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ namespace pvv\side;
|
|||
|
||||
use \DateTimeImmutable;
|
||||
|
||||
abstract class Event implements Activity {
|
||||
abstract class Event {
|
||||
|
||||
private $start;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 */;
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
<?php
|
||||
$url = "127.0.0.1";
|
||||
$user = "user";
|
||||
$pass = "password";
|
||||
$db = "events";
|
||||
?>
|
Reference in New Issue