Commit 29034e33 authored by Tino Goratsch's avatar Tino Goratsch

extracted the gallery pictures management into a separate controller action

parent 15367dbe
......@@ -8,7 +8,6 @@ namespace ACP3\Modules\ACP3\Gallery\Controller\Admin\Index;
use ACP3\Core;
use ACP3\Modules\ACP3\Gallery;
use ACP3\Modules\ACP3\System\Installer\Schema;
/**
* Class Edit
......@@ -24,10 +23,6 @@ class Edit extends Core\Controller\AbstractFrontendAction
* @var \ACP3\Modules\ACP3\Gallery\Validation\GalleryFormValidation
*/
protected $galleryFormValidation;
/**
* @var \ACP3\Modules\ACP3\Gallery\Model\Repository\PictureRepository
*/
protected $pictureRepository;
/**
* @var Gallery\Model\GalleryModel
*/
......@@ -38,21 +33,18 @@ class Edit extends Core\Controller\AbstractFrontendAction
*
* @param \ACP3\Core\Controller\Context\FrontendContext $context
* @param \ACP3\Core\Helpers\FormToken $formTokenHelper
* @param \ACP3\Modules\ACP3\Gallery\Model\Repository\PictureRepository $pictureRepository
* @param Gallery\Model\GalleryModel $galleryModel
* @param \ACP3\Modules\ACP3\Gallery\Validation\GalleryFormValidation $galleryFormValidation
*/
public function __construct(
Core\Controller\Context\FrontendContext $context,
Core\Helpers\FormToken $formTokenHelper,
Gallery\Model\Repository\PictureRepository $pictureRepository,
Gallery\Model\GalleryModel $galleryModel,
Gallery\Validation\GalleryFormValidation $galleryFormValidation
) {
parent::__construct($context);
$this->formTokenHelper = $formTokenHelper;
$this->pictureRepository = $pictureRepository;
$this->galleryModel = $galleryModel;
$this->galleryFormValidation = $galleryFormValidation;
}
......@@ -70,24 +62,19 @@ class Edit extends Core\Controller\AbstractFrontendAction
if (!empty($gallery)) {
$this->title->setPageTitlePrefix($gallery['title']);
return array_merge(
[
'gallery_id' => $id,
'form' => array_merge($gallery, $this->request->getPost()->all()),
'form_token' => $this->formTokenHelper->renderFormToken(),
'SEO_URI_PATTERN' => Gallery\Helpers::URL_KEY_PATTERN_GALLERY,
'SEO_ROUTE_NAME' => sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $id)
],
$this->executeListPictures($id)
);
return [
'form' => array_merge($gallery, $this->request->getPost()->all()),
'form_token' => $this->formTokenHelper->renderFormToken(),
'SEO_URI_PATTERN' => Gallery\Helpers::URL_KEY_PATTERN_GALLERY,
'SEO_ROUTE_NAME' => sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $id)
];
}
throw new Core\Controller\Exception\ResultNotExistsException();
}
/**
* @param int $id
* @param int $id
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
......@@ -105,72 +92,4 @@ class Edit extends Core\Controller\AbstractFrontendAction
return $this->galleryModel->save($formData, $id);
});
}
/**
* @param int $id
*
* @return array
*/
protected function executeListPictures($id)
{
$pictures = $this->pictureRepository->getPicturesByGalleryId($id);
/** @var Core\Helpers\DataGrid $dataGrid */
$dataGrid = $this->get('core.helpers.data_grid');
$dataGrid
->setResults($pictures)
->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))
->setIdentifier('#gallery-edit-data-grid')
->setResourcePathDelete('admin/gallery/pictures/delete/id_' . $id)
->setResourcePathEdit('admin/gallery/pictures/edit');
$this->addDataGridColumns($dataGrid);
return [
'grid' => $dataGrid->render(),
'show_mass_delete_button' => $dataGrid->countDbResults() > 0
];
}
/**
* @param Core\Helpers\DataGrid $dataGrid
*/
protected function addDataGridColumns(Core\Helpers\DataGrid$dataGrid)
{
$dataGrid
->addColumn([
'label' => $this->translator->t('gallery', 'picture'),
'type' => Core\Helpers\DataGrid\ColumnRenderer\PictureColumnRenderer::class,
'fields' => ['id'],
'custom' => [
'pattern' => 'gallery/index/image/id_%s/action_thumb',
'isRoute' => true
]
], 40)
->addColumn([
'label' => $this->translator->t('system', 'description'),
'type' => Core\Helpers\DataGrid\ColumnRenderer\TextColumnRenderer::class,
'fields' => ['description'],
], 30)
->addColumn([
'label' => $this->translator->t('system', 'id'),
'type' => Core\Helpers\DataGrid\ColumnRenderer\IntegerColumnRenderer::class,
'fields' => ['id'],
'primary' => true
], 10);
if ($this->acl->hasPermission('admin/gallery/pictures/order')) {
$dataGrid
->addColumn([
'label' => $this->translator->t('system', 'order'),
'type' => Core\Helpers\DataGrid\ColumnRenderer\SortColumnRenderer::class,
'fields' => ['pic'],
'default_sort' => true,
'custom' => [
'route_sort_down' => 'acp/gallery/pictures/order/id_%d/action_down',
'route_sort_up' => 'acp/gallery/pictures/order/id_%d/action_up',
]
], 20);
}
}
}
......@@ -9,6 +9,7 @@ namespace ACP3\Modules\ACP3\Gallery\Controller\Admin\Pictures;
use ACP3\Core\Controller\AbstractFrontendAction;
use ACP3\Core\Controller\Context\FrontendContext;
use ACP3\Core\Helpers\Forms;
use ACP3\Modules\ACP3\Gallery;
/**
* Class AbstractFormAction
......@@ -47,4 +48,12 @@ class AbstractFormAction extends AbstractFrontendAction
return $this->formsHelper->checkboxGenerator('comments', $comments, $currentValue);
}
protected function canUseComments()
{
$settings = $this->config->getSettings(Gallery\Installer\Schema::MODULE_NAME);
return $settings['overlay'] == 0 && $settings['comments'] == 1 && $this->modules->isActive('comments');
}
}
......@@ -66,12 +66,10 @@ class Create extends AbstractFormAction
$gallery = $this->galleryRepository->getGalleryTitle($id);
$this->breadcrumb
->append($gallery, 'acp/gallery/index/edit/id_' . $id)
->append($gallery, 'acp/gallery/pictures/index/id_' . $id)
->append($this->translator->t('gallery', 'admin_pictures_create'));
$settings = $this->config->getSettings(Gallery\Installer\Schema::MODULE_NAME);
if ($settings['overlay'] == 0 && $settings['comments'] == 1 && $this->modules->isActive('comments') === true) {
if ($this->canUseComments() === true) {
$this->view->assign('options', $this->getOptions('0'));
}
......@@ -111,7 +109,7 @@ class Create extends AbstractFormAction
$formData['gallery_id'] = $id;
return $this->pictureModel->save($formData);
},
'acp/gallery/index/edit/id_' . $id
'acp/gallery/pictures/index/id_' . $id
);
}
}
......@@ -98,7 +98,7 @@ class Delete extends Core\Controller\AbstractFrontendAction
return $bool;
},
'acp/gallery/pictures/delete/id_' . $id,
'acp/gallery/index/edit/id_' . $id
'acp/gallery/pictures/index/id_' . $id
);
}
}
......@@ -71,7 +71,7 @@ class Edit extends AbstractFormAction
if (!empty($picture)) {
$this->breadcrumb
->append($picture['title'], 'acp/gallery/index/edit/id_' . $picture['gallery_id'])
->append($picture['title'], 'acp/gallery/pictures/index/id_' . $picture['gallery_id'])
->append($this->translator->t('gallery', 'admin_pictures_edit'));
$this->title
......@@ -81,9 +81,7 @@ class Edit extends AbstractFormAction
. $this->translator->t('gallery', 'picture_x', ['%picture%' => $picture['pic']])
);
$settings = $this->config->getSettings(Gallery\Installer\Schema::MODULE_NAME);
if ($settings['overlay'] == 0 && $settings['comments'] == 1 && $this->modules->isActive('comments') === true) {
if ($this->canUseComments() === true) {
$this->view->assign('options', $this->getOptions($picture['comments']));
}
......@@ -129,7 +127,7 @@ class Edit extends AbstractFormAction
$formData['gallery_id'] = $picture['gallery_id'];
return $this->pictureModel->save($formData, $id);
},
'acp/gallery/index/edit/id_' . $picture['gallery_id']
'acp/gallery/pictures/index/id_' . $picture['gallery_id']
);
}
}
<?php
/**
* Copyright (c) by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\Gallery\Controller\Admin\Pictures;
use ACP3\Core;
use ACP3\Modules\ACP3\Gallery;
use ACP3\Modules\ACP3\System\Installer\Schema;
use ACP3\Core\Controller\AbstractFrontendAction;
class Index extends AbstractFrontendAction
{
/**
* @var \ACP3\Modules\ACP3\Gallery\Model\Repository\PictureRepository
*/
protected $pictureRepository;
/**
* @var Gallery\Model\GalleryModel
*/
protected $galleryModel;
/**
* Edit constructor.
*
* @param \ACP3\Core\Controller\Context\FrontendContext $context
* @param \ACP3\Modules\ACP3\Gallery\Model\Repository\PictureRepository $pictureRepository
* @param Gallery\Model\GalleryModel $galleryModel
*/
public function __construct(
Core\Controller\Context\FrontendContext $context,
Gallery\Model\Repository\PictureRepository $pictureRepository,
Gallery\Model\GalleryModel $galleryModel
) {
parent::__construct($context);
$this->pictureRepository = $pictureRepository;
$this->galleryModel = $galleryModel;
}
/**
* @param int $id
* @return array
* @throws Core\Controller\Exception\ResultNotExistsException
*/
public function execute($id)
{
$gallery = $this->galleryModel->getOneById($id);
if (!empty($gallery)) {
$this->breadcrumb->append($gallery['title'], 'acp/gallery/pictures/index/id_' . $id);
$this->title->setPageTitlePrefix($this->translator->t('gallery', 'admin_pictures_index'));
$pictures = $this->pictureRepository->getPicturesByGalleryId($id);
/** @var Core\Helpers\DataGrid $dataGrid */
$dataGrid = $this->get('core.helpers.data_grid');
$dataGrid
->setResults($pictures)
->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))
->setIdentifier('#gallery-pictures-data-grid')
->setResourcePathDelete('admin/gallery/pictures/delete/id_' . $id)
->setResourcePathEdit('admin/gallery/pictures/edit');
$this->addDataGridColumns($dataGrid);
return [
'gallery_id' => $id,
'grid' => $dataGrid->render(),
'show_mass_delete_button' => $dataGrid->countDbResults() > 0
];
}
throw new Core\Controller\Exception\ResultNotExistsException();
}
/**
* @param Core\Helpers\DataGrid $dataGrid
*/
protected function addDataGridColumns(Core\Helpers\DataGrid $dataGrid)
{
$dataGrid
->addColumn([
'label' => $this->translator->t('gallery', 'picture'),
'type' => Core\Helpers\DataGrid\ColumnRenderer\PictureColumnRenderer::class,
'fields' => ['id'],
'custom' => [
'pattern' => 'gallery/index/image/id_%s/action_thumb',
'isRoute' => true
]
], 40)
->addColumn([
'label' => $this->translator->t('system', 'description'),
'type' => Core\Helpers\DataGrid\ColumnRenderer\TextColumnRenderer::class,
'fields' => ['description'],
], 30)
->addColumn([
'label' => $this->translator->t('system', 'id'),
'type' => Core\Helpers\DataGrid\ColumnRenderer\IntegerColumnRenderer::class,
'fields' => ['id'],
'primary' => true
], 10);
if ($this->acl->hasPermission('admin/gallery/pictures/order')) {
$dataGrid
->addColumn([
'label' => $this->translator->t('system', 'order'),
'type' => Core\Helpers\DataGrid\ColumnRenderer\SortColumnRenderer::class,
'fields' => ['pic'],
'default_sort' => true,
'custom' => [
'route_sort_down' => 'acp/gallery/pictures/order/id_%d/action_down',
'route_sort_up' => 'acp/gallery/pictures/order/id_%d/action_up',
]
], 20);
}
}
}
......@@ -71,7 +71,7 @@ class Order extends Core\Controller\AbstractFrontendAction
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $this->redirect()->temporary('acp/gallery/index/edit/id_' . $galleryId);
return $this->redirect()->temporary('acp/gallery/pictures/index/id_' . $galleryId);
}
throw new Core\Controller\Exception\ResultNotExistsException();
......
<?php
/**
* Copyright (c) by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\Gallery\Event\Listener;
use ACP3\Core\ACL;
use ACP3\Core\Helpers\DataGrid\ColumnRenderer\Event\CustomOptionEvent;
use ACP3\Core\I18n\Translator;
/**
* Class OnDataGridCustomOptionBeforeListener
* @package ACP3\Modules\ACP3\Newsletter\Event\Listener
*/
class OnDataGridCustomOptionBeforeListener
{
/**
* @var \ACP3\Core\ACL
*/
protected $acl;
/**
* @var \ACP3\Core\I18n\Translator
*/
protected $translator;
/**
* OnDataGridCustomOptionBeforeListener constructor.
*
* @param \ACP3\Core\ACL $acl
* @param \ACP3\Core\I18n\Translator $translator
*/
public function __construct(
ACL $acl,
Translator $translator
) {
$this->acl = $acl;
$this->translator = $translator;
}
/**
* @param \ACP3\Core\Helpers\DataGrid\ColumnRenderer\Event\CustomOptionEvent $customOptionEvent
*/
public function addPicturesIndexButton(CustomOptionEvent $customOptionEvent)
{
if ($customOptionEvent->getIdentifier() === '#gallery-data-grid' &&
$this->acl->hasPermission('admin/gallery/pictures/index') === true
) {
$dbResultRow = $customOptionEvent->getDbResultRow();
$customOptionEvent->getOptionRenderer()->addOption(
'acp/gallery/pictures/index/id_' . $dbResultRow['id'],
$this->translator->t('gallery', 'admin_pictures_index'),
'glyphicon-picture',
'btn-default'
);
}
}
}
......@@ -62,6 +62,9 @@ class Migration extends Modules\Installer\AbstractMigration
41 => [
"ALTER TABLE `{pre}gallery` ADD COLUMN `updated_at` DATETIME NOT NULL AFTER `end`;",
"UPDATE `{pre}gallery` SET `updated_at` = `start`;"
],
42 => [
"INSERT INTO `{pre}acl_resources` (`id`, `module_id`, `area`, `controller`, `page`, `params`, `privilege_id`) VALUES('', '{moduleId}', 'admin', 'pictures', 'index', '', 3);",
]
];
}
......
......@@ -32,6 +32,7 @@ class Schema implements Modules\Installer\SchemaInterface
'create' => PrivilegeEnum::ADMIN_CREATE,
'delete' => PrivilegeEnum::ADMIN_DELETE,
'edit' => PrivilegeEnum::ADMIN_EDIT,
'index' => PrivilegeEnum::ADMIN_VIEW,
'order' => PrivilegeEnum::ADMIN_CREATE
]
],
......@@ -64,7 +65,7 @@ class Schema implements Modules\Installer\SchemaInterface
*/
public function getSchemaVersion()
{
return 41;
return 42;
}
/**
......
{extends file="asset:Gallery/Admin/index.create.tpl"}
{block CONTENT append}
<form action="{uri args="acp/gallery/pictures/delete/id_$gallery_id"}" method="post">
<nav id="adm-list" class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex2-collapse">
<span class="sr-only">{lang t="system|toggle_navigation"}</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">{lang t="gallery|pictures"}</span>
</div>
<div class="collapse navbar-collapse navbar-ex2-collapse">
<div class="navbar-text pull-right">
{check_access mode="link" path="acp/gallery/pictures/create/id_`$gallery_id`" class="glyphicon glyphicon-plus text-success"}
{if $show_mass_delete_button}
{check_access mode="button" path="acp/gallery/pictures/delete" class="glyphicon glyphicon-remove text-danger" lang="system|delete_marked"}
{/if}
</div>
</div>
</nav>
{redirect_message}
{include file="asset:System/Partials/datagrid.tpl" dataTable=$grid}
</form>
{/block}
{extends file="asset:System/layout.admin-grid.tpl"}
{$DELETE_ROUTE={uri args="acp/gallery/pictures/delete/id_$gallery_id"}}
{block HEADER_BAR_OPTIONS}
{check_access mode="link" path="acp/gallery/pictures/create/id_`$gallery_id`" class="glyphicon glyphicon-plus text-success"}
{if $show_mass_delete_button}
{check_access mode="button" path="acp/gallery/pictures/delete" class="glyphicon glyphicon-remove text-danger" lang="system|delete_marked"}
{/if}
{/block}
{block ADMIN_GRID_CONTENT}
{include file="asset:System/Partials/datagrid.tpl" dataTable=$grid}
{/block}
......@@ -23,7 +23,6 @@ services:
arguments:
- '@core.context.frontend'
- '@core.helpers.formToken'
- '@gallery.model.picturerepository'
- '@gallery.model.gallery_model'
- '@gallery.validation.gallery_form_validation'
......@@ -72,6 +71,13 @@ services:
- '@gallery.model.picture_model'
- '@gallery.validation.picture_form_validation'
gallery.controller.admin.pictures.index:
class: ACP3\Modules\ACP3\Gallery\Controller\Admin\Pictures\Index
arguments:
- '@core.context.frontend'
- '@gallery.model.picturerepository'
- '@gallery.model.gallery_model'
gallery.controller.admin.pictures.order:
class: ACP3\Modules\ACP3\Gallery\Controller\Admin\Pictures\Order
arguments:
......
......@@ -27,3 +27,11 @@ services:
- ['setMetaStatements', ['@?seo.helper.meta_statements']]
tags:
- { name: core.eventListener, event: core.model.after_save, method: generatePictureAliases, priority: -250 }
gallery.event.listener.on_data_grid_custom_option_before_listener:
class: ACP3\Modules\ACP3\Gallery\Event\Listener\OnDataGridCustomOptionBeforeListener
arguments:
- '@core.acl'
- '@core.i18n.translator'
tags:
- { name: core.eventListener, event: data_grid.column_renderer.custom_option_before, method: addPicturesIndexButton }
......@@ -8,6 +8,7 @@
<item key="admin_pictures_create">Bild hinzufügen</item>
<item key="admin_pictures_delete">Bilder löschen</item>
<item key="admin_pictures_edit">Bild bearbeiten</item>
<item key="admin_pictures_index">Bilderübersicht</item>
<item key="details">Bilddetails</item>
<item key="filename">Dateiname</item>
<item key="gallery">Fotogalerien</item>
......
......@@ -8,6 +8,7 @@
<item key="admin_pictures_create">Add picture</item>
<item key="admin_pictures_delete">Delete pictures</item>
<item key="admin_pictures_edit">Edit picture</item>
<item key="admin_pictures_index">Pictures overview</item>
<item key="details">Picture details</item>
<item key="filename">Filename</item>
<item key="gallery">Gallery</item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment