Add projects index page, and more detail on placeholder pages

This commit is contained in:
Alex Cabal 2024-12-14 21:08:45 -06:00
parent fe5bb8ed48
commit c7a4e34e31
15 changed files with 211 additions and 59 deletions

View file

@ -18,6 +18,9 @@ class Benefits{
public bool $CanEditCollections = false;
public bool $CanEditEbooks = false;
public bool $CanCreateEbookPlaceholders = false;
public bool $CanManageProjects = false;
public bool $CanReviewProjects = false;
public bool $CanEditProjects = false;
protected bool $_HasBenefits;
@ -36,6 +39,12 @@ class Benefits{
$this->CanEditEbooks
||
$this->CanCreateEbookPlaceholders
||
$this->CanManageProjects
||
$this->CanReviewProjects
||
$this->CanEditProjects
){
return true;
}

View file

@ -1028,6 +1028,17 @@ class Ebook{
return $ebook;
}
/**
* @throws Exceptions\EbookNotFoundException If the `Ebook` can't be found.
*/
public static function Get(?int $ebookId): Ebook{
if($ebookId === null){
throw new Exceptions\EbookNotFoundException();
}
return Db::Query('SELECT * from Ebooks where EbookId = ?', [$ebookId], Ebook::class)[0] ?? throw new Exceptions\EbookNotFoundException();
}
/**
* Joins the `Name` properites of `Contributor` objects as a URL slug, e.g.,
*

View file

@ -22,4 +22,7 @@ enum DateTimeFormat: string{
/** Like `1641426132`. */
case UnixTimestamp = 'U';
/** Like Jan 5, 2024 */
case ShortDate = 'M j, Y';
}

View file

@ -0,0 +1,7 @@
<?
namespace Exceptions;
class ProjectNotFoundException extends AppException{
/** @var string $message */
protected $message = 'We couldnt locate that project.';
}

View file

@ -62,7 +62,7 @@ class Library{
// Add a period to the abbreviated month, but not if it's May (the only 3-letter month)
$obj->UpdatedString = preg_replace('/^(.+?)(?<!May) /', '\1. ', $obj->UpdatedString);
if($obj->Updated->format('Y') != NOW->format('Y')){
$obj->UpdatedString = $obj->Updated->format('M j, Y');
$obj->UpdatedString = $obj->Updated->format(Enums\DateTimeFormat::ShortDate->value);
}
// Sort the downloads by filename extension

View file

@ -31,6 +31,11 @@ class Project{
protected User $_ReviewerUser;
protected string $_Url;
// *******
// GETTERS
// *******
protected function GetUrl(): string{
if(!isset($this->_Url)){
$this->_Url = '/projects/' . $this->ProjectId;
@ -39,6 +44,11 @@ class Project{
return $this->_Url;
}
// *******
// METHODS
// *******
/**
* @throws Exceptions\InvalidProjectException If the `Project` is invalid.
*/
@ -218,4 +228,27 @@ class Project{
$this->PropertyFromHttp('ManagerUserId');
$this->PropertyFromHttp('ReviewerUserId');
}
// ***********
// ORM METHODS
// ***********
/**
* @throws Exceptions\ProjectNotFoundException If the `Project` can't be found.
*/
public static function Get(?int $projectId): Project{
if($projectId === null){
throw new Exceptions\ProjectNotFoundException();
}
return Db::Query('SELECT * from Projects where ProjectId = ?', [$projectId], Project::class)[0] ?? throw new Exceptions\ProjectNotFoundException();
}
/**
* @return array<Project>
*/
public static function GetAllByStatus(Enums\ProjectStatusType $status): array{
return Db::Query('SELECT * from Projects where Status = ? order by Started desc', [$status], Project::class);
}
}