Add more detail to ebook placeholder page

This commit is contained in:
Alex Cabal 2024-12-13 13:02:41 -06:00
parent 77056dd267
commit bbb25488e1
2 changed files with 27 additions and 1 deletions

View file

@ -2,6 +2,7 @@
/**
* @property bool $IsPublicDomain
* @property string $TimeTillIsPublicDomain A string describing how much longer it will be before this work is in the U.S. public domain, like `3 months` or `20 years`.
*/
class EbookPlaceholder{
use Traits\Accessor;
@ -17,6 +18,7 @@ class EbookPlaceholder{
public ?string $Notes = null;
protected bool $_IsPublicDomain;
protected string $_TimeTillIsPublicDomain;
protected function GetIsPublicDomain(): bool{
if(!isset($this->_IsPublicDomain)){
@ -32,6 +34,30 @@ class EbookPlaceholder{
return $this->_IsPublicDomain;
}
protected function GetTimeTillIsPublicDomain(): string{
if(!isset($this->_TimeTillIsPublicDomain)){
if($this->IsPublicDomain || $this->YearPublished === null){
$this->_TimeTillIsPublicDomain = '';
}
else{
$years = (int)($this->YearPublished) + 96 - (int)(NOW->format('Y'));
if($years > 1){
$this->_TimeTillIsPublicDomain = $years . ' years';
}
else{
$months = 13 - (int)(NOW->format('n'));
$this->_TimeTillIsPublicDomain = $months . ' month';
if($months != 1){
$this->_TimeTillIsPublicDomain .= 's';
}
}
}
}
return $this->_TimeTillIsPublicDomain;
}
public function FillFromHttpPost(): void{
$this->PropertyFromHttp('YearPublished');
$this->PropertyFromHttp('IsWanted');

View file

@ -77,7 +77,7 @@ catch(Exceptions\EbookNotFoundException){
<p>We dont have this ebook in our catalog yet.</p>
<p>You can <a href="/donate#sponsor-an-ebook">sponsor the production of this ebook</a> and well get working on it immediately!</p>
<? }elseif($ebook->EbookPlaceholder->YearPublished !== null){ ?>
<p>This book was published in <?= $ebook->EbookPlaceholder->YearPublished ?>, and will therefore enter the U.S. public domain on <b>January 1, <?= $ebook->EbookPlaceholder->YearPublished + 96 ?>.</b></p>
<p>This book was published in <?= $ebook->EbookPlaceholder->YearPublished ?>, and will therefore enter the U.S. public domain <?= $ebook->EbookPlaceholder->TimeTillIsPublicDomain != '' ? 'in ' . $ebook->EbookPlaceholder->TimeTillIsPublicDomain : '' ?> on <b>January 1, <?= $ebook->EbookPlaceholder->YearPublished + 96 ?>.</b></p>
<p>We cant work on it any earlier than that.</p>
<? }else{ ?>
<p>This book is not yet in the U.S. public domain. We cant offer it until it is.</p>