Просмотр исходного кода

Ticket #4558 - Build-in API support: Connections validation.

AntonLV 2 лет назад
Родитель
Сommit
3cba4e32d0

+ 2 - 0
inc/classes/BxDolProfile.php

@@ -180,6 +180,8 @@ class BxDolProfile extends BxDolFactory implements iBxDolProfile
             'confirmed' => $oAccount->isConfirmed(),
             'notifications' => 0,
             'cart' => 0,
+            'profiles_count' => $oAccount->getProfilesNumber(true),
+            'profiles_limit' => (int)getParam('sys_account_limit_profiles_number'),
             'active' => $oProfile->isActive(),
             'status' => $oProfile->getStatus(),
         ];

+ 3 - 0
inc/utils.inc.php

@@ -2533,6 +2533,9 @@ function bx_api_get_browse_params($sParams, $bParamsOnly = false)
         return [];
 
     $aParams = json_decode($sParams, true);
+    if(isset($aParams['params']['validate']) && !is_array($aParams['params']['validate']))
+        $aParams['params']['validate'] = explode(',', $aParams['params']['validate']);
+
     if(!$bParamsOnly)
         return $aParams;
 

+ 3 - 0
modules/base/general/classes/BxBaseModGeneralSearchResult.php

@@ -258,6 +258,9 @@ class BxBaseModGeneralSearchResult extends BxTemplSearchResult
 
     function decodeDataAPI($a)
     {
+        if(!is_array($a))
+            return $a;
+
         $bExtendedUnits = getParam('sys_api_extended_units') == 'on';
 
         foreach($a as $i => $r)

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

@@ -138,8 +138,8 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
         $CNF = $this->_oConfig->CNF;
         
         $aResult = parent::decodeDataAPI($aData, $aParams);
-        
-        if ($aParams['template'] == 'unit_wo_info')
+
+        if(isset($aParams['template']) && $aParams['template'] == 'unit_wo_info')
             return $aResult;
 
         if(getParam('sys_api_conn_in_prof_units') == 'on' && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) !== false) {

+ 5 - 0
template/scripts/BxBaseProfileSearchResult.php

@@ -19,6 +19,8 @@ class BxBaseProfileSearchResult extends BxTemplSearchResult
         $this->_sMode = $sMode;
         $this->_aParams = $aParams;
 
+        $this->_bValidate = !empty($this->_aParams['validate']) && is_array($this->_aParams['validate']);
+
         parent::__construct();
 
         $this->_bIsApi = bx_is_api();
@@ -237,6 +239,9 @@ class BxBaseProfileSearchResult extends BxTemplSearchResult
 
     function decodeDataAPI($a)
     {
+        if(!is_array($a))
+            return $a;
+
         $aResult = [];
 
         foreach ($a as $index => $aItem) 

+ 21 - 7
template/scripts/BxBaseRecommendation.php

@@ -76,13 +76,17 @@ class BxBaseRecommendation extends BxDolRecommendation
         $iStart = !empty($aParams['start']) ? (int)$aParams['start'] : 0;
         $iPerPage = !empty($aParams['per_page']) ? (int)$aParams['per_page'] : $this->_iPerPageDefault;
 
-        $aItems = [];
-        if (!defined('BX_API_PAGE'))
-            $aItems = $this->_oDb->get($iProfileId, $this->_aObject['id'], $aParams);
-
-        $aData = [];
-        foreach($aItems as $iId => $iCount)
-            $aData[] = $this->getCodeItem($iId, $iCount);
+        if(empty($aParams['validate']) || !is_array($aParams['validate'])) {
+            $aItems = [];
+            if(!defined('BX_API_PAGE'))
+                $aItems = $this->_oDb->get($iProfileId, $this->_aObject['id'], $aParams);
+
+            $aData = [];
+            foreach($aItems as $iId => $iCount)
+                $aData[] = $this->getCodeItem($iId, $iCount);
+        }
+        else
+            $aData = $this->validate($iProfileId, $aParams);
 
         return [
             'request_url' => '',
@@ -93,6 +97,16 @@ class BxBaseRecommendation extends BxDolRecommendation
             ],
         ];
     }
+
+    public function validate($iProfileId = 0, $aParams = [])
+    {
+        $aItems = $this->_oDb->get($iProfileId, $this->_aObject['id'], array_merge($aParams, [
+            'start' => 0,
+            'per_page' => count($aParams['validate'])
+        ]));
+
+        return array_keys($aItems) == $aParams['validate'] ? 'valid' : 'invalid';
+    }
 }
 
 /** @} */