Browse Source

Ticket #4487 - Connections: Filter out contexts from 'Who to follow' suggestions.

AntonLV 3 years ago
parent
commit
ce10bd02f5

+ 7 - 0
inc/classes/BxDolProfileQuery.php

@@ -105,6 +105,13 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton
                 }
                 }
                 break;
                 break;
 
 
+            case 'id_to_type':
+                $aMethod['name'] = 'getPairs';
+                $aMethod['params'][1] = 'id';
+                $aMethod['params'][2] = 'type';
+                $sWhereClause = " AND `tp`.`id` IN (" . $this->implode_escape($aParams['ids']) . ")";
+                break;
+
             case 'all':
             case 'all':
                 break;
                 break;
     	}
     	}

+ 3 - 1
inc/classes/BxDolRecommendation.php

@@ -201,8 +201,10 @@ class BxDolRecommendation extends BxDolFactory implements iBxDolFactoryObject
             if($oConnection->isConnected($iProfileId, $aItem['item_id'], $bConnectionMutual))
             if($oConnection->isConnected($iProfileId, $aItem['item_id'], $bConnectionMutual))
                 $this->_oDb->delete($iProfileId, $this->_iObject, $aItem['item_id']);
                 $this->_oDb->delete($iProfileId, $this->_iObject, $aItem['item_id']);
 
 
+        $aItemItt = $this->getItemsTypes(array_keys($aResults));
+
         foreach($aResults as $iId => $iValue)
         foreach($aResults as $iId => $iValue)
-            $this->_oDb->add($iProfileId, $this->_iObject, $iId, $iValue);
+            $this->_oDb->add($iProfileId, $this->_iObject, $iId, (isset($aItemItt[$iId]) ? $aItemItt[$iId] : ''), $iValue);
     }
     }
 
 
     public function outputActionResult ($mixed, $sFormat = 'json')
     public function outputActionResult ($mixed, $sFormat = 'json')

+ 5 - 0
inc/classes/BxDolRecommendationProfile.php

@@ -30,6 +30,11 @@ class BxDolRecommendationProfile extends BxTemplRecommendation
 
 
         return ['code' => 0];
         return ['code' => 0];
     }
     }
+
+    public function getItemsTypes($aIds)
+    {
+        return BxDolProfileQuery::getInstance()->getProfiles(['type' => 'id_to_type', 'ids' => $aIds]);
+    }
 }
 }
 
 
 /** @} */
 /** @} */

+ 11 - 6
inc/classes/BxDolRecommendationQuery.php

@@ -71,12 +71,13 @@ class BxDolRecommendationQuery extends BxDolDb
         ]);
         ]);
     }
     }
 
 
-    public function add($iProfileId, $iObjectId, $iItemId, $iItemValue)
+    public function add($iProfileId, $iObjectId, $iItemId, $sItemType, $iItemValue)
     {
     {
-        return $this->query("INSERT INTO `" . self::$sTableData . "` (`profile_id`, `object_id`, `item_id`, `item_value`) VALUES (:profile_id, :object_id, :item_id, :item_value) ON DUPLICATE KEY UPDATE `item_value` = :item_value", [
+        return $this->query("INSERT INTO `" . self::$sTableData . "` (`profile_id`, `object_id`, `item_id`, `item_type`, `item_value`) VALUES (:profile_id, :object_id, :item_id, :item_type, :item_value) ON DUPLICATE KEY UPDATE `item_value` = :item_value", [
             'profile_id' => $iProfileId,
             'profile_id' => $iProfileId,
             'object_id' => $iObjectId,
             'object_id' => $iObjectId,
             'item_id' => $iItemId, 
             'item_id' => $iItemId, 
+            'item_type' => $sItemType,
             'item_value' => $iItemValue
             'item_value' => $iItemValue
         ]) !== false;
         ]) !== false;
     }
     }
@@ -102,13 +103,17 @@ class BxDolRecommendationQuery extends BxDolDb
         ]) !== false;
         ]) !== false;
     }
     }
 
 
-    public function get($iProfileId, $iObjectId, $iStart = 0, $iPerPage = 0)
+    public function get($iProfileId, $iObjectId, $aParams = [])
     {
     {
+        $sWhereClause = "";
+        if(!empty($aParams['type']))
+            $sWhereClause = " AND `item_type` IN (" . $this->implode_escape(is_array($aParams['type']) ? $aParams['type'] : [$aParams['type']]) . ")";
+
         $sLimitClause = "";
         $sLimitClause = "";
-        if($iPerPage)
-            $sLimitClause = " LIMIT " . $iStart . ", " . $iPerPage;
+        if(isset($aParams['start']) && !empty($aParams['per_page']))
+            $sLimitClause = " LIMIT " . $aParams['start'] . ", " . $aParams['per_page'];
 
 
-        return $this->getPairs("SELECT `item_id` AS `id`, (`item_value` - `item_reducer`) AS `value` FROM `" . self::$sTableData . "` WHERE `profile_id` = :profile_id AND `object_id` = :object_id AND (`item_value` - `item_reducer`) >= 0 ORDER BY `value` DESC" . $sLimitClause, 'id', 'value', [
+        return $this->getPairs("SELECT `item_id` AS `id`, (`item_value` - `item_reducer`) AS `value` FROM `" . self::$sTableData . "` WHERE `profile_id` = :profile_id AND `object_id` = :object_id AND (`item_value` - `item_reducer`) >= 0" . $sWhereClause . " ORDER BY `value` DESC" . $sLimitClause, 'id', 'value', [
             'profile_id' => $iProfileId,
             'profile_id' => $iProfileId,
             'object_id' => $iObjectId
             'object_id' => $iObjectId
         ]);
         ]);

+ 1 - 0
install/sql/system.sql

@@ -2364,6 +2364,7 @@ CREATE TABLE `sys_recommendation_data` (
   `profile_id` int(11) NOT NULL default '0',
   `profile_id` int(11) NOT NULL default '0',
   `object_id` int(11) NOT NULL default '0',
   `object_id` int(11) NOT NULL default '0',
   `item_id` int(11) NOT NULL default '0',
   `item_id` int(11) NOT NULL default '0',
+  `item_type` varchar(64) NOT NULL default '',
   `item_value` int(11) NOT NULL default '0',
   `item_value` int(11) NOT NULL default '0',
   `item_reducer` int(11) NOT NULL default '0',
   `item_reducer` int(11) NOT NULL default '0',
   PRIMARY KEY  (`id`),
   PRIMARY KEY  (`id`),

+ 2 - 2
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -728,7 +728,7 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
             return false;
             return false;
 
 
         if($this->_bIsApi) {
         if($this->_bIsApi) {
-            $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams['start'], $aParams['per_page']);
+            $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams);
             $aData = array_merge($aData, [
             $aData = array_merge($aData, [
                 'module' => 'system',
                 'module' => 'system',
                 'unit' => 'mixed', 
                 'unit' => 'mixed', 
@@ -738,7 +738,7 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
             return [bx_api_get_block('browse', $aData)];
             return [bx_api_get_block('browse', $aData)];
         }
         }
 
 
-        $sCode = $oRecommendation->getCode($iProfileId, $aParams['start'], $aParams['per_page']);
+        $sCode = $oRecommendation->getCode($iProfileId, $aParams);
         if(!$sCode && $aParams['empty_message'])
         if(!$sCode && $aParams['empty_message'])
             $sCode = MsgBox(_t(!empty($aParams['empty_message_text']) ? $aParams['empty_message_text'] : '_Empty'));
             $sCode = MsgBox(_t(!empty($aParams['empty_message_text']) ? $aParams['empty_message_text'] : '_Empty'));
 
 

+ 9 - 9
template/scripts/BxBaseRecommendation.php

@@ -27,19 +27,19 @@ class BxBaseRecommendation extends BxDolRecommendation
             $this->_oTemplate = BxDolTemplate::getInstance();
             $this->_oTemplate = BxDolTemplate::getInstance();
     }
     }
 
 
-    public function getCode($iProfileId = 0, $iStart = 0, $iPerPage = 0)
+    public function getCode($iProfileId = 0, $aParams = [])
     {
     {
         $sResult = '';
         $sResult = '';
 
 
         if(!$iProfileId)
         if(!$iProfileId)
             $iProfileId = $this->_iProfileId;
             $iProfileId = $this->_iProfileId;
 
 
-        if(!$iPerPage)
-            $iPerPage = $this->_iPerPageDefault;
+        $iStart = !empty($aParams['start']) ? (int)$aParams['start'] : 0;
+        $iPerPage = !empty($aParams['per_page']) ? (int)$aParams['per_page'] : $this->_iPerPageDefault;
 
 
-        $aItems = $this->_oDb->get($iProfileId, $this->_aObject['id'], $iStart, $iPerPage + 1);
+        $aItems = $this->_oDb->get($iProfileId, $this->_aObject['id'], array_merge($aParams, ['per_page' => $iPerPage + 1]));
         if(empty($aItems) || !is_array($aItems))
         if(empty($aItems) || !is_array($aItems))
-            return '';
+            return $sResult;
 
 
         $iItems = count($aItems);
         $iItems = count($aItems);
         $oPaginate = new BxTemplPaginate([
         $oPaginate = new BxTemplPaginate([
@@ -68,17 +68,17 @@ class BxBaseRecommendation extends BxDolRecommendation
         ]);
         ]);
     }
     }
 
 
-    public function getCodeAPI($iProfileId = 0, $iStart = 0, $iPerPage = 0)
+    public function getCodeAPI($iProfileId = 0, $aParams = [])
     {
     {
         if(!$iProfileId)
         if(!$iProfileId)
             $iProfileId = $this->_iProfileId;
             $iProfileId = $this->_iProfileId;
 
 
-        if(!$iPerPage)
-            $iPerPage = $this->_iPerPageDefault;
+        $iStart = !empty($aParams['start']) ? (int)$aParams['start'] : 0;
+        $iPerPage = !empty($aParams['per_page']) ? (int)$aParams['per_page'] : $this->_iPerPageDefault;
 
 
         $aItems = [];
         $aItems = [];
         if (!defined('BX_API_PAGE'))
         if (!defined('BX_API_PAGE'))
-            $aItems = $this->_oDb->get($iProfileId, $this->_aObject['id'], $iStart, $iPerPage);
+            $aItems = $this->_oDb->get($iProfileId, $this->_aObject['id'], $aParams);
 
 
         $aData = [];
         $aData = [];
         foreach($aItems as $iId => $iCount)
         foreach($aItems as $iId => $iCount)

+ 7 - 4
template/scripts/BxBaseServiceProfiles.php

@@ -737,7 +737,7 @@ class BxBaseServiceProfiles extends BxDol
             return false;
             return false;
 
 
         if(bx_is_api()) {
         if(bx_is_api()) {
-            $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams['start'], $aParams['per_page']);
+            $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams);
             $aData = array_merge($aData, [
             $aData = array_merge($aData, [
                 'module' => 'system',
                 'module' => 'system',
                 'unit' => 'mixed', 
                 'unit' => 'mixed', 
@@ -747,7 +747,7 @@ class BxBaseServiceProfiles extends BxDol
             return [bx_api_get_block('browse', $aData)];
             return [bx_api_get_block('browse', $aData)];
         }
         }
 
 
-        $sCode = $oRecommendation->getCode($iProfileId, $aParams['start'], $aParams['per_page']);
+        $sCode = $oRecommendation->getCode($iProfileId, $aParams);
         if(!$sCode && $aParams['empty_message'])
         if(!$sCode && $aParams['empty_message'])
             $sCode = MsgBox(_t('_Empty'));
             $sCode = MsgBox(_t('_Empty'));
 
 
@@ -764,8 +764,11 @@ class BxBaseServiceProfiles extends BxDol
         if(!$iProfileId)
         if(!$iProfileId)
             return '';
             return '';
 
 
+        $aModules = bx_srv('system', 'get_modules_by_type', ['profile', ['name_as_key' => true]]);
+
         $aParams = array_merge([
         $aParams = array_merge([
             'empty_message' => false,
             'empty_message' => false,
+            'type' => !empty($aModules) && is_array($aModules) ? array_keys($aModules) : '',
             'start' => 0,
             'start' => 0,
             'per_page' => 0
             'per_page' => 0
         ], $aParams);
         ], $aParams);
@@ -781,7 +784,7 @@ class BxBaseServiceProfiles extends BxDol
             return false;
             return false;
 
 
         if(bx_is_api()) {
         if(bx_is_api()) {
-            $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams['start'], $aParams['per_page']);
+            $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams);
             $aData = array_merge($aData, [
             $aData = array_merge($aData, [
                 'module' => 'system',
                 'module' => 'system',
                 'unit' => 'mixed',
                 'unit' => 'mixed',
@@ -791,7 +794,7 @@ class BxBaseServiceProfiles extends BxDol
             return [bx_api_get_block('browse', $aData)];
             return [bx_api_get_block('browse', $aData)];
         }
         }
 
 
-        $sCode = $oRecommendation->getCode($iProfileId, $aParams['start'], $aParams['per_page']);
+        $sCode = $oRecommendation->getCode($iProfileId, $aParams);
         if(!$sCode && $aParams['empty_message'])
         if(!$sCode && $aParams['empty_message'])
             $sCode = MsgBox(_t('_Empty'));
             $sCode = MsgBox(_t('_Empty'));
 
 

+ 12 - 4
template/scripts/BxBaseServices.php

@@ -479,11 +479,14 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
      * @param type $sType - string with type.
      * @param type $sType - string with type.
      * @return array of modules.
      * @return array of modules.
      */
      */
-    public function serviceGetModulesByType($sType)
+    public function serviceGetModulesByType($sType, $aParams = [])
     {
     {
-        $aResults = array();
+        $aResults = [];
+        
+        $bIdAsKey = isset($aParams['id_as_key']) && $aParams['id_as_key'] === true;
+        $bNameAsKey = !$bIdAsKey && isset($aParams['name_as_key']) && $aParams['name_as_key'] === true;
 
 
-        $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
+        $aModules = BxDolModuleQuery::getInstance()->getModulesBy(['type' => 'modules', 'active' => 1]);
         foreach($aModules as $aModule) {
         foreach($aModules as $aModule) {
             $oModule = BxDolModule::getInstance($aModule['name']);
             $oModule = BxDolModule::getInstance($aModule['name']);
             if(!$oModule)
             if(!$oModule)
@@ -498,7 +501,12 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
             if($sType == 'profile' && !$this->serviceIsModuleProfile($oModule))
             if($sType == 'profile' && !$this->serviceIsModuleProfile($oModule))
                 continue;
                 continue;
 
 
-            $aResults[] = $aModule;
+            if($bIdAsKey)
+                $aResults[$aModule['id']] = $aModule;
+            else if($bNameAsKey)
+                $aResults[$aModule['name']] = $aModule;
+            else
+                $aResults[] = $aModule;
         }
         }
 
 
         return $aResults;
         return $aResults;