2015-01-06 14:55:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-05 15:45:43 +02:00
|
|
|
* Leaflet maps for Contao CMS.
|
|
|
|
|
*
|
2016-10-11 10:40:15 +02:00
|
|
|
* @package contao-leaflet-maps
|
2015-01-06 14:55:53 +01:00
|
|
|
* @author David Molineus <david.molineus@netzmacht.de>
|
2017-10-11 15:00:48 +02:00
|
|
|
* @copyright 2014-2017 netzmacht David Molineus. All rights reserved.
|
2017-10-05 15:45:43 +02:00
|
|
|
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
|
2015-01-06 14:55:53 +01:00
|
|
|
* @filesource
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Netzmacht\Contao\Leaflet\Model;
|
|
|
|
|
|
2015-01-27 00:02:17 +01:00
|
|
|
use Netzmacht\Contao\Leaflet\Filter\BboxFilter;
|
|
|
|
|
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
2015-01-27 12:41:11 +01:00
|
|
|
use Netzmacht\LeafletPHP\Value\LatLngBounds;
|
2015-01-27 00:02:17 +01:00
|
|
|
|
2015-01-12 19:03:29 +01:00
|
|
|
/**
|
|
|
|
|
* Class MarkerModel for the tl_leaflet_marker table.
|
|
|
|
|
*
|
|
|
|
|
* @package Netzmacht\Contao\Leaflet\Model
|
|
|
|
|
*/
|
2015-01-12 09:32:21 +01:00
|
|
|
class MarkerModel extends AbstractActiveModel
|
2015-01-06 14:55:53 +01:00
|
|
|
{
|
2015-01-12 19:03:29 +01:00
|
|
|
/**
|
|
|
|
|
* Model table.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2015-01-06 14:55:53 +01:00
|
|
|
protected static $strTable = 'tl_leaflet_marker';
|
2015-01-27 00:02:17 +01:00
|
|
|
|
|
|
|
|
/**
|
2015-01-27 17:58:03 +01:00
|
|
|
* Find by a filter.
|
|
|
|
|
*
|
|
|
|
|
* @param int $pid The parent id.
|
|
|
|
|
* @param Filter $filter The filter.
|
2015-01-27 00:02:17 +01:00
|
|
|
*
|
2018-08-23 14:35:25 +02:00
|
|
|
* @return \Contao\Model\Collection|null
|
2015-01-27 00:02:17 +01:00
|
|
|
*/
|
|
|
|
|
public static function findByFilter($pid, Filter $filter = null)
|
|
|
|
|
{
|
|
|
|
|
if (!$filter) {
|
2017-10-17 18:11:28 +02:00
|
|
|
return static::findActiveBy('pid', $pid, ['order' => 'sorting']);
|
2015-01-27 00:02:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch ($filter->getName()) {
|
|
|
|
|
case 'bbox':
|
|
|
|
|
return static::findByBBoxFilter($pid, $filter);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-01-27 17:58:03 +01:00
|
|
|
* Find by the bbox filter.
|
|
|
|
|
*
|
|
|
|
|
* @param int $pid The layer id.
|
|
|
|
|
* @param BboxFilter $filter The bbox filter.
|
2015-01-27 00:02:17 +01:00
|
|
|
*
|
2018-08-23 14:35:25 +02:00
|
|
|
* @return \Contao\Model\Collection|null
|
2015-01-27 00:02:17 +01:00
|
|
|
*/
|
|
|
|
|
public static function findByBBoxFilter($pid, BboxFilter $filter)
|
|
|
|
|
{
|
2017-10-17 18:11:28 +02:00
|
|
|
$columns = [
|
2015-01-27 00:02:17 +01:00
|
|
|
'active=1',
|
|
|
|
|
'pid=?',
|
|
|
|
|
'latitude > ? AND latitude < ?',
|
2017-10-17 18:11:28 +02:00
|
|
|
'longitude > ? AND longitude < ?',
|
|
|
|
|
];
|
2015-01-27 00:02:17 +01:00
|
|
|
|
|
|
|
|
/** @var LatLngBounds $bounds */
|
|
|
|
|
$bounds = $filter->getValues()['bounds'];
|
2017-10-17 18:11:28 +02:00
|
|
|
$values = [
|
2015-01-27 00:02:17 +01:00
|
|
|
$pid,
|
|
|
|
|
$bounds->getSouthWest()->getLatitude(),
|
|
|
|
|
$bounds->getNorthEast()->getLatitude(),
|
|
|
|
|
$bounds->getSouthWest()->getLongitude(),
|
2017-10-17 18:11:28 +02:00
|
|
|
$bounds->getNorthEast()->getLongitude(),
|
|
|
|
|
];
|
2015-01-27 00:02:17 +01:00
|
|
|
|
2017-10-17 18:11:28 +02:00
|
|
|
return static::findBy($columns, $values, ['order' => 'sorting']);
|
2015-01-27 00:02:17 +01:00
|
|
|
}
|
2015-01-06 14:55:53 +01:00
|
|
|
}
|