Use the repository manager.

This commit is contained in:
David Molineus
2017-10-18 16:36:12 +02:00
parent 0716354952
commit 7741f44428
5 changed files with 83 additions and 69 deletions

View File

@@ -15,6 +15,7 @@ services:
- '@netzmacht.contao_leaflet.map.assets'
- '@netzmacht.contao_leaflet.cache'
- '@netzmacht.contao_leaflet.frontend.data_controller'
- '@netzmacht.contao_toolkit.repository_manager'
netzmacht.contao_leaflet.libraries:
class: Netzmacht\Contao\Leaflet\Frontend\Assets\LibrariesConfiguration
@@ -86,8 +87,8 @@ services:
- '@templating'
- '@translator'
- '@netzmacht.contao_leaflet.map.provider'
- '@netzmacht.contao_toolkit.repository_manager'
- '@netzmacht.contao_toolkit.contao.input_adapter'
- '@netzmacht.contao_toolkit.contao.config_adapter'
tags:
- { name: 'netzmacht.contao_toolkit.component.content_element_factory' }
- { name: 'netzmacht.contao_toolkit.component.content_element', alias: 'leaflet', category: 'includes' }
@@ -98,8 +99,8 @@ services:
- '@templating'
- '@translator'
- '@netzmacht.contao_leaflet.map.provider'
- '@netzmacht.contao_toolkit.repository_manager'
- '@netzmacht.contao_toolkit.contao.input_adapter'
- '@netzmacht.contao_toolkit.contao.config_adapter'
tags:
- { name: 'netzmacht.contao_toolkit.component.frontend_module_factory' }
- { name: 'netzmacht.contao_toolkit.component.frontend_module', alias: 'leaflet', category: 'includes' }

View File

