Przeglądaj źródła

#2135 Search by radius in custom search forms - improvement

RomanL 7 lat temu
rodzic
commit
b251f103b8

+ 2 - 4
inc/classes/BxDolSearchExtended.php

@@ -33,8 +33,7 @@ class BxDolSearchExtended extends BxDolFactory implements iBxDolFactoryObject
         'switcher' => array('checkbox', 'switcher'),
         'datepicker' => array('datepicker_range', 'datepicker_range_age'),
         'datetime' => array('datetime_range', 'datetime_range_age'),
-        'location' => array('location'),
-        'location_radius' => array('location_radius')
+        'location' => array('location', 'location_radius')
     );
 
     public static $TYPE_TO_OPERATOR = array(
@@ -50,8 +49,7 @@ class BxDolSearchExtended extends BxDolFactory implements iBxDolFactoryObject
         'switcher' => array('='),
     	'datepicker' => array('between'), 
     	'datetime' => array('between'),
-        'location' => array('locate'),
-        'location_radius' => array('locate_in_radius')
+        'location' => array('locate')
     );
 
     protected $_oDb;

+ 9 - 22
modules/base/general/classes/BxBaseModGeneralDb.php

@@ -193,28 +193,15 @@ class BxBaseModGeneralDb extends BxDolModuleDb
                 case 'locate':
                     if(!isset($CNF['OBJECT_METATAGS']))
                         break;
-
-                    list($fLatitude, $fLongitude, $sCountry, $sState, $sCity, $sZip) = $aSearchParam['value']['array'];
-
-                    $aSql = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])->locationsGetAsSQLPart($CNF['TABLE_ENTRIES'], $CNF['FIELD_ID'], $sCountry, $sState, $sCity, $sZip);
-
-                    if(!empty($aSql['where'])) {
-                        $sWhereConditions .= $aSql['where'];
-
-                        if(!empty($aSql['join']))
-                            $sJoinClause .= $aSql['join'];
+                    if ($aSearchParam['type'] == 'location_radius'){
+                        list($fLatitude, $fLongitude, $sCountry, $sState, $sCity, $sZip, $sStreet, $sStreetNumber, $iRadius) = $aSearchParam['value']['array'];
+                        $aBounds = bx_get_location_bounds_latlng($fLatitude, $fLongitude, $iRadius);   
+                        $aSql = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])->locationsGetAsSQLPart($CNF['TABLE_ENTRIES'], $CNF['FIELD_ID'], '', '', '', '', $aBounds);
+                    }
+                    else{
+                        list($fLatitude, $fLongitude, $sCountry, $sState, $sCity, $sZip) = $aSearchParam['value']['array'];
+                        $aSql = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])->locationsGetAsSQLPart($CNF['TABLE_ENTRIES'], $CNF['FIELD_ID'], $sCountry, $sState, $sCity, $sZip);
                     }
-                    break;
-                    
-                case 'locate_in_radius':
-                    if(!isset($CNF['OBJECT_METATAGS']))
-                        break;
-                    
-                    list($fLatitude, $fLongitude, $sCountry, $sState, $sCity, $sZip, $sStreet, $sStreetNumber, $iRadius) = $aSearchParam['value']['array'];
-                    $aBounds = bx_get_location_bounds_latlng($fLatitude, $fLongitude, $iRadius);
-                    
-                    $aSql = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])->locationsGetAsSQLPart($CNF['TABLE_ENTRIES'], $CNF['FIELD_ID'], '', '', '', '', $aBounds);
-                    
                     if(!empty($aSql['where'])) {
                         $sWhereConditions .= $aSql['where'];
 
@@ -222,7 +209,7 @@ class BxBaseModGeneralDb extends BxDolModuleDb
                             $sJoinClause .= $aSql['join'];
                     }
                     break;
-
+                    
                 case 'between':
                     if(!is_array($aSearchParam['value']) || count($aSearchParam['value']) != 2) 
                         break;

+ 2 - 12
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -216,7 +216,7 @@ class BxBaseModGeneralModule extends BxDolModule
         if(!empty($aInputsAdd) && is_array($aInputsAdd))
             $aInputs = array_merge($aInputs, $aInputsAdd);
 
-        foreach($aInputs as $aInput)
+        foreach($aInputs as $aInput){
             if(in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept)) {
                 $aField = array(
                     'type' => $aInput['type'], 
@@ -233,17 +233,7 @@ class BxBaseModGeneralModule extends BxDolModule
 
                 $aResult[$aInput['name']] = $aField;
             }
-            if(!empty($CNF['FIELD_LOCATION_PREFIX']) && !in_array($CNF['FIELD_LOCATION_PREFIX'], $this->_aSearchableNamesExcept))
-                $aResult['location_radius'] = array(
-                    'type' => 'location_radius', 
-                    'caption' => '_sys_form_input_location_radius',
-                    'caption_system' => '_sys_form_input_sys_location_radius',
-                    'info' => '',
-            	    'value' => '',
-                    'values' => '',
-                    'pass' => ''
-                );
-
+        }
         return $aResult;
     }
 

