Work on repository manager usage.

This commit is contained in:
David Molineus
2017-10-18 16:43:33 +02:00
parent a4192b4b1a
commit 451d13fe98
4 changed files with 49 additions and 16 deletions

View File

@@ -26,6 +26,7 @@ services:
- '@netzmacht.contao_toolkit.dca.manager' - '@netzmacht.contao_toolkit.dca.manager'
- '@database_connection' - '@database_connection'
- '@netzmacht.contao_toolkit.repository_manager' - '@netzmacht.contao_toolkit.repository_manager'
- '@netzmacht.contao_toolkit.repository_manager'
netzmacht.contao_leaflet.listeners.dca.control: netzmacht.contao_leaflet.listeners.dca.control:
class: Netzmacht\Contao\Leaflet\Listener\Dca\ControlDcaListener class: Netzmacht\Contao\Leaflet\Listener\Dca\ControlDcaListener
@@ -74,6 +75,7 @@ services:
netzmacht.contao_leaflet.listeners.geo_json_listener: netzmacht.contao_leaflet.listeners.geo_json_listener:
class: Netzmacht\Contao\Leaflet\Listener\GeoJsonListener class: Netzmacht\Contao\Leaflet\Listener\GeoJsonListener
arguments: arguments:
- '@netzmacht.contao_toolkit.repository_manager'
- '%netzmacht.contao_leaflet.feature_model_properties%' - '%netzmacht.contao_leaflet.feature_model_properties%'
tags: tags:
- { name: 'kernel.event_listener', event: 'netzmacht.contao_leaflet.mapper.convert_to_geojson', method: 'handle' } - { name: 'kernel.event_listener', event: 'netzmacht.contao_leaflet.mapper.convert_to_geojson', method: 'handle' }
@@ -88,6 +90,7 @@ services:
arguments: arguments:
- '@netzmacht.contao_leaflet.map.assets' - '@netzmacht.contao_leaflet.map.assets'
- '@netzmacht.contao_leaflet.definition.mapper' - '@netzmacht.contao_leaflet.definition.mapper'
- '@netzmacht.contao_toolkit.repository_manager'
- '@netzmacht.contao_leaflet.libraries' - '@netzmacht.contao_leaflet.libraries'
tags: tags:
- { name: 'kernel.event_listener', event: 'netzmacht.contao_leaflet.get_javascript', method: 'onGetJavascriptEvent' } - { name: 'kernel.event_listener', event: 'netzmacht.contao_leaflet.get_javascript', method: 'onGetJavascriptEvent' }

View File

