2022-06-20 19:52:31 +02:00
|
|
|
<?php
|
|
|
|
|
2022-11-18 18:06:46 +01:00
|
|
|
namespace Core\Objects\DatabaseEntity;
|
2022-06-20 19:52:31 +02:00
|
|
|
|
2023-01-05 22:47:17 +01:00
|
|
|
use Core\Driver\SQL\SQL;
|
2022-11-18 18:06:46 +01:00
|
|
|
use Core\Objects\DatabaseEntity\Attribute\MaxLength;
|
2022-11-20 17:13:53 +01:00
|
|
|
use Core\Objects\DatabaseEntity\Controller\DatabaseEntity;
|
2023-01-05 22:47:17 +01:00
|
|
|
use Core\Objects\DatabaseEntity\Controller\DatabaseEntityHandler;
|
|
|
|
use Core\Objects\DatabaseEntity\Controller\NMRelation;
|
2022-06-20 19:52:31 +02:00
|
|
|
|
|
|
|
class Group extends DatabaseEntity {
|
|
|
|
|
2022-11-20 17:13:53 +01:00
|
|
|
const ADMIN = 1;
|
|
|
|
const MODERATOR = 3;
|
|
|
|
const SUPPORT = 2;
|
|
|
|
|
|
|
|
const GROUPS = [
|
|
|
|
self::ADMIN => "Administrator",
|
|
|
|
self::MODERATOR => "Moderator",
|
|
|
|
self::SUPPORT => "Support",
|
|
|
|
];
|
|
|
|
|
2022-06-20 19:52:31 +02:00
|
|
|
#[MaxLength(32)] public string $name;
|
|
|
|
#[MaxLength(10)] public string $color;
|
|
|
|
|
2022-11-20 17:13:53 +01:00
|
|
|
public function __construct(?int $id, string $name, string $color) {
|
2022-06-20 19:52:31 +02:00
|
|
|
parent::__construct($id);
|
2022-11-20 17:13:53 +01:00
|
|
|
$this->name = $name;
|
|
|
|
$this->color = $color;
|
2022-06-20 19:52:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function jsonSerialize(): array {
|
|
|
|
return [
|
|
|
|
"id" => $this->getId(),
|
|
|
|
"name" => $this->name,
|
|
|
|
"color" => $this->color
|
|
|
|
];
|
|
|
|
}
|
2023-01-05 22:47:17 +01:00
|
|
|
|
|
|
|
public function getMembers(SQL $sql): array {
|
|
|
|
$nmTable = NMRelation::buildTableName(User::class, Group::class);
|
|
|
|
return User::findBy(User::createBuilder($sql, false)
|
|
|
|
->innerJoin($nmTable, "user_id", "User.id")
|
|
|
|
->whereEq("group_id", $this->id));
|
|
|
|
}
|
2022-06-20 19:52:31 +02:00
|
|
|
}
|