mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 14:50:39 -04:00
Add missing MultiTableSelect code
This commit is contained in:
parent
d0d79d637c
commit
93b8008c7e
4 changed files with 24 additions and 6 deletions
|
@ -40,6 +40,7 @@ parameters:
|
||||||
-'#^Safe\\#'
|
-'#^Safe\\#'
|
||||||
uncheckedExceptionClasses:
|
uncheckedExceptionClasses:
|
||||||
- 'Exceptions\DatabaseQueryException'
|
- 'Exceptions\DatabaseQueryException'
|
||||||
|
- 'Exceptions\MultiSelectMethodNotFoundException'
|
||||||
- 'PDOException'
|
- 'PDOException'
|
||||||
- 'TypeError'
|
- 'TypeError'
|
||||||
- 'ValueError'
|
- 'ValueError'
|
||||||
|
|
19
lib/Db.php
19
lib/Db.php
|
@ -19,6 +19,25 @@ class Db{
|
||||||
return $GLOBALS['DbConnection']->Query($query, $args, $class);
|
return $GLOBALS['DbConnection']->Query($query, $args, $class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute a select query that returns a join against multiple tables.
|
||||||
|
*
|
||||||
|
* @template T
|
||||||
|
*
|
||||||
|
* @param string $sql The SQL query to execute.
|
||||||
|
* @param array<mixed> $params An array of parameters to bind to the SQL statement.
|
||||||
|
* @param class-string<T> $class The class to instantiate for each row, or `null` to return an array of rows.
|
||||||
|
*
|
||||||
|
* @return array<T> An array of `$class`.
|
||||||
|
*
|
||||||
|
* @throws Exceptions\MultiSelectMethodNotFoundException If a class was specified but the class doesn't have a `FromMultiTableRow()` method.
|
||||||
|
* @throws Exceptions\DatabaseQueryException When an error occurs during execution of the query.
|
||||||
|
*/
|
||||||
|
public static function MultiTableSelect(string $sql, array $params, string $class): array{
|
||||||
|
/** @throws Exceptions\DatabaseQueryException|Exceptions\MultiSelectMethodNotFoundException */
|
||||||
|
return $GLOBALS['DbConnection']->MultiTableSelect($sql, $params, $class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a single integer value for the first column database query result.
|
* Returns a single integer value for the first column database query result.
|
||||||
*
|
*
|
||||||
|
|
|
@ -652,21 +652,21 @@ final class Project{
|
||||||
* @return array<Project>
|
* @return array<Project>
|
||||||
*/
|
*/
|
||||||
public static function GetAllByStatus(Enums\ProjectStatusType $status): array{
|
public static function GetAllByStatus(Enums\ProjectStatusType $status): array{
|
||||||
return Db::Query('SELECT * from Projects inner join Ebooks using (EbookId) where Projects.Status = ? order by Title asc', [$status], Project::class);
|
return Db::MultiTableSelect('SELECT * from Projects inner join Ebooks using (EbookId) where Projects.Status = ? order by Title asc', [$status], Project::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<Project>
|
* @return array<Project>
|
||||||
*/
|
*/
|
||||||
public static function GetAllByManagerUserId(int $userId): array{
|
public static function GetAllByManagerUserId(int $userId): array{
|
||||||
return Db::Query('SELECT * from Projects inner join Ebooks using (EbookId) where ManagerUserId = ? and Status in (?, ?) order by Title asc', [$userId, Enums\ProjectStatusType::InProgress, Enums\ProjectStatusType::Stalled], Project::class);
|
return Db::MultiTableSelect('SELECT * from Projects inner join Ebooks using (EbookId) where ManagerUserId = ? and Status in (?, ?) order by Title asc', [$userId, Enums\ProjectStatusType::InProgress, Enums\ProjectStatusType::Stalled], Project::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<Project>
|
* @return array<Project>
|
||||||
*/
|
*/
|
||||||
public static function GetAllByReviewerUserId(int $userId): array{
|
public static function GetAllByReviewerUserId(int $userId): array{
|
||||||
return Db::Query('SELECT * from Projects inner join Ebooks using (EbookId) where ReviewerUserId = ? and Status in (?, ?) order by Title asc', [$userId, Enums\ProjectStatusType::InProgress, Enums\ProjectStatusType::Stalled], Project::class);
|
return Db::MultiTableSelect('SELECT * from Projects inner join Ebooks using (EbookId) where ReviewerUserId = ? and Status in (?, ?) order by Title asc', [$userId, Enums\ProjectStatusType::InProgress, Enums\ProjectStatusType::Stalled], Project::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -677,9 +677,8 @@ final class Project{
|
||||||
public static function FromMultiTableRow(array $row): Project{
|
public static function FromMultiTableRow(array $row): Project{
|
||||||
$object = Project::FromRow($row['Projects']);
|
$object = Project::FromRow($row['Projects']);
|
||||||
|
|
||||||
// The Action may be null if it's a Scribophile adjustment. In that case, don't initialize the Action object.
|
|
||||||
if($row['Ebooks']->EbookId !== null){
|
if($row['Ebooks']->EbookId !== null){
|
||||||
$row['Ebooks']->Ebookid = $object->EbookId;
|
$row['Ebooks']->EbookId = $object->EbookId;
|
||||||
$object->Ebook = Ebook::FromRow($row['Ebooks']);
|
$object->Ebook = Ebook::FromRow($row['Ebooks']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,6 @@ try{
|
||||||
// DELETE an `EbookPlaceholder`.
|
// DELETE an `EbookPlaceholder`.
|
||||||
if($httpMethod == Enums\HttpMethod::Delete){
|
if($httpMethod == Enums\HttpMethod::Delete){
|
||||||
$ebook = Ebook::GetByIdentifier($identifier);
|
$ebook = Ebook::GetByIdentifier($identifier);
|
||||||
$exceptionRedirectUrl = $ebook->Url;
|
|
||||||
|
|
||||||
$ebook->Delete();
|
$ebook->Delete();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue