Files
contao-leaflet-maps/src/Model/MapModel.php

79 lines
1.7 KiB
PHP
Raw Normal View History

2014-12-29 12:17:40 +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
2014-12-29 12:17:40 +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
2014-12-29 12:17:40 +01:00
* @filesource
*/
namespace Netzmacht\Contao\Leaflet\Model;
use Contao\Database;
use Contao\Model;
use Contao\Model\Collection;
2014-12-29 12:17:40 +01:00
2015-01-12 19:03:29 +01:00
/**
* Class MapModel for the tl_leaflet_map table.
*
2015-01-24 11:38:15 +01:00
* @property mixed|null locate
* @property mixed|null title
*
2015-01-12 19:03:29 +01:00
* @package Netzmacht\Contao\Leaflet\Model
*/
class MapModel extends Model
2014-12-29 12:17:40 +01:00
{
2015-01-12 19:03:29 +01:00
/**
* Model table.
*
* @var string
*/
2014-12-29 12:17:40 +01:00
protected static $strTable = 'tl_leaflet_map';
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()
{
$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()
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 all 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.*
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);
2015-01-12 19:03:29 +01:00
if ($result->numRows) {
return Collection::createFromDbResult($result, 'tl_leaflet_layer');
}
2015-01-09 23:48:25 +01:00
2015-01-12 19:03:29 +01:00
return null;
2015-01-09 23:48:25 +01:00
}
2014-12-29 12:17:40 +01:00
}