mirror of
https://github.com/standardebooks/web.git
synced 2025-07-07 23:30:35 -04:00
Allow admin to view collection metadata
This commit is contained in:
parent
bcc2f331bc
commit
23b5c8ef31
8 changed files with 82 additions and 55 deletions
|
@ -3,6 +3,7 @@ use function Safe\preg_replace;
|
|||
|
||||
/**
|
||||
* @property string $Url
|
||||
* @property array<Ebook> $Ebooks
|
||||
*/
|
||||
class Collection{
|
||||
use Traits\Accessor;
|
||||
|
@ -13,7 +14,9 @@ class Collection{
|
|||
public ?Enums\CollectionType $Type = null;
|
||||
public bool $ArePlaceholdersComplete; /** Has a producer verified that every possible item in this `Collection` been added to our database? */
|
||||
|
||||
protected ?string $_Url = null;
|
||||
protected string $_Url;
|
||||
/** @var array<Ebook> $_Ebooks */
|
||||
protected array $_Ebooks;
|
||||
|
||||
|
||||
// *******
|
||||
|
@ -21,13 +24,24 @@ class Collection{
|
|||
// *******
|
||||
|
||||
protected function GetUrl(): string{
|
||||
if($this->_Url === null){
|
||||
if(!isset($this->_Url)){
|
||||
$this->_Url = '/collections/' . $this->UrlName;
|
||||
}
|
||||
|
||||
return $this->_Url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Ebook>
|
||||
*/
|
||||
protected function GetEbooks(): array{
|
||||
if(!isset($this->_Ebooks)){
|
||||
$this->_Ebooks = Ebook::GetAllByCollection($this->CollectionId);
|
||||
}
|
||||
|
||||
return $this->_Ebooks;
|
||||
}
|
||||
|
||||
|
||||
// ***********
|
||||
// ORM METHODS
|
||||
|
@ -57,6 +71,23 @@ class Collection{
|
|||
return $result[0] ?? throw new Exceptions\CollectionNotFoundException();;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exceptions\CollectionNotFoundException
|
||||
*/
|
||||
public static function GetByUrlName(?string $urlName): Collection{
|
||||
if($urlName === null){
|
||||
throw new Exceptions\CollectionNotFoundException();
|
||||
}
|
||||
|
||||
$result = Db::Query('
|
||||
SELECT *
|
||||
from Collections
|
||||
where UrlName = ?
|
||||
', [$urlName], Collection::class);
|
||||
|
||||
return $result[0] ?? throw new Exceptions\CollectionNotFoundException();;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Collection>
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue