Commit a1f5d5af authored by Tino Goratsch's avatar Tino Goratsch

- fixed the gallery picture number when adding a new gallery picture

- reworked the URI alias generation for gallery pictures to be an event
parent 80300128
......@@ -8,15 +8,8 @@ namespace ACP3\Modules\ACP3\Gallery\Controller\Admin\Pictures;
use ACP3\Core;
use ACP3\Modules\ACP3\Gallery;
use ACP3\Modules\ACP3\Seo\Core\Router\Aliases;
use ACP3\Modules\ACP3\Seo\Helper\MetaStatements;
use ACP3\Modules\ACP3\Seo\Helper\UriAliasManager;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Class Create
* @package ACP3\Modules\ACP3\Gallery\Controller\Admin\Pictures
*/
class Create extends AbstractFormAction
{
/**
......@@ -31,22 +24,6 @@ class Create extends AbstractFormAction
* @var \ACP3\Modules\ACP3\Gallery\Validation\PictureFormValidation
*/
protected $pictureFormValidation;
/**
* @var \ACP3\Modules\ACP3\Gallery\Model\Repository\PictureRepository
*/
protected $pictureRepository;
/**
* @var \ACP3\Modules\ACP3\Seo\Core\Router\Aliases
*/
protected $aliases;
/**
* @var \ACP3\Modules\ACP3\Seo\Helper\MetaStatements
*/
protected $metaStatements;
/**
* @var \ACP3\Modules\ACP3\Seo\Helper\UriAliasManager
*/
protected $uriAliasManager;
/**
* @var Gallery\Model\PictureModel
*/
......@@ -59,7 +36,6 @@ class Create extends AbstractFormAction
* @param \ACP3\Core\Helpers\Forms $formsHelper
* @param \ACP3\Core\Helpers\FormToken $formTokenHelper
* @param \ACP3\Modules\ACP3\Gallery\Model\Repository\GalleryRepository $galleryRepository
* @param \ACP3\Modules\ACP3\Gallery\Model\Repository\PictureRepository $pictureRepository
* @param Gallery\Model\PictureModel $pictureModel
* @param \ACP3\Modules\ACP3\Gallery\Validation\PictureFormValidation $pictureFormValidation
*/
......@@ -68,7 +44,6 @@ class Create extends AbstractFormAction
Core\Helpers\Forms $formsHelper,
Core\Helpers\FormToken $formTokenHelper,
Gallery\Model\Repository\GalleryRepository $galleryRepository,
Gallery\Model\Repository\PictureRepository $pictureRepository,
Gallery\Model\PictureModel $pictureModel,
Gallery\Validation\PictureFormValidation $pictureFormValidation
) {
......@@ -76,35 +51,10 @@ class Create extends AbstractFormAction
$this->formTokenHelper = $formTokenHelper;
$this->galleryRepository = $galleryRepository;
$this->pictureRepository = $pictureRepository;
$this->pictureFormValidation = $pictureFormValidation;
$this->pictureModel = $pictureModel;
}
/**
* @param \ACP3\Modules\ACP3\Seo\Core\Router\Aliases $aliases
*/
public function setAliases(Aliases $aliases)
{
$this->aliases = $aliases;
}
/**
* @param \ACP3\Modules\ACP3\Seo\Helper\MetaStatements $metaStatements
*/
public function setMetaStatements(MetaStatements $metaStatements)
{
$this->metaStatements = $metaStatements;
}
/**
* @param \ACP3\Modules\ACP3\Seo\Helper\UriAliasManager $uriAliasManager
*/
public function setUriAliasManager(UriAliasManager $uriAliasManager)
{
$this->uriAliasManager = $uriAliasManager;
}
/**
* @param int $id
* @return array
......@@ -159,44 +109,9 @@ class Create extends AbstractFormAction
$formData['file'] = $result['name'];
$formData['gallery_id'] = $id;
$pictureId = $this->pictureModel->save($formData);
$bool2 = $this->generatePictureAlias($pictureId);
return $pictureId && $bool2;
return $this->pictureModel->save($formData);
},
'acp/gallery/index/edit/id_' . $id
);
}
/**
* Setzt einen einzelnen Alias für ein Bild einer Fotogalerie
*
* @param integer $pictureId
*
* @return boolean
*/
protected function generatePictureAlias($pictureId)
{
if ($this->aliases && $this->metaStatements && $this->uriAliasManager) {
$galleryId = $this->pictureRepository->getGalleryIdFromPictureId($pictureId);
$alias = $this->aliases->getUriAlias(sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $galleryId), true);
if (!empty($alias)) {
$alias .= '/img-' . $pictureId;
}
$seoKeywords = $this->metaStatements->getKeywords(sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY,
$galleryId));
$seoDescription = $this->metaStatements->getDescription(sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY,
$galleryId));
return $this->uriAliasManager->insertUriAlias(
sprintf(Gallery\Helpers::URL_KEY_PATTERN_PICTURE, $pictureId),
$alias,
$seoKeywords,
$seoDescription
);
}
return true;
}
}
<?php
/**
* Copyright (c) 2016 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\Model\Event\ModelSaveEvent;
use ACP3\Modules\ACP3\Gallery;
use ACP3\Modules\ACP3\Seo\Core\Router\Aliases;
use ACP3\Modules\ACP3\Seo\Helper\MetaStatements;
use ACP3\Modules\ACP3\Seo\Helper\UriAliasManager;
class GeneratePictureUriAliasOnModelAfterSaveListener
{
/**
* @var Gallery\Model\Repository\PictureRepository
*/
private $pictureRepository;
/**
* @var Aliases
*/
private $aliases;
/**
* @var MetaStatements
*/
private $metaStatements;
/**
* @var UriAliasManager
*/
private $uriAliasManager;
/**
* UpdateUriAliasesOnModelAfterSaveListener constructor.
* @param Gallery\Model\Repository\PictureRepository $pictureRepository
*/
public function __construct(Gallery\Model\Repository\PictureRepository $pictureRepository)
{
$this->pictureRepository = $pictureRepository;
}
/**
* @param \ACP3\Modules\ACP3\Seo\Core\Router\Aliases $aliases
*/
public function setAliases(Aliases $aliases)
{
$this->aliases = $aliases;
}
/**
* @param \ACP3\Modules\ACP3\Seo\Helper\MetaStatements $metaStatements
*/
public function setMetaStatements(MetaStatements $metaStatements)
{
$this->metaStatements = $metaStatements;
}
/**
* @param \ACP3\Modules\ACP3\Seo\Helper\UriAliasManager $uriAliasManager
*/
public function setUriAliasManager(UriAliasManager $uriAliasManager)
{
$this->uriAliasManager = $uriAliasManager;
}
/**
* @param ModelSaveEvent $event
*/
public function generatePictureAlias(ModelSaveEvent $event)
{
if (!$event->isIsNewEntry()) {
return;
}
if ($this->aliases && $this->metaStatements && $this->uriAliasManager) {
$pictureId = $event->getEntryId();
$galleryId = $this->pictureRepository->getGalleryIdFromPictureId($pictureId);
$alias = $this->aliases->getUriAlias(sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $galleryId), true);
if (!empty($alias)) {
$alias .= '/img-' . $pictureId;
}
$seoKeywords = $this->metaStatements->getKeywords(
sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $galleryId)
);
$seoDescription = $this->metaStatements->getDescription(
sprintf(Gallery\Helpers::URL_KEY_PATTERN_GALLERY, $galleryId)
);
$this->uriAliasManager->insertUriAlias(
sprintf(Gallery\Helpers::URL_KEY_PATTERN_PICTURE, $pictureId),
$alias,
$seoKeywords,
$seoDescription
);
}
}
}
......@@ -59,7 +59,7 @@ class PictureModel extends AbstractModel
]);
if ($entryId === null) {
$picNum = $this->repository->getLastPictureByGalleryId($entryId);
$picNum = $this->repository->getLastPictureByGalleryId($data['gallery_id']);
$data['pic'] = !is_null($picNum) ? $picNum + 1 : 1;
}
......
......@@ -48,13 +48,8 @@ services:
- '@core.helpers.forms'
- '@core.helpers.formToken'
- '@gallery.model.galleryrepository'
- '@gallery.model.picturerepository'
- '@gallery.model.picture_model'
- '@gallery.validator.picture'
calls:
- ['setAliases', ['@?seo.core.router.aliases']]
- ['setMetaStatements', ['@?seo.helper.meta_statements']]
- ['setUriAliasManager', ['@?seo.helper.uri_alias_manager']]
gallery.controller.admin.pictures.delete:
class: ACP3\Modules\ACP3\Gallery\Controller\Admin\Pictures\Delete
......
......@@ -6,6 +6,17 @@ services:
tags:
- { name: core.eventListener, event: gallery.model.gallery_pictures.after_save, method: execute }
gallery.event.generate_picture_uri_alias_on_model_after_save_listener:
class: ACP3\Modules\ACP3\Gallery\Event\Listener\GeneratePictureUriAliasOnModelAfterSaveListener
arguments:
- '@gallery.model.picturerepository'
calls:
- ['setAliases', ['@?seo.core.router.aliases']]
- ['setUriAliasManager', ['@?seo.helper.uri_alias_manager']]
- ['setMetaStatements', ['@?seo.helper.meta_statements']]
tags:
- { name: core.eventListener, event: gallery.model.gallery_pictures.after_save, method: generatePictureAlias, priority: -250 }
gallery.event.generate_picture_uri_aliases_on_model_after_save_listener:
class: ACP3\Modules\ACP3\Gallery\Event\Listener\GeneratePictureUriAliasesOnModelAfterSaveListener
arguments:
......
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