Bläddra i källkod

#1519 Location improvements: move Nominatim to a separate file

Alex Trofimov 5 år sedan
förälder
incheckning
593d62bc82
3 ändrade filer med 108 tillägg och 86 borttagningar
  1. 2 85
      inc/classes/BxDolLocationField.php
  2. 105 0
      inc/classes/BxDolLocationFieldNominatim.php
  3. 1 1
      install/sql/system.sql

+ 2 - 85
inc/classes/BxDolLocationField.php

@@ -36,81 +36,8 @@ class BxDolLocationField extends BxDolFactoryObject
 
     public function genInputLocation (&$aInput, $oForm)
     {        
-        $isManualInput = (int)(isset($aInput['manual_input']) && $aInput['manual_input']);
-        if (!$isManualInput) {
-            $aVars = array();
-            $aInputField = $aInput;
-
-            $aLocationIndexes = BxDolForm::$LOCATION_INDEXES;
-            foreach ($aLocationIndexes as $sKey)
-                $aVars[$sKey] = $this->getLocationVal($aInput, $sKey, $oForm);
-
-            $aInputField['caption'] = _t('_sys_location_undefined');
-
-            if ($this->getLocationVal($aInput, 'lat', $oForm) && $this->getLocationVal($aInput, 'lng', $oForm))
-                $aInputField['checked'] = true;
-            else
-                $aInputField['checked'] = $oForm->getCleanValue($aInput['name'] . '_lat') && $oForm->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
-
-            $sLocationString = _t('_sys_location_undefined');
-            if ($aVars['country']) {
-                $aCountries = BxDolFormQuery::getDataItems('Country');
-                $sLocationString = ($aVars['street_number'] ? $aVars['street_number'] . ', ' : '') . ($aVars['street'] ? $aVars['street'] . ', ' : '') . ($aVars['city'] ? $aVars['city'] . ', ' : '') . ($aVars['state'] ? $aVars['state'] . ', ' : '') . $aCountries[$aVars['country']];
-            }
-            elseif ($aVars['lat'] || $aVars['lng']) {
-                $sLocationString = $aVars['lat'] . ', ' . $aVars['lng'];
-            }
-
-            $aVars['name'] = $aInput['name'];
-            $aVars['input'] = $oForm->genInputSwitcher($aInputField);
-            $aVars['id_status'] = $oForm->getInputId($aInput) . '_status';
-            $aVars['location_string'] = $sLocationString;
-            $aVars['nominatim_server'] = $this->getNominatimServer();
-            $aVars['nominatim_email'] = $this->getNominatimEmail();
-
-            $sRet = $oForm->getTemplate()->parseHtmlByName('location_field_plain_auto.html', $aVars);
-        }
-        else {
-            $aFields = array(
-                'lat' => array('type' => 'hidden'),
-                'lng' => array('type' => 'hidden'),
-                'street_number' => array('type' => 'text', 'ph' => _t('_sys_location_ph_number')),
-                'street' => array('type' => 'text', 'ph' => _t('_sys_location_ph_street')),
-                'city' => array('type' => 'text', 'ph' => _t('_sys_location_ph_city')),
-                'state' => array('type' => 'text', 'ph' => _t('_sys_location_ph_state')),
-                'zip' => array('type' => 'text', 'ph' => _t('_sys_location_ph_zip')),
-                'country' => array('type' => 'select'),
-            );
-
-            $sInputs = '';
-            foreach ($aFields as $sKey => $a) {
-                $aInputField = $aInput;
-                $aInputField['name'] = $aInput['name'] . '_' . $sKey;
-                $aInputField['type'] = $a['type'];
-                $aInputField['value'] = $this->getLocationVal($aInput, $sKey, $oForm);            
-                $aInputField['attrs']['placeholder'] = empty($a['ph']) ? '' : _t($a['ph']);
-                if (isset($aInputField['attrs']['class']))
-                    $aInputField['attrs']['class'] .= ' bx-form-input-location-' . $sKey;
-                else
-                    $aInputField['attrs']['class'] = 'bx-form-input-location-' . $sKey;
-                if ('country' == $sKey) {
-                    $aCountries = BxDolFormQuery::getDataItems('Country');
-                    array_unshift($aCountries, array('key' => '', 'value' => _t('_None')));
-                    $aInputField['values'] = $aCountries;
-                    $sInputs .= $oForm->genInputSelect($aInputField);
-                }
-                else {
-                    $sInputs .= $oForm->genInputStandard($aInputField);
-                }
-            }
-            $sRet = $oForm->getTemplate()->parseHtmlByName('location_field_plain.html', array(
-                'name' => $aInput['name'],
-                'nominatim_server' => $this->getNominatimServer(),
-                'nominatim_email' => $this->getNominatimEmail(),
-                'inputs' => $sInputs,
-            ));
-        }
-        return $sRet;
+        // override this
+        return 'not implemented';
     }
 
     protected function getLocationVal ($aInput, $sIndex, $oForm) 
@@ -123,16 +50,6 @@ class BxDolLocationField extends BxDolFactoryObject
 
         return $oForm->getCleanValue($s);
     }
-
-    protected function getNominatimServer ()
-    {
-        return trim(trim(getParam('sys_nominatim_server')), '/');
-    }
-
-    protected function getNominatimEmail ()
-    {
-        return trim(getParam('sys_nominatim_email'));
-    }
 }
 
 /** @} */