@@ -90,7 +90,8 @@ abstract class AbstractMapHybrid extends AbstractHybrid
$this->mapProvider->handleAjaxRequest($this->getIdentifier()); $this->mapProvider->handleAjaxRequest($this->getIdentifier());
if (TL_MODE === 'BE') { 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 = [ $parameters = [
'title' => $this->get('headline'), 'title' => $this->get('headline'),
]; ];

View File

@@ -14,9 +14,11 @@ declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Listener; namespace Netzmacht\Contao\Leaflet\Listener;
use Contao\FilesModel;
use Contao\Model; use Contao\Model;
use Netzmacht\Contao\Leaflet\Event\ConvertToGeoJsonEvent; use Netzmacht\Contao\Leaflet\Event\ConvertToGeoJsonEvent;
use Netzmacht\Contao\Leaflet\Model\LayerModel; use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
use Netzmacht\LeafletPHP\Definition as LeafletDefinition; use Netzmacht\LeafletPHP\Definition as LeafletDefinition;
use Netzmacht\LeafletPHP\Definition\HasPopup; use Netzmacht\LeafletPHP\Definition\HasPopup;
use Netzmacht\LeafletPHP\Definition\UI\Marker; use Netzmacht\LeafletPHP\Definition\UI\Marker;
@@ -40,13 +42,22 @@ final class GeoJsonListener
*/ */
private $featureModelProperties; private $featureModelProperties;
/**
* Repository manager.
*
* @var RepositoryManager
*/
private $repositoryManager;
/** /**
* GeoJsonSubscriber constructor. * 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; $this->featureModelProperties = $featureModelProperties;
} }
@@ -176,12 +187,14 @@ final class GeoJsonListener
break; break;
case 'file': case 'file':
$file = \FilesModel::findByUuid($value); $repository = $this->repositoryManager->getRepository(FilesModel::class);
$value = $file->path; $file = $repository->findByUuid($value);
$value = $file->path;
break; break;
case 'files': case 'files':
$collection = \FilesModel::findMultipleByUuids(deserialize($value, true)); $repository = $this->repositoryManager->getRepository(FilesModel::class);
$collection = $repository->findMultipleByUuids(deserialize($value, true));
if ($collection) { if ($collection) {
$value = $collection->fetchEach('path'); $value = $collection->fetchEach('path');
@@ -213,7 +226,8 @@ final class GeoJsonListener
if ($model->ignoreForBounds) { if ($model->ignoreForBounds) {
$feature->setProperty('ignoreForBounds', true); $feature->setProperty('ignoreForBounds', true);
} else { } else {
$parent = LayerModel::findByPk($model->pid); $repository = $this->repositoryManager->getRepository(LayerModel::class);
$parent = $repository->find((int) $model->pid);
if ($parent && $parent->boundsMode !== 'extend') { if ($parent && $parent->boundsMode !== 'extend') {
$feature->setProperty('ignoreForBounds', true); $feature->setProperty('ignoreForBounds', true);

View File

@@ -18,6 +18,7 @@ use Netzmacht\Contao\Leaflet\Encoder\ContaoAssets;
use Netzmacht\Contao\Leaflet\Frontend\Assets\LibrariesConfiguration; use Netzmacht\Contao\Leaflet\Frontend\Assets\LibrariesConfiguration;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\IconModel; use Netzmacht\Contao\Leaflet\Model\IconModel;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
use Netzmacht\LeafletPHP\Assets; use Netzmacht\LeafletPHP\Assets;
use Netzmacht\LeafletPHP\Definition\Type\Icon; use Netzmacht\LeafletPHP\Definition\Type\Icon;
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon; use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
@@ -50,18 +51,31 @@ class LoadAssetsListener
*/ */
private $libraries; private $libraries;
/**
* Repository manager.
*
* @var RepositoryManager
*/
private $repositoryManager;
/** /**
* LoadAssetsListener constructor. * LoadAssetsListener constructor.
* *
* @param Assets $assets Assets. * @param Assets $assets Assets.
* @param DefinitionMapper $definitionMapper Definition mapper. * @param DefinitionMapper $definitionMapper Definition mapper.
* @param LibrariesConfiguration $libraries Libraries. * @param RepositoryManager $repositoryManager Repository manager.
* @param LibrariesConfiguration $libraries Libraries.
*/ */
public function __construct(Assets $assets, DefinitionMapper $definitionMapper, LibrariesConfiguration $libraries) public function __construct(
{ Assets $assets,
$this->assets = $assets; DefinitionMapper $definitionMapper,
$this->definitionMapper = $definitionMapper; RepositoryManager $repositoryManager,
$this->libraries = $libraries; LibrariesConfiguration $libraries
) {
$this->assets = $assets;
$this->definitionMapper = $definitionMapper;
$this->libraries = $libraries;
$this->repositoryManager = $repositoryManager;
} }
/** /**
@@ -76,7 +90,8 @@ class LoadAssetsListener
ContaoAssets::TYPE_FILE ContaoAssets::TYPE_FILE
); );
$collection = IconModel::findBy('active', true); $repository = $this->repositoryManager->getRepository(IconModel::class);
$collection = $repository->findBy(['active=?'], [true]);
if ($collection) { if ($collection) {
$buffer = ''; $buffer = '';