mirror of
https://github.com/standardebooks/web.git
synced 2025-07-12 09:32:24 -04:00
Make collection type (series, set) an enum
This commit is contained in:
parent
d3b7f5015a
commit
b792dec9e5
4 changed files with 10 additions and 4 deletions
|
@ -2,7 +2,7 @@ CREATE TABLE `Collections` (
|
||||||
`CollectionId` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
`CollectionId` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`Name` varchar(255) NOT NULL,
|
`Name` varchar(255) NOT NULL,
|
||||||
`UrlName` varchar(255) NOT NULL,
|
`UrlName` varchar(255) NOT NULL,
|
||||||
`Type` varchar(255) NULL,
|
`Type` enum('series', 'set') NULL,
|
||||||
PRIMARY KEY (`CollectionId`),
|
PRIMARY KEY (`CollectionId`),
|
||||||
UNIQUE KEY `idxUnique` (`UrlName`)
|
UNIQUE KEY `idxUnique` (`UrlName`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Collection{
|
||||||
public int $CollectionId;
|
public int $CollectionId;
|
||||||
public string $Name;
|
public string $Name;
|
||||||
public string $UrlName;
|
public string $UrlName;
|
||||||
public ?string $Type = null;
|
public ?CollectionType $Type = null;
|
||||||
protected ?string $_Url = null;
|
protected ?string $_Url = null;
|
||||||
|
|
||||||
protected function GetUrl(): ?string{
|
protected function GetUrl(): ?string{
|
||||||
|
@ -59,7 +59,7 @@ class Collection{
|
||||||
$error->Add(new Exceptions\StringTooLongException('Collection name: '. $this->Name));
|
$error->Add(new Exceptions\StringTooLongException('Collection name: '. $this->Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->Type !== null && ($this->Type != 'series' && $this->Type != 'set')){
|
if($this->Type !== null && ($this->Type != CollectionType::Series && $this->Type != CollectionType::Set)){
|
||||||
$error->Add(new Exceptions\InvalidCollectionTypeException($this->Type));
|
$error->Add(new Exceptions\InvalidCollectionTypeException($this->Type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
lib/CollectionType.php
Normal file
6
lib/CollectionType.php
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?
|
||||||
|
enum CollectionType: string{
|
||||||
|
case Series = 'series';
|
||||||
|
case Set = 'set';
|
||||||
|
case Unknown = 'unknown';
|
||||||
|
}
|
|
@ -762,7 +762,7 @@ class Ebook{
|
||||||
$cm->SequenceNumber = (int)$s;
|
$cm->SequenceNumber = (int)$s;
|
||||||
}
|
}
|
||||||
foreach($xml->xpath('/package/metadata/meta[@refines="#' . $id . '"][@property="collection-type"]') ?: [] as $s){
|
foreach($xml->xpath('/package/metadata/meta[@refines="#' . $id . '"][@property="collection-type"]') ?: [] as $s){
|
||||||
$cm->Collection->Type = (string)$s;
|
$cm->Collection->Type = CollectionType::tryFrom((string)$s) ?? CollectionType::Unknown;
|
||||||
}
|
}
|
||||||
$collectionMemberships[] = $cm;
|
$collectionMemberships[] = $cm;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue