diff --git a/src/ContactInfo.php b/src/ContactInfo.php index ce627a2..84cbc67 100644 --- a/src/ContactInfo.php +++ b/src/ContactInfo.php @@ -3,6 +3,7 @@ namespace Makai; use Index\Colour\Colour; use Index\Colour\ColourRGB; +use Index\Data\IDbResult; class ContactInfo { private string $name; @@ -14,19 +15,15 @@ class ContactInfo { private string $display; private ?string $link; - public function __construct( - string $name, bool $homePage, int $order, - string $title, string $icon, int $colour, - string $display, ?string $link - ) { - $this->name = $name; - $this->homePage = $homePage; - $this->order = $order; - $this->title = $title; - $this->icon = $icon; - $this->colour = $colour; - $this->display = $display; - $this->link = $link; + public function __construct(IDbResult $result) { + $this->name = $result->getString(0); + $this->homePage = $result->getInteger(1) !== 0; + $this->order = $result->getInteger(2); + $this->title = $result->getString(3); + $this->icon = $result->getString(4); + $this->colour = $result->getInteger(5); + $this->display = $result->getString(6); + $this->link = $result->isNull(7) ? null : $result->getString(7); } public function getName(): string { diff --git a/src/Contacts.php b/src/Contacts.php index c03c3f2..27f0479 100644 --- a/src/Contacts.php +++ b/src/Contacts.php @@ -2,7 +2,6 @@ namespace Makai; use Index\Data\IDbConnection; -use Index\Data\IDbResult; 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`'; @@ -23,7 +22,7 @@ class Contacts { $objs = []; while($result->next()) - $objs[] = self::createObject($result); + $objs[] = new ContactInfo($result); return $objs; } @@ -35,21 +34,8 @@ class Contacts { $objs = []; while($result->next()) - $objs[] = self::createObject($result); + $objs[] = new ContactInfo($result); 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 - ); - } } diff --git a/src/LanguageInfo.php b/src/LanguageInfo.php index dc3d725..da9e984 100644 --- a/src/LanguageInfo.php +++ b/src/LanguageInfo.php @@ -3,20 +3,17 @@ namespace Makai; use Index\Colour\Colour; use Index\Colour\ColourRGB; +use Index\Data\IDbResult; class LanguageInfo { private string $id; private string $name; private ?int $colour; - public function __construct( - string $id, - string $name, - ?int $colour - ) { - $this->id = $id; - $this->name = $name; - $this->colour = $colour; + public function __construct(IDbResult $result) { + $this->id = $result->getString(0); + $this->name = $result->getString(1); + $this->colour = $result->isNull(2) ? null : $result->getInteger(2); } public function getId(): string { diff --git a/src/Languages.php b/src/Languages.php index cb21f5a..d9f3954 100644 --- a/src/Languages.php +++ b/src/Languages.php @@ -3,9 +3,7 @@ namespace Makai; use Index\Colour\Colour; use Index\Colour\ColourRGB; -use Index\Data\DbType; use Index\Data\IDbConnection; -use Index\Data\IDbResult; class Languages { 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 { $stmt = $this->conn->prepare(self::QUERY_PROJECT); - $stmt->addParameter(1, $project->getId(), DbType::STRING); + $stmt->addParameter(1, $project->getId()); $stmt->execute(); $result = $stmt->getResult(); $objs = []; while($result->next()) - $objs[] = self::createObject($result); + $objs[] = new LanguageInfo($result); return $objs; } @@ -43,7 +41,7 @@ class Languages { public function getProjectColourRaw(ProjectInfo $project): ?int { $stmt = $this->conn->prepare(self::QUERY_PROJECT_COLOUR); - $stmt->addParameter(1, $project->getId(), DbType::STRING); + $stmt->addParameter(1, $project->getId()); $stmt->execute(); $result = $stmt->getResult(); @@ -52,12 +50,4 @@ class Languages { 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 - ); - } } diff --git a/src/ProjectInfo.php b/src/ProjectInfo.php index 2377871..fc7f40a 100644 --- a/src/ProjectInfo.php +++ b/src/ProjectInfo.php @@ -4,6 +4,7 @@ namespace Makai; use Index\DateTime; use Index\Colour\Colour; use Index\Colour\ColourRGB; +use Index\Data\IDbResult; class ProjectInfo { private string $id; @@ -18,32 +19,26 @@ class ProjectInfo { private ?string $homepage; private ?string $source; private ?string $discussion; - private DateTime $createdAt; - private ?DateTime $archivedAt; - private ?DateTime $deletedAt; + private int $createdAt; + private ?int $archivedAt; + private ?int $deletedAt; - public function __construct( - string $id, string $name, string $nameClean, - ?string $summary, ?string $description, - bool $featured, int $order, ?int $colour, string $type, - ?string $homepage, ?string $source, ?string $discussion, - int $createdAt, ?int $archivedAt, ?int $deletedAt - ) { - $this->id = $id; - $this->name = $name; - $this->nameClean = $nameClean; - $this->summary = $summary; - $this->description = $description; - $this->featured = $featured; - $this->order = $order; - $this->colour = $colour; - $this->type = $type; - $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 __construct(IDbResult $result) { + $this->id = $result->getString(0); + $this->name = $result->getString(1); + $this->nameClean = $result->getString(2); + $this->summary = $result->isNull(3) ? null : $result->getString(3); + $this->description = $result->isNull(4) ? null : $result->getString(4); + $this->featured = $result->getInteger(5) !== 0; + $this->order = $result->getInteger(6); + $this->colour = $result->isNull(13) ? null : $result->getInteger(13); + $this->type = $result->getString(11); + $this->homepage = $result->isNull(7) ? null : $result->getString(7); + $this->source = $result->isNull(8) ? null : $result->getString(8); + $this->discussion = $result->isNull(9) ? null : $result->getString(9); + $this->createdAt = $result->getInteger(12); + $this->archivedAt = $result->isNull(10) ? null : $result->getInteger(10); + $this->deletedAt = null; } public function getId(): string { @@ -126,22 +121,34 @@ class ProjectInfo { return $this->discussion; } - public function getCreatedAt(): DateTime { + public function getCreatedTime(): int { return $this->createdAt; } - public function getArchivedAt(): ?DateTime { + public function getCreatedAt(): DateTime { + return DateTime::fromUnixTimeSeconds($this->createdAt); + } + + public function getArchivedTime(): ?int { return $this->archivedAt; } + public function getArchivedAt(): ?DateTime { + return $this->archivedAt === null ? null : DateTime::fromUnixTimeSeconds($this->archivedAt); + } + public function isArchived(): bool { return $this->archivedAt !== null; } - public function getDeletedAt(): ?DateTime { + public function getDeletedTime(): ?int { return $this->deletedAt; } + public function getDeletedAt(): ?DateTime { + return $this->deletedAt === null ? null : DateTime::fromUnixTimeSeconds($this->deletedAt); + } + public function isDeleted(): bool { return $this->deletedAt !== null; } diff --git a/src/Projects.php b/src/Projects.php index a20d52b..7d46f5c 100644 --- a/src/Projects.php +++ b/src/Projects.php @@ -2,7 +2,6 @@ namespace Makai; use Index\Data\IDbConnection; -use Index\Data\IDbResult; 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'; @@ -23,7 +22,7 @@ class Projects { $objs = []; while($result->next()) - $objs[] = self::createObject($result); + $objs[] = new ProjectInfo($result); return $objs; } @@ -35,28 +34,8 @@ class Projects { $objs = []; while($result->next()) - $objs[] = self::createObject($result); + $objs[] = new ProjectInfo($result); 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 - ); - } } diff --git a/src/SSHKeyInfo.php b/src/SSHKeyInfo.php index acdf5c0..188c006 100644 --- a/src/SSHKeyInfo.php +++ b/src/SSHKeyInfo.php @@ -2,6 +2,7 @@ namespace Makai; use Index\DateTime; +use Index\Data\IDbResult; class SSHKeyInfo { private string $id; @@ -9,25 +10,17 @@ class SSHKeyInfo { private string $algo; private string $body; private string $comment; - private DateTime $createdAt; - private ?DateTime $deprecatedAt; + private int $createdAt; + private ?int $deprecatedAt; - public function __construct( - string $id, - int $level, - string $algo, - string $body, - string $comment, - int $createdAt, - ?int $deprecatedAt - ) { - $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 __construct(IDbResult $result) { + $this->id = $result->getString(0); + $this->level = $result->getInteger(1); + $this->algo = $result->getString(2); + $this->body = $result->getString(3); + $this->comment = $result->getString(4); + $this->createdAt = $result->getInteger(5); + $this->deprecatedAt = $result->isNull(6) ? null : $result->getInteger(6); } public function getId(): string { @@ -50,18 +43,26 @@ class SSHKeyInfo { return $this->comment; } - public function getCreatedAt(): DateTime { + public function getCreatedTime(): int { return $this->createdAt; } + public function getCreatedAt(): DateTime { + return DateTime::fromUnixTimeSeconds($this->createdAt); + } + public function isDeprecated(): bool { return $this->deprecatedAt !== null; } - public function getDeprecatedAt(): ?DateTime { + public function getDeprecatedTime(): ?int { return $this->deprecatedAt; } + public function getDeprecatedAt(): ?DateTime { + return $this->deprecatedAt === null ? null : DateTime::fromUnixTimeSeconds($this->deprecatedAt); + } + public function toString(bool $includeComment): string { $line = sprintf('ssh-%s %s', $this->getAlgorithm(), $this->getBody()); if($includeComment) diff --git a/src/SSHKeys.php b/src/SSHKeys.php index 8631f55..3c1afd8 100644 --- a/src/SSHKeys.php +++ b/src/SSHKeys.php @@ -1,9 +1,7 @@ = ?'; @@ -23,26 +21,14 @@ class SSHKeys { $query .= ' ORDER BY `key_level` DESC, `key_id`'; $stmt = $this->conn->prepare($query); - $stmt->addParameter(1, $minLevel, DbType::INTEGER); + $stmt->addParameter(1, $minLevel); $stmt->execute(); $result = $stmt->getResult(); $objs = []; while($result->next()) - $objs[] = self::createObject($result); + $objs[] = new SSHKeyInfo($result); 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), - ); - } }