Files
contao-leaflet-maps/src/Netzmacht/Contao/Leaflet/Model/MarkerModel.php

85 lines
2.1 KiB
PHP
Raw Normal View History

2015-01-06 14:55:53 +01:00
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @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;
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
*
* @return \Model\Collection|null
*/
public static function findByFilter($pid, Filter $filter = null)
{
if (!$filter) {
2015-01-27 17:58:03 +01:00
return static::findActiveBy('pid', $pid, array('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
*
* @return \Model\Collection|null
*/
public static function findByBBoxFilter($pid, BboxFilter $filter)
{
$columns = array(
'active=1',
'pid=?',
'latitude > ? AND latitude < ?',
'longitude > ? AND longitude < ?'
);
/** @var LatLngBounds $bounds */
$bounds = $filter->getValues()['bounds'];
$values = array(
$pid,
$bounds->getSouthWest()->getLatitude(),
$bounds->getNorthEast()->getLatitude(),
$bounds->getSouthWest()->getLongitude(),
$bounds->getNorthEast()->getLongitude()
);
return static::findBy($columns, $values, array('order' => 'sorting'));
}
2015-01-06 14:55:53 +01:00
}