Updated data constructors.
This commit is contained in:
parent
fc46d04f78
commit
7321e72e89
8 changed files with 80 additions and 137 deletions
|
@ -3,6 +3,7 @@ namespace Makai;
|
||||||
|
|
||||||
use Index\Colour\Colour;
|
use Index\Colour\Colour;
|
||||||
use Index\Colour\ColourRGB;
|
use Index\Colour\ColourRGB;
|
||||||
|
use Index\Data\IDbResult;
|
||||||
|
|
||||||
class ContactInfo {
|
class ContactInfo {
|
||||||
private string $name;
|
private string $name;
|
||||||
|
@ -14,19 +15,15 @@ class ContactInfo {
|
||||||
private string $display;
|
private string $display;
|
||||||
private ?string $link;
|
private ?string $link;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(IDbResult $result) {
|
||||||
string $name, bool $homePage, int $order,
|
$this->name = $result->getString(0);
|
||||||
string $title, string $icon, int $colour,
|
$this->homePage = $result->getInteger(1) !== 0;
|
||||||
string $display, ?string $link
|
$this->order = $result->getInteger(2);
|
||||||
) {
|
$this->title = $result->getString(3);
|
||||||
$this->name = $name;
|
$this->icon = $result->getString(4);
|
||||||
$this->homePage = $homePage;
|
$this->colour = $result->getInteger(5);
|
||||||
$this->order = $order;
|
$this->display = $result->getString(6);
|
||||||
$this->title = $title;
|
$this->link = $result->isNull(7) ? null : $result->getString(7);
|
||||||
$this->icon = $icon;
|
|
||||||
$this->colour = $colour;
|
|
||||||
$this->display = $display;
|
|
||||||
$this->link = $link;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName(): string {
|
public function getName(): string {
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
namespace Makai;
|
namespace Makai;
|
||||||
|
|
||||||
use Index\Data\IDbConnection;
|
use Index\Data\IDbConnection;
|
||||||
use Index\Data\IDbResult;
|
|
||||||
|
|
||||||
class Contacts {
|
class Contacts {
|
||||||
private const QUERY = 'SELECT `cont_name`, `cont_homepage`, `cont_order`, `cont_title`, `cont_icon`, `cont_colour`, `cont_display`, `cont_link` FROM `fm_contacts`';
|
private const QUERY = 'SELECT `cont_name`, `cont_homepage`, `cont_order`, `cont_title`, `cont_icon`, `cont_colour`, `cont_display`, `cont_link` FROM `fm_contacts`';
|
||||||
|
@ -23,7 +22,7 @@ class Contacts {
|
||||||
$objs = [];
|
$objs = [];
|
||||||
|
|
||||||
while($result->next())
|
while($result->next())
|
||||||
$objs[] = self::createObject($result);
|
$objs[] = new ContactInfo($result);
|
||||||
|
|
||||||
return $objs;
|
return $objs;
|
||||||
}
|
}
|
||||||
|
@ -35,21 +34,8 @@ class Contacts {
|
||||||
$objs = [];
|
$objs = [];
|
||||||
|
|
||||||
while($result->next())
|
while($result->next())
|
||||||
$objs[] = self::createObject($result);
|
$objs[] = new ContactInfo($result);
|
||||||
|
|
||||||
return $objs;
|
return $objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function createObject(IDbResult $result): ContactInfo {
|
|
||||||
return new ContactInfo(
|
|
||||||
$result->getString(0), // name
|
|
||||||
$result->getInteger(1) !== 0, // homepage
|
|
||||||
$result->getInteger(2), // order
|
|
||||||
$result->getString(3), // title
|
|
||||||
$result->getString(4), // icon
|
|
||||||
$result->getInteger(5), // colour
|
|
||||||
$result->getString(6), // display
|
|
||||||
$result->isNull(7) ? null : $result->getString(7) // link
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,20 +3,17 @@ namespace Makai;
|
||||||
|
|
||||||
use Index\Colour\Colour;
|
use Index\Colour\Colour;
|
||||||
use Index\Colour\ColourRGB;
|
use Index\Colour\ColourRGB;
|
||||||
|
use Index\Data\IDbResult;
|
||||||
|
|
||||||
class LanguageInfo {
|
class LanguageInfo {
|
||||||
private string $id;
|
private string $id;
|
||||||
private string $name;
|
private string $name;
|
||||||
private ?int $colour;
|
private ?int $colour;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(IDbResult $result) {
|
||||||
string $id,
|
$this->id = $result->getString(0);
|
||||||
string $name,
|
$this->name = $result->getString(1);
|
||||||
?int $colour
|
$this->colour = $result->isNull(2) ? null : $result->getInteger(2);
|
||||||
) {
|
|
||||||
$this->id = $id;
|
|
||||||
$this->name = $name;
|
|
||||||
$this->colour = $colour;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): string {
|
public function getId(): string {
|
||||||
|
|
|
@ -3,9 +3,7 @@ namespace Makai;
|
||||||
|
|
||||||
use Index\Colour\Colour;
|
use Index\Colour\Colour;
|
||||||
use Index\Colour\ColourRGB;
|
use Index\Colour\ColourRGB;
|
||||||
use Index\Data\DbType;
|
|
||||||
use Index\Data\IDbConnection;
|
use Index\Data\IDbConnection;
|
||||||
use Index\Data\IDbResult;
|
|
||||||
|
|
||||||
class Languages {
|
class Languages {
|
||||||
private const QUERY = 'SELECT pl.`language_id`, pl.`language_name`, pl.`language_colour` FROM `fm_proglangs` AS pl';
|
private const QUERY = 'SELECT pl.`language_id`, pl.`language_name`, pl.`language_colour` FROM `fm_proglangs` AS pl';
|
||||||
|
@ -22,13 +20,13 @@ class Languages {
|
||||||
|
|
||||||
public function getByProject(ProjectInfo $project): array {
|
public function getByProject(ProjectInfo $project): array {
|
||||||
$stmt = $this->conn->prepare(self::QUERY_PROJECT);
|
$stmt = $this->conn->prepare(self::QUERY_PROJECT);
|
||||||
$stmt->addParameter(1, $project->getId(), DbType::STRING);
|
$stmt->addParameter(1, $project->getId());
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->getResult();
|
$result = $stmt->getResult();
|
||||||
$objs = [];
|
$objs = [];
|
||||||
|
|
||||||
while($result->next())
|
while($result->next())
|
||||||
$objs[] = self::createObject($result);
|
$objs[] = new LanguageInfo($result);
|
||||||
|
|
||||||
return $objs;
|
return $objs;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +41,7 @@ class Languages {
|
||||||
|
|
||||||
public function getProjectColourRaw(ProjectInfo $project): ?int {
|
public function getProjectColourRaw(ProjectInfo $project): ?int {
|
||||||
$stmt = $this->conn->prepare(self::QUERY_PROJECT_COLOUR);
|
$stmt = $this->conn->prepare(self::QUERY_PROJECT_COLOUR);
|
||||||
$stmt->addParameter(1, $project->getId(), DbType::STRING);
|
$stmt->addParameter(1, $project->getId());
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->getResult();
|
$result = $stmt->getResult();
|
||||||
|
|
||||||
|
@ -52,12 +50,4 @@ class Languages {
|
||||||
|
|
||||||
return $result->isNull(0) ? null : $result->getInteger(0);
|
return $result->isNull(0) ? null : $result->getInteger(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function createObject(IDbResult $result): LanguageInfo {
|
|
||||||
return new LanguageInfo(
|
|
||||||
$result->getString(0), // id
|
|
||||||
$result->getString(1), // name
|
|
||||||
$result->isNull(2) ? null : $result->getInteger(2) // colour
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Makai;
|
||||||
use Index\DateTime;
|
use Index\DateTime;
|
||||||
use Index\Colour\Colour;
|
use Index\Colour\Colour;
|
||||||
use Index\Colour\ColourRGB;
|
use Index\Colour\ColourRGB;
|
||||||
|
use Index\Data\IDbResult;
|
||||||
|
|
||||||
class ProjectInfo {
|
class ProjectInfo {
|
||||||
private string $id;
|
private string $id;
|
||||||
|
@ -18,32 +19,26 @@ class ProjectInfo {
|
||||||
private ?string $homepage;
|
private ?string $homepage;
|
||||||
private ?string $source;
|
private ?string $source;
|
||||||
private ?string $discussion;
|
private ?string $discussion;
|
||||||
private DateTime $createdAt;
|
private int $createdAt;
|
||||||
private ?DateTime $archivedAt;
|
private ?int $archivedAt;
|
||||||
private ?DateTime $deletedAt;
|
private ?int $deletedAt;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(IDbResult $result) {
|
||||||
string $id, string $name, string $nameClean,
|
$this->id = $result->getString(0);
|
||||||
?string $summary, ?string $description,
|
$this->name = $result->getString(1);
|
||||||
bool $featured, int $order, ?int $colour, string $type,
|
$this->nameClean = $result->getString(2);
|
||||||
?string $homepage, ?string $source, ?string $discussion,
|
$this->summary = $result->isNull(3) ? null : $result->getString(3);
|
||||||
int $createdAt, ?int $archivedAt, ?int $deletedAt
|
$this->description = $result->isNull(4) ? null : $result->getString(4);
|
||||||
) {
|
$this->featured = $result->getInteger(5) !== 0;
|
||||||
$this->id = $id;
|
$this->order = $result->getInteger(6);
|
||||||
$this->name = $name;
|
$this->colour = $result->isNull(13) ? null : $result->getInteger(13);
|
||||||
$this->nameClean = $nameClean;
|
$this->type = $result->getString(11);
|
||||||
$this->summary = $summary;
|
$this->homepage = $result->isNull(7) ? null : $result->getString(7);
|
||||||
$this->description = $description;
|
$this->source = $result->isNull(8) ? null : $result->getString(8);
|
||||||
$this->featured = $featured;
|
$this->discussion = $result->isNull(9) ? null : $result->getString(9);
|
||||||
$this->order = $order;
|
$this->createdAt = $result->getInteger(12);
|
||||||
$this->colour = $colour;
|
$this->archivedAt = $result->isNull(10) ? null : $result->getInteger(10);
|
||||||
$this->type = $type;
|
$this->deletedAt = null;
|
||||||
$this->homepage = $homepage;
|
|
||||||
$this->source = $source;
|
|
||||||
$this->discussion = $discussion;
|
|
||||||
$this->createdAt = DateTime::fromUnixTimeSeconds($createdAt);
|
|
||||||
$this->archivedAt = $archivedAt === null ? null : DateTime::fromUnixTimeSeconds($archivedAt);
|
|
||||||
$this->deletedAt = $deletedAt === null ? null : DateTime::fromUnixTimeSeconds($deletedAt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): string {
|
public function getId(): string {
|
||||||
|
@ -126,22 +121,34 @@ class ProjectInfo {
|
||||||
return $this->discussion;
|
return $this->discussion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCreatedAt(): DateTime {
|
public function getCreatedTime(): int {
|
||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArchivedAt(): ?DateTime {
|
public function getCreatedAt(): DateTime {
|
||||||
|
return DateTime::fromUnixTimeSeconds($this->createdAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArchivedTime(): ?int {
|
||||||
return $this->archivedAt;
|
return $this->archivedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getArchivedAt(): ?DateTime {
|
||||||
|
return $this->archivedAt === null ? null : DateTime::fromUnixTimeSeconds($this->archivedAt);
|
||||||
|
}
|
||||||
|
|
||||||
public function isArchived(): bool {
|
public function isArchived(): bool {
|
||||||
return $this->archivedAt !== null;
|
return $this->archivedAt !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDeletedAt(): ?DateTime {
|
public function getDeletedTime(): ?int {
|
||||||
return $this->deletedAt;
|
return $this->deletedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDeletedAt(): ?DateTime {
|
||||||
|
return $this->deletedAt === null ? null : DateTime::fromUnixTimeSeconds($this->deletedAt);
|
||||||
|
}
|
||||||
|
|
||||||
public function isDeleted(): bool {
|
public function isDeleted(): bool {
|
||||||
return $this->deletedAt !== null;
|
return $this->deletedAt !== null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
namespace Makai;
|
namespace Makai;
|
||||||
|
|
||||||
use Index\Data\IDbConnection;
|
use Index\Data\IDbConnection;
|
||||||
use Index\Data\IDbResult;
|
|
||||||
|
|
||||||
class Projects {
|
class Projects {
|
||||||
private const QUERY = 'SELECT `project_id`, `project_name`, COALESCE(`project_name_clean`, REPLACE(LOWER(`project_name`), \' \', \'-\')), `project_summary`, `project_description`, `project_featured`, `project_order`, `project_homepage`, `project_repository`, `project_forum`, UNIX_TIMESTAMP(`project_archived`), `project_type`, UNIX_TIMESTAMP(`project_created`), `project_colour` FROM `fm_projects` WHERE `project_deleted` IS NULL';
|
private const QUERY = 'SELECT `project_id`, `project_name`, COALESCE(`project_name_clean`, REPLACE(LOWER(`project_name`), \' \', \'-\')), `project_summary`, `project_description`, `project_featured`, `project_order`, `project_homepage`, `project_repository`, `project_forum`, UNIX_TIMESTAMP(`project_archived`), `project_type`, UNIX_TIMESTAMP(`project_created`), `project_colour` FROM `fm_projects` WHERE `project_deleted` IS NULL';
|
||||||
|
@ -23,7 +22,7 @@ class Projects {
|
||||||
$objs = [];
|
$objs = [];
|
||||||
|
|
||||||
while($result->next())
|
while($result->next())
|
||||||
$objs[] = self::createObject($result);
|
$objs[] = new ProjectInfo($result);
|
||||||
|
|
||||||
return $objs;
|
return $objs;
|
||||||
}
|
}
|
||||||
|
@ -35,28 +34,8 @@ class Projects {
|
||||||
$objs = [];
|
$objs = [];
|
||||||
|
|
||||||
while($result->next())
|
while($result->next())
|
||||||
$objs[] = self::createObject($result);
|
$objs[] = new ProjectInfo($result);
|
||||||
|
|
||||||
return $objs;
|
return $objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function createObject(IDbResult $result): ProjectInfo {
|
|
||||||
return new ProjectInfo(
|
|
||||||
$result->getString(0), // id
|
|
||||||
$result->getString(1), // name
|
|
||||||
$result->getString(2), // clean name
|
|
||||||
$result->isNull(3) ? null : $result->getString(3), // summary
|
|
||||||
$result->isNull(4) ? null : $result->getString(4), // description
|
|
||||||
$result->getInteger(5) !== 0, // featured
|
|
||||||
$result->getInteger(6), // order
|
|
||||||
$result->isNull(13) ? null : $result->getInteger(13), // colour
|
|
||||||
$result->getString(11), // type
|
|
||||||
$result->isNull(7) ? null : $result->getString(7), // homepage
|
|
||||||
$result->isNull(8) ? null : $result->getString(8), // repository
|
|
||||||
$result->isNull(9) ? null : $result->getString(9), // forum
|
|
||||||
$result->getInteger(12), // created
|
|
||||||
$result->isNull(10) ? null : $result->getInteger(10), // archived
|
|
||||||
null // deleted
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
namespace Makai;
|
namespace Makai;
|
||||||
|
|
||||||
use Index\DateTime;
|
use Index\DateTime;
|
||||||
|
use Index\Data\IDbResult;
|
||||||
|
|
||||||
class SSHKeyInfo {
|
class SSHKeyInfo {
|
||||||
private string $id;
|
private string $id;
|
||||||
|
@ -9,25 +10,17 @@ class SSHKeyInfo {
|
||||||
private string $algo;
|
private string $algo;
|
||||||
private string $body;
|
private string $body;
|
||||||
private string $comment;
|
private string $comment;
|
||||||
private DateTime $createdAt;
|
private int $createdAt;
|
||||||
private ?DateTime $deprecatedAt;
|
private ?int $deprecatedAt;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(IDbResult $result) {
|
||||||
string $id,
|
$this->id = $result->getString(0);
|
||||||
int $level,
|
$this->level = $result->getInteger(1);
|
||||||
string $algo,
|
$this->algo = $result->getString(2);
|
||||||
string $body,
|
$this->body = $result->getString(3);
|
||||||
string $comment,
|
$this->comment = $result->getString(4);
|
||||||
int $createdAt,
|
$this->createdAt = $result->getInteger(5);
|
||||||
?int $deprecatedAt
|
$this->deprecatedAt = $result->isNull(6) ? null : $result->getInteger(6);
|
||||||
) {
|
|
||||||
$this->id = $id;
|
|
||||||
$this->level = $level;
|
|
||||||
$this->algo = $algo;
|
|
||||||
$this->body = $body;
|
|
||||||
$this->comment = $comment;
|
|
||||||
$this->createdAt = DateTime::fromUnixTimeSeconds($createdAt);
|
|
||||||
$this->deprecatedAt = $deprecatedAt === null ? null : DateTime::fromUnixTimeSeconds($deprecatedAt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): string {
|
public function getId(): string {
|
||||||
|
@ -50,18 +43,26 @@ class SSHKeyInfo {
|
||||||
return $this->comment;
|
return $this->comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCreatedAt(): DateTime {
|
public function getCreatedTime(): int {
|
||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt(): DateTime {
|
||||||
|
return DateTime::fromUnixTimeSeconds($this->createdAt);
|
||||||
|
}
|
||||||
|
|
||||||
public function isDeprecated(): bool {
|
public function isDeprecated(): bool {
|
||||||
return $this->deprecatedAt !== null;
|
return $this->deprecatedAt !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDeprecatedAt(): ?DateTime {
|
public function getDeprecatedTime(): ?int {
|
||||||
return $this->deprecatedAt;
|
return $this->deprecatedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDeprecatedAt(): ?DateTime {
|
||||||
|
return $this->deprecatedAt === null ? null : DateTime::fromUnixTimeSeconds($this->deprecatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
public function toString(bool $includeComment): string {
|
public function toString(bool $includeComment): string {
|
||||||
$line = sprintf('ssh-%s %s', $this->getAlgorithm(), $this->getBody());
|
$line = sprintf('ssh-%s %s', $this->getAlgorithm(), $this->getBody());
|
||||||
if($includeComment)
|
if($includeComment)
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Makai;
|
namespace Makai;
|
||||||
|
|
||||||
use Index\Data\DbType;
|
|
||||||
use Index\Data\IDbConnection;
|
use Index\Data\IDbConnection;
|
||||||
use Index\Data\IDbResult;
|
|
||||||
|
|
||||||
class SSHKeys {
|
class SSHKeys {
|
||||||
private const QUERY = 'SELECT `key_id`, `key_level`, `key_algo`, `key_body`, `key_comment`, UNIX_TIMESTAMP(`key_created`), UNIX_TIMESTAMP(`key_deprecated`) FROM `fm_public_keys` WHERE `key_level` >= ?';
|
private const QUERY = 'SELECT `key_id`, `key_level`, `key_algo`, `key_body`, `key_comment`, UNIX_TIMESTAMP(`key_created`), UNIX_TIMESTAMP(`key_deprecated`) FROM `fm_public_keys` WHERE `key_level` >= ?';
|
||||||
|
@ -23,26 +21,14 @@ class SSHKeys {
|
||||||
$query .= ' ORDER BY `key_level` DESC, `key_id`';
|
$query .= ' ORDER BY `key_level` DESC, `key_id`';
|
||||||
|
|
||||||
$stmt = $this->conn->prepare($query);
|
$stmt = $this->conn->prepare($query);
|
||||||
$stmt->addParameter(1, $minLevel, DbType::INTEGER);
|
$stmt->addParameter(1, $minLevel);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->getResult();
|
$result = $stmt->getResult();
|
||||||
$objs = [];
|
$objs = [];
|
||||||
|
|
||||||
while($result->next())
|
while($result->next())
|
||||||
$objs[] = self::createObject($result);
|
$objs[] = new SSHKeyInfo($result);
|
||||||
|
|
||||||
return $objs;
|
return $objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function createObject(IDbResult $result): SSHKeyInfo {
|
|
||||||
return new SSHKeyInfo(
|
|
||||||
$result->getString(0),
|
|
||||||
$result->getInteger(1),
|
|
||||||
$result->getString(2),
|
|
||||||
$result->getString(3),
|
|
||||||
$result->getString(4),
|
|
||||||
$result->getInteger(5),
|
|
||||||
$result->isNull(6) ? null : $result->getInteger(6),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue