Sfoglia il codice sorgente

Ticket #5186 - Tasks: Functionality improvements. Point 3.

AntonLV 1 anno fa
parent
commit
35b07bb5c4

+ 19 - 12
modules/base/profile/classes/BxBaseModProfileDb.php

@@ -96,28 +96,32 @@ class BxBaseModProfileDb extends BxBaseModGeneralDb
         return $this->query($sQuery, $aBindings);
     }
 
-    public function searchByTerm($sTerm, $iLimit)
+    public function searchByTerm($sTerm, $mixedParams)
     {
-        if (!$this->_oConfig->CNF['FIELDS_QUICK_SEARCH'])
-            return array();
+        if(!$this->_oConfig->CNF['FIELDS_QUICK_SEARCH'])
+            return [];
 
-		$aBindings = array(
-			'type' => $this->_oConfig->getName(),
-			'status' => BX_PROFILE_STATUS_ACTIVE
-		);
+        $aBindings = [
+            'type' => $this->_oConfig->getName(),
+            'status' => BX_PROFILE_STATUS_ACTIVE
+        ];
         $sSelect = "`c`.`id` AS `content_id`, `p`.`account_id`, `p`.`id` AS `profile_id`, `p`.`status` AS `profile_status` ";
         
         $sJoin = "INNER JOIN `sys_profiles` AS `p` ON (`p`.`content_id` = `c`.`id` AND `p`.`type` = :type) INNER JOIN `sys_accounts` AS `a` ON (`a`.`id` =  `p`.`account_id`)";
         
         $sWhere = '';
         foreach ($this->_oConfig->CNF['FIELDS_QUICK_SEARCH'] as $sField) {
-        	$aBindings[$sField] = '%' . $sTerm . '%';
+            $aBindings[$sField] = '%' . $sTerm . '%';
 
             $sWhere .= " OR `c`.`$sField` LIKE :" . $sField;
         }
         $sWhere = "`p`.`status` = :status AND (0 $sWhere) ";
 
-        $sOrderBy = $this->prepareAsString(" ORDER BY `a`.`logged` DESC LIMIT ?", (int)$iLimit);
+        $sOrderBy = " ORDER BY `a`.`logged` DESC";
+
+        $sLimit = "";
+        if((is_numeric($mixedParams) && ($iLimit = (int)$mixedParams)) || (is_array($mixedParams) && isset($mixedParams['limit']) && ($iLimit = (int)$mixedParams['limit'])))
+            $sLimit = $this->prepareAsString(" LIMIT ?", $iLimit);
 
         /**
          * @hooks
@@ -133,18 +137,21 @@ class BxBaseModProfileDb extends BxBaseModGeneralDb
          *      - `join` - [string] by ref, 'join' part of SQL query, can be overridden in hook processing
          *      - `where` - [string] by ref, 'where' part of SQL query, can be overridden in hook processing
          *      - `order_by` - [string] by ref, 'order' part of SQL query, can be overridden in hook processing
+         *      - `limit` - [string] by ref, 'limit' part of SQL query, can be overridden in hook processing
          * @hook @ref hook-profile-search_by_term
          */
         bx_alert('profile', 'search_by_term', 0, 0, [
             'module' => $this->_oConfig->getName(), 
+            'params' => $mixedParams['search_params'] ?? '',
             'table' => $this->_oConfig->CNF['TABLE_ENTRIES'], 
             'select' => &$sSelect,  
             'join' => &$sJoin, 
             'where' => &$sWhere, 
-            'order_by' => &$sOrderBy
+            'order_by' => &$sOrderBy,
+            'limit' => &$sLimit
         ]);
-        
-        return $this->getAll("SELECT " . $sSelect . " FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` AS `c` " . $sJoin . " WHERE " . $sWhere . $sOrderBy, $aBindings);
+
+        return $this->getAll("SELECT " . $sSelect . " FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` AS `c` " . $sJoin . " WHERE " . $sWhere . $sOrderBy . $sLimit, $aBindings);
     }
 
     protected function _getEntriesBySearchIds($aParams, &$aMethod, &$sSelectClause, &$sJoinClause, &$sWhereClause, &$sOrderClause, &$sLimitClause)

+ 5 - 5
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -381,11 +381,11 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
         return '';
     }
 
