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

Ticket #4971 - Build-in API support: Connections object.

AntonLV 7 месяцев назад
Родитель
Сommit
bfd7e19124

+ 3 - 1
modules/base/profile/classes/BxBaseModProfileMenuViewActionsAll.php

@@ -75,7 +75,9 @@ class BxBaseModProfileMenuViewActionsAll extends BxBaseModGeneralMenuViewActions
                 'id' => $aItem['id'],
                 'id' => $aItem['id'],
                 'name' => $aItem['name'],
                 'name' => $aItem['name'],
                 'display_type' => 'element',
                 'display_type' => 'element',
-                'data' => $oObject->getElementApi($aObjectOptions)
+                'data' => array_merge($oObject->getElementApi($iId, false, $aObjectOptions), [
+                    'primary' => !empty($aItem['primary']),
+                ])
             ];
             ];
 
 
         $sResult = $oObject->getElement($iId, false, $aObjectOptions);
         $sResult = $oObject->getElement($iId, false, $aObjectOptions);

+ 39 - 0
template/scripts/BxBaseConnection.php

@@ -207,6 +207,45 @@ class BxBaseConnection extends BxDolConnection
         ]);
         ]);
     }
     }
 
 
+    public function getElementAPI($iContent, $iInitiator = false, $aParams = [])
+    {
+        if(!($this->_bApi = bx_is_api()))
+            return;
+
+        if(!$iInitiator && (!($iInitiator = bx_get_logged_profile_id()) || $iInitiator == $iContent))
+            return [];
+
+        $aActions = $this->_getActions($iInitiator, $iContent, $aParams);
+        if((empty($aActions['items']) || !is_array($aActions['items'])))
+            return [];
+
+        $aName = $aActions['name'] ?? '';
+        $sTitle = $aActions['title'] ?? '';
+        $aActions = $aActions['items'];
+
+        if(count($aActions) == 1) {
+            list($aName, $sTitle) = array_values(reset($aActions));
+            $aActions = [];
+        }
+        else {
+            foreach($aActions as $iKey => $aAction)
+                if(!$aAction || !isset($aAction['name'], $aAction['title']))
+                    unset($aActions[$iKey]);
+                else
+                    $aActions[$iKey]['title'] = _t($aAction['title']);
+        }       
+
+        return [
+            'type' => 'connections_ext',
+            'o' => $this->_sObject,
+            'iid' => $iInitiator,
+            'cid' => $iContent,
+            'name' => $aName,
+            'title' => _t($sTitle),
+            'actions' => $aActions,
+        ];
+    }
+
     public function getCounter($iProfileId, $bIsMutual = false, $aParams = [])
     public function getCounter($iProfileId, $bIsMutual = false, $aParams = [])
     {
     {
         $aParams = $this->_prepareParamsData($aParams);
         $aParams = $this->_prepareParamsData($aParams);

+ 3 - 0
template/scripts/BxBaseServiceConnections.php

@@ -71,6 +71,9 @@ class BxBaseServiceConnections extends BxDol
         if($aResult['err'] !== false)
         if($aResult['err'] !== false)
             return ['code' => 3, 'message' => $aResult['msg']];
             return ['code' => 3, 'message' => $aResult['msg']];
 
 
+        if(($aParams['r'] ?? '') == 'object') 
+            return $oConnection->getElementAPI($aParams['cid'], $aParams['iid']);
+
         $aFlip = ['add' => 'remove', 'remove' => 'add'];
         $aFlip = ['add' => 'remove', 'remove' => 'add'];
 
 
         return [
         return [