2015-01-05 12:25:46 +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-05 12:25:46 +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-05 12:25:46 +01:00
|
|
|
* @filesource
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Netzmacht\Contao\Leaflet\Model;
|
|
|
|
|
|
2018-08-23 14:35:25 +02:00
|
|
|
use Contao\Database;
|
|
|
|
|
use Contao\Model\Collection;
|
2015-01-12 19:03:29 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class ControlModel for the tl_leaflet_vector table.
|
|
|
|
|
*
|
|
|
|
|
* @package Netzmacht\Contao\Leaflet\Model
|
|
|
|
|
*/
|
2015-01-09 15:24:34 +01:00
|
|
|
class ControlModel extends AbstractActiveModel
|
2015-01-05 12:25:46 +01:00
|
|
|
{
|
2015-01-12 19:03:29 +01:00
|
|
|
/**
|
|
|
|
|
* Model table.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2015-01-05 12:25:46 +01:00
|
|
|
protected static $strTable = 'tl_leaflet_control';
|
2015-01-09 22:33:57 +01:00
|
|
|
|
|
|
|
|
/**
|
2015-01-12 19:03:29 +01:00
|
|
|
* Find all related layers.
|
|
|
|
|
*
|
|
|
|
|
* @return Collection|null
|
2015-01-09 22:33:57 +01:00
|
|
|
*/
|
|
|
|
|
public function findLayers()
|
|
|
|
|
{
|
2015-01-12 19:03:29 +01:00
|
|
|
$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=?
|
2019-02-13 12:06:30 +01:00
|
|
|
ORDER BY c.sorting
|
2015-01-12 19:03:29 +01:00
|
|
|
SQL;
|
|
|
|
|
|
2018-08-23 14:35:25 +02:00
|
|
|
$result = Database::getInstance()
|
2015-01-09 22:33:57 +01:00
|
|
|
->prepare($query)
|
|
|
|
|
->execute($this->id);
|
|
|
|
|
|
2015-01-12 19:03:29 +01:00
|
|
|
if ($result->numRows < 1) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Collection::createFromDbResult($result, 'tl_leaflet_layer');
|
2015-01-09 22:33:57 +01:00
|
|
|
}
|
2015-01-09 23:48:25 +01:00
|
|
|
|
|
|
|
|
/**
|
2015-01-12 19:03:29 +01:00
|
|
|
* Find active layers.
|
|
|
|
|
*
|
|
|
|
|
* @return Collection|null
|
2015-01-09 23:48:25 +01:00
|
|
|
*/
|
|
|
|
|
public function findActiveLayers()
|
|
|
|
|
{
|
2015-01-12 19:03:29 +01:00
|
|
|
$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
|
2019-02-13 12:06:30 +01:00
|
|
|
ORDER BY c.sorting
|
2015-01-12 19:03:29 +01:00
|
|
|
SQL;
|
|
|
|
|
|
2018-08-23 14:35:25 +02:00
|
|
|
$result = Database::getInstance()
|
2015-01-09 23:48:25 +01:00
|
|
|
->prepare($query)
|
|
|
|
|
->execute($this->id);
|
|
|
|
|
|
2015-01-12 19:03:29 +01:00
|
|
|
if ($result->numRows < 1) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Collection::createFromDbResult($result, 'tl_leaflet_layer');
|
2015-01-09 23:48:25 +01:00
|
|
|
}
|
2015-01-05 12:25:46 +01:00
|
|
|
}
|