mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-02 04:53:56 +01:00
Use the repository manager.
This commit is contained in:
@@ -18,6 +18,7 @@ use Contao\FilesModel;
|
||||
use Contao\Model;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\Request;
|
||||
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
||||
use Netzmacht\JavascriptBuilder\Type\Expression;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\FeatureGroup;
|
||||
@@ -50,6 +51,25 @@ class FileLayerMapper extends AbstractLayerMapper
|
||||
*/
|
||||
protected static $definitionClass = FeatureGroup::class;
|
||||
|
||||
/**
|
||||
* Repository manager.
|
||||
*
|
||||
* @var RepositoryManager
|
||||
*/
|
||||
private $repositoryManager;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param RepositoryManager $repositoryManager Repository manager.
|
||||
*/
|
||||
public function __construct(RepositoryManager $repositoryManager)
|
||||
{
|
||||
$this->repositoryManager = $repositoryManager;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -60,7 +80,8 @@ class FileLayerMapper extends AbstractLayerMapper
|
||||
$elementId = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
$fileModel = FilesModel::findByPk($model->file);
|
||||
$repository = $this->repositoryManager->getRepository(FilesModel::class);
|
||||
$fileModel = $repository->findByPk($model->file);
|
||||
$definition = $this->createInstance($model, $mapper, $request, $elementId, $fileModel);
|
||||
|
||||
$this->optionsBuilder->build($definition, $model);
|
||||
|
||||
@@ -16,6 +16,7 @@ use Contao\Model;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\Request;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\FeatureGroup;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
|
||||
@@ -35,6 +36,25 @@ class GroupLayerMapper extends AbstractLayerMapper
|
||||
*/
|
||||
protected static $type = 'group';
|
||||
|
||||
/**
|
||||
* Repository manager.
|
||||
*
|
||||
* @var RepositoryManager
|
||||
*/
|
||||
private $repositoryManager;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param RepositoryManager $repositoryManager Repository manager.
|
||||
*/
|
||||
public function __construct(RepositoryManager $repositoryManager)
|
||||
{
|
||||
$this->repositoryManager = $repositoryManager;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -61,7 +81,8 @@ class GroupLayerMapper extends AbstractLayerMapper
|
||||
return;
|
||||
}
|
||||
|
||||
$collection = LayerModel::findBy(
|
||||
$repository = $this->repositoryManager->getRepository(LayerModel::class);
|
||||
$collection = $repository->findBy(
|
||||
['pid=?', 'active=1'],
|
||||
[$model->id],
|
||||
['order' => 'sorting']
|
||||
|
||||
@@ -17,6 +17,7 @@ use Netzmacht\Contao\Leaflet\Encoder\ContaoAssets;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\Request;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
||||
use Netzmacht\JavascriptBuilder\Type\AnonymousFunction;
|
||||
use Netzmacht\JavascriptBuilder\Type\Expression;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
@@ -53,15 +54,24 @@ class MarkerClusterLayerMapper extends AbstractLayerMapper
|
||||
private $assets;
|
||||
|
||||
/**
|
||||
* MarkerClusterLayerMapper constructor.
|
||||
* Repository manager.
|
||||
*
|
||||
* @param ContaoAssets $assets Assets manager.
|
||||
* @var RepositoryManager
|
||||
*/
|
||||
public function __construct(ContaoAssets $assets)
|
||||
{
|
||||
parent::__construct();
|
||||
private $repositoryManager;
|
||||
|
||||
$this->assets = $assets;
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param ContaoAssets $assets Assets manager.
|
||||
* @param RepositoryManager $repositoryManager Repository manager.
|
||||
*/
|
||||
public function __construct(ContaoAssets $assets, RepositoryManager $repositoryManager)
|
||||
{
|
||||
$this->repositoryManager = $repositoryManager;
|
||||
$this->assets = $assets;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +117,8 @@ class MarkerClusterLayerMapper extends AbstractLayerMapper
|
||||
$this->assets->addStylesheet('assets/leaflet/libs/leaflet-markercluster/MarkerCluster.Default.css');
|
||||
}
|
||||
|
||||
$collection = LayerModel::findBy(
|
||||
$repository = $this->repositoryManager->getRepository(LayerModel::class);
|
||||
$collection = $repository->findBy(
|
||||
['pid=?', 'active=1'],
|
||||
[$model->id],
|
||||
['order' => 'sorting']
|
||||
|
||||
@@ -18,6 +18,7 @@ use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\Request;
|
||||
use Netzmacht\Contao\Leaflet\Model\MarkerModel;
|
||||
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
||||
use Netzmacht\JavascriptBuilder\Type\Expression;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
|
||||
@@ -38,6 +39,25 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
*/
|
||||
protected static $type = 'markers';
|
||||
|
||||
/**
|
||||
* Repository manager.
|
||||
*
|
||||
* @var RepositoryManager
|
||||
*/
|
||||
private $repositoryManager;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param RepositoryManager $repositoryManager Repository manager.
|
||||
*/
|
||||
public function __construct(RepositoryManager $repositoryManager)
|
||||
{
|
||||
$this->repositoryManager = $repositoryManager;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -154,10 +174,12 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
*/
|
||||
protected function loadMarkerModels(Model $model, Request $request = null)
|
||||
{
|
||||
$repository = $this->repositoryManager->getRepository(MarkerModel::class);
|
||||
|
||||
if ($model->boundsMode == 'fit') {
|
||||
return MarkerModel::findByFilter($model->id, $request->getFilter());
|
||||
return $repository->findByFilter($model->id, $request->getFilter());
|
||||
}
|
||||
|
||||
return MarkerModel::findByFilter($model->id);
|
||||
return $repository->findByFilter($model->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ use Netzmacht\Contao\Leaflet\Definition\Layer\OverpassLayer;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\Request;
|
||||
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
||||
use Netzmacht\JavascriptBuilder\Type\Expression;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
|
||||
@@ -41,6 +42,25 @@ class OverpassLayerMapper extends AbstractLayerMapper
|
||||
*/
|
||||
protected static $definitionClass = OverpassLayer::class;
|
||||
|
||||
/**
|
||||
* Repository manager.
|
||||
*
|
||||
* @var RepositoryManager
|
||||
*/
|
||||
private $repositoryManager;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param RepositoryManager $repositoryManager Repository manager.
|
||||
*/
|
||||
public function __construct(RepositoryManager $repositoryManager)
|
||||
{
|
||||
$this->repositoryManager = $repositoryManager;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -97,7 +117,8 @@ class OverpassLayerMapper extends AbstractLayerMapper
|
||||
$amenityIconsMap = $this->filterAmenityIconsConfig($model->amenityIcons);
|
||||
|
||||
if ($amenityIconsMap) {
|
||||
$collection = IconModel::findMultipleByIds(array_unique($amenityIconsMap));
|
||||
$repository = $this->repositoryManager->getRepository(IconModel::class);
|
||||
$collection = $repository->findMultipleByIds(array_unique($amenityIconsMap));
|
||||
$icons = [];
|
||||
|
||||
if ($collection) {
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\Request;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
|
||||
/**
|
||||
@@ -31,6 +32,25 @@ class ReferenceLayerMapper extends AbstractLayerMapper
|
||||
*/
|
||||
protected static $type = 'reference';
|
||||
|
||||
/**
|
||||
* Repository manager.
|
||||
*
|
||||
* @var RepositoryManager
|
||||
*/
|
||||
private $repositoryManager;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param RepositoryManager $repositoryManager Repository manager.
|
||||
*/
|
||||
public function __construct(RepositoryManager $repositoryManager)
|
||||
{
|
||||
$this->repositoryManager = $repositoryManager;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -41,7 +61,8 @@ class ReferenceLayerMapper extends AbstractLayerMapper
|
||||
$elementId = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
$reference = LayerModel::findByPk($model->reference);
|
||||
$repository = $this->repositoryManager->getRepository(LayerModel::class);
|
||||
$reference = $repository->findByPk($model->reference);
|
||||
|
||||
if (!$reference || !$reference->active) {
|
||||
return null;
|
||||
|
||||
@@ -19,6 +19,7 @@ use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\Request;
|
||||
use Netzmacht\Contao\Leaflet\Model\VectorModel;
|
||||
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
||||
use Netzmacht\JavascriptBuilder\Type\Expression;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
|
||||
@@ -39,6 +40,25 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
*/
|
||||
protected static $type = 'vectors';
|
||||
|
||||
/**
|
||||
* Repository manager.
|
||||
*
|
||||
* @var RepositoryManager
|
||||
*/
|
||||
private $repositoryManager;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param RepositoryManager $repositoryManager Repository manager.
|
||||
*/
|
||||
public function __construct(RepositoryManager $repositoryManager)
|
||||
{
|
||||
$this->repositoryManager = $repositoryManager;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -159,7 +179,9 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
*/
|
||||
protected function loadVectorModels(Model $model)
|
||||
{
|
||||
return VectorModel::findActiveBy('pid', $model->id, ['order' => 'sorting']);
|
||||
$repository = $this->repositoryManager->getRepository(VectorModel::class);
|
||||
|
||||
return $repository->findActiveBy(['pid=?'], [$model->id], ['order' => 'sorting']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user