From 451d13fe9812b469e46276d8b11b2858f213f14e Mon Sep 17 00:00:00 2001 From: David Molineus Date: Wed, 18 Oct 2017 16:43:33 +0200 Subject: [PATCH] Work on repository manager usage. --- src/Bundle/Resources/config/listeners.yml | 3 +++ src/Frontend/AbstractMapHybrid.php | 3 ++- src/Listener/GeoJsonListener.php | 26 +++++++++++++----- src/Listener/LoadAssetsListener.php | 33 ++++++++++++++++------- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/Bundle/Resources/config/listeners.yml b/src/Bundle/Resources/config/listeners.yml index e8b98fa..d786162 100644 --- a/src/Bundle/Resources/config/listeners.yml +++ b/src/Bundle/Resources/config/listeners.yml @@ -26,6 +26,7 @@ services: - '@netzmacht.contao_toolkit.dca.manager' - '@database_connection' - '@netzmacht.contao_toolkit.repository_manager' + - '@netzmacht.contao_toolkit.repository_manager' netzmacht.contao_leaflet.listeners.dca.control: class: Netzmacht\Contao\Leaflet\Listener\Dca\ControlDcaListener @@ -74,6 +75,7 @@ services: netzmacht.contao_leaflet.listeners.geo_json_listener: class: Netzmacht\Contao\Leaflet\Listener\GeoJsonListener arguments: + - '@netzmacht.contao_toolkit.repository_manager' - '%netzmacht.contao_leaflet.feature_model_properties%' tags: - { name: 'kernel.event_listener', event: 'netzmacht.contao_leaflet.mapper.convert_to_geojson', method: 'handle' } @@ -88,6 +90,7 @@ services: arguments: - '@netzmacht.contao_leaflet.map.assets' - '@netzmacht.contao_leaflet.definition.mapper' + - '@netzmacht.contao_toolkit.repository_manager' - '@netzmacht.contao_leaflet.libraries' tags: - { name: 'kernel.event_listener', event: 'netzmacht.contao_leaflet.get_javascript', method: 'onGetJavascriptEvent' } diff --git a/src/Frontend/AbstractMapHybrid.php b/src/Frontend/AbstractMapHybrid.php index 4142b1f..71d23b1 100644 --- a/src/Frontend/AbstractMapHybrid.php +++ b/src/Frontend/AbstractMapHybrid.php @@ -90,7 +90,8 @@ abstract class AbstractMapHybrid extends AbstractHybrid $this->mapProvider->handleAjaxRequest($this->getIdentifier()); if (TL_MODE === 'BE') { - $model = MapModel::findByPk($this->get('leaflet_map')); + $repository = $this->repositoryManager->getRepository(MapModel::class); + $model = $repository->find((int) $this->get('leaflet_map')); $parameters = [ 'title' => $this->get('headline'), ]; diff --git a/src/Listener/GeoJsonListener.php b/src/Listener/GeoJsonListener.php index 3719ea2..4c64914 100644 --- a/src/Listener/GeoJsonListener.php +++ b/src/Listener/GeoJsonListener.php @@ -14,9 +14,11 @@ declare(strict_types=1); namespace Netzmacht\Contao\Leaflet\Listener; +use Contao\FilesModel; use Contao\Model; use Netzmacht\Contao\Leaflet\Event\ConvertToGeoJsonEvent; use Netzmacht\Contao\Leaflet\Model\LayerModel; +use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager; use Netzmacht\LeafletPHP\Definition as LeafletDefinition; use Netzmacht\LeafletPHP\Definition\HasPopup; use Netzmacht\LeafletPHP\Definition\UI\Marker; @@ -40,13 +42,22 @@ final class GeoJsonListener */ private $featureModelProperties; + /** + * Repository manager. + * + * @var RepositoryManager + */ + private $repositoryManager; + /** * GeoJsonSubscriber constructor. * - * @param array $featureModelProperties Property mapping between models and features. + * @param RepositoryManager $repositoryManager Repository manager. + * @param array $featureModelProperties Property mapping between models and features. */ - public function __construct(array $featureModelProperties) + public function __construct(RepositoryManager $repositoryManager, array $featureModelProperties) { + $this->repositoryManager = $repositoryManager; $this->featureModelProperties = $featureModelProperties; } @@ -176,12 +187,14 @@ final class GeoJsonListener break; case 'file': - $file = \FilesModel::findByUuid($value); - $value = $file->path; + $repository = $this->repositoryManager->getRepository(FilesModel::class); + $file = $repository->findByUuid($value); + $value = $file->path; break; case 'files': - $collection = \FilesModel::findMultipleByUuids(deserialize($value, true)); + $repository = $this->repositoryManager->getRepository(FilesModel::class); + $collection = $repository->findMultipleByUuids(deserialize($value, true)); if ($collection) { $value = $collection->fetchEach('path'); @@ -213,7 +226,8 @@ final class GeoJsonListener if ($model->ignoreForBounds) { $feature->setProperty('ignoreForBounds', true); } else { - $parent = LayerModel::findByPk($model->pid); + $repository = $this->repositoryManager->getRepository(LayerModel::class); + $parent = $repository->find((int) $model->pid); if ($parent && $parent->boundsMode !== 'extend') { $feature->setProperty('ignoreForBounds', true); diff --git a/src/Listener/LoadAssetsListener.php b/src/Listener/LoadAssetsListener.php index 21c7a05..79715f8 100644 --- a/src/Listener/LoadAssetsListener.php +++ b/src/Listener/LoadAssetsListener.php @@ -18,6 +18,7 @@ use Netzmacht\Contao\Leaflet\Encoder\ContaoAssets; use Netzmacht\Contao\Leaflet\Frontend\Assets\LibrariesConfiguration; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\IconModel; +use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager; use Netzmacht\LeafletPHP\Assets; use Netzmacht\LeafletPHP\Definition\Type\Icon; use Netzmacht\LeafletPHP\Definition\Type\ImageIcon; @@ -50,18 +51,31 @@ class LoadAssetsListener */ private $libraries; + /** + * Repository manager. + * + * @var RepositoryManager + */ + private $repositoryManager; + /** * LoadAssetsListener constructor. * - * @param Assets $assets Assets. - * @param DefinitionMapper $definitionMapper Definition mapper. - * @param LibrariesConfiguration $libraries Libraries. + * @param Assets $assets Assets. + * @param DefinitionMapper $definitionMapper Definition mapper. + * @param RepositoryManager $repositoryManager Repository manager. + * @param LibrariesConfiguration $libraries Libraries. */ - public function __construct(Assets $assets, DefinitionMapper $definitionMapper, LibrariesConfiguration $libraries) - { - $this->assets = $assets; - $this->definitionMapper = $definitionMapper; - $this->libraries = $libraries; + public function __construct( + Assets $assets, + DefinitionMapper $definitionMapper, + RepositoryManager $repositoryManager, + LibrariesConfiguration $libraries + ) { + $this->assets = $assets; + $this->definitionMapper = $definitionMapper; + $this->libraries = $libraries; + $this->repositoryManager = $repositoryManager; } /** @@ -76,7 +90,8 @@ class LoadAssetsListener ContaoAssets::TYPE_FILE ); - $collection = IconModel::findBy('active', true); + $repository = $this->repositoryManager->getRepository(IconModel::class); + $collection = $repository->findBy(['active=?'], [true]); if ($collection) { $buffer = '';