mirror of
https://github.com/standardebooks/web.git
synced 2025-07-20 05:14:48 -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
|
@ -15,6 +15,7 @@ class Benefits{
|
|||
public bool $CanReviewArtwork = false;
|
||||
public bool $CanReviewOwnArtwork = false;
|
||||
public bool $CanEditUsers = false;
|
||||
public bool $CanEditCollections = false;
|
||||
public bool $CanCreateEbookPlaceholders = false;
|
||||
|
||||
protected bool $_HasBenefits;
|
||||
|
|
|
@ -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>
|
||||
*/
|
||||
|
|
|
@ -2020,17 +2020,17 @@ class Ebook{
|
|||
* Queries for books in a collection.
|
||||
*
|
||||
* Puts ebooks without a `SequenceNumber` at the end of the list, which is more common in a collection with both published and placeholder ebooks.
|
||||
*
|
||||
* @return array<Ebook>
|
||||
*/
|
||||
public static function GetAllByCollection(string $collection): array{
|
||||
public static function GetAllByCollection(int $collectionId): array{
|
||||
$ebooks = Db::Query('
|
||||
SELECT e.*
|
||||
from Ebooks e
|
||||
inner join CollectionEbooks ce using (EbookId)
|
||||
inner join Collections c using (CollectionId)
|
||||
where c.UrlName = ?
|
||||
where ce.CollectionId = ?
|
||||
order by ce.SequenceNumber is null, ce.SequenceNumber, e.EbookCreated desc
|
||||
', [$collection], Ebook::class);
|
||||
', [$collectionId], Ebook::class);
|
||||
|
||||
return $ebooks;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue