vendor/con4gis/maps/Resources/contao/dca/tl_module.php line 21

Open in your IDE?
  1. <?php if (!defined('TL_ROOT')) die('You can not access this file directly!');
  2. /**
  3.  * con4gis - the gis-kit
  4.  *
  5.  * @version   php 7
  6.  * @package   con4gis
  7.  * @author    con4gis contributors (see "authors.txt")
  8.  * @license   GNU/LGPL http://opensource.org/licenses/lgpl-3.0.html
  9.  * @copyright Küstenschmiede GmbH Software & Design 2011 - 2018
  10.  * @link      https://www.kuestenschmiede.de
  11.  */
  12. /***
  13.  * Palettes
  14.  */
  15. $GLOBALS['TL_DCA']['tl_module']['palettes']['c4g_maps']         =   '{title_legend},name,headline,type;'.
  16.                                                                     '{c4g_map_legend},c4g_map_id,c4g_map_default_mapservice,c4g_map_width,c4g_map_height,c4g_map_zoom;'.
  17.                                                                     '{protected_legend:hide},protected;'.
  18.                                                                     '{expert_legend:hide},guests,cssID,space';
  19. if ($GLOBALS['con4gis']['forum']['installed'])
  20. {
  21.     $insert '{c4g_forum_maps_legend},c4g_forum_enable_maps;{expert_legend:hide}';
  22.     //insert c4g-maps support when forum is installed
  23.     $GLOBALS['TL_DCA']['tl_module']['palettes']['c4g_forum'] = str_replace('{expert_legend:hide}'$insert$GLOBALS['TL_DCA']['tl_module']['palettes']['c4g_forum']);
  24.     $GLOBALS['TL_DCA']['tl_module']['fields']['c4g_forum_enable_maps'] = array
  25.     (
  26.         'label' => &$GLOBALS['TL_LANG']['tl_module']['c4g_forum_enable_maps'],
  27.         'exclude' => true,
  28.         'default' => '',
  29.         'inputType' => 'checkbox',
  30.         'sql' => "char(1) NOT NULL default ''"
  31.     );
  32. }
  33. /***
  34.  * Fields
  35.  */
  36. $GLOBALS['TL_DCA']['tl_module']['fields']['c4g_map_id'] = array
  37. (
  38.     'label'                   => &$GLOBALS['TL_LANG']['tl_module']['c4g_map_id'],
  39.     'exclude'                 => true,
  40.     'inputType'               => 'select',
  41.     'options_callback'        => array('tl_module_c4g_maps''get_maps'),
  42.     'eval'                    => array('submitOnChange'=>true),
  43.     'sql'                     => "int(10) unsigned NOT NULL default '0'"
  44. );
  45. $GLOBALS['TL_DCA']['tl_module']['fields']['c4g_map_width'] = array
  46. (
  47.     'label'                   => &$GLOBALS['TL_LANG']['tl_module']['c4g_map_width'],
  48.     'exclude'                 => true,
  49.     'inputType'               => 'inputUnit',
  50.     'options'                 => array('px''%''em''vh''vw''vmin''vmax''pt''pc''in''cm''mm'),
  51.     'eval'                    => array(
  52.                                     'rgxp'=>'digit_auto_inherit',
  53.                                     'tl_class'=>'w50',
  54.                                     'includeBlankOption'=>true
  55.                                 ),
  56.     'sql'                     => "varchar(64) NOT NULL default ''"
  57. );
  58. $GLOBALS['TL_DCA']['tl_module']['fields']['c4g_map_height'] = array
  59. (
  60.     'label'                   => &$GLOBALS['TL_LANG']['tl_module']['c4g_map_height'],
  61.     'exclude'                 => true,
  62.     'inputType'               => 'inputUnit',
  63.     'options'                 => array('px''%''em''vh''vw''vmin''vmax''pt''pc''in''cm''mm'),
  64.     'eval'                    => array(
  65.                                     'rgxp'=>'digit_auto_inherit',
  66.                                     'tl_class'=>'w50',
  67.                                     'includeBlankOption'=>true
  68.                                 ),
  69.     'sql'                     => "varchar(64) NOT NULL default ''"
  70. );
  71. $GLOBALS['TL_DCA']['tl_module']['fields']['c4g_map_zoom'] = array
  72. (
  73.     'label'                   => &$GLOBALS['TL_LANG']['tl_module']['c4g_map_zoom'],
  74.     'exclude'                 => true,
  75.     'inputType'               => 'text',
  76.     'eval'                    => array('mandatory'=>false'rgxp'=>'digit'),
  77.     'sql'                     => "int(10) unsigned NOT NULL default '0'"
  78. );
  79. $GLOBALS['TL_DCA']['tl_module']['fields']['c4g_map_default_mapservice'] = array
  80. (
  81.     'label'                   => &$GLOBALS['TL_LANG']['tl_module']['c4g_map_default_mapservice'],
  82.     'exclude'                 => true,
  83.     'inputType'               => 'select',
  84.     'options_callback'        => array('tl_module_c4g_maps''get_baselayers'),
  85.     'sql'                     => "int(10) unsigned NOT NULL default '0'"
  86. );
  87. /**
  88.  * Class tl_module_c4g_maps
  89.  */
  90. class tl_module_c4g_maps extends Backend
  91. {
  92.     protected $firstMapId null;
  93.     /**
  94.      * Return all base layers for current Map Profile as array
  95.      * @param object
  96.      * @return array
  97.      */
  98.     public function get_baselayers(DataContainer $dc)
  99.     {
  100.         $id 0;
  101.         if ($dc->activeRecord->c4g_map_id != 0) {
  102.             $id $dc->activeRecord->c4g_map_id;
  103.         } else {
  104.             // take firstMapId, because it will be chosen as DEFAULT value for c4g_map_id
  105.             $id $this->firstMapId;
  106.         }
  107.         $profile $this->Database->prepare(
  108.                 "SELECT b.baselayers ".
  109.                 "FROM tl_c4g_maps a, tl_c4g_map_profiles b ".
  110.                 "WHERE a.id = ? and a.profile = b.id")
  111.                 ->execute($id);
  112.         $ids deserialize($profile->baselayers,true);
  113.         if (count($ids)>0) {
  114.             $baseLayers $this->Database->prepare("SELECT id,name FROM tl_c4g_map_baselayers WHERE id IN (".implode(',',$ids).") ORDER BY name")->execute();
  115.         } else {
  116.             $baseLayers $this->Database->prepare("SELECT id,name FROM tl_c4g_map_baselayers ORDER BY name")->execute();
  117.         }
  118.         if ($baseLayers->numRows 0) {
  119.             while ( $baseLayers->next () ) {
  120.                 $return [$baseLayers->id] = $baseLayers->name;
  121.             }
  122.         }
  123.         return $return;
  124.     }
  125.     /**
  126.      * Return all defined maps
  127.      * @param object
  128.      * @return array
  129.      */
  130.     public function get_maps(DataContainer $dc)
  131.     {
  132.         $maps $this->Database->prepare "SELECT * FROM tl_c4g_maps WHERE is_map=1 AND published=1" )->execute ();
  133.         if ($maps->numRows 0) {
  134.             while ( $maps->next () ) {
  135.                 if (!isset($this->firstMapId)) {
  136.                     // save first map id
  137.                     $this->firstMapId $maps->id;
  138.                 }
  139.                 $return [$maps->id] = $maps->name;
  140.             }
  141.         }
  142.         return $return;
  143.     }
  144. }