-    public function serviceProfilesSearch ($sTerm, $iLimit)
+    public function serviceProfilesSearch ($sTerm, $mixedParams)
     {
-        $aRet = array();
+        $aRet = [];
 
-        $a = $this->_oDb->searchByTerm($sTerm, $iLimit);
+        $a = $this->_oDb->searchByTerm($sTerm, $mixedParams);
         foreach ($a as $r) {
             $oProfile = BxDolProfile::getInstance($r['profile_id']);
 
@@ -396,13 +396,13 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
                 $aRet[] = $aData['author_data'];
             }
             else{
-                $aRet[] = array (
+                $aRet[] = [
                     'label' => $this->serviceProfileName($r['content_id']), 
                     'value' => $r['profile_id'], 
                     'url' => $oProfile->getUrl(),
                     'thumb' => $oProfile->getThumb(),
                     'unit' => $oProfile->getUnit(0, ['template' => ['name' => 'unit_wo_info', 'size' => 'icon']])
-                );
+                ];
             }
         }
 

+ 28 - 18
template/scripts/BxBaseServiceProfiles.php

@@ -461,13 +461,15 @@ class BxBaseServiceProfiles extends BxDol
         return $aRet;
     }
 
-    public function serviceProfilesSearch ($sTerm, $mixedParems = [])
+    public function serviceProfilesSearch ($sTerm, $mixedParams = [])
     {
-        $iLimit = (int)getParam('sys_profiles_search_limit');
-        if(is_int($mixedParems)) 
-            $iLimit = (int)$mixedParems;
-        else if(is_array($mixedParems) && isset($mixedParems['limit']))
-            $iLimit = (int)$mixedParems['limit'];
+        $bParams = is_array($mixedParams);
+
+        $iLimit = 0;
+        if((is_numeric($mixedParams) && ($_iLimit = (int)$mixedParams)) || ($bParams && isset($mixedParams['limit']) && ($_iLimit = (int)$mixedParams['limit']))) 
+            $iLimit = $_iLimit;
+        else
+            $iLimit = (int)getParam('sys_profiles_search_limit');
 
         // display friends by default
         if (!$sTerm)
@@ -476,12 +478,20 @@ class BxBaseServiceProfiles extends BxDol
         // get list of "profiles" modules
         $aModules = $this->serviceGetProfilesModules();
 
+        $mixedSearchParams = (int)getParam('sys_per_page_search_keyword_single');
+        if($bParams && !empty($mixedParams['search_params']) && is_array($mixedParams['search_params']))
+            $mixedSearchParams = [
+                'search_params' => $mixedParams['search_params'], 
+                'limit' => $mixedSearchParams
+            ];
+
         // search in each module
-        $a = array();
+        $a = [];
         foreach ($aModules as $aModule) {
-            if (!BxDolService::call($aModule['name'], 'act_as_profile'))
+            if(!bx_srv($aModule['name'], 'act_as_profile'))
                 continue;
-            $a = array_merge($a, BxDolService::call($aModule['name'], 'profiles_search', array($sTerm, getParam('sys_per_page_search_keyword_single'))));
+
+            $a = array_merge($a, bx_srv($aModule['name'], 'profiles_search', [$sTerm, $mixedSearchParams]));
         }
 
         // sort result
@@ -502,27 +512,27 @@ class BxBaseServiceProfiles extends BxDol
          *      - `result` - [array] by ref, array of results, can be overridden in hook processing
          * @hook @ref hook-account-profiles_search_by_location
          */
-        bx_alert('system', 'profiles_search', 0, 0, array(
-            'module' => is_array($mixedParems) && isset($mixedParems['module']) ? $mixedParems['module'] : '',
+        bx_alert('system', 'profiles_search', 0, 0, [
+            'module' => $bParams && isset($mixedParams['module']) ? $mixedParams['module'] : '',
             'term' => $sTerm,
             'result' => &$a
-        ));
+        ]);
 
         // return as array
         return array_slice($a, 0, $iLimit);
     }
 
-    public function serviceProfilesSearchByLocation ($aLocation, $iRadius, $mixedParems = [])
+    public function serviceProfilesSearchByLocation ($aLocation, $iRadius, $mixedParams = [])
     {
-        $sModule = !empty($mixedParems['module']) ? $mixedParems['module'] : '';
+        $sModule = !empty($mixedParams['module']) ? $mixedParams['module'] : '';
         $aModules = !empty($sModule) ? [BxDolModuleDb::getInstance()->getModuleByName($sModule)] : $this->serviceGetProfilesModules();
 
         $iStart = 0;
         $iLimit = 20;
-        if(is_int($mixedParems)) 
-            $iLimit = (int)$mixedParems;
-        else if(is_array($mixedParems) && isset($mixedParems['limit']))
-            $iLimit = (int)$mixedParems['limit'];
+        if(is_int($mixedParams)) 
+            $iLimit = (int)$mixedParams;
+        else if(is_array($mixedParams) && isset($mixedParams['limit']))
+            $iLimit = (int)$mixedParams['limit'];
 
         $aLocation[] = $iRadius;
         $oProfileQuery = BxDolProfileQuery::getInstance();