+ 2 - 3
modules/boonex/english/data/langs/system/en.xml

@@ -831,7 +831,8 @@
 	<string name="_adm_form_txt_field_type_image"><![CDATA[image]]></string>
 	<string name="_adm_form_txt_field_type_input_set"><![CDATA[input set]]></string>
 	<string name="_adm_form_txt_field_type_location"><![CDATA[location]]></string>
-	<string name="_adm_form_txt_field_type_number"><![CDATA[number]]></string>
+  <string name="_adm_form_txt_field_type_location_radius"><![CDATA[location radius]]></string>
+  <string name="_adm_form_txt_field_type_number"><![CDATA[number]]></string>
 	<string name="_adm_form_txt_field_type_password"><![CDATA[password]]></string>
 	<string name="_adm_form_txt_field_type_radio_set"><![CDATA[radio set]]></string>
 	<string name="_adm_form_txt_field_type_reset"><![CDATA[reset]]></string>
@@ -2038,8 +2039,6 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_form_input_age"><![CDATA[Age]]></string>
 	<string name="_sys_form_input_sys_location"><![CDATA[Location]]></string>
 	<string name="_sys_form_input_location"><![CDATA[Location]]></string>
-  <string name="_sys_form_input_sys_location_radius"><![CDATA[Location Radius]]></string>
-	<string name="_sys_form_input_location_radius"><![CDATA[Location Radius]]></string>
   <string name="_sys_form_input_location_radius_label"><![CDATA[Radius (in km)]]></string>
 	<string name="_sys_form_input_sys_labels"><![CDATA[Labels]]></string>
   <string name="_sys_form_input_labels"><![CDATA[Labels]]></string>

+ 3 - 4
modules/boonex/russian/data/langs/system/ru.xml

@@ -831,6 +831,7 @@
 	<string name="_adm_form_txt_field_type_image"><![CDATA[картинка]]></string>
 	<string name="_adm_form_txt_field_type_input_set"><![CDATA[набор полей ввода]]></string>
 	<string name="_adm_form_txt_field_type_location"><![CDATA[местонахождение]]></string>
+  <string name="_adm_form_txt_field_type_location_radius"><![CDATA[радиус местонахождения]]></string>
 	<string name="_adm_form_txt_field_type_number"><![CDATA[число]]></string>
 	<string name="_adm_form_txt_field_type_password"><![CDATA[пароль]]></string>
 	<string name="_adm_form_txt_field_type_radio_set"><![CDATA[набор переключателей]]></string>
@@ -2038,11 +2039,9 @@
 	<string name="_sys_form_forgot_password_input_submit"><![CDATA[Выполнить]]></string>
 	<string name="_sys_form_input_age"><![CDATA[Возраст]]></string>
 	<string name="_sys_form_input_sys_location"><![CDATA[Расположение]]></string>
-    <string name="_sys_form_input_location"><![CDATA[Расположение по радиусу]]></string>
-  <string name="_sys_form_input_sys_location_radius"><![CDATA[Расположение по радиусу]]></string>
+  <string name="_sys_form_input_location"><![CDATA[Расположение по радиусу]]></string>
   <string name="_sys_form_input_location_radius_label"><![CDATA[Радиус (в км)]]></string>
-  <string name="_sys_form_input_location_radius"><![CDATA[Расположение]]></string>
-	<string name="_sys_form_input_sys_labels"><![CDATA[Метки]]></string>
+  <string name="_sys_form_input_sys_labels"><![CDATA[Метки]]></string>
     <string name="_sys_form_input_labels"><![CDATA[Метки]]></string>
 	<string name="_sys_form_input_sys_anonymous"><![CDATA[Анонимная публикация]]></string>
 	<string name="_sys_form_input_anonymous"><![CDATA[Анонимная публикация]]></string>

BIN
studio/template/images/icons/ui-location_radius.png


+ 5 - 2
template/scripts/BxBaseSearchExtendedForm.php

@@ -124,6 +124,9 @@ class BxBaseSearchExtendedForm extends BxTemplFormView
 				}
 
                 return $this->genInputStandard($aInput);
+                
+            case 'location_radius':
+                return $this->genInputLocationRadius($aInput);
         }
 
         return parent::genInput($aInput);
@@ -142,7 +145,7 @@ class BxBaseSearchExtendedForm extends BxTemplFormView
         return $this->genCustomInputUsernamesSuggestions($aInput);
     }
     
-    public function genCustomInputLocationRadius(&$aInput)
+    public function genInputLocationRadius(&$aInput)
     {
         $aInput['manual_input'] = true;
         
@@ -150,7 +153,7 @@ class BxBaseSearchExtendedForm extends BxTemplFormView
         $aInputRadius['type'] = 'text';
         $aInputRadius['name'] = $aInputRadius['name'] . '_rad';
         $sValue = bx_get($aInputRadius['name']);
-        $aInputRadius['value'] = is_numeric($sValue) ? $sValue : 0;
+        $aInputRadius['value'] = is_numeric($sValue) ? $sValue : '';
         $aInputRadius['attrs']['placeholder'] = _t('_sys_form_input_location_radius_label');
         
         $aVars = array (