mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 14:50:39 -04:00
Use static class names instead of strings when getting objects from the DB
This commit is contained in:
parent
a442f92e28
commit
acb6b2949f
16 changed files with 36 additions and 34 deletions
|
@ -130,7 +130,7 @@ class Artist{
|
||||||
SELECT *
|
SELECT *
|
||||||
from Artists
|
from Artists
|
||||||
where ArtistId = ?
|
where ArtistId = ?
|
||||||
', [$artistId], 'Artist');
|
', [$artistId], Artist::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\ArtistNotFoundException();;
|
return $result[0] ?? throw new Exceptions\ArtistNotFoundException();;
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ class Artist{
|
||||||
where a.UrlName = ?
|
where a.UrlName = ?
|
||||||
or aan.UrlName = ?
|
or aan.UrlName = ?
|
||||||
limit 1
|
limit 1
|
||||||
', [$artist->UrlName, $artist->UrlName], 'Artist');
|
', [$artist->UrlName, $artist->UrlName], Artist::class);
|
||||||
|
|
||||||
if(isset($result[0])){
|
if(isset($result[0])){
|
||||||
return $result[0];
|
return $result[0];
|
||||||
|
@ -178,6 +178,7 @@ class Artist{
|
||||||
from Artists
|
from Artists
|
||||||
where ArtistId = ?
|
where ArtistId = ?
|
||||||
', [$this->ArtistId]);
|
', [$this->ArtistId]);
|
||||||
|
|
||||||
Db::Query('
|
Db::Query('
|
||||||
DELETE
|
DELETE
|
||||||
from ArtistAlternateNames
|
from ArtistAlternateNames
|
||||||
|
|
|
@ -158,7 +158,7 @@ class Artwork{
|
||||||
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');
|
', [$this->ArtworkId], ArtworkTag::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_Tags;
|
return $this->_Tags;
|
||||||
|
@ -849,7 +849,7 @@ class Artwork{
|
||||||
SELECT *
|
SELECT *
|
||||||
from Artworks
|
from Artworks
|
||||||
where ArtworkId = ?
|
where ArtworkId = ?
|
||||||
', [$artworkId], 'Artwork');
|
', [$artworkId], Artwork::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\ArtworkNotFoundException();
|
return $result[0] ?? throw new Exceptions\ArtworkNotFoundException();
|
||||||
}
|
}
|
||||||
|
@ -867,7 +867,7 @@ class Artwork{
|
||||||
from Artworks
|
from Artworks
|
||||||
inner join Artists using (ArtistId)
|
inner join Artists using (ArtistId)
|
||||||
where Artists.UrlName = ? and Artworks.UrlName = ?
|
where Artists.UrlName = ? and Artworks.UrlName = ?
|
||||||
', [$artistUrlName, $artworkUrlName], 'Artwork');
|
', [$artistUrlName, $artworkUrlName], Artwork::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\ArtworkNotFoundException();
|
return $result[0] ?? throw new Exceptions\ArtworkNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ class ArtworkTag extends Tag{
|
||||||
SELECT *
|
SELECT *
|
||||||
from Tags
|
from Tags
|
||||||
where Name = ?
|
where Name = ?
|
||||||
', [$artworkTag->Name], 'ArtworkTag');
|
', [$artworkTag->Name], ArtworkTag::class);
|
||||||
|
|
||||||
if(isset($result[0])){
|
if(isset($result[0])){
|
||||||
return $result[0];
|
return $result[0];
|
||||||
|
|
|
@ -48,7 +48,7 @@ class HttpInput{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int The maximum size for an HTTP POST request, in bytes
|
* @return int The maximum size for an HTTP POST request, in bytes.
|
||||||
*/
|
*/
|
||||||
public static function GetMaxPostSize(): int{
|
public static function GetMaxPostSize(): int{
|
||||||
$post_max_size = ini_get('post_max_size');
|
$post_max_size = ini_get('post_max_size');
|
||||||
|
|
|
@ -171,7 +171,7 @@ class Library{
|
||||||
* @param string $query
|
* @param string $query
|
||||||
* @param string $status
|
* @param string $status
|
||||||
* @param ArtworkSort $sort
|
* @param ArtworkSort $sort
|
||||||
* @return Array<mixed>
|
* @return array<string, array<Artwork>|int>
|
||||||
*/
|
*/
|
||||||
public static function FilterArtwork(string $query = null, string $status = null, ArtworkSort $sort = null, int $submitterUserId = null, int $page = 1, int $perPage = ARTWORK_PER_PAGE): array{
|
public static function FilterArtwork(string $query = null, string $status = null, ArtworkSort $sort = null, int $submitterUserId = null, int $page = 1, int $perPage = ARTWORK_PER_PAGE): array{
|
||||||
// Returns an array of:
|
// Returns an array of:
|
||||||
|
@ -253,7 +253,7 @@ class Library{
|
||||||
where ' . $statusCondition . '
|
where ' . $statusCondition . '
|
||||||
order by ' . $orderBy . '
|
order by ' . $orderBy . '
|
||||||
limit ?
|
limit ?
|
||||||
offset ?', $params, 'Artwork');
|
offset ?', $params, Artwork::class);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Split the query on word boundaries followed by spaces. This keeps words with apostrophes intact.
|
// Split the query on word boundaries followed by spaces. This keeps words with apostrophes intact.
|
||||||
|
@ -308,13 +308,12 @@ class Library{
|
||||||
group by art.ArtworkId
|
group by art.ArtworkId
|
||||||
order by ' . $orderBy . '
|
order by ' . $orderBy . '
|
||||||
limit ?
|
limit ?
|
||||||
offset ?', $params, 'Artwork');
|
offset ?', $params, Artwork::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['artworks' => $artworks, 'artworksCount' => $artworksCount];
|
return ['artworks' => $artworks, 'artworksCount' => $artworksCount];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<Artwork>
|
* @return array<Artwork>
|
||||||
* @throws Exceptions\ArtistNotFoundException
|
* @throws Exceptions\ArtistNotFoundException
|
||||||
|
@ -354,7 +353,7 @@ class Library{
|
||||||
inner join Artists a using (ArtistId)
|
inner join Artists a using (ArtistId)
|
||||||
where ' . $statusCondition . '
|
where ' . $statusCondition . '
|
||||||
and a.UrlName = ?
|
and a.UrlName = ?
|
||||||
order by art.Created desc', $params, 'Artwork');
|
order by art.Created desc', $params, Artwork::class);
|
||||||
|
|
||||||
return $artworks;
|
return $artworks;
|
||||||
}
|
}
|
||||||
|
@ -819,6 +818,6 @@ class Library{
|
||||||
return Db::Query('
|
return Db::Query('
|
||||||
SELECT *
|
SELECT *
|
||||||
from Artists
|
from Artists
|
||||||
order by Name asc', [], 'Artist');
|
order by Name asc', [], Artist::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -592,7 +592,7 @@ class Museum{
|
||||||
from Museums
|
from Museums
|
||||||
where ? like concat("%", Domain, "%")
|
where ? like concat("%", Domain, "%")
|
||||||
limit 1;
|
limit 1;
|
||||||
', [$parsedUrl['host']], 'Museum');
|
', [$parsedUrl['host']], Museum::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\MuseumNotFoundException();
|
return $result[0] ?? throw new Exceptions\MuseumNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,7 +166,7 @@ class NewsletterSubscription{
|
||||||
from NewsletterSubscriptions ns
|
from NewsletterSubscriptions ns
|
||||||
inner join Users u using(UserId)
|
inner join Users u using(UserId)
|
||||||
where u.Uuid = ?
|
where u.Uuid = ?
|
||||||
', [$uuid], 'NewsletterSubscription');
|
', [$uuid], NewsletterSubscription::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\NewsletterSubscriptionNotFoundException();
|
return $result[0] ?? throw new Exceptions\NewsletterSubscriptionNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ class Patron{
|
||||||
SELECT *
|
SELECT *
|
||||||
from Patrons
|
from Patrons
|
||||||
where UserId = ?
|
where UserId = ?
|
||||||
', [$userId], 'Patron');
|
', [$userId], Patron::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\PatronNotFoundException();;
|
return $result[0] ?? throw new Exceptions\PatronNotFoundException();;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ class Patron{
|
||||||
from Patrons p
|
from Patrons p
|
||||||
inner join Users u using(UserId)
|
inner join Users u using(UserId)
|
||||||
where u.Email = ?
|
where u.Email = ?
|
||||||
', [$email], 'Patron');
|
', [$email], Patron::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\PatronNotFoundException();
|
return $result[0] ?? throw new Exceptions\PatronNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ class Poll{
|
||||||
from PollItems
|
from PollItems
|
||||||
where PollId = ?
|
where PollId = ?
|
||||||
order by SortOrder asc
|
order by SortOrder asc
|
||||||
', [$this->PollId], 'PollItem');
|
', [$this->PollId], PollItem::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_PollItems;
|
return $this->_PollItems;
|
||||||
|
@ -113,7 +113,7 @@ class Poll{
|
||||||
SELECT *
|
SELECT *
|
||||||
from Polls
|
from Polls
|
||||||
where PollId = ?
|
where PollId = ?
|
||||||
', [$pollId], 'Poll');
|
', [$pollId], Poll::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\PollNotFoundException();
|
return $result[0] ?? throw new Exceptions\PollNotFoundException();
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ class Poll{
|
||||||
SELECT *
|
SELECT *
|
||||||
from Polls
|
from Polls
|
||||||
where UrlName = ?
|
where UrlName = ?
|
||||||
', [$urlName], 'Poll');
|
', [$urlName], Poll::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\PollNotFoundException();
|
return $result[0] ?? throw new Exceptions\PollNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ class PollItem{
|
||||||
SELECT *
|
SELECT *
|
||||||
from PollItems
|
from PollItems
|
||||||
where PollItemId = ?
|
where PollItemId = ?
|
||||||
', [$pollItemId], 'PollItem');
|
', [$pollItemId], PollItem::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\PollItemNotFoundException();
|
return $result[0] ?? throw new Exceptions\PollItemNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ class PollVote{
|
||||||
inner join Polls p using (PollId)
|
inner join Polls p using (PollId)
|
||||||
where p.UrlName = ? ) x using (PollItemId)
|
where p.UrlName = ? ) x using (PollItemId)
|
||||||
where pv.UserId = ?
|
where pv.UserId = ?
|
||||||
', [$pollUrlName, $userId], 'PollVote');
|
', [$pollUrlName, $userId], PollVote::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\PollVoteNotFoundException();
|
return $result[0] ?? throw new Exceptions\PollVoteNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ class Session{
|
||||||
from Users u
|
from Users u
|
||||||
inner join Sessions s using (UserId)
|
inner join Sessions s using (UserId)
|
||||||
where s.SessionId = ?
|
where s.SessionId = ?
|
||||||
', [$sessionId], 'User');
|
', [$sessionId], User::class);
|
||||||
|
|
||||||
if(sizeof($result) > 0){
|
if(sizeof($result) > 0){
|
||||||
self::SetSessionCookie($sessionId);
|
self::SetSessionCookie($sessionId);
|
||||||
|
@ -113,7 +113,7 @@ class Session{
|
||||||
SELECT *
|
SELECT *
|
||||||
from Sessions
|
from Sessions
|
||||||
where SessionId = ?
|
where SessionId = ?
|
||||||
', [$sessionId], 'Session');
|
', [$sessionId], Session::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\SessionNotFoundException();
|
return $result[0] ?? throw new Exceptions\SessionNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
10
lib/User.php
10
lib/User.php
|
@ -38,7 +38,7 @@ class User{
|
||||||
from Payments
|
from Payments
|
||||||
where UserId = ?
|
where UserId = ?
|
||||||
order by Created desc
|
order by Created desc
|
||||||
', [$this->UserId], 'Payment');
|
', [$this->UserId], Payment::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_Payments;
|
return $this->_Payments;
|
||||||
|
@ -50,7 +50,7 @@ class User{
|
||||||
SELECT *
|
SELECT *
|
||||||
from Benefits
|
from Benefits
|
||||||
where UserId = ?
|
where UserId = ?
|
||||||
', [$this->UserId], 'Benefits');
|
', [$this->UserId], Benefits::class);
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
if(sizeof($result) == 0){
|
||||||
$this->_Benefits = new Benefits();
|
$this->_Benefits = new Benefits();
|
||||||
|
@ -129,7 +129,7 @@ class User{
|
||||||
SELECT *
|
SELECT *
|
||||||
from Users
|
from Users
|
||||||
where UserId = ?
|
where UserId = ?
|
||||||
', [$userId], 'User');
|
', [$userId], User::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\UserNotFoundException();
|
return $result[0] ?? throw new Exceptions\UserNotFoundException();
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ class User{
|
||||||
SELECT *
|
SELECT *
|
||||||
from Users
|
from Users
|
||||||
where Email = ?
|
where Email = ?
|
||||||
', [$email], 'User');
|
', [$email], User::class);
|
||||||
|
|
||||||
return $result[0] ?? throw new Exceptions\UserNotFoundException();
|
return $result[0] ?? throw new Exceptions\UserNotFoundException();
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ class User{
|
||||||
inner join Benefits using (UserId)
|
inner join Benefits using (UserId)
|
||||||
where u.Email = ?
|
where u.Email = ?
|
||||||
or u.Uuid = ?
|
or u.Uuid = ?
|
||||||
', [$identifier, $identifier], 'User');
|
', [$identifier, $identifier], User::class);
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
if(sizeof($result) == 0){
|
||||||
throw new Exceptions\UserNotFoundException();
|
throw new Exceptions\UserNotFoundException();
|
||||||
|
|
|
@ -26,7 +26,7 @@ $expiredPatrons = Db::Query('
|
||||||
(IsRecurring = false and Amount >= 100 and Created > ? - interval 1 year)
|
(IsRecurring = false and Amount >= 100 and Created > ? - interval 1 year)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
', [$now, $now], 'Patron');
|
', [$now, $now], Patron::class);
|
||||||
|
|
||||||
if(sizeof($expiredPatrons) > 0){
|
if(sizeof($expiredPatrons) > 0){
|
||||||
$ebooksThisYear = 0;
|
$ebooksThisYear = 0;
|
||||||
|
@ -70,7 +70,7 @@ if(sizeof($expiredPatrons) > 0){
|
||||||
where UserId = ?
|
where UserId = ?
|
||||||
order by Created desc
|
order by Created desc
|
||||||
limit 1
|
limit 1
|
||||||
', [$patron->UserId], 'Payment');
|
', [$patron->UserId], Payment::class);
|
||||||
|
|
||||||
if(sizeof($lastPayment) > 0 && $patron->User->Email !== null){
|
if(sizeof($lastPayment) > 0 && $patron->User->Email !== null){
|
||||||
$em = new Email();
|
$em = new Email();
|
||||||
|
|
|
@ -63,12 +63,14 @@ try{
|
||||||
}
|
}
|
||||||
|
|
||||||
if($queryEbookUrl !== null){
|
if($queryEbookUrl !== null){
|
||||||
$artworks = Db::Query('SELECT * from Artworks where EbookUrl = ? and Status = ? limit 1', [$queryEbookUrl, ArtworkStatus::Approved], 'Artwork');
|
$artworks = Db::Query('SELECT * from Artworks where EbookUrl = ? and Status = ? limit 1', [$queryEbookUrl, ArtworkStatus::Approved], Artwork::class);
|
||||||
$totalArtworkCount = sizeof($artworks);
|
$totalArtworkCount = sizeof($artworks);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$result = Library::FilterArtwork($query, $filterArtworkStatus, $sort, $submitterUserId, $page, $perPage);
|
$result = Library::FilterArtwork($query, $filterArtworkStatus, $sort, $submitterUserId, $page, $perPage);
|
||||||
|
/** @var array<Artwork> $artworks */
|
||||||
$artworks = $result['artworks'];
|
$artworks = $result['artworks'];
|
||||||
|
/** @var int $totalArtworkCount */
|
||||||
$totalArtworkCount = $result['artworksCount'];
|
$totalArtworkCount = $result['artworksCount'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ $pastPolls = Db::Query('
|
||||||
from Polls
|
from Polls
|
||||||
where utc_timestamp() >= end
|
where utc_timestamp() >= end
|
||||||
order by Start desc
|
order by Start desc
|
||||||
', [], 'Poll');
|
', [], Poll::class);
|
||||||
|
|
||||||
$openPolls = Db::Query('
|
$openPolls = Db::Query('
|
||||||
SELECT *
|
SELECT *
|
||||||
|
@ -15,7 +15,7 @@ $openPolls = Db::Query('
|
||||||
(Start is null
|
(Start is null
|
||||||
or Start <= utc_timestamp())
|
or Start <= utc_timestamp())
|
||||||
order by Start desc
|
order by Start desc
|
||||||
', [], 'Poll');
|
', [], Poll::class);
|
||||||
|
|
||||||
?><?= Template::Header(['title' => 'Polls', 'highlight' => '', 'description' => 'The various polls active at Standard Ebooks.']) ?>
|
?><?= Template::Header(['title' => 'Polls', 'highlight' => '', 'description' => 'The various polls active at Standard Ebooks.']) ?>
|
||||||
<main>
|
<main>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue