mirror of
https://github.com/standardebooks/web.git
synced 2025-07-19 12:54:48 -04:00
Allow editing of projects
This commit is contained in:
parent
e21f411191
commit
b2191d1219
16 changed files with 191 additions and 75 deletions
|
@ -3,21 +3,11 @@ use function Safe\session_unset;
|
|||
|
||||
session_start();
|
||||
|
||||
|
||||
$exception = HttpInput::SessionObject('exception', Exceptions\AppException::class);
|
||||
|
||||
/** @var string $identifier Passed from script this is included from. */
|
||||
$ebook = HttpInput::SessionObject('ebook', Ebook::class);
|
||||
$exception = HttpInput::SessionObject('exception', Exceptions\AppException::class);
|
||||
|
||||
try{
|
||||
if(Session::$User === null){
|
||||
throw new Exceptions\LoginRequiredException();
|
||||
}
|
||||
|
||||
if(!Session::$User->Benefits->CanEditEbookPlaceholders){
|
||||
throw new Exceptions\InvalidPermissionsException();
|
||||
}
|
||||
|
||||
if($ebook === null){
|
||||
$ebook = Ebook::GetByIdentifier($identifier);
|
||||
}
|
||||
|
@ -26,6 +16,14 @@ try{
|
|||
throw new Exceptions\EbookNotFoundException();
|
||||
}
|
||||
|
||||
if(Session::$User === null){
|
||||
throw new Exceptions\LoginRequiredException();
|
||||
}
|
||||
|
||||
if(!Session::$User->Benefits->CanEditEbookPlaceholders){
|
||||
throw new Exceptions\InvalidPermissionsException();
|
||||
}
|
||||
|
||||
if($exception){
|
||||
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
||||
session_unset();
|
||||
|
@ -57,7 +55,7 @@ catch(Exceptions\InvalidPermissionsException){
|
|||
|
||||
<form class="create-update-ebook-placeholder" method="<?= Enums\HttpMethod::Post->value ?>" action="<?= $ebook->Url ?>" autocomplete="off">
|
||||
<input type="hidden" name="_method" value="<?= Enums\HttpMethod::Put->value ?>" />
|
||||
<?= Template::EbookPlaceholderForm(['ebook' => $ebook]) ?>
|
||||
<?= Template::EbookPlaceholderForm(['ebook' => $ebook, 'isEditForm' => true]) ?>
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
|
|
|
@ -8,6 +8,7 @@ session_start();
|
|||
$ebook = null;
|
||||
|
||||
$isSaved = HttpInput::Bool(SESSION, 'is-ebook-placeholder-saved') ?? false;
|
||||
$isProjectSaved = HttpInput::Bool(SESSION, 'is-project-saved') ?? false;
|
||||
|
||||
try{
|
||||
$ebook = Ebook::GetByIdentifier($identifier);
|
||||
|
@ -63,7 +64,11 @@ catch(Exceptions\EbookNotFoundException){
|
|||
</header>
|
||||
|
||||
<? if($isSaved){ ?>
|
||||
<p class="message success">Ebook Placeholder saved!</p>
|
||||
<p class="message success">Ebook placeholder saved!</p>
|
||||
<? } ?>
|
||||
|
||||
<? if($isProjectSaved){ ?>
|
||||
<p class="message success">Project saved!</p>
|
||||
<? } ?>
|
||||
|
||||
<aside id="reading-ease">
|
||||
|
@ -115,17 +120,12 @@ catch(Exceptions\EbookNotFoundException){
|
|||
<? } ?>
|
||||
</section>
|
||||
|
||||
<? if(Session::$User?->Benefits->CanEditEbooks){ ?>
|
||||
<?= Template::EbookMetadata(['ebook' => $ebook]) ?>
|
||||
<? if(Session::$User?->Benefits->CanEditEbooks || Session::$User?->Benefits->CanEditEbookPlaceholders){ ?>
|
||||
<?= Template::EbookMetadata(['ebook' => $ebook, 'showPlaceholderMetadata' => Session::$User?->Benefits->CanEditEbookPlaceholders]) ?>
|
||||
<? } ?>
|
||||
|
||||
<? if(Session::$User?->Benefits->CanEditProjects || Session::$User?->Benefits->CanManageProjects || Session::$User?->Benefits->CanReviewProjects){ ?>
|
||||
<?= Template::EbookProjects(['ebook' => $ebook, 'showAddButton' => Session::$User->Benefits->CanEditProjects && $ebook->ProjectInProgress === null]) ?>
|
||||
<? } ?>
|
||||
|
||||
<? if(Session::$User?->Benefits->CanEditEbookPlaceholders){ ?>
|
||||
<h2>Edit ebook placeholder</h2>
|
||||
<p><a href="<?= $ebook->EditUrl ?>">Edit this ebook placeholder.</a></p>
|
||||
<?= Template::EbookProjects(['ebook' => $ebook, 'showAddButton' => Session::$User->Benefits->CanEditProjects && $ebook->ProjectInProgress === null, 'showEditButton' => Session::$User->Benefits->CanEditProjects]) ?>
|
||||
<? } ?>
|
||||
</article>
|
||||
</main>
|
||||
|
|
|
@ -16,7 +16,7 @@ try{
|
|||
throw new Exceptions\InvalidPermissionsException();
|
||||
}
|
||||
|
||||
// POSTing a new ebook placeholder.
|
||||
// POSTing an `EbookPlaceholder`.
|
||||
if($httpMethod == Enums\HttpMethod::Post){
|
||||
$ebook = new Ebook();
|
||||
|
||||
|
@ -61,7 +61,8 @@ try{
|
|||
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||
header('Location: /ebook-placeholders/new');
|
||||
}
|
||||
// PUT a new ebook placeholder.
|
||||
|
||||
// PUT an `EbookPlaceholder`.
|
||||
if($httpMethod == Enums\HttpMethod::Put){
|
||||
$originalEbook = Ebook::GetByIdentifier($identifier);
|
||||
$exceptionRedirectUrl = $originalEbook->EditUrl;
|
||||
|
@ -72,35 +73,8 @@ try{
|
|||
$ebook->EbookId = $originalEbook->EbookId;
|
||||
$ebook->Created = $originalEbook->Created;
|
||||
|
||||
// Do we have a `Project` to create/save at the same time?
|
||||
$project = null;
|
||||
if($ebook->EbookPlaceholder?->IsInProgress){
|
||||
$originalProject = $originalEbook->ProjectInProgress;
|
||||
$project = new Project();
|
||||
$project->FillFromHttpPost();
|
||||
$project->EbookId = $ebook->EbookId;
|
||||
$project->Ebook = $ebook;
|
||||
if(isset($originalProject)){
|
||||
$project->ProjectId = $originalProject->ProjectId;
|
||||
$project->Started = $originalProject->Started;
|
||||
}
|
||||
else{
|
||||
$project->Started = NOW;
|
||||
}
|
||||
$project->Validate();
|
||||
}
|
||||
|
||||
$ebook->Save();
|
||||
|
||||
if($ebook->EbookPlaceholder?->IsInProgress && $project !== null){
|
||||
if(isset($originalProject)){
|
||||
$project->Save();
|
||||
}
|
||||
else{
|
||||
$project->Create();
|
||||
}
|
||||
}
|
||||
|
||||
$_SESSION['is-ebook-placeholder-saved'] = true;
|
||||
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||
header('Location: ' . $ebook->Url);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue