Changes the ConfirmDelete page and updates database code.

The ConfirmDelete page now uses parts of the photopage. The
Confirmation dialog is its own template which is based on Alert.

The database now updates the album thumb to the most recent
addition to the album, when the album thumb asset is being deleted.
When there are no pictures left in the album 0 will be set.
This commit is contained in:
2018-07-08 08:19:37 +00:00
parent e40c05c1f8
commit 16ec547064
12 changed files with 197 additions and 113 deletions

View File

@@ -11,17 +11,53 @@ class ViewPhoto extends HTMLController
public function __construct()
{
// Ensure we're logged in at this point.
if (!Registry::get('user')->isLoggedIn())
$user = Registry::get('user');
if (!$user->isLoggedIn())
throw new NotAllowedException();
$photo = Asset::fromSlug($_GET['slug']);
if (empty($photo))
throw new NotFoundException();
parent::__construct($photo->getTitle() . ' - ' . SITE_TITLE);
$author = $photo->getAuthor();
if (isset($_REQUEST['confirm_delete']) || isset($_REQUEST['delete_confirmed']))
$this->handleConfirmDelete($user, $author, $photo);
else
$this->handleViewPhoto($user, $author, $photo);
// Add an edit button to the admin bar.
if ($user->isAdmin())
$this->admin_bar->appendItem(BASEURL . '/editasset/?id=' . $photo->getId(), 'Edit this photo');
}
private function handleConfirmDelete(User $user, User $author, Asset $photo)
{
if (!($user->isAdmin() || $user->getUserId() === $author->getUserId()))
throw new NotAllowedException();
if (isset($_REQUEST['confirm_delete']))
{
$page = new ConfirmDeletePage($photo->getImage());
$this->page->adopt($page);
}
else if (isset($_REQUEST['delete_confirmed']))
{
$album_url = $photo->getSubdir();
$photo->delete();
header('Location: ' . BASEURL . '/' . $album_url);
exit;
}
}
private function handleViewPhoto(User $user, User $author, Asset $photo)
{
if (!empty($_POST))
$this->handleTagging($photo->getImage());
parent::__construct($photo->getTitle() . ' - ' . SITE_TITLE);
$page = new PhotoPage($photo->getImage());
// Exif data?
@@ -43,17 +79,11 @@ class ViewPhoto extends HTMLController
if ($next_url)
$page->setNextPhotoUrl($next_url);
$user = Registry::get('user');
$author = $photo->getAuthor();
if ($user->isAdmin() || $user->getUserId() === $author->getUserId())
$page->setIsAssetOwner(true);
$this->page->adopt($page);
$this->page->setCanonicalUrl($photo->getPageUrl());
// Add an edit button to the admin bar.
if (Registry::get('user')->isAdmin())
$this->admin_bar->appendItem(BASEURL . '/editasset/?id=' . $photo->getId(), 'Edit this photo');
}
private function handleTagging(Image $photo)