Switch from EbookPlaceholder.Status to EbookPlaceholder.IsInProgress, and some type tweaks

This commit is contained in:
Alex Cabal 2024-12-14 13:39:28 -06:00
parent 1a742baa51
commit e56de4b19d
8 changed files with 56 additions and 39 deletions

View file

@ -1,10 +1,10 @@
CREATE TABLE IF NOT EXISTS `EbookPlaceholders` ( CREATE TABLE IF NOT EXISTS `EbookPlaceholders` (
`EbookId` int(10) unsigned NOT NULL, `EbookId` int(10) unsigned NOT NULL,
`YearPublished` smallint unsigned NULL, `YearPublished` smallint unsigned NULL,
`Status` enum('wanted', 'in_progress') NULL,
`Difficulty` enum('beginner', 'intermediate', 'advanced') NULL, `Difficulty` enum('beginner', 'intermediate', 'advanced') NULL,
`TranscriptionUrl` varchar(511) NULL, `TranscriptionUrl` varchar(511) NULL,
`IsWanted` boolean NOT NULL DEFAULT FALSE, `IsWanted` boolean NOT NULL DEFAULT FALSE,
`IsInProgress` boolean NOT NULL DEFAULT FALSE,
`IsPatron` boolean NOT NULL DEFAULT FALSE, `IsPatron` boolean NOT NULL DEFAULT FALSE,
`Notes` TEXT NULL DEFAULT NULL, `Notes` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`EbookId`) PRIMARY KEY (`EbookId`)

View file

@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS `Projects` (
`ProjectId` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Status` enum('in_progress','stalled','completed','abandoned') NOT NULL DEFAULT 'in_progress',
`EbookId` int(11) NOT NULL,
`ProducerName` varchar(151) DEFAULT NULL,
`ProducerEmail` varchar(80) DEFAULT NULL,
`DiscussionUrl` varchar(255) DEFAULT NULL,
`VcsUrl` varchar(255) NOT NULL,
`Created` timestamp NOT NULL DEFAULT current_timestamp(),
`Updated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`Started` datetime NOT NULL,
`Ended` datetime DEFAULT NULL,
`ManagerUserId` int(11) NOT NULL,
`ReviewerUserId` int(11) NOT NULL,
PRIMARY KEY (`ProjectId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

View file

@ -612,11 +612,16 @@ class Ebook{
protected function GetEbookPlaceholder(): ?EbookPlaceholder{ protected function GetEbookPlaceholder(): ?EbookPlaceholder{
if(!isset($this->_EbookPlaceholder)){ if(!isset($this->_EbookPlaceholder)){
$this->_EbookPlaceholder = Db::Query(' if(!isset($this->EbookId)){
SELECT * $this->_EbookPlaceholder = null;
from EbookPlaceholders }
where EbookId = ? else{
', [$this->EbookId], EbookPlaceholder::class)[0] ?? null; $this->_EbookPlaceholder = Db::Query('
SELECT *
from EbookPlaceholders
where EbookId = ?
', [$this->EbookId], EbookPlaceholder::class)[0] ?? null;
}
} }
return $this->_EbookPlaceholder; return $this->_EbookPlaceholder;

View file

@ -11,7 +11,7 @@ class EbookPlaceholder{
public int $EbookId; public int $EbookId;
public ?int $YearPublished = null; public ?int $YearPublished = null;
public bool $IsWanted = false; public bool $IsWanted = false;
public ?Enums\EbookPlaceholderStatus $Status = null; public bool $IsInProgress = false;
public ?Enums\EbookPlaceholderDifficulty $Difficulty = null; public ?Enums\EbookPlaceholderDifficulty $Difficulty = null;
public ?string $TranscriptionUrl = null; public ?string $TranscriptionUrl = null;
public bool $IsPatron = false; public bool $IsPatron = false;
@ -61,10 +61,10 @@ class EbookPlaceholder{
public function FillFromHttpPost(): void{ public function FillFromHttpPost(): void{
$this->PropertyFromHttp('YearPublished'); $this->PropertyFromHttp('YearPublished');
$this->PropertyFromHttp('IsWanted'); $this->PropertyFromHttp('IsWanted');
$this->PropertyFromHttp('IsInProgress');
// These properties apply only to books on the SE wanted list. // These properties apply only to books on the SE wanted list.
if($this->IsWanted){ if($this->IsWanted){
$this->PropertyFromHttp('Status');
$this->PropertyFromHttp('Difficulty'); $this->PropertyFromHttp('Difficulty');
$this->PropertyFromHttp('TranscriptionUrl'); $this->PropertyFromHttp('TranscriptionUrl');
$this->PropertyFromHttp('IsPatron'); $this->PropertyFromHttp('IsPatron');
@ -104,8 +104,8 @@ class EbookPlaceholder{
public function Create(): void{ public function Create(): void{
$this->Validate(); $this->Validate();
Db::Query(' Db::Query('
INSERT into EbookPlaceholders (EbookId, YearPublished, Status, Difficulty, TranscriptionUrl, INSERT into EbookPlaceholders (EbookId, YearPublished, Difficulty, TranscriptionUrl,
IsWanted, IsPatron, Notes) IsWanted, IsInProgress, IsPatron, Notes)
values (?, values (?,
?, ?,
?, ?,
@ -114,7 +114,7 @@ class EbookPlaceholder{
?, ?,
?, ?,
?) ?)
', [$this->EbookId, $this->YearPublished, $this->Status, $this->Difficulty, $this->TranscriptionUrl, ', [$this->EbookId, $this->YearPublished, $this->Difficulty, $this->TranscriptionUrl,
$this->IsWanted, $this->IsPatron, $this->Notes]); $this->IsWanted, $this->IsInProgress, $this->IsPatron, $this->Notes]);
} }
} }

View file

@ -1,7 +0,0 @@
<?
namespace Enums;
enum EbookPlaceholderStatus: string{
case Wanted = 'wanted';
case InProgress = 'in_progress';
}

View file

@ -12,7 +12,7 @@ $collection = $collection ?? null;
<meta property="schema:name" content="<?= Formatter::EscapeHtml($collection->Name) ?>"/> <meta property="schema:name" content="<?= Formatter::EscapeHtml($collection->Name) ?>"/>
<? } ?> <? } ?>
<? foreach($ebooks as $ebook){ ?> <? foreach($ebooks as $ebook){ ?>
<li typeof="schema:Book"<? if($collection !== null){ ?> resource="<?= $ebook->Url ?>" property="schema:hasPart"<? if($ebook->GetCollectionPosition($collection) !== null){ ?> value="<?= $ebook->GetCollectionPosition($collection) ?>"<? } ?><? }else{ ?> about="<?= $ebook->Url ?>"<? } ?><? if($ebook->EbookPlaceholder?->IsWanted){ ?> class="ribbon <? if($ebook->EbookPlaceholder->Status == \Enums\EbookPlaceholderStatus::InProgress){ ?>in-progress<? }else{ ?>wanted<? } ?>"<? }elseif($ebook->EbookPlaceholder !== null && !$ebook->EbookPlaceholder->IsPublicDomain){ ?> class="ribbon not-pd"<? } ?>> <li typeof="schema:Book"<? if($collection !== null){ ?> resource="<?= $ebook->Url ?>" property="schema:hasPart"<? if($ebook->GetCollectionPosition($collection) !== null){ ?> value="<?= $ebook->GetCollectionPosition($collection) ?>"<? } ?><? }else{ ?> about="<?= $ebook->Url ?>"<? } ?><? if($ebook->EbookPlaceholder?->IsInProgress){ ?> class="ribbon in-progress"<? }elseif($ebook->EbookPlaceholder?->IsWanted){ ?> class="ribbon wanted"<? }elseif($ebook->EbookPlaceholder !== null && !$ebook->EbookPlaceholder->IsPublicDomain){ ?> class="ribbon not-pd"<? } ?>>
<? if($collection !== null && $ebook->GetCollectionPosition($collection) !== null){ ?> <? if($collection !== null && $ebook->GetCollectionPosition($collection) !== null){ ?>
<meta property="schema:position" content="<?= $ebook->GetCollectionPosition($collection) ?>"/> <meta property="schema:position" content="<?= $ebook->GetCollectionPosition($collection) ?>"/>
<? } ?> <? } ?>

View file

@ -74,7 +74,7 @@ $ebook = $ebook ?? new Ebook();
<label class="icon book"> <label class="icon book">
<span>Title</span> <span>Title</span>
<input type="text" name="ebook-title" required="required" <input type="text" name="ebook-title" required="required"
value="<? if(isset($ebook->Title)){ ?><?= Formatter::EscapeHtml($ebook->Title) ?><? } ?>"/> value="<?= Formatter::EscapeHtml($ebook->Title ?? '') ?>"/>
</label> </label>
<fieldset> <fieldset>
<label class="icon year"> <label class="icon year">
@ -84,7 +84,7 @@ $ebook = $ebook ?? new Ebook();
name="ebook-placeholder-year-published" name="ebook-placeholder-year-published"
inputmode="numeric" inputmode="numeric"
pattern="[0-9]{1,4}" pattern="[0-9]{1,4}"
value="<? if(isset($ebook->EbookPlaceholder)){ ?><?= Formatter::EscapeHtml((string)$ebook->EbookPlaceholder->YearPublished) ?><? } ?>" value="<?= Formatter::EscapeHtml((string)($ebook?->EbookPlaceholder?->YearPublished)) ?>"
/> />
</label> </label>
</fieldset> </fieldset>
@ -165,22 +165,34 @@ $ebook = $ebook ?? new Ebook();
</fieldset> </fieldset>
</details> </details>
<fieldset> <fieldset>
<label>
<span>In progress?</span>
<input type="hidden" name="ebook-placeholder-is-in-progress" value="false" />
<input
type="checkbox"
name="ebook-placeholder-is-in-progress"
<? if($ebook?->EbookPlaceholder?->IsInProgress){ ?>checked="checked"<? } ?>
/>
</label>
<legend>Wanted list</legend> <legend>Wanted list</legend>
<label class="controls-following-fieldset"> <label class="controls-following-fieldset">
<span>On the wanted list?</span> <span>On the wanted list?</span>
<input type="hidden" name="ebook-placeholder-is-wanted" value="false" />
<input <input
type="checkbox" type="checkbox"
name="ebook-placeholder-is-wanted" name="ebook-placeholder-is-wanted"
<? if(isset($ebook->EbookPlaceholder) && $ebook->EbookPlaceholder->IsWanted){ ?>checked="checked"<? } ?> <? if($ebook?->EbookPlaceholder?->IsWanted){ ?>checked="checked"<? } ?>
/> />
</label> </label>
<fieldset> <fieldset>
<label> <label>
<span>Did a Patron request this book?</span> <span>Did a Patron request this book?</span>
<input type="hidden" name="ebook-placeholder-is-patron" value="false" />
<input <input
type="checkbox" type="checkbox"
name="ebook-placeholder-is-patron" name="ebook-placeholder-is-patron"
<? if(isset($ebook->EbookPlaceholder) && $ebook->EbookPlaceholder->IsPatron){ ?>checked="checked"<? } ?> <? if($ebook?->EbookPlaceholder?->IsPatron){ ?>checked="checked"<? } ?>
/> />
</label> </label>
<label class="icon meter"> <label class="icon meter">
@ -188,18 +200,9 @@ $ebook = $ebook ?? new Ebook();
<span> <span>
<select name="ebook-placeholder-difficulty"> <select name="ebook-placeholder-difficulty">
<option value=""></option> <option value=""></option>
<option value="<?= Enums\EbookPlaceholderDifficulty::Beginner->value ?>"<? if(isset($ebook->EbookPlaceholder) && $ebook->EbookPlaceholder->Difficulty == Enums\EbookPlaceholderDifficulty::Beginner){ ?> selected="selected"<? } ?>>Beginner</option> <option value="<?= Enums\EbookPlaceholderDifficulty::Beginner->value ?>"<? if($ebook?->EbookPlaceholder?->Difficulty == Enums\EbookPlaceholderDifficulty::Beginner){ ?> selected="selected"<? } ?>>Beginner</option>
<option value="<?= Enums\EbookPlaceholderDifficulty::Intermediate->value ?>"<? if(isset($ebook->EbookPlaceholder) && $ebook->EbookPlaceholder->Difficulty == Enums\EbookPlaceholderDifficulty::Intermediate){ ?> selected="selected"<? } ?>>Intermediate</option> <option value="<?= Enums\EbookPlaceholderDifficulty::Intermediate->value ?>"<? if($ebook?->EbookPlaceholder?->Difficulty == Enums\EbookPlaceholderDifficulty::Intermediate){ ?> selected="selected"<? } ?>>Intermediate</option>
<option value="<?= Enums\EbookPlaceholderDifficulty::Advanced->value ?>"<? if(isset($ebook->EbookPlaceholder) && $ebook->EbookPlaceholder->Difficulty == Enums\EbookPlaceholderDifficulty::Advanced){ ?> selected="selected"<? } ?>>Advanced</option> <option value="<?= Enums\EbookPlaceholderDifficulty::Advanced->value ?>"<? if($ebook?->EbookPlaceholder?->Difficulty == Enums\EbookPlaceholderDifficulty::Advanced){ ?> selected="selected"<? } ?>>Advanced</option>
</select>
</span>
</label>
<label class="icon hourglass">
<span>Wanted list status</span>
<span>
<select name="ebook-placeholder-status">
<option value="<?= Enums\EbookPlaceholderStatus::Wanted->value ?>"<? if(isset($ebook->EbookPlaceholder) && $ebook->EbookPlaceholder->Status == Enums\EbookPlaceholderStatus::Wanted){ ?> selected="selected"<? } ?>>Wanted</option>
<option value="<?= Enums\EbookPlaceholderStatus::InProgress->value ?>"<? if(isset($ebook->EbookPlaceholder) && $ebook->EbookPlaceholder->Status == Enums\EbookPlaceholderStatus::InProgress){ ?> selected="selected"<? } ?>>In progress</option>
</select> </select>
</span> </span>
</label> </label>
@ -208,13 +211,13 @@ $ebook = $ebook ?? new Ebook();
<input <input
type="url" type="url"
name="ebook-placeholder-transcription-url" name="ebook-placeholder-transcription-url"
value="<? if(isset($ebook->EbookPlaceholder)){ ?><?= Formatter::EscapeHtml($ebook->EbookPlaceholder->TranscriptionUrl) ?><? } ?>" value="<?= Formatter::EscapeHtml($ebook?->EbookPlaceholder?->TranscriptionUrl) ?>"
/> />
</label> </label>
<label> <label>
<span>Notes</span> <span>Notes</span>
<span>Markdown accepted.</span> <span>Markdown accepted.</span>
<textarea maxlength="1024" name="ebook-placeholder-notes"><? if(isset($ebook->EbookPlaceholder)){ ?><?= Formatter::EscapeHtml($ebook->EbookPlaceholder->Notes) ?><? } ?></textarea> <textarea maxlength="1024" name="ebook-placeholder-notes"><?= Formatter::EscapeHtml($ebook?->EbookPlaceholder?->Notes) ?></textarea>
</label> </label>
</fieldset> </fieldset>
</fieldset> </fieldset>

View file

@ -78,7 +78,7 @@ catch(Exceptions\EbookNotFoundException){
<section class="placeholder-details"> <section class="placeholder-details">
<? if($ebook->EbookPlaceholder->IsPublicDomain){ ?> <? if($ebook->EbookPlaceholder->IsPublicDomain){ ?>
<? if($ebook->EbookPlaceholder->Status == \Enums\EbookPlaceholderStatus::InProgress){ ?> <? if($ebook->EbookPlaceholder->IsInProgress){ ?>
<p>We dont have this ebook in our catalog yet, but someone is working on it now! We hope to have it available for you to read very soon.</p> <p>We dont have this ebook in our catalog yet, but someone is working on it now! We hope to have it available for you to read very soon.</p>
<? }else{ ?> <? }else{ ?>
<p>We dont have this ebook in our catalog yet, but its <? if($ebook->EbookPlaceholder->IsWanted){ ?>on our <a href="/contribute/wanted-ebooks">Wanted Ebooks list</a><? }else{ ?>in the U.S. public domain<? } ?>!</p> <p>We dont have this ebook in our catalog yet, but its <? if($ebook->EbookPlaceholder->IsWanted){ ?>on our <a href="/contribute/wanted-ebooks">Wanted Ebooks list</a><? }else{ ?>in the U.S. public domain<? } ?>!</p>