Use shorthand assignment for basic getters

This commit is contained in:
Alex Cabal 2025-02-27 16:03:26 -06:00
parent 99b5fd66f2
commit 7f5ffb4aea
21 changed files with 142 additions and 326 deletions

View file

@ -41,11 +41,7 @@ class Artist{
} }
protected function GetUrl(): string{ protected function GetUrl(): string{
if(!isset($this->_Url)){ return $this->_Url ??= '/artworks/' . $this->UrlName;
$this->_Url = '/artworks/' . $this->UrlName;
}
return $this->_Url;
} }
/** /**
@ -82,7 +78,9 @@ class Artist{
$error = new Exceptions\InvalidArtistException(); $error = new Exceptions\InvalidArtistException();
if(!isset($this->Name) || $this->Name == ''){ $this->Name = trim($this->Name ?? '');
if($this->Name == ''){
$error->Add(new Exceptions\ArtistNameRequiredException()); $error->Add(new Exceptions\ArtistNameRequiredException());
} }
elseif(strlen($this->Name) > ARTWORK_MAX_STRING_LENGTH){ elseif(strlen($this->Name) > ARTWORK_MAX_STRING_LENGTH){

View file

@ -146,35 +146,23 @@ class Artwork{
} }
protected function GetUrl(): string{ protected function GetUrl(): string{
if(!isset($this->_Url)){ return $this->_Url ??= '/artworks/' . $this->Artist->UrlName . '/' . $this->UrlName;
$this->_Url = '/artworks/' . $this->Artist->UrlName . '/' . $this->UrlName;
}
return $this->_Url;
} }
protected function GetEditUrl(): string{ protected function GetEditUrl(): string{
if(!isset($this->_EditUrl)){ return $this->_EditUrl ??= $this->Url . '/edit';
$this->_EditUrl = $this->Url . '/edit';
}
return $this->_EditUrl;
} }
/** /**
* @return array<ArtworkTag> * @return array<ArtworkTag>
*/ */
protected function GetTags(): array{ protected function GetTags(): array{
if(!isset($this->_Tags)){ return $this->_Tags ??= Db::Query('
$this->_Tags = Db::Query('
SELECT t.* SELECT t.*
from Tags t from Tags t
inner join ArtworkTags at using (TagId) inner join ArtworkTags at using (TagId)
where ArtworkId = ? where ArtworkId = ?
', [$this->ArtworkId], ArtworkTag::class); ', [$this->ArtworkId], ArtworkTag::class);
}
return $this->_Tags;
} }
/** /**
@ -359,28 +347,29 @@ class Artwork{
} }
} }
if($this->Exception !== null && trim($this->Exception) == ''){ $this->Exception = trim($this->Exception ?? '');
if($this->Exception == ''){
$this->Exception = null; $this->Exception = null;
} }
if($this->Notes !== null && trim($this->Notes) == ''){ $this->Notes = trim($this->Notes ?? '');
if($this->Notes == ''){
$this->Notes = null; $this->Notes = null;
} }
if(isset($this->Name)){ $this->Name = trim($this->Name ?? '');
if($this->Name == ''){
$error->Add(new Exceptions\ArtworkNameRequiredException());
}
if(strlen($this->Name) > ARTWORK_MAX_STRING_LENGTH){ if($this->Name == ''){
$error->Add(new Exceptions\StringTooLongException('Artwork Name'));
}
}
else{
$error->Add(new Exceptions\ArtworkNameRequiredException()); $error->Add(new Exceptions\ArtworkNameRequiredException());
} }
if($this->CompletedYear !== null && ($this->CompletedYear <= 0 || $this->CompletedYear > $thisYear)){ if(strlen($this->Name) > ARTWORK_MAX_STRING_LENGTH){
$error->Add(new Exceptions\StringTooLongException('Artwork Name'));
}
if(isset($this->CompletedYear) && ($this->CompletedYear <= 0 || $this->CompletedYear > $thisYear)){
$error->Add(new Exceptions\InvalidCompletedYearException()); $error->Add(new Exceptions\InvalidCompletedYearException());
} }
@ -388,7 +377,7 @@ class Artwork{
$this->CompletedYearIsCirca = false; $this->CompletedYearIsCirca = false;
} }
if($this->PublicationYear !== null && ($this->PublicationYear <= 0 || $this->PublicationYear > $thisYear)){ if(isset($this->PublicationYear) && ($this->PublicationYear <= 0 || $this->PublicationYear > $thisYear)){
$error->Add(new Exceptions\InvalidPublicationYearException()); $error->Add(new Exceptions\InvalidPublicationYearException());
} }
@ -396,29 +385,28 @@ class Artwork{
$error->Add(new Exceptions\InvalidArtworkStatusException()); $error->Add(new Exceptions\InvalidArtworkStatusException());
} }
if(isset($this->Tags)){ $this->Tags ??= [];
if(count($this->Tags) == 0){
$error->Add(new Exceptions\TagsRequiredException());
}
if(count($this->Tags) > ARTWORK_MAX_TAGS){ if(sizeof($this->Tags) == 0){
$error->Add(new Exceptions\TooManyTagsException());
}
foreach($this->Tags as $tag){
try{
$tag->Validate();
}
catch(Exceptions\ValidationException $ex){
$error->Add($ex);
}
}
}
else{
$error->Add(new Exceptions\TagsRequiredException()); $error->Add(new Exceptions\TagsRequiredException());
} }
if($this->MuseumUrl !== null){ if(sizeof($this->Tags) > ARTWORK_MAX_TAGS){
$error->Add(new Exceptions\TooManyTagsException());
}
foreach($this->Tags as $tag){
try{
$tag->Validate();
}
catch(Exceptions\ValidationException $ex){
$error->Add($ex);
}
}
$this->MuseumUrl = trim($this->MuseumUrl ?? '');
if($this->MuseumUrl != ''){
if(strlen($this->MuseumUrl) > ARTWORK_MAX_STRING_LENGTH){ if(strlen($this->MuseumUrl) > ARTWORK_MAX_STRING_LENGTH){
$error->Add(new Exceptions\StringTooLongException('Link to an approved museum page')); $error->Add(new Exceptions\StringTooLongException('Link to an approved museum page'));
} }
@ -431,13 +419,18 @@ class Artwork{
$error->Add($ex); $error->Add($ex);
} }
} }
else{
$this->MuseumUrl = null;
}
if($this->PublicationYearPageUrl !== null){ $this->PublicationYearPageUrl = trim($this->PublicationYearPageUrl ?? '');
if($this->PublicationYearPageUrl != ''){
if(strlen($this->PublicationYearPageUrl) > ARTWORK_MAX_STRING_LENGTH){ if(strlen($this->PublicationYearPageUrl) > ARTWORK_MAX_STRING_LENGTH){
$error->Add(new Exceptions\StringTooLongException('Link to page with year of publication')); $error->Add(new Exceptions\StringTooLongException('Link to page with year of publication'));
} }
if($this->PublicationYearPageUrl == '' || filter_var($this->PublicationYearPageUrl, FILTER_VALIDATE_URL) === false){ if(filter_var($this->PublicationYearPageUrl, FILTER_VALIDATE_URL) === false){
$error->Add(new Exceptions\InvalidPublicationYearPageUrlException()); $error->Add(new Exceptions\InvalidPublicationYearPageUrlException());
} }
else{ else{
@ -449,13 +442,18 @@ class Artwork{
} }
} }
} }
else{
$this->PublicationYearPageUrl = null;
}
if($this->CopyrightPageUrl !== null){ $this->CopyrightPageUrl = trim($this->CopyrightPageUrl ?? '');
if($this->CopyrightPageUrl != ''){
if(strlen($this->CopyrightPageUrl) > ARTWORK_MAX_STRING_LENGTH){ if(strlen($this->CopyrightPageUrl) > ARTWORK_MAX_STRING_LENGTH){
$error->Add(new Exceptions\StringTooLongException('Link to page with copyright details')); $error->Add(new Exceptions\StringTooLongException('Link to page with copyright details'));
} }
if($this->CopyrightPageUrl == '' || filter_var($this->CopyrightPageUrl, FILTER_VALIDATE_URL) === false){ if(filter_var($this->CopyrightPageUrl, FILTER_VALIDATE_URL) === false){
$error->Add(new Exceptions\InvalidCopyrightPageUrlException()); $error->Add(new Exceptions\InvalidCopyrightPageUrlException());
} }
else{ else{
@ -467,13 +465,18 @@ class Artwork{
} }
} }
} }
else{
$this->CopyrightPageUrl = null;
}
if($this->ArtworkPageUrl !== null){ $this->ArtworkPageUrl = trim($this->ArtworkPageUrl ?? '');
if($this->ArtworkPageUrl != ''){
if(strlen($this->ArtworkPageUrl) > ARTWORK_MAX_STRING_LENGTH){ if(strlen($this->ArtworkPageUrl) > ARTWORK_MAX_STRING_LENGTH){
$error->Add(new Exceptions\StringTooLongException('Link to page with artwork')); $error->Add(new Exceptions\StringTooLongException('Link to page with artwork'));
} }
if($this->ArtworkPageUrl == '' || filter_var($this->ArtworkPageUrl, FILTER_VALIDATE_URL) === false){ if(filter_var($this->ArtworkPageUrl, FILTER_VALIDATE_URL) === false){
$error->Add(new Exceptions\InvalidArtworkPageUrlException()); $error->Add(new Exceptions\InvalidArtworkPageUrlException());
} }
else{ else{
@ -485,18 +488,20 @@ class Artwork{
} }
} }
} }
else{
$this->ArtworkPageUrl = null;
}
$hasMuseumProof = $this->MuseumUrl !== null && $this->MuseumUrl != ''; $hasMuseumProof = $this->MuseumUrl !== null;
$hasBookProof = $this->PublicationYear !== null $hasBookProof = $this->PublicationYear !== null && $this->PublicationYearPageUrl !== null && $this->ArtworkPageUrl !== null;
&& ($this->PublicationYearPageUrl !== null && $this->PublicationYearPageUrl != '')
&& ($this->ArtworkPageUrl !== null && $this->ArtworkPageUrl != '');
if(!$hasMuseumProof && !$hasBookProof && $this->Exception === null){ if(!$hasMuseumProof && !$hasBookProof && $this->Exception === null){
$error->Add(new Exceptions\MissingPdProofException()); $error->Add(new Exceptions\MissingPdProofException());
} }
// Check the ebook URL. $this->EbookUrl = trim($this->EbookUrl ?? '');
if($this->EbookUrl !== null){
if($this->EbookUrl != ''){
try{ try{
Ebook::GetByIdentifier('url:' . $this->EbookUrl); Ebook::GetByIdentifier('url:' . $this->EbookUrl);
@ -507,6 +512,9 @@ class Artwork{
$error->Add(new Exceptions\EbookNotFoundException('Couldnt find an ebook with that URL.')); $error->Add(new Exceptions\EbookNotFoundException('Couldnt find an ebook with that URL.'));
} }
} }
else{
$this->EbookUrl = null;
}
// Check for existing `Artwork` objects with the same URL but different `ArtworkID`s. // Check for existing `Artwork` objects with the same URL but different `ArtworkID`s.
try{ try{

View file

@ -13,11 +13,7 @@ class ArtworkTag extends Tag{
// ******* // *******
protected function GetUrl(): string{ protected function GetUrl(): string{
if(!isset($this->_Url)){ return $this->_Url ??= '/artworks?query=' . Formatter::MakeUrlSafe($this->Name);
$this->_Url = '/artworks?query=' . Formatter::MakeUrlSafe($this->Name);
}
return $this->_Url;
} }

View file

@ -24,22 +24,14 @@ class Collection{
// ******* // *******
protected function GetUrl(): string{ protected function GetUrl(): string{
if(!isset($this->_Url)){ return $this->_Url ??= '/collections/' . $this->UrlName;
$this->_Url = '/collections/' . $this->UrlName;
}
return $this->_Url;
} }
/** /**
* @return array<Ebook> * @return array<Ebook>
*/ */
protected function GetEbooks(): array{ protected function GetEbooks(): array{
if(!isset($this->_Ebooks)){ return $this->_Ebooks ??= Ebook::GetAllByCollection($this->CollectionId);
$this->_Ebooks = Ebook::GetAllByCollection($this->CollectionId);
}
return $this->_Ebooks;
} }

View file

@ -73,7 +73,6 @@ class Contributor{
$error->Add(new Exceptions\ContributorEbookIdRequiredException()); $error->Add(new Exceptions\ContributorEbookIdRequiredException());
} }
$this->Name = trim($this->Name ?? ''); $this->Name = trim($this->Name ?? '');
if($this->Name == ''){ if($this->Name == ''){
$error->Add(new Exceptions\ContributorNameRequiredException()); $error->Add(new Exceptions\ContributorNameRequiredException());

View file

@ -24,33 +24,30 @@ class DonationDrive{
// ******* // *******
protected function GetDonationCount(): int{ protected function GetDonationCount(): int{
if(!isset($this->_DonationCount)){ return $this->_DonationCount ??= Db::QueryInt('
$this->_DonationCount = Db::QueryInt(' SELECT sum(cnt)
SELECT sum(cnt) from
from (
( (
# Anonymous patrons, i.e. from AOGF
select count(*) cnt from Payments
where
UserId is null
and
( (
# Anonymous patrons, i.e. from AOGF (IsRecurring = true and Amount >= 10 and Created >= ?)
select count(*) cnt from Payments or
where (IsRecurring = false and Amount >= 100 and Created >= ?)
UserId is null
and
(
(IsRecurring = true and Amount >= 10 and Created >= ?)
or
(IsRecurring = false and Amount >= 100 and Created >= ?)
)
) )
union all )
( union all
# All non-anonymous patrons (
select count(*) as cnt from Patrons # All non-anonymous patrons
where Created >= ? select count(*) as cnt from Patrons
) where Created >= ?
) x )
', [$this->Start, $this->Start, $this->Start]); ) x
} ', [$this->Start, $this->Start, $this->Start]);
return $this->_DonationCount;
} }
protected function GetTargetDonationCount(): int{ protected function GetTargetDonationCount(): int{

View file

@ -143,8 +143,7 @@ final class Ebook{
// ******* // *******
protected function GetArtwork(): ?Artwork{ protected function GetArtwork(): ?Artwork{
if(!isset($this->_Artwork)){ return $this->_Artwork ??= Db::Query('
$this->_Artwork = Db::Query('
SELECT SELECT
* *
from from
@ -152,17 +151,13 @@ final class Ebook{
where where
EbookUrl = ? EbookUrl = ?
', [preg_replace('/^url:/iu', '', $this->Identifier)], Artwork::class)[0] ?? null; ', [preg_replace('/^url:/iu', '', $this->Identifier)], Artwork::class)[0] ?? null;
}
return $this->_Artwork;
} }
/** /**
* @return array<Project> * @return array<Project>
*/ */
protected function GetProjects(): array{ protected function GetProjects(): array{
if(!isset($this->_Projects)){ return $this->_Projects ??= Db::MultiTableSelect('
$this->_Projects = Db::MultiTableSelect('
SELECT * SELECT *
from Projects from Projects
inner join Ebooks inner join Ebooks
@ -170,9 +165,6 @@ final class Ebook{
where Ebooks.EbookId = ? where Ebooks.EbookId = ?
order by Projects.Created desc order by Projects.Created desc
', [$this->EbookId], Project::class); ', [$this->EbookId], Project::class);
}
return $this->_Projects;
} }
protected function GetProjectInProgress(): ?Project{ protected function GetProjectInProgress(): ?Project{
@ -222,82 +214,62 @@ final class Ebook{
* @return array<GitCommit> * @return array<GitCommit>
*/ */
protected function GetGitCommits(): array{ protected function GetGitCommits(): array{
if(!isset($this->_GitCommits)){ return $this->_GitCommits ??= Db::Query('
$this->_GitCommits = Db::Query('
SELECT * SELECT *
from GitCommits from GitCommits
where EbookId = ? where EbookId = ?
order by Created desc order by Created desc
', [$this->EbookId], GitCommit::class); ', [$this->EbookId], GitCommit::class);
}
return $this->_GitCommits;
} }
/** /**
* @return array<EbookTag> * @return array<EbookTag>
*/ */
protected function GetTags(): array{ protected function GetTags(): array{
if(!isset($this->_Tags)){ return $this->_Tags ??= Db::Query('
$this->_Tags = Db::Query('
SELECT t.* SELECT t.*
from Tags t from Tags t
inner join EbookTags et using (TagId) inner join EbookTags et using (TagId)
where EbookId = ? where EbookId = ?
order by SortOrder asc order by SortOrder asc
', [$this->EbookId], EbookTag::class); ', [$this->EbookId], EbookTag::class);
}
return $this->_Tags;
} }
/** /**
* @return array<LocSubject> * @return array<LocSubject>
*/ */
protected function GetLocSubjects(): array{ protected function GetLocSubjects(): array{
if(!isset($this->_LocSubjects)){ return $this->_LocSubjects ??= Db::Query('
$this->_LocSubjects = Db::Query('
SELECT l.* SELECT l.*
from LocSubjects l from LocSubjects l
inner join EbookLocSubjects el using (LocSubjectId) inner join EbookLocSubjects el using (LocSubjectId)
where EbookId = ? where EbookId = ?
order by SortOrder asc order by SortOrder asc
', [$this->EbookId], LocSubject::class); ', [$this->EbookId], LocSubject::class);
}
return $this->_LocSubjects;
} }
/** /**
* @return array<CollectionMembership> * @return array<CollectionMembership>
*/ */
protected function GetCollectionMemberships(): array{ protected function GetCollectionMemberships(): array{
if(!isset($this->_CollectionMemberships)){ return $this->_CollectionMemberships ??= Db::Query('
$this->_CollectionMemberships = Db::Query('
SELECT * SELECT *
from CollectionEbooks from CollectionEbooks
where EbookId = ? where EbookId = ?
order by SortOrder asc order by SortOrder asc
', [$this->EbookId], CollectionMembership::class); ', [$this->EbookId], CollectionMembership::class);
}
return $this->_CollectionMemberships;
} }
/** /**
* @return array<EbookSource> * @return array<EbookSource>
*/ */
protected function GetSources(): array{ protected function GetSources(): array{
if(!isset($this->_Sources)){ return $this->_Sources ??= Db::Query('
$this->_Sources = Db::Query('
SELECT * SELECT *
from EbookSources from EbookSources
where EbookId = ? where EbookId = ?
order by SortOrder asc order by SortOrder asc
', [$this->EbookId], EbookSource::class); ', [$this->EbookId], EbookSource::class);
}
return $this->_Sources;
} }
/** /**
@ -418,51 +390,27 @@ final class Ebook{
} }
protected function GetUrl(): string{ protected function GetUrl(): string{
if(!isset($this->_Url)){ return $this->_Url ??= str_replace(EBOOKS_IDENTIFIER_ROOT, '', $this->Identifier);
$this->_Url = str_replace(EBOOKS_IDENTIFIER_ROOT, '', $this->Identifier);
}
return $this->_Url;
} }
protected function GetEditUrl(): string{ protected function GetEditUrl(): string{
if(!isset($this->_EditUrl)){ return $this->_EditUrl ??= $this->Url . '/edit';
$this->_EditUrl = $this->Url . '/edit';
}
return $this->_EditUrl;
} }
protected function GetDeleteUrl(): string{ protected function GetDeleteUrl(): string{
if(!isset($this->_DeleteUrl)){ return $this->_DeleteUrl ??= $this->Url . '/delete';
$this->_DeleteUrl = $this->Url . '/delete';
}
return $this->_DeleteUrl;
} }
protected function GetHasDownloads(): bool{ protected function GetHasDownloads(): bool{
if(!isset($this->_HasDownloads)){ return $this->_HasDownloads ??= $this->EpubUrl || $this->AdvancedEpubUrl || $this->KepubUrl || $this->Azw3Url;
$this->_HasDownloads = $this->EpubUrl || $this->AdvancedEpubUrl || $this->KepubUrl || $this->Azw3Url;
}
return $this->_HasDownloads;
} }
protected function GetUrlSafeIdentifier(): string{ protected function GetUrlSafeIdentifier(): string{
if(!isset($this->_UrlSafeIdentifier)){ return $this->_UrlSafeIdentifier ??= str_replace(['url:https://standardebooks.org/ebooks/', '/'], ['', '_'], $this->Identifier);
$this->_UrlSafeIdentifier = str_replace(['url:https://standardebooks.org/ebooks/', '/'], ['', '_'], $this->Identifier);
}
return $this->_UrlSafeIdentifier;
} }
protected function GetHeroImageUrl(): string{ protected function GetHeroImageUrl(): string{
if(!isset($this->_HeroImageUrl)){ return $this->_HeroImageUrl ??= '/images/covers/' . $this->UrlSafeIdentifier . '-' . substr(sha1($this->Updated->format(Enums\DateTimeFormat::UnixTimestamp->value)), 0, 8) . '-hero.jpg';
$this->_HeroImageUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . substr(sha1($this->Updated->format(Enums\DateTimeFormat::UnixTimestamp->value)), 0, 8) . '-hero.jpg';
}
return $this->_HeroImageUrl;
} }
protected function GetHeroImageAvifUrl(): string{ protected function GetHeroImageAvifUrl(): string{
@ -479,11 +427,7 @@ final class Ebook{
} }
protected function GetHeroImage2xUrl(): string{ protected function GetHeroImage2xUrl(): string{
if(!isset($this->_HeroImage2xUrl)){ return $this->_HeroImage2xUrl ??= '/images/covers/' . $this->UrlSafeIdentifier . '-' . substr(sha1($this->Updated->format(Enums\DateTimeFormat::UnixTimestamp->value)), 0, 8) . '-hero@2x.jpg';
$this->_HeroImage2xUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . substr(sha1($this->Updated->format(Enums\DateTimeFormat::UnixTimestamp->value)), 0, 8) . '-hero@2x.jpg';
}
return $this->_HeroImage2xUrl;
} }
protected function GetHeroImage2xAvifUrl(): string{ protected function GetHeroImage2xAvifUrl(): string{
@ -500,11 +444,7 @@ final class Ebook{
} }
protected function GetCoverImageUrl(): string{ protected function GetCoverImageUrl(): string{
if(!isset($this->_CoverImageUrl)){ return $this->_CoverImageUrl ??= '/images/covers/' . $this->UrlSafeIdentifier . '-' . substr(sha1($this->Updated->format(Enums\DateTimeFormat::UnixTimestamp->value)), 0, 8) . '-cover.jpg';
$this->_CoverImageUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . substr(sha1($this->Updated->format(Enums\DateTimeFormat::UnixTimestamp->value)), 0, 8) . '-cover.jpg';
}
return $this->_CoverImageUrl;
} }
protected function GetCoverImageAvifUrl(): string{ protected function GetCoverImageAvifUrl(): string{
@ -521,11 +461,7 @@ final class Ebook{
} }
protected function GetCoverImage2xUrl(): string{ protected function GetCoverImage2xUrl(): string{
if(!isset($this->_CoverImage2xUrl)){ return $this->_CoverImage2xUrl ??= '/images/covers/' . $this->UrlSafeIdentifier . '-' . substr(sha1($this->Updated->format(Enums\DateTimeFormat::UnixTimestamp->value)), 0, 8) . '-cover@2x.jpg';
$this->_CoverImage2xUrl = '/images/covers/' . $this->UrlSafeIdentifier . '-' . substr(sha1($this->Updated->format(Enums\DateTimeFormat::UnixTimestamp->value)), 0, 8) . '-cover@2x.jpg';
}
return $this->_CoverImage2xUrl;
} }
protected function GetCoverImage2xAvifUrl(): string{ protected function GetCoverImage2xAvifUrl(): string{
@ -601,27 +537,15 @@ final class Ebook{
} }
protected function GetAuthorsHtml(): string{ protected function GetAuthorsHtml(): string{
if(!isset($this->_AuthorsHtml)){ return $this->_AuthorsHtml ??= Ebook::GenerateContributorList($this->Authors, true);
$this->_AuthorsHtml = Ebook::GenerateContributorList($this->Authors, true);
}
return $this->_AuthorsHtml;
} }
protected function GetAuthorsUrl(): string{ protected function GetAuthorsUrl(): string{
if(!isset($this->_AuthorsUrl)){ return $this->_AuthorsUrl ??= preg_replace('|url:https://standardebooks.org/ebooks/([^/]+)/.*|ius', '/ebooks/\1', $this->Identifier);
$this->_AuthorsUrl = preg_replace('|url:https://standardebooks.org/ebooks/([^/]+)/.*|ius', '/ebooks/\1', $this->Identifier);
}
return $this->_AuthorsUrl;
} }
protected function GetAuthorsString(): string{ protected function GetAuthorsString(): string{
if(!isset($this->_AuthorsString)){ return $this->_AuthorsString ??= strip_tags(Ebook::GenerateContributorList($this->Authors, false));
$this->_AuthorsString = strip_tags(Ebook::GenerateContributorList($this->Authors, false));
}
return $this->_AuthorsString;
} }
protected function GetContributorsHtml(): string{ protected function GetContributorsHtml(): string{
@ -673,19 +597,11 @@ final class Ebook{
} }
protected function GetTextUrl(): string{ protected function GetTextUrl(): string{
if(!isset($this->_TextUrl)){ return $this->_TextUrl ??= $this->Url . '/text';
$this->_TextUrl = $this->Url . '/text';
}
return $this->_TextUrl;
} }
protected function GetTextSinglePageUrl(): string{ protected function GetTextSinglePageUrl(): string{
if(!isset($this->_TextSinglePageUrl)){ return $this->_TextSinglePageUrl ??= $this->Url . '/text/single-page';
$this->_TextSinglePageUrl = $this->Url . '/text/single-page';
}
return $this->_TextSinglePageUrl;
} }
protected function GetTextSinglePageSizeFormatted(): string{ protected function GetTextSinglePageSizeFormatted(): string{

View file

@ -10,11 +10,7 @@ class EbookTag extends Tag{
// ******* // *******
protected function GetUrl(): string{ protected function GetUrl(): string{
if(!isset($this->_Url)){ return $this->_Url ??= '/subjects/' . $this->UrlName;
$this->_Url = '/subjects/' . $this->UrlName;
}
return $this->_Url;
} }

View file

@ -23,11 +23,7 @@ class NewsletterSubscription{
// ******* // *******
protected function GetUrl(): string{ protected function GetUrl(): string{
if(!isset($this->_Url)){ return $this->_Url ??= '/newsletter/subscriptions/' . $this->User->Uuid;
$this->_Url = '/newsletter/subscriptions/' . $this->User->Uuid;
}
return $this->_Url;
} }

View file

@ -13,10 +13,6 @@ class OpdsAcquisitionFeed extends OpdsFeed{
// ******* // *******
protected function GetXmlString(): string{ protected function GetXmlString(): string{
if(!isset($this->_XmlString)){ return $this->_XmlString ??= $this->CleanXmlString(Template::OpdsAcquisitionFeed(['id' => $this->Id, 'url' => $this->Url, 'title' => $this->Title, 'parentUrl' => $this->Parent ? $this->Parent->Url : null, 'updated' => $this->Updated, 'isCrawlable' => $this->IsCrawlable, 'subtitle' => $this->Subtitle, 'entries' => $this->Entries]));
$this->_XmlString = $this->CleanXmlString(Template::OpdsAcquisitionFeed(['id' => $this->Id, 'url' => $this->Url, 'title' => $this->Title, 'parentUrl' => $this->Parent ? $this->Parent->Url : null, 'updated' => $this->Updated, 'isCrawlable' => $this->IsCrawlable, 'subtitle' => $this->Subtitle, 'entries' => $this->Entries]));
}
return $this->_XmlString;
} }
} }

View file

@ -38,10 +38,6 @@ class OpdsNavigationFeed extends OpdsFeed{
// ******* // *******
protected function GetXmlString(): string{ protected function GetXmlString(): string{
if(!isset($this->_XmlString)){ return $this->_XmlString ??= $this->CleanXmlString(Template::OpdsNavigationFeed(['id' => $this->Id, 'url' => $this->Url, 'title' => $this->Title, 'parentUrl' => $this->Parent ? $this->Parent->Url : null, 'updated' => $this->Updated, 'subtitle' => $this->Subtitle, 'entries' => $this->Entries]));
$this->_XmlString = $this->CleanXmlString(Template::OpdsNavigationFeed(['id' => $this->Id, 'url' => $this->Url, 'title' => $this->Title, 'parentUrl' => $this->Parent ? $this->Parent->Url : null, 'updated' => $this->Updated, 'subtitle' => $this->Subtitle, 'entries' => $this->Entries]));
}
return $this->_XmlString;
} }
} }

View file

@ -26,17 +26,13 @@ class Patron{
// ******* // *******
protected function GetLastPayment(): ?Payment{ protected function GetLastPayment(): ?Payment{
if(!isset($this->_LastPayment)){ return $this->_LastPayment ??= Db::Query('
$this->_LastPayment = Db::Query('
SELECT * SELECT *
from Payments from Payments
where UserId = ? where UserId = ?
order by Created desc order by Created desc
limit 1 limit 1
', [$this->UserId], Payment::class)[0] ?? null; ', [$this->UserId], Payment::class)[0] ?? null;
}
return $this->_LastPayment;
} }

View file

@ -30,11 +30,7 @@ class Payment{
* @throws Exceptions\UserNotFoundException * @throws Exceptions\UserNotFoundException
*/ */
protected function GetUser(): ?User{ protected function GetUser(): ?User{
if(!isset($this->_User) && $this->UserId !== null){ return $this->_User ??= User::Get($this->UserId);
$this->_User = User::Get($this->UserId);
}
return $this->_User;
} }
protected function GetProcessorUrl(): string{ protected function GetProcessorUrl(): string{

View file

@ -31,40 +31,28 @@ class Poll{
// ******* // *******
protected function GetUrl(): string{ protected function GetUrl(): string{
if(!isset($this->_Url)){ return $this->_Url ??= '/polls/' . $this->UrlName;
$this->_Url = '/polls/' . $this->UrlName;
}
return $this->_Url;
} }
protected function GetVoteCount(): int{ protected function GetVoteCount(): int{
if(!isset($this->_VoteCount)){ return $this->_VoteCount ??= Db::QueryInt('
$this->_VoteCount = Db::QueryInt('
SELECT count(*) SELECT count(*)
from PollVotes pv from PollVotes pv
inner join PollItems pi using (PollItemId) inner join PollItems pi using (PollItemId)
where pi.PollId = ? where pi.PollId = ?
', [$this->PollId]); ', [$this->PollId]);
}
return $this->_VoteCount;
} }
/** /**
* @return array<PollItem> * @return array<PollItem>
*/ */
protected function GetPollItems(): array{ protected function GetPollItems(): array{
if(!isset($this->_PollItems)){ return $this->_PollItems ??= Db::Query('
$this->_PollItems = Db::Query('
SELECT * SELECT *
from PollItems from PollItems
where PollId = ? where PollId = ?
order by SortOrder asc order by SortOrder asc
', [$this->PollId], PollItem::class); ', [$this->PollId], PollItem::class);
}
return $this->_PollItems;
} }
/** /**

View file

@ -20,16 +20,12 @@ class PollItem{
// ******* // *******
protected function GetVoteCount(): int{ protected function GetVoteCount(): int{
if(!isset($this->_VoteCount)){ return $this->_VoteCount ??= Db::QueryInt('
$this->_VoteCount = Db::QueryInt('
SELECT count(*) SELECT count(*)
from PollVotes pv from PollVotes pv
inner join PollItems pi using (PollItemId) inner join PollItems pi using (PollItemId)
where pi.PollItemId = ? where pi.PollItemId = ?
', [$this->PollItemId]); ', [$this->PollItemId]);
}
return $this->_VoteCount;
} }

View file

@ -24,11 +24,7 @@ class PollVote{
// ******* // *******
protected function GetUrl(): string{ protected function GetUrl(): string{
if(!isset($this->_Url)){ return $this->_Url ??= $this->PollItem->Poll->Url . '/votes/' . $this->UserId;
$this->_Url = $this->PollItem->Poll->Url . '/votes/' . $this->UserId;
}
return $this->_Url;
} }

View file

@ -115,19 +115,11 @@ final class Project{
} }
protected function GetUrl(): string{ protected function GetUrl(): string{
if(!isset($this->_Url)){ return $this->_Url ??= '/projects/' . $this->ProjectId;
$this->_Url = '/projects/' . $this->ProjectId;
}
return $this->_Url;
} }
protected function GetEditUrl(): string{ protected function GetEditUrl(): string{
if(!isset($this->_EditUrl)){ return $this->_EditUrl ??= $this->Url . '/edit';
$this->_EditUrl = $this->Url . '/edit';
}
return $this->_EditUrl;
} }
protected function GetLastActivityTimestamp(): DateTimeImmutable{ protected function GetLastActivityTimestamp(): DateTimeImmutable{
@ -150,33 +142,21 @@ final class Project{
* @throws Exceptions\UserNotFoundException If the `User` can't be found. * @throws Exceptions\UserNotFoundException If the `User` can't be found.
*/ */
protected function GetManager(): User{ protected function GetManager(): User{
if(!isset($this->_Manager)){ return $this->_Manager ??= User::Get($this->ManagerUserId);
$this->_Manager = User::Get($this->ManagerUserId);
}
return $this->_Manager;
} }
/** /**
* @throws Exceptions\UserNotFoundException If the `User` can't be found. * @throws Exceptions\UserNotFoundException If the `User` can't be found.
*/ */
protected function GetReviewer(): User{ protected function GetReviewer(): User{
if(!isset($this->_Reviewer)){ return $this->_Reviewer ??= User::Get($this->ReviewerUserId);
$this->_Reviewer = User::Get($this->ReviewerUserId);
}
return $this->_Reviewer;
} }
/** /**
* @return array<ProjectReminder> * @return array<ProjectReminder>
*/ */
protected function GetReminders(): array{ protected function GetReminders(): array{
if(!isset($this->_Reminders)){ return $this->_Reminders ??= Db::Query('SELECT * from ProjectReminders where ProjectId = ? order by Created asc', [$this->ProjectId], ProjectReminder::class);
$this->_Reminders = Db::Query('SELECT * from ProjectReminders where ProjectId = ? order by Created asc', [$this->ProjectId], ProjectReminder::class);
}
return $this->_Reminders;
} }

View file

@ -21,13 +21,7 @@ class RssFeed extends Feed{
// ******* // *******
protected function GetXmlString(): string{ protected function GetXmlString(): string{
if(!isset($this->_XmlString)){ return $this->_XmlString ??= $this->CleanXmlString(Template::RssFeed(['url' => $this->Url, 'description' => $this->Description, 'title' => $this->Title, 'entries' => $this->Entries, 'updated' => NOW]));
$feed = Template::RssFeed(['url' => $this->Url, 'description' => $this->Description, 'title' => $this->Title, 'entries' => $this->Entries, 'updated' => NOW]);
$this->_XmlString = $this->CleanXmlString($feed);
}
return $this->_XmlString;
} }
public function SaveIfChanged(): bool{ public function SaveIfChanged(): bool{

View file

@ -24,11 +24,7 @@ class Session{
// ******* // *******
protected function GetUrl(): string{ protected function GetUrl(): string{
if(!isset($this->_Url)){ return $this->_Url ??= '/sessions/' . $this->SessionId;
$this->_Url = '/sessions/' . $this->SessionId;
}
return $this->_Url;
} }

View file

@ -4,8 +4,8 @@ use function Safe\ob_start;
class Template{ class Template{
/** /**
* @param array<mixed> $arguments * @param array<mixed> $arguments
*/ */
protected static function Get(string $templateName, array $arguments = []): string{ protected static function Get(string $templateName, array $arguments = []): string{
// Expand the passed variables to make them available to the included template. // Expand the passed variables to make them available to the included template.
// We use these funny names so that we can use 'name' and 'value' as template variables if we want to. // We use these funny names so that we can use 'name' and 'value' as template variables if we want to.
@ -22,8 +22,8 @@ class Template{
} }
/** /**
* @param array<mixed> $arguments * @param array<mixed> $arguments
*/ */
public static function __callStatic(string $function, array $arguments): string{ public static function __callStatic(string $function, array $arguments): string{
if(isset($arguments[0]) && is_array($arguments[0])){ if(isset($arguments[0]) && is_array($arguments[0])){
return self::Get($function, $arguments[0]); return self::Get($function, $arguments[0]);

View file

@ -116,49 +116,33 @@ class User{
} }
protected function GetUrl(): string{ protected function GetUrl(): string{
if(!isset($this->_Url)){ return $this->_Url ??= '/users/' . $this->UserId;
$this->_Url = '/users/' . $this->UserId;
}
return $this->_Url;
} }
protected function GetEditUrl(): string{ protected function GetEditUrl(): string{
if(!isset($this->_EditUrl)){ return $this->_EditUrl ??= $this->Url . '/edit';
$this->_EditUrl = $this->Url . '/edit';
}
return $this->_EditUrl;
} }
/** /**
* @return array<Payment> * @return array<Payment>
*/ */
protected function GetPayments(): array{ protected function GetPayments(): array{
if(!isset($this->_Payments)){ return $this->_Payments ??= Db::Query('
$this->_Payments = Db::Query('
SELECT * SELECT *
from Payments from Payments
where UserId = ? where UserId = ?
order by Created desc order by Created desc
', [$this->UserId], Payment::class); ', [$this->UserId], Payment::class);
}
return $this->_Payments;
} }
protected function GetLastPayment(): ?Payment{ protected function GetLastPayment(): ?Payment{
if(!isset($this->_LastPayment)){ return $this->_LastPayment ??= Db::Query('
$this->_LastPayment = Db::Query('
SELECT * SELECT *
from Payments from Payments
where UserId = ? where UserId = ?
order by Created desc order by Created desc
limit 1 limit 1
', [$this->UserId], Payment::class)[0] ?? null; ', [$this->UserId], Payment::class)[0] ?? null;
}
return $this->_LastPayment;
} }
protected function GetBenefits(): Benefits{ protected function GetBenefits(): Benefits{