mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 06:40:33 -04:00
Add endpoint to get reviewer for an in-progress project
This commit is contained in:
parent
87620287f1
commit
bc16b1fff8
5 changed files with 110 additions and 2 deletions
|
@ -2,5 +2,11 @@ RewriteRule ^/ebooks/([^\.]+?)/projects/new$ /projects/new.php?ebook-url-path=$
|
|||
|
||||
RewriteRule ^/projects/([\d]+)/edit$ /projects/edit.php?project-id=$1
|
||||
|
||||
# Query string may contain `indent=<BOOL>`.
|
||||
RewriteRule ^/projects/([\d]+)/reviewer$ /projects/reviewer/get.php?project-id=$1 [QSA]
|
||||
|
||||
# Query string may contain `indent=<BOOL>`.
|
||||
RewriteRule ^/ebooks/(.+?)/projects/in-progress/reviewer$ /projects/reviewer/get.php?url-path=$1 [QSA]
|
||||
|
||||
RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/"
|
||||
RewriteRule ^/projects/([\d]+)$ /projects/post.php?project-id=$1 [L]
|
||||
|
|
|
@ -675,6 +675,17 @@ final class Project{
|
|||
return Db::Query('SELECT * from Projects where ProjectId = ?', [$projectId], Project::class)[0] ?? throw new Exceptions\ProjectNotFoundException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exceptions\ProjectNotFoundException If the `Project` can't be found.
|
||||
*/
|
||||
public static function GetByIdentifierAndIsInProgress(?string $identifier): Project{
|
||||
if($identifier === null){
|
||||
throw new Exceptions\ProjectNotFoundException();
|
||||
}
|
||||
|
||||
return Db::Query('SELECT Projects.* from Ebooks inner join Projects using (EbookId) where Ebooks.Identifier = ? and Projects.Status = ?', [$identifier, Enums\ProjectStatusType::InProgress], Project::class)[0] ?? throw new Exceptions\ProjectNotFoundException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Project>
|
||||
*/
|
||||
|
|
32
lib/User.php
32
lib/User.php
|
@ -13,7 +13,8 @@ use function Safe\preg_match;
|
|||
* @property ?Patron $Patron
|
||||
* @property ?NewsletterSubscription $NewsletterSubscription
|
||||
* @property ?Payment $LastPayment
|
||||
* @property string $DisplayName A string that represent's the `User`'s name, or email, or ID.
|
||||
* @property string $DisplayName The `User`'s name, or email, or ID.
|
||||
* @property ?string $SortName The `User`'s name in an (attempted) sort order, or `null` if the `User` has no name.
|
||||
*/
|
||||
class User{
|
||||
use Traits\Accessor;
|
||||
|
@ -37,12 +38,41 @@ class User{
|
|||
protected ?Patron $_Patron;
|
||||
protected ?NewsletterSubscription $_NewsletterSubscription;
|
||||
protected string $_DisplayName;
|
||||
protected ?string $_SortName = null;
|
||||
|
||||
|
||||
// *******
|
||||
// GETTERS
|
||||
// *******
|
||||
|
||||
protected function GetSortName(): string{
|
||||
if(!isset($this->_SortName)){
|
||||
if($this->Name !== null){
|
||||
preg_match('/\s(?:de |de la |di |van |von )?[^\s]+$/iu', $this->Name, $lastNameMatches);
|
||||
if(sizeof($lastNameMatches) == 0){
|
||||
$this->SortName = $this->Name;
|
||||
}
|
||||
else{
|
||||
$lastName = trim($lastNameMatches[0]);
|
||||
|
||||
preg_match('/^(.+)' . preg_quote($lastName, '/') . '$/u', $this->Name, $firstNameMatches);
|
||||
|
||||
if(sizeof($firstNameMatches) == 0){
|
||||
$this->SortName = $this->Name;
|
||||
}
|
||||
else{
|
||||
$this->_SortName = $lastName . ', ' . trim($firstNameMatches[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$this->_SortName = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_SortName;
|
||||
}
|
||||
|
||||
protected function GetDisplayName(): string{
|
||||
if(!isset($this->_DisplayName)){
|
||||
if($this->Name !== null){
|
||||
|
|
61
www/projects/reviewer/get.php
Normal file
61
www/projects/reviewer/get.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?
|
||||
try{
|
||||
$urlPath = HttpInput::Str(GET, 'url-path');
|
||||
|
||||
if($urlPath !== null){
|
||||
$identifier = EBOOKS_IDENTIFIER_PREFIX . trim(str_replace('.', '', $urlPath), '/'); // Contains the portion of the URL (without query string) that comes after `https://standardebooks.org/ebooks/`.
|
||||
|
||||
$project = Project::GetByIdentifierAndIsInProgress($identifier);
|
||||
}
|
||||
else{
|
||||
$project = Project::Get(HttpInput::Int(GET, 'project-id'));
|
||||
}
|
||||
|
||||
$indent = HttpInput::Bool(GET, 'indent') ?? false;
|
||||
|
||||
$output = new stdClass();
|
||||
$output->Name = $project->Reviewer->Name;
|
||||
$output->SortName = $project->Reviewer->SortName;
|
||||
|
||||
switch($output->Name){
|
||||
case 'Alex Cabal':
|
||||
$output->Url = 'https://alexcabal.com';
|
||||
break;
|
||||
|
||||
case 'Emma Sweeney':
|
||||
$output->Url = 'https://www.linkedin.com/in/emma-sweeney-554927190/';
|
||||
break;
|
||||
|
||||
case 'Weijia Cheng':
|
||||
$output->Url = 'https://weijiarhymeswith.asia';
|
||||
break;
|
||||
|
||||
case 'Robin Whittleton':
|
||||
$output->Url = 'https://www.robinwhittleton.com';
|
||||
break;
|
||||
|
||||
case 'Vince Rice':
|
||||
$output->Url = 'https://www.brokenandsa';
|
||||
break;
|
||||
|
||||
case 'David Reimer':
|
||||
$output->Url = 'https://github.com/dajare';
|
||||
$output->NacoafUrl = 'http://id.loc.gov/authorities/names/n92075987';
|
||||
break;
|
||||
}
|
||||
|
||||
header('Content-type: text/plain');
|
||||
}
|
||||
catch(Exceptions\ProjectNotFoundException){
|
||||
Template::ExitWithCode(Enums\HttpCode::NotFound);
|
||||
}
|
||||
?>
|
||||
<? if($indent){ ?> <? } ?><dc:contributor id="producer-2"><?= Formatter::EscapeXml($output->Name) ?></dc:contributor>
|
||||
<? if($indent){ ?> <? } ?><meta property="file-as" refines="#producer-2"><?= Formatter::EscapeXml($output->SortName) ?></meta>
|
||||
<? if(isset($output->Url)){ ?>
|
||||
<? if($indent){ ?> <? } ?><meta property="se:url.homepage" refines="#producer-2"><?= Formatter::EscapeXml($output->Url) ?></meta>
|
||||
<? } ?>
|
||||
<? if(isset($output->NacoafUrl)){ ?>
|
||||
<? if($indent){ ?> <? } ?><meta property="se:url.authority.nacoaf" refines="#producer-2"><?= Formatter::EscapeXml($output->NacoafUrl) ?></meta>
|
||||
<? } ?>
|
||||
<? if($indent){ ?> <? } ?><meta property="role" refines="#producer-2" scheme="marc:relators">pfr</meta>
|
Loading…
Add table
Add a link
Reference in a new issue