Files
contao-leaflet-maps/src/Netzmacht/Contao/Leaflet/Dca/Marker.php

88 lines
2.0 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\Dca;
2015-01-06 21:30:57 +01:00
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
use Netzmacht\Contao\Leaflet\Model\IconModel;
2015-01-12 19:03:29 +01:00
/**
* Class Marker is the dca helper class for the tl_leaflet_marker dca.
*
* @package Netzmacht\Contao\Leaflet\Dca
*/
2015-01-06 14:55:53 +01:00
class Marker
{
2015-01-12 19:03:29 +01:00
/**
* Generate the row label.
*
* @param array $row Current data row.
*
* @return string
*/
2015-01-06 14:55:53 +01:00
public function generateRow($row)
{
return $row['title'];
}
2015-01-12 19:03:29 +01:00
/**
* Get all icons.
*
* @return array
*/
2015-01-06 21:30:57 +01:00
public function getIcons()
{
$collection = IconModel::findAll(array('order' => 'title'));
$builder = OptionsBuilder::fromCollection(
2015-01-12 19:03:29 +01:00
$collection,
'id',
function ($model) {
2015-01-06 21:30:57 +01:00
return sprintf('%s [%s]', $model['title'], $model['type']);
}
);
return $builder->getOptions();
}
2015-01-27 00:02:17 +01:00
/**
* Save the coordinates.
*
* @param string $value The raw data.
* @param \DataContainer $dataContainer The data container driver.
*
* @return string
*/
public function saveCoordinates($value, $dataContainer)
{
$combined = array(
'latitude' => null,
'longitude' => null,
'altitude' => null
);
$values = trimsplit(',', $value);
$keys = array_keys($combined);
if (count($values) >= 2 && count($values) <= 3) {
for ($i = 0; $i < count($values); $i++) {
$combined[$keys[$i]] = $values[$i];
}
}
\Database::getInstance()
->prepare('UPDATE tl_leaflet_marker %s WHERE id=?')
->set($combined)
->execute($dataContainer->id);
return $value;
}
2015-01-06 14:55:53 +01:00
}