AntonLV 9 سال پیش
والد
کامیت
27c8116122

+ 40 - 5
inc/classes/BxDolMetatags.php

@@ -408,6 +408,31 @@ class BxDolMetatags extends BxDolFactory implements iBxDolFactoryObject
         return $this->_oQuery->locationsAdd($iId, $sLatitude, $sLongitude, $sCountryCode, $sState, $sCity, $sZip, $sStreet, $sStreetNumber);
     }
 
+	/**
+     * Retrieve location for the content from POST data
+     * @param $sPrefix field prefix for POST data, or empty -  if no prefix
+     * @param $oForm form to use to get POST data, or null - then new form instance will be created
+     */
+    public static function locationsRetrieveFromForm($sPrefix = '', $oForm = null)
+    {
+        if ($sPrefix)
+            $sPrefix .= '_';
+
+        if (!$oForm)
+            $oForm = new BxDolForm(array(), false);
+
+        return array(
+            $oForm->getCleanValue($sPrefix.'lat'), 
+            $oForm->getCleanValue($sPrefix.'lng'), 
+            $oForm->getCleanValue($sPrefix.'country'), 
+            $oForm->getCleanValue($sPrefix.'state'), 
+            $oForm->getCleanValue($sPrefix.'city'), 
+            $oForm->getCleanValue($sPrefix.'zip'), 
+            $oForm->getCleanValue($sPrefix.'street'), 
+            $oForm->getCleanValue($sPrefix.'street_number')
+        );
+    }
+
     /**
      * Add location for the content from POST data
      * @param $iId content id
@@ -419,11 +444,7 @@ class BxDolMetatags extends BxDolFactory implements iBxDolFactoryObject
         if (!$this->locationsIsEnabled())
             return;
 
-        if ($sPrefix)
-            $sPrefix .= '_';
-        if (!$oForm)
-            $oForm = new BxDolForm(array(), false);
-        $this->locationsAdd($iId, $oForm->getCleanValue($sPrefix.'lat'), $oForm->getCleanValue($sPrefix.'lng'), $oForm->getCleanValue($sPrefix.'country'), $oForm->getCleanValue($sPrefix.'state'), $oForm->getCleanValue($sPrefix.'city'), $oForm->getCleanValue($sPrefix.'zip'), $oForm->getCleanValue($sPrefix.'street'), $oForm->getCleanValue($sPrefix.'street_number'));
+        call_user_func_array(array($this, 'locationsAdd'), array_merge(array($iId), self::locationsRetrieveFromForm($sPrefix, $oForm)));
     }
 
     /**
@@ -504,6 +525,20 @@ class BxDolMetatags extends BxDolFactory implements iBxDolFactoryObject
         );
     }
 
+    /**
+     * Set condition for search results object for meta locations
+     * @param $sContentTable content table or alias
+     * @param $sContentField content table field or field alias
+     * @param $sCountry country and other location info
+     */
+    public function locationsGetAsSQLPart($sContentTable, $sContentField, $sCountry = false, $sState = false, $sCity = false, $sZip = false)
+    {
+        if (empty($this->_aObject['table_locations']))
+            return array();
+
+        return call_user_func_array(array($this->_oQuery, 'locationsGetSQLParts'), func_get_args());
+    }
+
     /**
      * Get location
      * @param $iId content id

+ 17 - 0
inc/classes/BxDolMetatagsQuery.php

@@ -87,6 +87,23 @@ class BxDolMetatagsQuery extends BxDolDb
         return $this->getRow($sQuery);
     }
 
+    public function locationsGetSQLParts($sContentTable, $sContentField, $sCountry = false, $sState = false, $sCity = false, $sZip = false)
+    {
+        $aFields = array('country' => 'sCountry', 'state' => 'sState', 'city' => 'sCity', 'zip' => 'sZip');
+
+        $aWhere = array();
+        foreach ($aFields as $sIndex => $sVar) {
+            if (!$$sVar)
+                continue;
+
+            $aWhere['tl`.`' . $sIndex] = $$sVar;
+        }
+
+        return array(
+            'where' => ' AND ' . $this->arrayToSQL($aWhere, ' AND '),
+            'join' => 'INNER JOIN `' . $this->_aObject['table_locations'] . '` AS `tl` ON `' . $sContentTable . '`.`' . $sContentField . '`=`tl`.`object_id`'
+        );
+    }
 
     protected function metaDelete($sTable, $mixedContentId)
     {

+ 12 - 9
inc/classes/BxDolSearchExtended.php

@@ -13,9 +13,10 @@ class BxDolSearchExtended extends BxDolFactory implements iBxDolFactoryObject
 {
     public static $SEARCHABLE_TYPES = array(
         'text', 'textarea', 'number', 
-    	'select', 'radio_set',
+        'select', 'radio_set',
         'checkbox_set', 'select_multiple',
-    	'checkbox', 'switcher'
+        'checkbox', 'switcher',
+        'location'
     );
 
     public static $TYPE_TO_TYPE_SEARCH = array(
@@ -25,23 +26,25 @@ class BxDolSearchExtended extends BxDolFactory implements iBxDolFactoryObject
         'text_auto' => array('text_auto'),
         'select' => array('checkbox_set', 'select_multiple', 'select'),
         'radio_set' => array('checkbox_set', 'select_multiple', 'select'),
-    	'checkbox_set' => array('checkbox_set', 'select_multiple', 'select'),
-    	'select_multiple' => array('checkbox_set', 'select_multiple', 'select'),
+        'checkbox_set' => array('checkbox_set', 'select_multiple', 'select'),
+        'select_multiple' => array('checkbox_set', 'select_multiple', 'select'),
         'checkbox' => array('checkbox', 'switcher'),
-    	'switcher' => array('checkbox', 'switcher'),
+        'switcher' => array('checkbox', 'switcher'),
+        'location' => array('location')
     );
 
     public static $TYPE_TO_OPERATOR = array(
-    	'text' => array('like', '='),
+        'text' => array('like', '='),
         'textarea' => array('like', '='),
         'number' => array('='),
         'text_auto' => array('in'),
         'select' => array('in'),
         'radio_set' => array('in'),
-    	'checkbox_set' => array('and'), 
-    	'select_multiple' => array('and'),
+        'checkbox_set' => array('and'), 
+        'select_multiple' => array('and'),
         'checkbox' => array('='),
-    	'switcher' => array('='),
+        'switcher' => array('='),
+        'location' => array('locate')
     );
 
     protected $_oDb;

+ 17 - 1
modules/base/general/classes/BxBaseModGeneralDb.php

@@ -85,12 +85,28 @@ class BxBaseModGeneralDb extends BxDolModuleDb
                             $sSearchValue = " & " . $iResult . "";
                             break;
 
+                        case 'locate':
+                            if(!isset($CNF['OBJECT_METATAGS']))
+                                break;
+
+                            list($fLatitude, $fLongitude, $sCountry, $sState, $sCity, $sZip) = $aSearchParam['value'];
+
+                            $aSql = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])->locationsGetAsSQLPart($CNF['TABLE_ENTRIES'], $CNF['FIELD_ID'], $sCountry, $sState, $sCity, $sZip);
+
+                            if(!empty($aSql['join']))
+                                $sJoinClause .= $aSql['join'];
+
+                            if(!empty($aSql['where']))
+                                $sWhereConditions .= $aSql['where'];
+                            break;
+
                         default:
                              $sSearchValue = " " . $aSearchParam['operator'] . " :" . $sSearchParam;
                              $aMethod['params'][1][$sSearchParam] = $aSearchParam['value'];                             
                     }
 
-                    $sWhereConditions .= " AND `{$CNF['TABLE_ENTRIES']}`.`" . $sSearchParam . "`" . $sSearchValue;
+                    if(!empty($sSearchValue))
+                        $sWhereConditions .= " AND `{$CNF['TABLE_ENTRIES']}`.`" . $sSearchParam . "`" . $sSearchValue;
                 }
 
                 $sWhereClause .= " AND (" . $sWhereConditions . ")"; 

+ 14 - 0
template/scripts/BxBaseSearchExtendedForm.php

@@ -19,6 +19,20 @@ class BxBaseSearchExtendedForm extends BxTemplFormView
         parent::__construct($aInfo, $oTemplate);
     }
 
+    function getCleanValue ($sName)
+    {
+        if(isset($this->aInputs[$sName]['type']) && $this->aInputs[$sName]['type'] == 'location')
+            return BxDolMetatags::locationsRetrieveFromForm($sName, $this);
+
+        return parent::getCleanValue($sName);
+    }
+
+    public function genInputLocation(&$aInput)
+    {
+        $aInput['manual_input'] = true;
+        return parent::genInputLocation($aInput);
+    }
+
 	protected function genCustomInputAuthor($aInput)
     {
         $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . 'searchExtended.php?action=get_authors';