@@ -14,7 +14,6 @@ declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Frontend;
use Contao\Config;
use Contao\Database\Result;
use Contao\Input;
use Contao\Model;
@@ -22,6 +21,7 @@ use Contao\Model\Collection;
use Netzmacht\Contao\Leaflet\MapProvider;
use Netzmacht\Contao\Leaflet\Model\MapModel;
use Netzmacht\Contao\Toolkit\Component\Hybrid\AbstractHybrid;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
use Symfony\Component\Templating\EngineInterface as TemplateEngine;
use Symfony\Component\Translation\TranslatorInterface as Translator;
@@ -42,42 +42,42 @@ abstract class AbstractMapHybrid extends AbstractHybrid
/**
* The user input.
*
* @var \Input
* @var Input
*/
private $input;
/**
* The Contao config.
* Repository manager.
*
* @var \Config
* @var RepositoryManager
*/
private $config;
private $repositoryManager;
/**
* HybridTrait constructor.
*
* @param Result|Model|Collection $model Component model.
* @param TemplateEngine $templateEngine Template engine.
* @param Translator $translator Translator.
* @param MapProvider $mapProvider Map provider.
* @param Input $input Request Input.
* @param Config $config Config.
* @param string $column Column in which the element appears.
* @param Result|Model|Collection $model Component model.
* @param TemplateEngine $templateEngine Template engine.
* @param Translator $translator Translator.
* @param MapProvider $mapProvider Map provider.
* @param RepositoryManager $repositoryManager Repository manager.
* @param Input $input Request Input.
* @param string $column Column in which the element appears.
*/
public function __construct(
$model,
TemplateEngine $templateEngine,
Translator $translator,
MapProvider $mapProvider,
RepositoryManager $repositoryManager,
$input,
$config,
$column = null
) {
parent::__construct($model, $templateEngine, $translator, $column);
$this->mapProvider = $mapProvider;
$this->input = $input;
$this->config = $config;
$this->mapProvider = $mapProvider;
$this->input = $input;
$this->repositoryManager = $repositoryManager;
}
/**

View File

@@ -20,6 +20,7 @@ use Contao\Input;
use Netzmacht\Contao\Leaflet\MapProvider;
use Netzmacht\Contao\Toolkit\Component\Component;
use Netzmacht\Contao\Toolkit\Component\ComponentFactory;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
use Symfony\Component\Templating\EngineInterface as TemplateEngine;
use Symfony\Component\Translation\TranslatorInterface as Translator;
@@ -59,33 +60,33 @@ class MapElementFactory implements ComponentFactory
private $input;
/**
* Config adapter.
* Repository manager.
*
* @var Config|Adapter
* @var RepositoryManager
*/
private $config;
private $repositoryManager;
/**
* MapElementFactory constructor.
*
* @param TemplateEngine $engine Template engine.
* @param Translator $translator Translator.
* @param MapProvider $mapProvider Map provider.
* @param Input|Adapter $input Input adapter.
* @param Config|Adapter $config Config adapter.
* @param TemplateEngine $engine Template engine.
* @param Translator $translator Translator.
* @param MapProvider $mapProvider Map provider.
* @param RepositoryManager $repositoryManager Repository manager.
* @param Input|Adapter $input Input adapter.
*/
public function __construct(
TemplateEngine $engine,
Translator $translator,
MapProvider $mapProvider,
$input,
$config
RepositoryManager $repositoryManager,
$input
) {
$this->templating = $engine;
$this->translator = $translator;
$this->mapProvider = $mapProvider;
$this->input = $input;
$this->config = $config;
$this->templating = $engine;
$this->translator = $translator;
$this->mapProvider = $mapProvider;
$this->input = $input;
$this->repositoryManager = $repositoryManager;
}
/**
@@ -106,8 +107,8 @@ class MapElementFactory implements ComponentFactory
$this->templating,
$this->translator,
$this->mapProvider,
$this->repositoryManager,
$this->input,
$this->config,
$column
);
}

View File

@@ -20,6 +20,7 @@ use Contao\Input;
use Netzmacht\Contao\Leaflet\MapProvider;
use Netzmacht\Contao\Toolkit\Component\Component;
use Netzmacht\Contao\Toolkit\Component\ComponentFactory;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
use Symfony\Component\Templating\EngineInterface as TemplateEngine;
use Symfony\Component\Translation\TranslatorInterface as Translator;
@@ -59,33 +60,33 @@ class MapModuleFactory implements ComponentFactory
private $input;
/**
* Config adapter.
* Repository manager.
*
* @var Config|Adapter
* @var RepositoryManager
*/
private $config;
private $repositoryManager;
/**
* MapElementFactory constructor.
*
* @param TemplateEngine $engine Template engine.
* @param Translator $translator Translator.
* @param MapProvider $mapProvider Map provider.
* @param Input|Adapter $input Input adapter.
* @param Config|Adapter $config Config adapter.
* @param TemplateEngine $engine Template engine.
* @param Translator $translator Translator.
* @param MapProvider $mapProvider Map provider.
* @param RepositoryManager $repositoryManager Repository manager.
* @param Input|Adapter $input Input adapter.
*/
public function __construct(
TemplateEngine $engine,
Translator $translator,
MapProvider $mapProvider,
$input,
$config
RepositoryManager $repositoryManager,
$input
) {
$this->templating = $engine;
$this->translator = $translator;
$this->mapProvider = $mapProvider;
$this->input = $input;
$this->config = $config;
$this->templating = $engine;
$this->translator = $translator;
$this->mapProvider = $mapProvider;
$this->input = $input;
$this->repositoryManager = $repositoryManager;
}
/**
@@ -106,8 +107,8 @@ class MapModuleFactory implements ComponentFactory
$this->templating,
$this->translator,
$this->mapProvider,
$this->repositoryManager,
$this->input,
$this->config,
$column
);
}

View File

@@ -22,6 +22,7 @@ use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\Request;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\Contao\Leaflet\Model\MapModel;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
use Netzmacht\LeafletPHP\Definition\Map;
use Netzmacht\LeafletPHP\Leaflet;
use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection;
@@ -83,18 +84,24 @@ class MapProvider
*/
private $dataController;
/**
* Repository manager.
*
* @var RepositoryManager
*/
private $repositoryManager;
/**
* Construct.
*
* @param DefinitionMapper $mapper The definition mapper.
* @param Leaflet $leaflet The Leaflet instance.
* @param EventDispatcher $eventDispatcher The Contao event dispatcher.
* @param Input $input Thw request input.
* @param ContaoAssets $assets Assets handler.
* @param Cache $cache Cache.
* @param DataController $dataController Data controller.
*
* @internal param FilterFactory $filterFactory Filter factory.
* @param DefinitionMapper $mapper The definition mapper.
* @param Leaflet $leaflet The Leaflet instance.
* @param EventDispatcher $eventDispatcher The Contao event dispatcher.
* @param Input $input Thw request input.
* @param ContaoAssets $assets Assets handler.
* @param Cache $cache Cache.
* @param DataController $dataController Data controller.
* @param RepositoryManager $repositoryManager Repository manager.
*/
public function __construct(
DefinitionMapper $mapper,
@@ -103,15 +110,17 @@ class MapProvider
$input,
ContaoAssets $assets,
Cache $cache,
DataController $dataController
DataController $dataController,
RepositoryManager $repositoryManager
) {
$this->mapper = $mapper;
$this->leaflet = $leaflet;
$this->eventDispatcher = $eventDispatcher;
$this->input = $input;
$this->assets = $assets;
$this->cache = $cache;
$this->dataController = $dataController;
$this->mapper = $mapper;
$this->leaflet = $leaflet;
$this->eventDispatcher = $eventDispatcher;
$this->input = $input;
$this->assets = $assets;
$this->cache = $cache;
$this->dataController = $dataController;
$this->repositoryManager = $repositoryManager;
}
/**
@@ -149,7 +158,8 @@ class MapProvider
*/
public function getModel($mapId)
{
$model = MapModel::findByIdOrAlias($mapId);
$repository = $this->repositoryManager->getRepository(MapModel::class);
$model = $repository->findByIdOrAlias($mapId);
if ($model === null) {
throw new \InvalidArgumentException(sprintf('Model "%s" not found', $mapId));
@@ -226,7 +236,8 @@ class MapProvider
if ($layerId instanceof LayerModel) {
$model = $layerId;
} else {
$model = LayerModel::findByPK($layerId);
$repository = $this->repositoryManager->getRepository(LayerModel::class);
$model = $repository->find((int) $layerId);
}
if (!$model || !$model->active) {