MAPG-203 add new table and model for multi_room
This commit is contained in:
parent
fc40c18679
commit
e5fb725c69
@ -0,0 +1,9 @@
|
||||
CREATE TABLE `multi_rooms` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`room_id` varchar(6) NOT NULL,
|
||||
`state` text NOT NULL,
|
||||
`members` text NOT NULL,
|
||||
`updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `room_id` (`room_id`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
88
src/PersistentData/Model/MultiRoom.php
Normal file
88
src/PersistentData/Model/MultiRoom.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php namespace MapGuesser\PersistentData\Model;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class MultiRoom extends Model
|
||||
{
|
||||
protected static string $table = 'multi_rooms';
|
||||
|
||||
protected static array $fields = ['room_id', 'state', 'members', 'updated'];
|
||||
|
||||
private string $roomId = '';
|
||||
|
||||
private array $state = [];
|
||||
|
||||
private array $members = [];
|
||||
|
||||
private DateTime $updated;
|
||||
|
||||
public function setRoomId(string $roomId): void
|
||||
{
|
||||
$this->roomId = $roomId;
|
||||
}
|
||||
|
||||
public function setStateArray(array $state): void
|
||||
{
|
||||
$this->state = $state;
|
||||
}
|
||||
|
||||
public function setMembersArray(array $members): void
|
||||
{
|
||||
$this->members = $members;
|
||||
}
|
||||
|
||||
public function setState(string $state): void
|
||||
{
|
||||
$this->state = unserialize($state);
|
||||
}
|
||||
|
||||
public function setMembers(string $members): void
|
||||
{
|
||||
$this->members = unserialize($members);
|
||||
}
|
||||
|
||||
public function setUpdatedDate(DateTime $updated): void
|
||||
{
|
||||
$this->updated = $updated;
|
||||
}
|
||||
|
||||
public function setUpdated(string $updated): void
|
||||
{
|
||||
$this->updated = new DateTime($updated);
|
||||
}
|
||||
|
||||
public function getRoomId(): string
|
||||
{
|
||||
return $this->roomId;
|
||||
}
|
||||
|
||||
public function getStateArray(): array
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
public function getState(): string
|
||||
{
|
||||
return serialize($this->state);
|
||||
}
|
||||
|
||||
public function getMembersArray(): array
|
||||
{
|
||||
return $this->members;
|
||||
}
|
||||
|
||||
public function getMembers(): string
|
||||
{
|
||||
return serialize($this->members);
|
||||
}
|
||||
|
||||
public function getUpdatedDate(): DateTime
|
||||
{
|
||||
return $this->updated;
|
||||
}
|
||||
|
||||
public function getUpdated(): string
|
||||
{
|
||||
return $this->updated->format('Y-m-d H:i:s');
|
||||
}
|
||||
}
|
38
src/Repository/MultiRoomRepository.php
Normal file
38
src/Repository/MultiRoomRepository.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php namespace MapGuesser\Repository;
|
||||
|
||||
use DateTime;
|
||||
use Generator;
|
||||
use MapGuesser\Database\Query\Select;
|
||||
use MapGuesser\PersistentData\Model\MultiRoom;
|
||||
use MapGuesser\PersistentData\PersistentDataManager;
|
||||
|
||||
class MultiRoomRepository
|
||||
{
|
||||
private PersistentDataManager $pdm;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->pdm = new PersistentDataManager();
|
||||
}
|
||||
|
||||
public function getById(int $id): ?MultiRoom
|
||||
{
|
||||
return $this->pdm->selectFromDbById($id, MultiRoom::class);
|
||||
}
|
||||
|
||||
public function getByRoomId(string $roomId): ?MultiRoom
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('room_id', '=', $roomId);
|
||||
|
||||
return $this->pdm->selectFromDb($select, MultiRoom::class);
|
||||
}
|
||||
|
||||
public function getAllExpired(): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('updated', '<', (new DateTime('-7 day'))->format('Y-m-d H:i:s'));
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, MultiRoom::class);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user