+ 105 - 0
inc/classes/BxDolLocationFieldNominatim.php

@@ -0,0 +1,105 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+/**
+ * Plain fields with Nomination service geocoding
+ */
+class BxDolLocationFieldNominatim extends BxDolLocationField
+{
+    public function genInputLocation (&$aInput, $oForm)
+    {        
+        $isManualInput = (int)(isset($aInput['manual_input']) && $aInput['manual_input']);
+        if (!$isManualInput) {
+            $aVars = array();
+            $aInputField = $aInput;
+
+            $aLocationIndexes = BxDolForm::$LOCATION_INDEXES;
+            foreach ($aLocationIndexes as $sKey)
+                $aVars[$sKey] = $this->getLocationVal($aInput, $sKey, $oForm);
+
+            $aInputField['caption'] = _t('_sys_location_undefined');
+
+            if ($this->getLocationVal($aInput, 'lat', $oForm) && $this->getLocationVal($aInput, 'lng', $oForm))
+                $aInputField['checked'] = true;
+            else
+                $aInputField['checked'] = $oForm->getCleanValue($aInput['name'] . '_lat') && $oForm->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
+
+            $sLocationString = _t('_sys_location_undefined');
+            if ($aVars['country']) {
+                $aCountries = BxDolFormQuery::getDataItems('Country');
+                $sLocationString = ($aVars['street_number'] ? $aVars['street_number'] . ', ' : '') . ($aVars['street'] ? $aVars['street'] . ', ' : '') . ($aVars['city'] ? $aVars['city'] . ', ' : '') . ($aVars['state'] ? $aVars['state'] . ', ' : '') . $aCountries[$aVars['country']];
+            }
+            elseif ($aVars['lat'] || $aVars['lng']) {
+                $sLocationString = $aVars['lat'] . ', ' . $aVars['lng'];
+            }
+
+            $aVars['name'] = $aInput['name'];
+            $aVars['input'] = $oForm->genInputSwitcher($aInputField);
+            $aVars['id_status'] = $oForm->getInputId($aInput) . '_status';
+            $aVars['location_string'] = $sLocationString;
+            $aVars['nominatim_server'] = $this->getNominatimServer();
+            $aVars['nominatim_email'] = $this->getNominatimEmail();
+
+            $sRet = $oForm->getTemplate()->parseHtmlByName('location_field_plain_auto.html', $aVars);
+        }
+        else {
+            $aFields = array(
+                'lat' => array('type' => 'hidden'),
+                'lng' => array('type' => 'hidden'),
+                'street_number' => array('type' => 'text', 'ph' => _t('_sys_location_ph_number')),
+                'street' => array('type' => 'text', 'ph' => _t('_sys_location_ph_street')),
+                'city' => array('type' => 'text', 'ph' => _t('_sys_location_ph_city')),
+                'state' => array('type' => 'text', 'ph' => _t('_sys_location_ph_state')),
+                'zip' => array('type' => 'text', 'ph' => _t('_sys_location_ph_zip')),
+                'country' => array('type' => 'select'),
+            );
+
+            $sInputs = '';
+            foreach ($aFields as $sKey => $a) {
+                $aInputField = $aInput;
+                $aInputField['name'] = $aInput['name'] . '_' . $sKey;
+                $aInputField['type'] = $a['type'];
+                $aInputField['value'] = $this->getLocationVal($aInput, $sKey, $oForm);            
+                $aInputField['attrs']['placeholder'] = empty($a['ph']) ? '' : _t($a['ph']);
+                if (isset($aInputField['attrs']['class']))
+                    $aInputField['attrs']['class'] .= ' bx-form-input-location-' . $sKey;
+                else
+                    $aInputField['attrs']['class'] = 'bx-form-input-location-' . $sKey;
+                if ('country' == $sKey) {
+                    $aCountries = BxDolFormQuery::getDataItems('Country');
+                    array_unshift($aCountries, array('key' => '', 'value' => _t('_None')));
+                    $aInputField['values'] = $aCountries;
+                    $sInputs .= $oForm->genInputSelect($aInputField);
+                }
+                else {
+                    $sInputs .= $oForm->genInputStandard($aInputField);
+                }
+            }
+            $sRet = $oForm->getTemplate()->parseHtmlByName('location_field_plain.html', array(
+                'name' => $aInput['name'],
+                'nominatim_server' => $this->getNominatimServer(),
+                'nominatim_email' => $this->getNominatimEmail(),
+                'inputs' => $sInputs,
+            ));
+        }
+        return $sRet;
+    }
+
+    protected function getNominatimServer ()
+    {
+        return trim(trim(getParam('sys_nominatim_server')), '/');
+    }
+
+    protected function getNominatimEmail ()
+    {
+        return trim(getParam('sys_nominatim_email'));
+    }
+}
+
+/** @} */

+ 1 - 1
install/sql/system.sql

@@ -5254,7 +5254,7 @@ CREATE TABLE `sys_objects_location_field` (
 
 INSERT INTO `sys_objects_location_field` (`object`, `module`, `title`, `class_name`, `class_file`) VALUES
 ('sys_google', 'system', '_sys_location_field_google', 'BxDolLocationFieldGoogle', ''),
-('sys_plain', 'system', '_sys_location_field_plain', 'BxDolLocationField', '');
+('sys_plain', 'system', '_sys_location_field_plain', 'BxDolLocationFieldNominatim', '');
 
 -- --------------------------------------------------------