Mark data classes and functions with types
This commit is contained in:
@@ -4,20 +4,22 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\admin;
|
||||
|
||||
class UserManager {
|
||||
private $pdo;
|
||||
use PDO;
|
||||
|
||||
public $usergroups = [
|
||||
class UserManager {
|
||||
private PDO $pdo;
|
||||
|
||||
public array $usergroups = [
|
||||
'admin' => 1,
|
||||
'prosjekt' => 2,
|
||||
'aktiviteter' => 4,
|
||||
];
|
||||
|
||||
public function __construct($pdo) {
|
||||
public function __construct(PDO $pdo) {
|
||||
$this->pdo = $pdo;
|
||||
}
|
||||
|
||||
public function setupUser($uname, $groups = 0): void {
|
||||
public function setupUser(string $uname, int $groups = 0): void {
|
||||
$query = 'INSERT INTO users (uname, groups) VALUES (:uname, :groups)';
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':uname', $uname, \PDO::PARAM_STR);
|
||||
@@ -25,14 +27,14 @@ class UserManager {
|
||||
$statement->execute();
|
||||
}
|
||||
|
||||
public function updateFlags($uname, $flags): void {
|
||||
public function updateFlags(string $uname, int $flags): void {
|
||||
$query = 'UPDATE users set groups=:groups WHERE uname=:uname';
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':groups', $flags, \PDO::PARAM_INT);
|
||||
$statement->bindParam(':uname', $uname, \PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
public function addGroup($uname, $group): void {
|
||||
public function addGroup(string $uname, int $group): void {
|
||||
$userFlags = $this->getUsergroups($uname);
|
||||
|
||||
if ($userFlags) {
|
||||
@@ -41,7 +43,7 @@ class UserManager {
|
||||
}
|
||||
}
|
||||
|
||||
public function removeGroup($uname, $group): void {
|
||||
public function removeGroup(string $uname, int $group): void {
|
||||
$userFlags = $this->getUsergroups($uname);
|
||||
|
||||
if ($userFlags) {
|
||||
@@ -50,7 +52,7 @@ class UserManager {
|
||||
}
|
||||
}
|
||||
|
||||
public function setGroups($uname, $groups): void {
|
||||
public function setGroups(string $uname, int $groups): void {
|
||||
$query = 'SELECT * FROM users WHERE uname=:uname LIMIT 1';
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':uname', $uname, \PDO::PARAM_STR);
|
||||
@@ -68,18 +70,18 @@ class UserManager {
|
||||
}
|
||||
}
|
||||
|
||||
public function hasGroup($uname, $groupName) {
|
||||
public function hasGroup(string $uname, string $groupName): bool {
|
||||
$userFlags = $this->getUsergroups($uname);
|
||||
|
||||
return $userFlags & $this->usergroups[$groupName];
|
||||
return (bool) ($userFlags & $this->usergroups[$groupName]);
|
||||
}
|
||||
|
||||
// for convenience
|
||||
public function isAdmin($uname) {
|
||||
public function isAdmin(string $uname): bool {
|
||||
return $this->hasGroup($uname, 'admin');
|
||||
}
|
||||
|
||||
public function getFlagfromNames($names) {
|
||||
public function getFlagfromNames(array $names): int {
|
||||
$resultFlag = 0;
|
||||
|
||||
foreach ($this->usergroups as $name => $flag) {
|
||||
@@ -91,7 +93,7 @@ class UserManager {
|
||||
return $resultFlag;
|
||||
}
|
||||
|
||||
public function getUsergroups($uname) {
|
||||
public function getUsergroups(string $uname): int {
|
||||
$query = 'SELECT groups FROM users WHERE uname=:uname LIMIT 1';
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':uname', $uname, \PDO::PARAM_STR);
|
||||
@@ -105,7 +107,10 @@ class UserManager {
|
||||
return $row[0];
|
||||
}
|
||||
|
||||
public function getUsergroupNames($uname) {
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getUsergroupNames($uname): array {
|
||||
$usersGroups = [];
|
||||
|
||||
$userFlags = $this->getUsergroups($uname);
|
||||
@@ -119,7 +124,10 @@ class UserManager {
|
||||
return $usersGroups;
|
||||
}
|
||||
|
||||
public function getAllUserData() {
|
||||
/**
|
||||
* @return array<int,array{name:string,groups:string[]}>
|
||||
*/
|
||||
public function getAllUserData(): array {
|
||||
$query = 'SELECT uname FROM users ORDER BY uname ASC';
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
@@ -4,8 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side;
|
||||
|
||||
interface Activity {
|
||||
public function getNextEventFrom(\DateTimeImmutable $date) /* : Event */;
|
||||
use pvv\side\Event;
|
||||
|
||||
public function getPreviousEventFrom(\DateTimeImmutable $date) /* : Event */;
|
||||
interface Activity {
|
||||
public function getNextEventFrom(\DateTimeImmutable $date): ?Event;
|
||||
|
||||
public function getPreviousEventFrom(\DateTimeImmutable $date): ?Event;
|
||||
}
|
||||
|
||||
@@ -4,25 +4,37 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
|
||||
class Agenda {
|
||||
private $activities;
|
||||
private array $activities;
|
||||
|
||||
public const TODAY = 0;
|
||||
public const TOMORROW = 1;
|
||||
public const THIS_WEEK = 2;
|
||||
public const NEXT_WEEK = 3;
|
||||
public const THIS_MONTH = 4;
|
||||
public const NEXT_MONTH = 5;
|
||||
public const int TODAY = 0;
|
||||
public const int TOMORROW = 1;
|
||||
public const int THIS_WEEK = 2;
|
||||
public const int NEXT_WEEK = 3;
|
||||
public const int THIS_MONTH = 4;
|
||||
public const int NEXT_MONTH = 5;
|
||||
|
||||
public function __construct($activities) {
|
||||
/**
|
||||
* @param array<int,DBActivity> $activities
|
||||
*/
|
||||
public function __construct(array $activities) {
|
||||
$this->activities = $activities;
|
||||
}
|
||||
|
||||
public static function getFormattedDate($date) {
|
||||
return $date->format('l j. M H.i');
|
||||
public static function getFormattedDate(DateTime $date): string {
|
||||
return $date->format("l j. M H.i");
|
||||
}
|
||||
|
||||
public function getEventsBetween(\DateTimeImmutable $from, \DateTimeImmutable $to) {
|
||||
/**
|
||||
* @return array<Event>
|
||||
*/
|
||||
public function getEventsBetween(
|
||||
\DateTimeImmutable $from,
|
||||
\DateTimeImmutable $to,
|
||||
) {
|
||||
$results = [];
|
||||
for ($i = 0; $i < \count($this->activities); ++$i) {
|
||||
$result = [];
|
||||
@@ -47,16 +59,22 @@ class Agenda {
|
||||
$result[] = $b;
|
||||
}
|
||||
}
|
||||
usort($result, static fn($a, $b) => ($a->getStart() < $b->getStart()) ? -1 : 1);
|
||||
usort(
|
||||
$result,
|
||||
static fn($a, $b) => $a->getStart() < $b->getStart() ? -1 : 1,
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getNextDays() {
|
||||
/**
|
||||
* @return array<int,array>
|
||||
*/
|
||||
public function getNextDays(): array {
|
||||
$result = [[], [], [], [], [], []];
|
||||
$events = $this->getEventsBetween(
|
||||
(new \DateTimeImmutable())->setTime(0, 0),
|
||||
(new \DateTimeImmutable())->setTime(23, 59)->add(new \DateInterval('P1M'))
|
||||
new \DateTimeImmutable()->setTime(0, 0),
|
||||
new \DateTimeImmutable()->setTime(23, 59)->add(new \DateInterval("P1M")),
|
||||
);
|
||||
foreach ($events as $event) {
|
||||
$index = self::NEXT_MONTH;
|
||||
@@ -77,38 +95,45 @@ class Agenda {
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getNextOfEach(\DateTimeImmutable $startDate) {
|
||||
$result = array_filter(array_map(
|
||||
static fn($a) => $a->getNextEventFrom($startDate),
|
||||
$this->activities
|
||||
), static fn($a) => isset($a));
|
||||
/**
|
||||
* @return array<Event>
|
||||
*/
|
||||
public function getNextOfEach(\DateTimeImmutable $startDate): array {
|
||||
$result = array_filter(
|
||||
array_map(
|
||||
static fn($a) => $a->getNextEventFrom($startDate),
|
||||
$this->activities,
|
||||
),
|
||||
static fn($a) => isset($a),
|
||||
);
|
||||
usort(
|
||||
$result,
|
||||
static fn($a, $b) => ($a->getStart()->getTimeStamp() < $b->getStart()->getTimeStamp())
|
||||
? -1
|
||||
: 1
|
||||
static fn($a, $b) => $a->getStart()->getTimeStamp() <
|
||||
$b->getStart()->getTimeStamp()
|
||||
? -1
|
||||
: 1,
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function isToday(\DateTimeImmutable $date) {
|
||||
return $date->format('dmY') == date('dmY');
|
||||
public static function isToday(\DateTimeImmutable $date): bool {
|
||||
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 isTomorrow(\DateTimeImmutable $date): bool {
|
||||
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 isThisWeek(\DateTimeImmutable $date): bool {
|
||||
return $date->format("WY") == date("WY");
|
||||
}
|
||||
|
||||
public static function isNextWeek(\DateTimeImmutable $date) {
|
||||
return $date->sub(new \DateInterval('P7D'))->format('WY') == date('WY');
|
||||
public static function isNextWeek(\DateTimeImmutable $date): bool {
|
||||
return $date->sub(new \DateInterval("P7D"))->format("WY") == date("WY");
|
||||
}
|
||||
|
||||
public static function isThisMonth(\DateTimeImmutable $date) {
|
||||
return $date->format('mY') == date('mY');
|
||||
public static function isThisMonth(\DateTimeImmutable $date): bool {
|
||||
return $date->format("mY") == date("mY");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,28 +4,34 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PDO;
|
||||
|
||||
class DBActivity implements Activity {
|
||||
private $pdo;
|
||||
|
||||
public function __construct(\PDO $pdo) {
|
||||
public function __construct(PDO $pdo) {
|
||||
$this->pdo = $pdo;
|
||||
}
|
||||
|
||||
public function getAllEvents() {
|
||||
$query = 'SELECT * FROM events ORDER BY id DESC';
|
||||
/**
|
||||
* @return SimpleEvent[]
|
||||
*/
|
||||
public function getAllEvents(): array {
|
||||
$query = "SELECT * FROM events ORDER BY id DESC";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
$events = [];
|
||||
foreach ($statement->fetchAll() as $dbEvent) {
|
||||
$event = new SimpleEvent(
|
||||
$dbEvent['id'],
|
||||
$dbEvent['name'],
|
||||
\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['start']),
|
||||
\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['stop']),
|
||||
$dbEvent['organiser'],
|
||||
$dbEvent['location'],
|
||||
$dbEvent['description']
|
||||
$dbEvent["id"],
|
||||
$dbEvent["name"],
|
||||
\DateTimeImmutable::createFromFormat("Y-m-d H:i:s", $dbEvent["start"]),
|
||||
\DateTimeImmutable::createFromFormat("Y-m-d H:i:s", $dbEvent["stop"]),
|
||||
$dbEvent["organiser"],
|
||||
$dbEvent["location"],
|
||||
$dbEvent["description"],
|
||||
);
|
||||
$events[] = $event;
|
||||
}
|
||||
@@ -33,51 +39,57 @@ class DBActivity implements Activity {
|
||||
return $events;
|
||||
}
|
||||
|
||||
public function getEventByID($id) {
|
||||
$query = 'SELECT * FROM events WHERE id=:id LIMIT 1';
|
||||
public function getEventByID(int $id): SimpleEvent {
|
||||
$query = "SELECT * FROM events WHERE id=:id LIMIT 1";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':id', $id, \PDO::PARAM_INT);
|
||||
$statement->bindParam(":id", $id, PDO::PARAM_INT);
|
||||
$statement->execute();
|
||||
|
||||
$dbEvent = $statement->fetch();
|
||||
|
||||
return new SimpleEvent(
|
||||
$dbEvent['id'],
|
||||
$dbEvent['name'],
|
||||
\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['start']),
|
||||
\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['stop']),
|
||||
$dbEvent['organiser'],
|
||||
$dbEvent['location'],
|
||||
$dbEvent['description']
|
||||
$dbEvent["id"],
|
||||
$dbEvent["name"],
|
||||
\DateTimeImmutable::createFromFormat("Y-m-d H:i:s", $dbEvent["start"]),
|
||||
\DateTimeImmutable::createFromFormat("Y-m-d H:i:s", $dbEvent["stop"]),
|
||||
$dbEvent["organiser"],
|
||||
$dbEvent["location"],
|
||||
$dbEvent["description"],
|
||||
);
|
||||
}
|
||||
|
||||
public function getNextEventFrom(\DateTimeImmutable $date) {
|
||||
$query = 'SELECT id,name,start,stop,organiser,location,description FROM events WHERE start > :date ORDER BY start ASC LIMIT 1';
|
||||
public function getNextEventFrom(\DateTimeImmutable $date): ?Event {
|
||||
$query =
|
||||
"SELECT id,name,start,stop,organiser,location,description FROM events WHERE start > :date ORDER BY start ASC LIMIT 1";
|
||||
|
||||
return $this->retrieve($date, $query);
|
||||
}
|
||||
|
||||
public function getPreviousEventFrom(\DateTimeImmutable $date) {
|
||||
$query = 'SELECT id,name,start,stop,organiser,location,description FROM events WHERE start < :date ORDER BY start DESC LIMIT 1';
|
||||
public function getPreviousEventFrom(\DateTimeImmutable $date): ?Event {
|
||||
$query =
|
||||
"SELECT id,name,start,stop,organiser,location,description FROM events WHERE start < :date ORDER BY start DESC LIMIT 1";
|
||||
|
||||
return $this->retrieve($date, $query);
|
||||
}
|
||||
|
||||
private function retrieve($date, $query) {
|
||||
private function retrieve(
|
||||
DateTimeImmutable $date,
|
||||
string $query,
|
||||
): ?SimpleEvent {
|
||||
$stmt = $this->pdo->prepare($query);
|
||||
$stmt->execute(['date' => $date->format('Y-m-d H:i:s')]);
|
||||
$stmt->execute(["date" => $date->format("Y-m-d H:i:s")]);
|
||||
if ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
return new SimpleEvent(
|
||||
$result['id'],
|
||||
$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'],
|
||||
$result['description']
|
||||
$result["id"],
|
||||
$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"],
|
||||
$result["description"],
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PDO;
|
||||
|
||||
class Door {
|
||||
private $pdo;
|
||||
|
||||
@@ -11,64 +14,74 @@ class Door {
|
||||
$this->pdo = $pdo;
|
||||
}
|
||||
|
||||
public function getAll() {
|
||||
$query = 'SELECT time, open FROM door ORDER BY time DESC';
|
||||
/**
|
||||
* @return array{time: int, open: bool}[]
|
||||
*/
|
||||
public function getAll(): array {
|
||||
$query = "SELECT time, open FROM door ORDER BY time DESC";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
$doorEvents = [];
|
||||
foreach ($statement->fetchAll() as $row) {
|
||||
$doorEvents[] = [
|
||||
'time' => (int) $row['time'],
|
||||
'open' => (bool) $row['open'],
|
||||
"time" => (int) $row["time"],
|
||||
"open" => (bool) $row["open"],
|
||||
];
|
||||
}
|
||||
|
||||
return $doorEvents;
|
||||
}
|
||||
|
||||
public function getEntriesAfter($startTime) {
|
||||
$query = 'SELECT time, open FROM door WHERE time > :startTime ORDER BY time DESC';
|
||||
/**
|
||||
* @return array{time: int, open: bool}[]
|
||||
*/
|
||||
public function getEntriesAfter(DateTimeImmutable $startTime): array {
|
||||
$query =
|
||||
"SELECT time, open FROM door WHERE time > :startTime ORDER BY time DESC";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':startTime', $startTime, \PDO::PARAM_STR);
|
||||
$statement->bindParam(":startTime", $startTime, \PDO::PARAM_STR);
|
||||
$statement->execute();
|
||||
|
||||
$doorEvents = [];
|
||||
foreach ($statement->fetchAll() as $row) {
|
||||
$doorEvents[] = [
|
||||
'time' => (int) $row['time'],
|
||||
'open' => (bool) $row['open'],
|
||||
"time" => (int) $row["time"],
|
||||
"open" => (bool) $row["open"],
|
||||
];
|
||||
}
|
||||
|
||||
return $doorEvents;
|
||||
}
|
||||
|
||||
public function getCurrent() {
|
||||
$query = 'SELECT time, open FROM door ORDER BY time DESC LIMIT 1';
|
||||
/**
|
||||
* @return array{time: int, open: bool}
|
||||
*/
|
||||
public function getCurrent(): array {
|
||||
$query = "SELECT time, open FROM door ORDER BY time DESC LIMIT 1";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->execute();
|
||||
$row = $statement->fetch();
|
||||
|
||||
return [
|
||||
'time' => (int) $row['time'],
|
||||
'open' => (bool) $row['open'],
|
||||
"time" => (int) $row["time"],
|
||||
"open" => (bool) $row["open"],
|
||||
];
|
||||
}
|
||||
|
||||
private function removeOld(): void {
|
||||
$firstValidTime = time() - 60 * 60 * 24 * 7; // One week before now
|
||||
$query = 'DELETE FROM door WHERE time < :firstValid';
|
||||
$query = "DELETE FROM door WHERE time < :firstValid";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':firstValid', $firstValidTime, \PDO::PARAM_STR);
|
||||
$statement->bindParam(":firstValid", $firstValidTime, \PDO::PARAM_STR);
|
||||
$statement->execute();
|
||||
}
|
||||
|
||||
public function createEvent($time, $open): void {
|
||||
$query = 'INSERT INTO door(time, open) VALUES (:time, :open)';
|
||||
public function createEvent(DateTimeImmutable $time, bool $open): void {
|
||||
$query = "INSERT INTO door(time, open) VALUES (:time, :open)";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':time', $time, \PDO::PARAM_STR);
|
||||
$statement->bindParam(':open', $open, \PDO::PARAM_STR);
|
||||
$statement->bindParam(":time", $time, \PDO::PARAM_STR);
|
||||
$statement->bindParam(":open", $open, \PDO::PARAM_STR);
|
||||
$statement->execute();
|
||||
|
||||
$this->removeOld();
|
||||
|
||||
@@ -5,51 +5,58 @@ declare(strict_types=1);
|
||||
namespace pvv\side;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
|
||||
abstract class Event {
|
||||
private $start;
|
||||
private DateTimeImmutable $start;
|
||||
|
||||
public function __construct(\DateTimeImmutable $start) {
|
||||
public function __construct(DateTimeImmutable $start) {
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
public function getStart() {
|
||||
public function getStart(): DateTimeImmutable {
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
public function getRelativeDate() {
|
||||
public function getRelativeDate(): string {
|
||||
if (Agenda::isToday($this->getStart())) {
|
||||
return 'i dag';
|
||||
return "i dag";
|
||||
}
|
||||
if (Agenda::isTomorrow($this->getStart())) {
|
||||
return 'i morgen';
|
||||
return "i morgen";
|
||||
}
|
||||
if (Agenda::isThisWeek($this->getStart()) || $this->getStart()->sub(new \DateInterval('P4D'))->getTimestamp() < time()) {
|
||||
return $this->getStart()->format('l');
|
||||
if (
|
||||
Agenda::isThisWeek($this->getStart()) ||
|
||||
$this->getStart()->sub(new DateInterval("P4D"))->getTimestamp() < time()
|
||||
) {
|
||||
return $this->getStart()->format("l");
|
||||
}
|
||||
if (Agenda::isNextWeek($this->getStart())) {
|
||||
return 'neste uke';
|
||||
return "neste uke";
|
||||
}
|
||||
if (Agenda::isThisMonth($this->getStart())) {
|
||||
return 'denne måneden';
|
||||
return "denne måneden";
|
||||
}
|
||||
|
||||
return $this->getStart()->format('j. F');
|
||||
return $this->getStart()->format("j. F");
|
||||
}
|
||||
|
||||
abstract public function getStop(); /* : DateTimeImmutable */
|
||||
abstract public function getStop(): DateTimeImmutable;
|
||||
|
||||
abstract public function getName();
|
||||
abstract public function getName(): string;
|
||||
|
||||
abstract public function getLocation();
|
||||
abstract public function getLocation(): string;
|
||||
|
||||
abstract public function getOrganiser();
|
||||
abstract public function getOrganiser(): string;
|
||||
|
||||
abstract public function getURL(); /* : string */
|
||||
abstract public function getURL(): string;
|
||||
|
||||
abstract public function getImageURL(); /* : string */
|
||||
abstract public function getImageURL(): string;
|
||||
|
||||
abstract public function getDescription(); /* : string */
|
||||
/*
|
||||
* @return string[]
|
||||
*/
|
||||
abstract public function getDescription(): array;
|
||||
|
||||
abstract public function getColor(); /* : string */
|
||||
abstract public function getColor(): string;
|
||||
}
|
||||
|
||||
@@ -4,44 +4,53 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side;
|
||||
|
||||
use PDO;
|
||||
|
||||
class MOTD {
|
||||
private $pdo;
|
||||
|
||||
public function __construct($pdo) {
|
||||
public function __construct(PDO $pdo) {
|
||||
$this->pdo = $pdo;
|
||||
}
|
||||
|
||||
public function setMOTD($title, $content): void {
|
||||
public function setMOTD(string $title, string $content): void {
|
||||
if (\is_array($content)) {
|
||||
$content = implode('_', $content);
|
||||
$content = implode("_", $content);
|
||||
}
|
||||
$query = 'INSERT INTO motd(title, content) VALUES (:title, :content);';
|
||||
$query = "INSERT INTO motd(title, content) VALUES (:title, :content);";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
|
||||
$statement->bindParam(':title', $title, \PDO::PARAM_STR);
|
||||
$statement->bindParam(':content', $content, \PDO::PARAM_STR);
|
||||
$statement->bindParam(":title", $title, \PDO::PARAM_STR);
|
||||
$statement->bindParam(":content", $content, \PDO::PARAM_STR);
|
||||
|
||||
$statement->execute();
|
||||
}
|
||||
|
||||
public function getMOTD() {
|
||||
$query = 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT 1';
|
||||
/**
|
||||
* @return array{title: string, content: string[]}
|
||||
*/
|
||||
public function getMOTD(): array {
|
||||
$query =
|
||||
"SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT 1";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
$data = $statement->fetch();
|
||||
|
||||
return ['title' => $data[0], 'content' => explode("\n", $data[1])];
|
||||
return ["title" => $data[0], "content" => explode("\n", $data[1])];
|
||||
}
|
||||
|
||||
public function getMOTD_history($limit = 5) {
|
||||
$query = 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT :limit';
|
||||
/**
|
||||
* @return array{title: string, content: string[]}
|
||||
*/
|
||||
public function getMOTD_history(int $limit = 5): array {
|
||||
$query =
|
||||
"SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT :limit";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':limit', $limit, \PDO::PARAM_STR);
|
||||
$statement->bindParam(":limit", $limit, \PDO::PARAM_STR);
|
||||
$statement->execute();
|
||||
|
||||
$data = $statement->fetch();
|
||||
|
||||
return ['title' => $data[0], 'content' => explode("\n", $data[1])];
|
||||
return ["title" => $data[0], "content" => explode("\n", $data[1])];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,31 +5,36 @@ declare(strict_types=1);
|
||||
namespace pvv\side;
|
||||
|
||||
class Project {
|
||||
private $id;
|
||||
private $name;
|
||||
private $descr;
|
||||
private $active;
|
||||
private int $id;
|
||||
private string $name;
|
||||
private array $descr;
|
||||
private bool $active;
|
||||
|
||||
public function __construct($id, $name, $descr, $active) {
|
||||
public function __construct(
|
||||
int $id,
|
||||
string $name,
|
||||
string $descr,
|
||||
bool $active,
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->descr = explode("\n", $descr);
|
||||
$this->active = $active;
|
||||
}
|
||||
|
||||
public function getID() {
|
||||
public function getID(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
public function getName(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
public function getDescription(): array {
|
||||
return $this->descr;
|
||||
}
|
||||
|
||||
public function getActive() {
|
||||
public function getActive(): bool {
|
||||
return $this->active;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side;
|
||||
|
||||
use PDO;
|
||||
|
||||
class ProjectManager {
|
||||
private $pdo;
|
||||
|
||||
@@ -11,18 +13,21 @@ class ProjectManager {
|
||||
$this->pdo = $pdo;
|
||||
}
|
||||
|
||||
public function getAll() {
|
||||
$query = 'SELECT * FROM projects ORDER BY id ASC';
|
||||
/**
|
||||
* @return Project[]
|
||||
*/
|
||||
public function getAll(): array {
|
||||
$query = "SELECT * FROM projects ORDER BY id ASC";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
$projects = [];
|
||||
foreach ($statement->fetchAll() as $dbProj) {
|
||||
$project = new Project(
|
||||
$dbProj['id'],
|
||||
$dbProj['name'],
|
||||
$dbProj['description'],
|
||||
$dbProj['active']
|
||||
$dbProj["id"],
|
||||
$dbProj["name"],
|
||||
$dbProj["description"],
|
||||
$dbProj["active"],
|
||||
);
|
||||
$projects[] = $project;
|
||||
}
|
||||
@@ -30,47 +35,50 @@ class ProjectManager {
|
||||
return $projects;
|
||||
}
|
||||
|
||||
public function getByID($id) {
|
||||
$query = 'SELECT * FROM projects WHERE id=:id LIMIT 1';
|
||||
public function getByID(int $id): ?Project {
|
||||
$query = "SELECT * FROM projects WHERE id=:id LIMIT 1";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':id', $id, \PDO::PARAM_INT);
|
||||
$statement->bindParam(":id", $id, \PDO::PARAM_INT);
|
||||
$statement->execute();
|
||||
|
||||
$dbProj = $statement->fetch();
|
||||
if (!$dbProj) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Project(
|
||||
$dbProj['id'],
|
||||
$dbProj['name'],
|
||||
$dbProj['description'],
|
||||
$dbProj['active']
|
||||
$dbProj["id"],
|
||||
$dbProj["name"],
|
||||
$dbProj["description"],
|
||||
$dbProj["active"],
|
||||
);
|
||||
}
|
||||
|
||||
public function getByOwner($uname) {
|
||||
$query = 'SELECT projectid FROM projectmembers WHERE uname=:uname';
|
||||
/**
|
||||
* @return Project[]
|
||||
*/
|
||||
public function getByOwner(string $uname): array {
|
||||
$query = "SELECT projectid FROM projectmembers WHERE uname=:uname";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':uname', $uname, \PDO::PARAM_STR);
|
||||
$statement->bindParam(":uname", $uname, \PDO::PARAM_STR);
|
||||
$statement->execute();
|
||||
|
||||
$projectIDs = $statement->fetchAll();
|
||||
$projects = [];
|
||||
foreach ($projectIDs as $id) {
|
||||
$id = $id['projectid'];
|
||||
$id = $id["projectid"];
|
||||
|
||||
$query = 'SELECT * FROM projects WHERE id=:id';
|
||||
$query = "SELECT * FROM projects WHERE id=:id";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':id', $id, \PDO::PARAM_INT);
|
||||
$statement->bindParam(":id", $id, \PDO::PARAM_INT);
|
||||
$statement->execute();
|
||||
|
||||
foreach ($statement->fetchAll() as $dbProj) {
|
||||
$project = new Project(
|
||||
$dbProj['id'],
|
||||
$dbProj['name'],
|
||||
$dbProj['description'],
|
||||
$dbProj['active']
|
||||
$dbProj["id"],
|
||||
$dbProj["name"],
|
||||
$dbProj["description"],
|
||||
$dbProj["active"],
|
||||
);
|
||||
$projects[] = $project;
|
||||
}
|
||||
@@ -79,42 +87,48 @@ class ProjectManager {
|
||||
return $projects;
|
||||
}
|
||||
|
||||
public function getProjectMembers($id) {
|
||||
$query = 'SELECT * FROM projectmembers WHERE projectid=:id';
|
||||
/**
|
||||
* @return array<int,array>
|
||||
*/
|
||||
public function getProjectMembers(int $id): array {
|
||||
$query = "SELECT * FROM projectmembers WHERE projectid=:id";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':id', $id, \PDO::PARAM_STR);
|
||||
$statement->bindParam(":id", $id, \PDO::PARAM_STR);
|
||||
$statement->execute();
|
||||
|
||||
$members = [];
|
||||
foreach ($statement->fetchAll() as $dbUsr) {
|
||||
$members[] = [
|
||||
'name' => $dbUsr['name'],
|
||||
'uname' => $dbUsr['uname'],
|
||||
'mail' => $dbUsr['mail'],
|
||||
'role' => $dbUsr['role'],
|
||||
'lead' => $dbUsr['lead'],
|
||||
'owner' => $dbUsr['owner'],
|
||||
"name" => $dbUsr["name"],
|
||||
"uname" => $dbUsr["uname"],
|
||||
"mail" => $dbUsr["mail"],
|
||||
"role" => $dbUsr["role"],
|
||||
"lead" => $dbUsr["lead"],
|
||||
"owner" => $dbUsr["owner"],
|
||||
];
|
||||
}
|
||||
|
||||
return $members;
|
||||
}
|
||||
|
||||
public function getProjectOwner($id) {
|
||||
$query = 'SELECT * FROM projectmembers WHERE (projectid=:id AND owner=1)';
|
||||
/**
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function getProjectOwner(int $id): array {
|
||||
$query = "SELECT * FROM projectmembers WHERE (projectid=:id AND owner=1)";
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':id', $id, \PDO::PARAM_STR);
|
||||
$statement->bindParam(":id", $id, \PDO::PARAM_STR);
|
||||
$statement->execute();
|
||||
|
||||
$dbOwner = $statement->fetch();
|
||||
|
||||
return [
|
||||
'name' => $dbOwner['name'],
|
||||
'uname' => $dbOwner['uname'],
|
||||
'mail' => $dbOwner['mail'],
|
||||
'role' => $dbOwner['role'],
|
||||
'lead' => $dbOwner['lead'],
|
||||
'owner' => $dbOwner['owner'],
|
||||
"name" => $dbOwner["name"],
|
||||
"uname" => $dbOwner["uname"],
|
||||
"mail" => $dbOwner["mail"],
|
||||
"role" => $dbOwner["role"],
|
||||
"lead" => $dbOwner["lead"],
|
||||
"owner" => $dbOwner["owner"],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,27 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side;
|
||||
|
||||
class SimpleEvent extends Event {
|
||||
private $id;
|
||||
private $name;
|
||||
private $descr;
|
||||
private $start;
|
||||
private $end;
|
||||
private $org;
|
||||
private $loc;
|
||||
use DateTimeImmutable;
|
||||
|
||||
public function __construct($id, $name, \DateTimeImmutable $start, \DateTimeImmutable $end, $org, $loc, $descr, $_isDBEvent = false) {
|
||||
class SimpleEvent extends Event {
|
||||
private int $id;
|
||||
private string $name;
|
||||
private array $descr;
|
||||
private DateTimeImmutable $start;
|
||||
private DateTimeImmutable $end;
|
||||
private string $org;
|
||||
private string $loc;
|
||||
|
||||
public function __construct(
|
||||
int $id,
|
||||
string $name,
|
||||
\DateTimeImmutable $start,
|
||||
\DateTimeImmutable $end,
|
||||
string $org,
|
||||
string $loc,
|
||||
string $descr,
|
||||
bool $_isDBEvent = false,
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->start = $start;
|
||||
@@ -23,41 +34,43 @@ class SimpleEvent extends Event {
|
||||
$this->descr = explode("\n", $descr);
|
||||
}
|
||||
|
||||
public function getID() {
|
||||
public function getID(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getStart() {
|
||||
public function getStart(): DateTimeImmutable {
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
public function getStop() {
|
||||
public function getStop(): DateTimeImmutable {
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
public function getOrganiser() {
|
||||
public function getOrganiser(): string {
|
||||
return $this->org;
|
||||
}
|
||||
|
||||
public function getLocation() {
|
||||
public function getLocation(): string {
|
||||
return $this->loc;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
public function getName(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getURL() {
|
||||
return '/hendelser/info.php?id=' . $this->id;
|
||||
public function getURL(): string {
|
||||
return "/hendelser/info.php?id=" . $this->id;
|
||||
}
|
||||
|
||||
public function getImageURL(): void {}
|
||||
public function getImageURL(): string {
|
||||
return "/";
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
public function getDescription(): array {
|
||||
return $this->descr;
|
||||
}
|
||||
|
||||
public function getColor() {
|
||||
return '#3b7';
|
||||
public function getColor(): string {
|
||||
return "#3b7";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,38 +4,51 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side\social;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use pvv\side\Activity;
|
||||
|
||||
class AnimekveldActivity implements Activity {
|
||||
public function nextDate(\DateTimeImmutable $date) {
|
||||
if (intval($date->format('H')) > 20 || intval($date->format('H')) === 19 && intval($date->format('i')) > 30) {
|
||||
return $this->nextDate($date->add(new \DateInterval('P1D'))->setTime(19, 30, 0));
|
||||
public function nextDate(\DateTimeImmutable $date): DateTimeImmutable {
|
||||
if (
|
||||
intval($date->format("H")) > 20 ||
|
||||
(intval($date->format("H")) === 19 && intval($date->format("i")) > 30)
|
||||
) {
|
||||
return $this->nextDate(
|
||||
$date->add(new \DateInterval("P1D"))->setTime(19, 30, 0),
|
||||
);
|
||||
}
|
||||
$date = $date->setTime(19, 30, 0);
|
||||
if (intval($date->format('N')) !== 5) {
|
||||
return $this->nextDate($date->add(new \DateInterval('P1D')));
|
||||
if (intval($date->format("N")) !== 5) {
|
||||
return $this->nextDate($date->add(new \DateInterval("P1D")));
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function prevDate(\DateTimeImmutable $date) {
|
||||
if (intval($date->format('H')) < 19 || intval($date->format('H')) === 20 && intval($date->format('i')) < 30) {
|
||||
return $this->prevDate($date->sub(new \DateInterval('P1D'))->setTime(19, 30, 0));
|
||||
public function prevDate(\DateTimeImmutable $date): DateTimeImmutable {
|
||||
if (
|
||||
intval($date->format("H")) < 19 ||
|
||||
(intval($date->format("H")) === 20 && intval($date->format("i")) < 30)
|
||||
) {
|
||||
return $this->prevDate(
|
||||
$date->sub(new \DateInterval("P1D"))->setTime(19, 30, 0),
|
||||
);
|
||||
}
|
||||
$date = $date->setTime(19, 30, 0);
|
||||
if (intval($date->format('N')) !== 5) {
|
||||
return $this->prevDate($date->sub(new \DateInterval('P1D')));
|
||||
if (intval($date->format("N")) !== 5) {
|
||||
return $this->prevDate($date->sub(new \DateInterval("P1D")));
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function getNextEventFrom(\DateTimeImmutable $date) { /* : Event */
|
||||
public function getNextEventFrom(\DateTimeImmutable $date): AnimekveldEvent {
|
||||
return new AnimekveldEvent($this->nextDate($date));
|
||||
}
|
||||
|
||||
public function getPreviousEventFrom(\DateTimeImmutable $date) { /* : Event */
|
||||
public function getPreviousEventFrom(
|
||||
\DateTimeImmutable $date,
|
||||
): AnimekveldEvent {
|
||||
return new AnimekveldEvent($this->prevDate($date));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,44 +4,46 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side\social;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use pvv\side\Event;
|
||||
|
||||
class AnimekveldEvent extends Event {
|
||||
public function getStop() {
|
||||
return $this->getStart()->add(new \DateInterval('PT4H1800S'));
|
||||
public function getStop(): DateTimeImmutable {
|
||||
return $this->getStart()->add(new \DateInterval("PT4H1800S"));
|
||||
}
|
||||
|
||||
public function getName() { /* : string */
|
||||
return 'Animekveld';
|
||||
public function getName(): string {
|
||||
return "Animekveld";
|
||||
}
|
||||
|
||||
public function getLocation() { /* : Location */
|
||||
return 'Koserommet';
|
||||
public function getLocation(): string {
|
||||
/* : Location */
|
||||
return "Koserommet";
|
||||
}
|
||||
|
||||
public function getOrganiser() { /* : User */
|
||||
return 'Christoffer Viken';
|
||||
public function getOrganiser(): string {
|
||||
return "Christoffer Viken";
|
||||
}
|
||||
|
||||
public function getURL() { /* : string */
|
||||
return '/anime/';
|
||||
public function getURL(): string {
|
||||
return "/anime/";
|
||||
}
|
||||
|
||||
public function getImageURL() {
|
||||
return '/sosiale/animekveld.jpg';
|
||||
public function getImageURL(): string {
|
||||
return "/sosiale/animekveld.jpg";
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
public function getDescription(): array {
|
||||
return [
|
||||
'Er du glad i japanske tegneserier eller bare nysgjerrig på hva anime er?',
|
||||
'Bli med oss hver fredag, der vi finner frem de nyeste episodene for sesongen!',
|
||||
'',
|
||||
'Alle kan være med på å anbefale eller veto serier.',
|
||||
'',
|
||||
"Er du glad i japanske tegneserier eller bare nysgjerrig på hva anime er?",
|
||||
"Bli med oss hver fredag, der vi finner frem de nyeste episodene for sesongen!",
|
||||
"",
|
||||
"Alle kan være med på å anbefale eller veto serier.",
|
||||
"",
|
||||
];
|
||||
}
|
||||
|
||||
public function getColor() {
|
||||
return '#35a';
|
||||
public function getColor(): string {
|
||||
return "#35a";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,41 +7,53 @@ namespace pvv\side\social;
|
||||
use pvv\side\Activity;
|
||||
|
||||
class BrettspillActivity implements Activity {
|
||||
public function nextDate(\DateTimeImmutable $date) {
|
||||
if (intval($date->format('H')) > 17 || intval($date->format('H')) === 16 && intval($date->format('i')) > 15) {
|
||||
return $this->nextDate($date->add(new \DateInterval('P1D'))->setTime(16, 15, 0));
|
||||
public function nextDate(\DateTimeImmutable $date): \DateTimeImmutable {
|
||||
if (
|
||||
intval($date->format("H")) > 17 ||
|
||||
(intval($date->format("H")) === 16 && intval($date->format("i")) > 15)
|
||||
) {
|
||||
return $this->nextDate(
|
||||
$date->add(new \DateInterval("P1D"))->setTime(16, 15, 0),
|
||||
);
|
||||
}
|
||||
$date = $date->setTime(16, 15, 0);
|
||||
if (intval($date->format('N')) !== 7) {
|
||||
return $this->nextDate($date->add(new \DateInterval('P1D')));
|
||||
if (intval($date->format("N")) !== 7) {
|
||||
return $this->nextDate($date->add(new \DateInterval("P1D")));
|
||||
}
|
||||
if (intval($date->format('W')) % 2 - 1) {
|
||||
return $this->nextDate($date->add(new \DateInterval('P7D')));
|
||||
if ((intval($date->format("W")) % 2) - 1) {
|
||||
return $this->nextDate($date->add(new \DateInterval("P7D")));
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function prevDate(\DateTimeImmutable $date) {
|
||||
if (intval($date->format('H')) < 16 || intval($date->format('H')) === 17 && intval($date->format('i')) < 15) {
|
||||
return $this->prevDate($date->sub(new \DateInterval('P1D'))->setTime(16, 15, 0));
|
||||
public function prevDate(\DateTimeImmutable $date): \DateTimeImmutable {
|
||||
if (
|
||||
intval($date->format("H")) < 16 ||
|
||||
(intval($date->format("H")) === 17 && intval($date->format("i")) < 15)
|
||||
) {
|
||||
return $this->prevDate(
|
||||
$date->sub(new \DateInterval("P1D"))->setTime(16, 15, 0),
|
||||
);
|
||||
}
|
||||
$date = $date->setTime(16, 15, 0);
|
||||
if (intval($date->format('N')) !== 7) {
|
||||
return $this->prevDate($date->sub(new \DateInterval('P1D')));
|
||||
if (intval($date->format("N")) !== 7) {
|
||||
return $this->prevDate($date->sub(new \DateInterval("P1D")));
|
||||
}
|
||||
if (intval($date->format('W')) % 2 - 1) {
|
||||
return $this->prevDate($date->sub(new \DateInterval('P7D')));
|
||||
if ((intval($date->format("W")) % 2) - 1) {
|
||||
return $this->prevDate($date->sub(new \DateInterval("P7D")));
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function getNextEventFrom(\DateTimeImmutable $date) { /* : Event */
|
||||
public function getNextEventFrom(\DateTimeImmutable $date): BrettspillEvent {
|
||||
return new BrettspillEvent($this->nextDate($date));
|
||||
}
|
||||
|
||||
public function getPreviousEventFrom(\DateTimeImmutable $date) { /* : Event */
|
||||
public function getPreviousEventFrom(
|
||||
\DateTimeImmutable $date,
|
||||
): BrettspillEvent {
|
||||
return new BrettspillEvent($this->prevDate($date));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,61 +4,62 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side\social;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use pvv\side\Event;
|
||||
|
||||
class BrettspillEvent extends Event {
|
||||
public function getStop() {
|
||||
return $this->getStart()->add(new \DateInterval('PT4H1800S'));
|
||||
public function getStop(): DateTimeImmutable {
|
||||
return $this->getStart()->add(new \DateInterval("PT4H1800S"));
|
||||
}
|
||||
|
||||
public function getName() { /* : string */
|
||||
return 'Brettspillkveld';
|
||||
public function getName(): string {
|
||||
return "Brettspillkveld";
|
||||
}
|
||||
|
||||
public function getLocation() { /* : Location */
|
||||
return 'Programvareverkstedet';
|
||||
public function getLocation(): string {
|
||||
return "Programvareverkstedet";
|
||||
}
|
||||
|
||||
public function getOrganiser() { /* : User */
|
||||
return 'Programvareverkstedet';
|
||||
public function getOrganiser(): string {
|
||||
return "Programvareverkstedet";
|
||||
}
|
||||
|
||||
public function getURL() { /* : string */
|
||||
return '/brettspill/';
|
||||
public function getURL(): string {
|
||||
return "/brettspill/";
|
||||
}
|
||||
|
||||
public function getImageURL() {
|
||||
return '/sosiale/brettspill.jpg';
|
||||
public function getImageURL(): string {
|
||||
return "/sosiale/brettspill.jpg";
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
public function getDescription(): array {
|
||||
return [
|
||||
'Er du en hardcore brettspillentusiast eller en nybegynner som har så vidt spilt ludo? ' .
|
||||
'Da er vår brettspillkveld noe for deg! ' .
|
||||
'Vi tar ut et par spill fra vårt samling of spiller så mye vi orker. Kom innom!',
|
||||
'',
|
||||
'## Vår samling',
|
||||
'',
|
||||
'* Dominion\*',
|
||||
'* Three cheers for master',
|
||||
'* Avalon',
|
||||
'* Hanabi',
|
||||
'* Cards aginst humanity\*',
|
||||
'* Citadels',
|
||||
'* Munchkin\*\*',
|
||||
'* Exploding kittens\*\*',
|
||||
'* Aye dark overlord',
|
||||
'* Settlers of catan\*',
|
||||
'* Risk\*\*',
|
||||
'* og mange flere...',
|
||||
'',
|
||||
'\* Vi har flere ekspansjoner til spillet',
|
||||
'',
|
||||
'\*\* Vi har flere varianter av spillet',
|
||||
"Er du en hardcore brettspillentusiast eller en nybegynner som har så vidt spilt ludo? " .
|
||||
"Da er vår brettspillkveld noe for deg! " .
|
||||
"Vi tar ut et par spill fra vårt samling of spiller så mye vi orker. Kom innom!",
|
||||
"",
|
||||
"## Vår samling",
|
||||
"",
|
||||
"* Dominion\*",
|
||||
"* Three cheers for master",
|
||||
"* Avalon",
|
||||
"* Hanabi",
|
||||
"* Cards aginst humanity\*",
|
||||
"* Citadels",
|
||||
"* Munchkin\*\*",
|
||||
"* Exploding kittens\*\*",
|
||||
"* Aye dark overlord",
|
||||
"* Settlers of catan\*",
|
||||
"* Risk\*\*",
|
||||
"* og mange flere...",
|
||||
"",
|
||||
"\* Vi har flere ekspansjoner til spillet",
|
||||
"",
|
||||
"\*\* Vi har flere varianter av spillet",
|
||||
];
|
||||
}
|
||||
|
||||
public function getColor() {
|
||||
return '#000';
|
||||
public function getColor(): string {
|
||||
return "#000";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,44 +4,57 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side\social;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use pvv\side\Activity;
|
||||
|
||||
class DriftkveldActivity implements Activity {
|
||||
public function nextDate(\DateTimeImmutable $date) {
|
||||
if (intval($date->format('H')) > 18 || intval($date->format('H')) === 17 && intval($date->format('i')) > 30) {
|
||||
return $this->nextDate($date->add(new \DateInterval('P1D'))->setTime(18, 15, 0));
|
||||
public function nextDate(\DateTimeImmutable $date): DateTimeImmutable {
|
||||
if (
|
||||
intval($date->format("H")) > 18 ||
|
||||
(intval($date->format("H")) === 17 && intval($date->format("i")) > 30)
|
||||
) {
|
||||
return $this->nextDate(
|
||||
$date->add(new \DateInterval("P1D"))->setTime(18, 15, 0),
|
||||
);
|
||||
}
|
||||
$date = $date->setTime(18, 15, 0);
|
||||
if (intval($date->format('N')) !== 6) {
|
||||
return $this->nextDate($date->add(new \DateInterval('P1D')));
|
||||
if (intval($date->format("N")) !== 6) {
|
||||
return $this->nextDate($date->add(new \DateInterval("P1D")));
|
||||
}
|
||||
if (intval($date->format('W')) % 2 - 1) {
|
||||
return $this->nextDate($date->add(new \DateInterval('P7D')));
|
||||
if ((intval($date->format("W")) % 2) - 1) {
|
||||
return $this->nextDate($date->add(new \DateInterval("P7D")));
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function prevDate(\DateTimeImmutable $date) {
|
||||
if (intval($date->format('H')) < 17 || intval($date->format('H')) === 18 && intval($date->format('i')) < 30) {
|
||||
return $this->prevDate($date->sub(new \DateInterval('P1D'))->setTime(18, 15, 0));
|
||||
public function prevDate(\DateTimeImmutable $date): DateTimeImmutable {
|
||||
if (
|
||||
intval($date->format("H")) < 17 ||
|
||||
(intval($date->format("H")) === 18 && intval($date->format("i")) < 30)
|
||||
) {
|
||||
return $this->prevDate(
|
||||
$date->sub(new \DateInterval("P1D"))->setTime(18, 15, 0),
|
||||
);
|
||||
}
|
||||
$date = $date->setTime(18, 15, 0);
|
||||
if (intval($date->format('N')) !== 6) {
|
||||
return $this->prevDate($date->sub(new \DateInterval('P1D')));
|
||||
if (intval($date->format("N")) !== 6) {
|
||||
return $this->prevDate($date->sub(new \DateInterval("P1D")));
|
||||
}
|
||||
if (intval($date->format('W')) % 2 - 1) {
|
||||
return $this->prevDate($date->sub(new \DateInterval('P7D')));
|
||||
if ((intval($date->format("W")) % 2) - 1) {
|
||||
return $this->prevDate($date->sub(new \DateInterval("P7D")));
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function getNextEventFrom(\DateTimeImmutable $date) { /* : Event */
|
||||
public function getNextEventFrom(\DateTimeImmutable $date): DriftkveldEvent {
|
||||
return new DriftkveldEvent($this->nextDate($date));
|
||||
}
|
||||
|
||||
public function getPreviousEventFrom(\DateTimeImmutable $date) { /* : Event */
|
||||
public function getPreviousEventFrom(
|
||||
\DateTimeImmutable $date,
|
||||
): DriftkveldEvent {
|
||||
return new DriftkveldEvent($this->prevDate($date));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,34 +4,35 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side\social;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use pvv\side\Event;
|
||||
|
||||
class DriftkveldEvent extends Event {
|
||||
public function getStop() {
|
||||
public function getStop(): DateTimeImmutable {
|
||||
return $this->getStart()->add(new \DateInterval('PT4H1800S'));
|
||||
}
|
||||
|
||||
public function getName() { /* : string */
|
||||
public function getName(): string {
|
||||
return 'Driftkveld';
|
||||
}
|
||||
|
||||
public function getLocation() { /* : Location */
|
||||
public function getLocation(): string {
|
||||
return 'Terminalrommet / Discord / IRC';
|
||||
}
|
||||
|
||||
public function getOrganiser() { /* : User */
|
||||
public function getOrganiser(): string {
|
||||
return 'Torstein Nordgård-Hansen';
|
||||
}
|
||||
|
||||
public function getURL() { /* : string */
|
||||
public function getURL(): string {
|
||||
return '/driftkveld/';
|
||||
}
|
||||
|
||||
public function getImageURL() {
|
||||
public function getImageURL(): string {
|
||||
return '/sosiale/drift.jpg';
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
public function getDescription(): array {
|
||||
return [
|
||||
'Vil du drifte?',
|
||||
'Vil du være kul kis TM?',
|
||||
@@ -42,7 +43,7 @@ class DriftkveldEvent extends Event {
|
||||
];
|
||||
}
|
||||
|
||||
public function getColor() {
|
||||
public function getColor(): string {
|
||||
return '#35a';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side\social;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use pvv\side\Activity;
|
||||
|
||||
class HackekveldActivity implements Activity {
|
||||
public function nextDate(\DateTimeImmutable $date) {
|
||||
public function nextDate(\DateTimeImmutable $date): DateTimeImmutable {
|
||||
if (intval($date->format('H')) > 18 || intval($date->format('H')) === 17 && intval($date->format('i')) > 30) {
|
||||
return $this->nextDate($date->add(new \DateInterval('P1D'))->setTime(18, 15, 0));
|
||||
}
|
||||
@@ -22,7 +23,7 @@ class HackekveldActivity implements Activity {
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function prevDate(\DateTimeImmutable $date) {
|
||||
public function prevDate(\DateTimeImmutable $date): DateTimeImmutable {
|
||||
if (intval($date->format('H')) < 17 || intval($date->format('H')) === 18 && intval($date->format('i')) < 30) {
|
||||
return $this->prevDate($date->sub(new \DateInterval('P1D'))->setTime(18, 15, 0));
|
||||
}
|
||||
@@ -37,11 +38,11 @@ class HackekveldActivity implements Activity {
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function getNextEventFrom(\DateTimeImmutable $date) { /* : Event */
|
||||
public function getNextEventFrom(\DateTimeImmutable $date): HackekveldEvent {
|
||||
return new HackekveldEvent($this->nextDate($date));
|
||||
}
|
||||
|
||||
public function getPreviousEventFrom(\DateTimeImmutable $date) { /* : Event */
|
||||
public function getPreviousEventFrom(\DateTimeImmutable $date): HackekveldEvent {
|
||||
return new HackekveldEvent($this->prevDate($date));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,41 +4,42 @@ declare(strict_types=1);
|
||||
|
||||
namespace pvv\side\social;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use pvv\side\Event;
|
||||
|
||||
class HackekveldEvent extends Event {
|
||||
public function getStop() {
|
||||
public function getStop(): DateTimeImmutable {
|
||||
return $this->getStart()->add(new \DateInterval('PT4H1800S'));
|
||||
}
|
||||
|
||||
public function getName() { /* : string */
|
||||
public function getName(): string {
|
||||
return 'Hackekveld';
|
||||
}
|
||||
|
||||
public function getLocation() { /* : Location */
|
||||
public function getLocation(): string {
|
||||
return 'Terminalrommet / Discord / IRC';
|
||||
}
|
||||
|
||||
public function getOrganiser() { /* : User */
|
||||
public function getOrganiser(): string {
|
||||
return 'PVV';
|
||||
}
|
||||
|
||||
public function getURL() { /* : string */
|
||||
public function getURL(): string {
|
||||
return '#';
|
||||
}
|
||||
|
||||
public function getImageURL() {
|
||||
public function getImageURL(): string {
|
||||
return '/pvv-logo.png';
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
public function getDescription(): array {
|
||||
return [
|
||||
'Mange PVV-medlemmer liker å programmere.',
|
||||
'Hvis du også liker å programmere, så bli med! Her kan du jobbe med dine egne prosjekter eller starte noe med andre nerder her på huset. Vi møtes for en hyggelig prat, mye god programmering og delsponset pizza.',
|
||||
];
|
||||
}
|
||||
|
||||
public function getColor() {
|
||||
public function getColor(): string {
|
||||
return '#35a';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@ declare(strict_types=1);
|
||||
namespace pvv\side\social;
|
||||
|
||||
use pvv\side\Activity;
|
||||
use pvv\side\Event;
|
||||
|
||||
class NerdepitsaActivity implements Activity {
|
||||
public function nextDate(\DateTimeImmutable $date) {
|
||||
public function nextDate(\DateTimeImmutable $date): \DateTimeImmutable {
|
||||
if (intval($date->format('H')) > 19) {
|
||||
return $this->nextDate($date->add(new \DateInterval('P1D'))->setTime(19, 0, 0));
|
||||
}
|
||||
@@ -22,7 +23,7 @@ class NerdepitsaActivity implements Activity {
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function prevDate(\DateTimeImmutable $date) {
|
||||
public function prevDate(\DateTimeImmutable $date): \DateTimeImmutable {
|
||||
if (intval($date->format('H')) < 19) {
|
||||
return $this->prevDate($date->sub(new \DateInterval('P1D'))->setTime(19, 0, 0));
|
||||
}
|
||||
@@ -37,11 +38,11 @@ class NerdepitsaActivity implements Activity {
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function getNextEventFrom(\DateTimeImmutable $date) { /* : Event */
|
||||
public function getNextEventFrom(\DateTimeImmutable $date): ?Event {
|
||||
return new NerdepitsaEvent($this->nextDate($date));
|
||||
}
|
||||
|
||||
public function getPreviousEventFrom(\DateTimeImmutable $date) { /* : Event */
|
||||
public function getPreviousEventFrom(\DateTimeImmutable $date): ?Event {
|
||||
return new NerdepitsaEvent($this->prevDate($date));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,31 +7,31 @@ namespace pvv\side\social;
|
||||
use pvv\side\Event;
|
||||
|
||||
class NerdepitsaEvent extends Event {
|
||||
public function getStop() {
|
||||
public function getStop(): \DateTimeImmutable {
|
||||
return $this->getStart()->add(new \DateInterval('PT2H1800S'));
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
public function getName(): string {
|
||||
return 'Nerdepitsa';
|
||||
}
|
||||
|
||||
public function getLocation() { /* : Location */
|
||||
public function getLocation(): string {
|
||||
return 'Peppes Kjøpmansgata';
|
||||
}
|
||||
|
||||
public function getOrganiser() { /* : User */
|
||||
public function getOrganiser(): string {
|
||||
return 'Anders Christensen';
|
||||
}
|
||||
|
||||
public function getURL() { /* : string */
|
||||
public function getURL(): string {
|
||||
return '/nerdepitsa/';
|
||||
}
|
||||
|
||||
public function getImageURL() {
|
||||
public function getImageURL(): string {
|
||||
return '/sosiale/nerdepitsa.jpg';
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
public function getDescription(): array {
|
||||
return [
|
||||
'Hei, har du lyst til å bli med på pizzaspising annenhver fredag? Vi møtes på Peppes i Kjøpmannsgata fredag klokken 19.00 hver partallsuke!',
|
||||
'',
|
||||
@@ -43,7 +43,7 @@ class NerdepitsaEvent extends Event {
|
||||
];
|
||||
}
|
||||
|
||||
public function getColor() {
|
||||
public function getColor(): string {
|
||||
return '#c35';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user