Explorar o código

Ticket #5652 - Mentions: Order suggestions list by weight.

AntonLV hai 1 mes
pai
achega
527764882c

+ 14 - 1
inc/classes/BxDolSearchExtended.php

@@ -128,7 +128,20 @@ class BxDolSearchExtended extends BxDolFactory implements iBxDolFactoryObject
         $aResult = [];
         switch($sSymbol) {
             case '@':
-                $aResult = BxDolService::call('system', 'profiles_search', array(bx_get('term')), 'TemplServiceProfiles');
+                $aSearchParams = [];
+                if(($iCid = bx_get('cid')) !== false)
+                    $aSearchParams['cid'] = $iCid;
+                if(($sCmod = bx_get('cmod')) !== false)
+                    $aSearchParams['cmod'] = bx_process_input($sCmod);
+
+                $aSrvParams = [];
+                if($aSearchParams)
+                    $aSrvParams = [
+                        'search_params' => $aSearchParams,
+                        'order_by' => 'weight'
+                ];
+
+                $aResult = bx_srv('system', 'profiles_search', [bx_get('term'), $aSrvParams], 'TemplServiceProfiles');
                 foreach ($aResult as &$aItem)
                     $aItem['symbol'] = bx_get('symbol');
                 break;

+ 1 - 0
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -723,6 +723,7 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         $aQueryParams = parent::getHtmlEditorQueryParams($aInput);
         if (isset($this->MODULE)){
             $aQueryParams['m'] = $this->MODULE;
+            $aQueryParams['cmod'] = $this->MODULE;
         }
         if (isset($this->_iContentId) && $this->_iContentId){
             $aQueryParams['cid'] = $this->_iContentId;

+ 17 - 0
modules/base/profile/classes/BxBaseModProfileDb.php

@@ -133,6 +133,23 @@ class BxBaseModProfileDb extends BxBaseModGeneralDb
         if((is_numeric($mixedParams) && ($iLimit = (int)$mixedParams)) || (is_array($mixedParams) && isset($mixedParams['limit']) && ($iLimit = (int)$mixedParams['limit'])))
             $sLimit = $this->prepareAsString(" LIMIT ?", $iLimit);
 
+        if(($iCid = $mixedParams['search_params']['cid'] ?? false) && ($sCmod = $mixedParams['search_params']['cmod'] ?? false)) {
+            $aContent = bx_srv($sCmod, 'get_info', [$iCid, false]);
+
+            $aPreferred = [];
+            if(bx_srv('system', 'is_module_context', [$sCmod])) {
+                $aPreferred = bx_srv($sCmod, 'fans', [$iCid, true]);
+            }
+            else if(($sK = 'allow_view_to') && ($iContext = $aContent[$sK] ?? 0) < 0 && ($oContext = BxDolProfile::getInstance(abs($iContext))) !== false) {
+                $aPreferred = bx_srv($oContext->getModule(), 'fans', [$oContext->getContentId(), true]);
+            }
+
+            if($aPreferred) {
+                $sSelect .= ", IF(`p`.`id` IN (" . $this->implode_escape($aPreferred) . "), 1, 0) AS `profile_weight`";
+                $sOrderBy = " ORDER BY `profile_weight` DESC, `a`.`logged` DESC";
+            }
+        }
+
         /**
          * @hooks
          * @hookdef hook-profile-search_by_term 'profile', 'search_by_term' - hook to modify a list of profiles found by term

+ 7 - 2
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -389,14 +389,15 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
         foreach ($a as $r) {
             $oProfile = BxDolProfile::getInstance($r['profile_id']);
 
+            $aItem = [];
             if ($this->_bIsApi) {
                 $aData = $oProfile->getUnitAPI(0, ['template' => 'unit_wo_info']);
                 $aData['author_data']['label'] = $this->serviceProfileName($r['content_id']);
 
-                $aRet[] = $aData['author_data'];
+                $aItem = $aData['author_data'];
             }
             else{
-                $aRet[] = [
+                $aItem = [
                     'label' => $this->serviceProfileName($r['content_id']), 
                     'value' => $r['profile_id'], 
                     'url' => $oProfile->getUrl(),
@@ -404,6 +405,10 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
                     'unit' => $oProfile->getUnit(0, ['template' => ['name' => 'unit_wo_info', 'size' => 'icon']])
                 ];
             }
+
+            $aRet[] = array_merge($aItem, [
+                'weight' => $r['profile_weight'] ?? 0
+            ]);
         }
 
         return $aRet;

+ 7 - 1
template/scripts/BxBaseCmtsForm.php

@@ -45,9 +45,15 @@ class BxBaseCmtsForm extends BxTemplFormView
     function getHtmlEditorQueryParams($aInput)
     {
         $aQueryParams = parent::getHtmlEditorQueryParams($aInput);
-        if (isset($this->aInputs['id'])){
+        if (isset($this->aInputs['id'])) {
             $aQueryParams['cid'] = $this->aInputs['id']['value'];
         }
+
+        $oObject = $this->_getObject(bx_process_input($this->aInputs['sys']['value']), (int)$this->aInputs['id']['value']);
+        if($oObject && ($aCmtInfo = $this->_oObject->getSystemInfo())) {
+            $aQueryParams['cmod'] = $aCmtInfo['module'] ?? '';
+        }
+
         $aQueryParams['m'] = 'sys_cmts';
         $aQueryParams['fi'] = '';
 

+ 6 - 2
template/scripts/BxBaseServiceProfiles.php

@@ -495,8 +495,12 @@ class BxBaseServiceProfiles extends BxDol
         }
 
         // sort result
-        usort($a, function($r1, $r2) {
-            return strcmp($r1['label'], $r2['label']);
+        $sOrderField = $mixedParams['order_by'] ?? 'label';
+        usort($a, function($r1, $r2) use ($sOrderField) {    
+            if($sOrderField == 'weight')
+                return -((int)$r1[$sOrderField] - (int)$r2[$sOrderField]);
+            else
+                return strcmp($r1[$sOrderField], $r2[$sOrderField]);
         });
 
          /**