mirror of
https://github.com/standardebooks/web.git
synced 2025-07-13 01:52:02 -04:00
Add form to delete placeholders
This commit is contained in:
parent
18bcde3bf6
commit
d0d79d637c
6 changed files with 79 additions and 1 deletions
|
@ -2156,6 +2156,27 @@ final class Ebook{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function Delete(): void{
|
||||||
|
$this->RemoveTags();
|
||||||
|
$this->RemoveLocSubjects();
|
||||||
|
$this->RemoveCollectionMemberships();
|
||||||
|
$this->RemoveGitCommits();
|
||||||
|
$this->RemoveSources();
|
||||||
|
$this->RemoveContributors();
|
||||||
|
$this->RemoveTocEntries();
|
||||||
|
$this->RemoveEbookPlaceholder();
|
||||||
|
|
||||||
|
foreach($this->Projects as $project){
|
||||||
|
$project->Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
Db::Query('
|
||||||
|
DELETE
|
||||||
|
from Ebooks
|
||||||
|
where EbookId = ?
|
||||||
|
', [$this->EbookId]);
|
||||||
|
}
|
||||||
|
|
||||||
// ***********
|
// ***********
|
||||||
// ORM METHODS
|
// ORM METHODS
|
||||||
// ***********
|
// ***********
|
||||||
|
|
|
@ -455,6 +455,20 @@ final class Project{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function Delete(): void{
|
||||||
|
Db::Query('
|
||||||
|
DELETE
|
||||||
|
from ProjectReminders
|
||||||
|
where ProjectId = ?
|
||||||
|
', [$this->ProjectId]);
|
||||||
|
|
||||||
|
Db::Query('
|
||||||
|
DELETE
|
||||||
|
from Projects
|
||||||
|
where ProjectId = ?
|
||||||
|
', [$this->ProjectId]);
|
||||||
|
}
|
||||||
|
|
||||||
public function FillFromHttpPost(): void{
|
public function FillFromHttpPost(): void{
|
||||||
$this->PropertyFromHttp('EbookId');
|
$this->PropertyFromHttp('EbookId');
|
||||||
$this->PropertyFromHttp('ProducerName');
|
$this->PropertyFromHttp('ProducerName');
|
||||||
|
|
|
@ -21,6 +21,16 @@ $showPlaceholderMetadata = $showPlaceholderMetadata ?? false;
|
||||||
<section id="placeholder-metadata">
|
<section id="placeholder-metadata">
|
||||||
<h2>Placeholder metadata</h2>
|
<h2>Placeholder metadata</h2>
|
||||||
<p><a href="<?= $ebook->EditUrl ?>">Edit placeholder</a></p>
|
<p><a href="<?= $ebook->EditUrl ?>">Edit placeholder</a></p>
|
||||||
|
<details>
|
||||||
|
<summary>Delete placeholder</summary>
|
||||||
|
<form method="<?= Enums\HttpMethod::Post->value ?>" action="<?= $ebook->Url ?>">
|
||||||
|
<input type="hidden" name="_method" value="<?= Enums\HttpMethod::Delete->value ?>" />
|
||||||
|
<p>Delete the <code>Ebook</code>, <code>EbookPlaceholder</code>, <code>Project</code>, and other related objects.</p>
|
||||||
|
<div class="footer">
|
||||||
|
<button class="delete">Delete</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</details>
|
||||||
<table class="admin-table">
|
<table class="admin-table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -933,6 +933,14 @@ main.front-page > a.button{
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button.delete{
|
||||||
|
background-color: maroon;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.delete:hover{
|
||||||
|
background-color: firebrick;
|
||||||
|
}
|
||||||
|
|
||||||
article.ebook ul,
|
article.ebook ul,
|
||||||
article.ebook ol{
|
article.ebook ol{
|
||||||
list-style: none;
|
list-style: none;
|
||||||
|
|
|
@ -5,9 +5,11 @@ session_start();
|
||||||
|
|
||||||
$isCreated = HttpInput::Bool(SESSION, 'is-ebook-placeholder-created') ?? false;
|
$isCreated = HttpInput::Bool(SESSION, 'is-ebook-placeholder-created') ?? false;
|
||||||
$isOnlyProjectCreated = HttpInput::Bool(SESSION, 'is-only-ebook-project-created') ?? false;
|
$isOnlyProjectCreated = HttpInput::Bool(SESSION, 'is-only-ebook-project-created') ?? false;
|
||||||
|
$isDeleted = HttpInput::Bool(SESSION, 'is-ebook-placeholder-deleted') ?? false;
|
||||||
$exception = HttpInput::SessionObject('exception', Exceptions\AppException::class);
|
$exception = HttpInput::SessionObject('exception', Exceptions\AppException::class);
|
||||||
$ebook = HttpInput::SessionObject('ebook', Ebook::class);
|
$ebook = HttpInput::SessionObject('ebook', Ebook::class);
|
||||||
$project = HttpInput::SessionObject('project', Project::class);
|
$project = HttpInput::SessionObject('project', Project::class);
|
||||||
|
$deletedEbookTitle = '';
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if(Session::$User === null){
|
if(Session::$User === null){
|
||||||
|
@ -45,6 +47,13 @@ try{
|
||||||
|
|
||||||
session_unset();
|
session_unset();
|
||||||
}
|
}
|
||||||
|
elseif($isDeleted){
|
||||||
|
if($ebook !== null){
|
||||||
|
$deletedEbookTitle = $ebook->Title;
|
||||||
|
$ebook = null;
|
||||||
|
}
|
||||||
|
session_unset();
|
||||||
|
}
|
||||||
elseif($exception){
|
elseif($exception){
|
||||||
// We got here because an `Ebook` submission had errors and the user has to try again.
|
// We got here because an `Ebook` submission had errors and the user has to try again.
|
||||||
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
http_response_code(Enums\HttpCode::UnprocessableContent->value);
|
||||||
|
@ -78,6 +87,8 @@ catch(Exceptions\InvalidPermissionsException){
|
||||||
<? }elseif($isCreated){ ?>
|
<? }elseif($isCreated){ ?>
|
||||||
<p class="message success">Ebook placeholder created: <a href="<?= $createdEbook->Url ?>"><?= Formatter::EscapeHtml($createdEbook->Title) ?></a>!</p>
|
<p class="message success">Ebook placeholder created: <a href="<?= $createdEbook->Url ?>"><?= Formatter::EscapeHtml($createdEbook->Title) ?></a>!</p>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
|
<? }elseif($isDeleted){ ?>
|
||||||
|
<p class="message success">Ebook placeholder deleted: <?= Formatter::EscapeHtml($deletedEbookTitle) ?></p>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
|
|
||||||
<form class="create-update-ebook-placeholder" method="<?= Enums\HttpMethod::Post->value ?>" action="/ebook-placeholders" autocomplete="off">
|
<form class="create-update-ebook-placeholder" method="<?= Enums\HttpMethod::Post->value ?>" action="/ebook-placeholders" autocomplete="off">
|
||||||
|
|
|
@ -5,7 +5,7 @@ $ebook = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
session_start();
|
session_start();
|
||||||
$httpMethod = HttpInput::ValidateRequestMethod([Enums\HttpMethod::Post, Enums\HttpMethod::Put]);
|
$httpMethod = HttpInput::ValidateRequestMethod([Enums\HttpMethod::Post, Enums\HttpMethod::Put, Enums\HttpMethod::Delete]);
|
||||||
$exceptionRedirectUrl = '/ebook-placeholders/new';
|
$exceptionRedirectUrl = '/ebook-placeholders/new';
|
||||||
|
|
||||||
if(Session::$User === null){
|
if(Session::$User === null){
|
||||||
|
@ -78,6 +78,20 @@ try{
|
||||||
http_response_code(Enums\HttpCode::SeeOther->value);
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
header('Location: ' . $ebook->Url);
|
header('Location: ' . $ebook->Url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DELETE an `EbookPlaceholder`.
|
||||||
|
if($httpMethod == Enums\HttpMethod::Delete){
|
||||||
|
$ebook = Ebook::GetByIdentifier($identifier);
|
||||||
|
$exceptionRedirectUrl = $ebook->Url;
|
||||||
|
|
||||||
|
$ebook->Delete();
|
||||||
|
|
||||||
|
$_SESSION['ebook'] = $ebook;
|
||||||
|
$_SESSION['is-ebook-placeholder-deleted'] = true;
|
||||||
|
|
||||||
|
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||||
|
header('Location: /ebook-placeholders/new');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(Exceptions\LoginRequiredException){
|
catch(Exceptions\LoginRequiredException){
|
||||||
Template::RedirectToLogin();
|
Template::RedirectToLogin();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue