Support 'quick create subalbums' style, too.

This commit is contained in:
Aaron van Geffen 2017-11-05 17:31:17 +01:00
parent 2a25434862
commit 096cea078c
3 changed files with 27 additions and 8 deletions

View File

@ -15,11 +15,11 @@ class EditAlbum extends HTMLController
throw new NotAllowedException();
$id_tag = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if (empty($id_tag) && !isset($_GET['add']))
if (empty($id_tag) && !isset($_GET['add']) && $_GET['action'] !== 'addalbum')
throw new UnexpectedValueException('Requested album not found or not requesting a new album.');
// Adding an album?
if (isset($_GET['add']))
if (isset($_GET['add']) || $_GET['action'] === 'addalbum')
{
parent::__construct('Add a new album');
$form_title = 'Add a new album';
@ -30,7 +30,7 @@ class EditAlbum extends HTMLController
{
// So far so good?
$album = Tag::fromId($id_tag);
if (Session::validateSession('get') && $tag->kind === 'Album' && $tag->delete())
if (Session::validateSession('get') && $album->kind === 'Album' && $album->delete())
{
header('Location: ' . BASEURL . '/managealbums/');
exit;
@ -96,8 +96,24 @@ class EditAlbum extends HTMLController
],
]);
if (empty($_POST) && isset($_GET['tag']))
{
$parentTag = Tag::fromId($_GET['tag']);
if ($parentTag->kind === 'Album')
{
$formDefaults = [
'id_parent' => $parentTag->id_tag,
'tag' => 'New Album Title Here',
'slug' => ($parentTag->slug ? $parentTag->slug . '/' : '') . 'NEW_ALBUM_SLUG_HERE',
];
}
}
if (!isset($formDefaults))
$formDefaults = isset($album) ? get_object_vars($album) : $_POST;
// Create the form, add in default values.
$form->setData($id_tag ? get_object_vars($album) : $_POST);
$form->setData($formDefaults);
$formview = new FormView($form, $form_title ?? '');
$this->page->adopt($formview);
@ -112,6 +128,8 @@ class EditAlbum extends HTMLController
$data = $form->getData();
// Quick stripping.
$data['tag'] = htmlentities($data['tag']);
$data['description'] = htmlentities($data['description']);
$data['slug'] = strtr(strtolower($data['slug']), [' ' => '-', '--' => '-', '&' => 'and', '=>' => '', "'" => "", ":"=> "", '/' => '-', '\\' => '-']);
// TODO: when updating slug, update slug for all photos in this album.
@ -120,13 +138,13 @@ class EditAlbum extends HTMLController
if (!$id_tag)
{
$data['kind'] = 'Album';
$return = Tag::createNew($data);
if ($return === false)
$newTag = Tag::createNew($data);
if ($newTag === false)
return $formview->adopt(new Alert('Cannot create this album', 'Something went wrong while creating the album...', 'error'));
if (isset($_POST['submit_and_new']))
{
header('Location: ' . BASEURL . '/editalbum/?add');
header('Location: ' . BASEURL . '/editalbum/?add&tag=' . $data['id_parent']);
exit;
}
}

View File

@ -11,6 +11,7 @@ class Dispatcher
public static function route()
{
$possibleActions = [
'addalbum' => 'EditAlbum',
'albums' => 'ViewPhotoAlbums',
'editalbum' => 'EditAlbum',
'editasset' => 'EditAsset',

View File

@ -272,7 +272,7 @@ class Tag
$db = Registry::get('db');
$res = $db->query('
DELETE FROM posts_tags
DELETE FROM assets_tags
WHERE id_tag = {int:id_tag}',
[
'id_tag' => $this->id_tag,