Switch to PSR-4.

This commit is contained in:
David Molineus
2017-10-05 14:16:56 +02:00
parent e3344ffd4f
commit 827c746b0d
87 changed files with 4 additions and 6 deletions

View File

@@ -0,0 +1,65 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Model;
/**
* Class AbstractActiveModel is the base model for models with an active field.
*
* @package Netzmacht\Contao\Leaflet\Model
*/
abstract class AbstractActiveModel extends \Model
{
/**
* Find an active model by its model id.
*
* @param int $modelId The model id.
* @param array $options The query options.
*
* @return \Model|null
*/
public static function findActiveByPK($modelId, $options = array())
{
return static::findOneBy('active=1 AND id', $modelId, $options);
}
/**
* Find active models by a defined column.
*
* @param string|array $column The query columns.
* @param mixed $value The column value.
* @param array $options The options.
*
* @return \Model|null
*/
public static function findActiveBy($column, $value, $options = array())
{
if (is_array($column)) {
$column[] = 'active=1';
} else {
$column = 'active=1 AND ' . $column;
}
return static::findBy($column, $value, $options);
}
/**
* Find collection activated models.
*
* @param array $options The query options.
*
* @return \Model\Collection|null
*/
public static function findActives($options = array())
{
return static::findBy('active', '1', $options);
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Model;
use Model\Collection;
/**
* Class ControlModel for the tl_leaflet_vector table.
*
* @package Netzmacht\Contao\Leaflet\Model
*/
class ControlModel extends AbstractActiveModel
{
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_control';
/**
* Find all related layers.
*
* @return Collection|null
*/
public function findLayers()
{
$query = <<<SQL
SELECT l.*, c.mode as controlMode
FROM tl_leaflet_layer l
LEFT JOIN tl_leaflet_control_layer c ON l.id = c.lid
WHERE c.cid=?
SQL;
$result = \Database::getInstance()
->prepare($query)
->execute($this->id);
if ($result->numRows < 1) {
return null;
}
return Collection::createFromDbResult($result, 'tl_leaflet_layer');
}
/**
* Find active layers.
*
* @return Collection|null
*/
public function findActiveLayers()
{
$query = <<<SQL
SELECT l.*, c.mode as controlMode
FROM tl_leaflet_layer l
LEFT JOIN tl_leaflet_control_layer
c ON l.id = c.lid
WHERE c.cid=? AND l.active=1
SQL;
$result = \Database::getInstance()
->prepare($query)
->execute($this->id);
if ($result->numRows < 1) {
return null;
}
return Collection::createFromDbResult($result, 'tl_leaflet_layer');
}
}

33
src/Model/IconModel.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Model;
/**
* IconModel class for the tl_leaflet_icon table.
*
* @property mixed|null iconImage
* @property mixed|null iconAnchor
* @property mixed|null popupAnchor
* @property mixed|null iconRetinaImage
* @property mixed|null shadowAnchor
* @property mixed|null shadowRetinaImage
* @property mixed|null shadowImage
*/
class IconModel extends AbstractActiveModel
{
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_icon';
}

62
src/Model/LayerModel.php Normal file
View File

@@ -0,0 +1,62 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Model;
use Model\Collection;
/**
* Class LayerModel for the tl_leaflet_layer table.
*
* @property mixed|null id
* @property mixed|null alias
* @property mixed|null pointToLayer
* @property mixed|null onEachFeature
* @property mixed|null boundsMode
*
* @package Netzmacht\Contao\Leaflet\Model
*/
class LayerModel extends AbstractActiveModel
{
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_layer';
/**
* Find multiple layers by given type.
*
* @param array $types List of layer types.
* @param array $options Query options.
*
* @return Collection|null
*/
public static function findMultipleByTypes(array $types, $options = array())
{
if (empty($types)) {
return null;
}
$options['column'] = array(
sprintf(
'type IN (%s)',
substr(str_repeat('?,', count($types)), 0, -1)
)
);
$options['value'] = $types;
$options['return'] = 'Collection';
return static::find($options);
}
}

75
src/Model/MapModel.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Model;
use Model\Collection;
/**
* Class MapModel for the tl_leaflet_map table.
*
* @property mixed|null locate
* @property mixed|null title
*
* @package Netzmacht\Contao\Leaflet\Model
*/
class MapModel extends \Model
{
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_map';
/**
* Find all related layers.
*
* @return Collection|null
*/
public function findLayers()
{
$query = 'SELECT l.* FROM tl_leaflet_layer l LEFT JOIN tl_leaflet_map_layer m ON l.id = m.lid WHERE m.mid=?';
$result = \Database::getInstance()
->prepare($query)
->execute($this->id);
if ($result->numRows < 1) {
return null;
}
return Collection::createFromDbResult($result, 'tl_leaflet_layer');
}
/**
* Find all active layers.
*
* @return Collection|null
*/
public function findActiveLayers()
{
$query = <<<SQL
SELECT l.*
FROM tl_leaflet_layer l
LEFT JOIN tl_leaflet_map_layer m
ON l.id = m.lid
WHERE m.mid=? AND l.active=1
SQL;
$result = \Database::getInstance()->prepare($query)->execute($this->id);
if ($result->numRows) {
return Collection::createFromDbResult($result, 'tl_leaflet_layer');
}
return null;
}
}

84
src/Model/MarkerModel.php Normal file
View File

@@ -0,0 +1,84 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Model;
use Netzmacht\Contao\Leaflet\Filter\BboxFilter;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\LeafletPHP\Value\LatLngBounds;
/**
* Class MarkerModel for the tl_leaflet_marker table.
*
* @package Netzmacht\Contao\Leaflet\Model
*/
class MarkerModel extends AbstractActiveModel
{
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_marker';
/**
* Find by a filter.
*
* @param int $pid The parent id.
* @param Filter $filter The filter.
*
* @return \Model\Collection|null
*/
public static function findByFilter($pid, Filter $filter = null)
{
if (!$filter) {
return static::findActiveBy('pid', $pid, array('order' => 'sorting'));
}
switch ($filter->getName()) {
case 'bbox':
return static::findByBBoxFilter($pid, $filter);
default:
return null;
}
}
/**
* Find by the bbox filter.
*
* @param int $pid The layer id.
* @param BboxFilter $filter The bbox filter.
*
* @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'));
}
}

29
src/Model/PopupModel.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Model;
/**
* Class PopupModel.
*
* @property mixed|null offset
*
* @package Netzmacht\Contao\Leaflet\Model
*/
class PopupModel extends AbstractActiveModel
{
/**
* The table name.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_popup';
}

27
src/Model/StyleModel.php Normal file
View File

@@ -0,0 +1,27 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Model;
/**
* Class StyleModel for the tl_leaflet_style table.
*
* @package Netzmacht\Contao\Leaflet\Model
*/
class StyleModel extends AbstractActiveModel
{
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_style';
}

27
src/Model/VectorModel.php Normal file
View File

@@ -0,0 +1,27 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Model;
/**
* Class VectorModel for the tl_leaflet_vector table.
*
* @package Netzmacht\Contao\Leaflet\Model
*/
class VectorModel extends AbstractActiveModel
{
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_vector';
}