Skip to content

Commit

Permalink
Ticket #4148 - Build-in API support: Browse profile/context connecti…
Browse files Browse the repository at this point in the history
…ons.
  • Loading branch information
AntonLV committed Jun 30, 2023
1 parent d0b1fa2 commit d8e58b4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 17 deletions.
11 changes: 11 additions & 0 deletions inc/utils.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2430,4 +2430,15 @@ function bx_api_get_image($sStorage, $iId)
return false;
}

function bx_api_get_browse_params($sParams)
{
if(!$sParams || !is_string($sParams))
return [];

$aParams = json_decode($sParams, true);
if(!isset($aParams['params']))
return [];

return $aParams['params'];
}
/** @} */
76 changes: 59 additions & 17 deletions template/scripts/BxBaseServiceProfiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
*/
class BxBaseServiceProfiles extends BxDol
{
protected $_bIsApi;
public function __construct()
{
parent::__construct();

$this->_bIsApi = bx_is_api();
}

public function serviceGetProfileTypes()
Expand Down Expand Up @@ -471,8 +474,11 @@ public function serviceProfilesList ($iAccountId = 0)
return $s . '<div class="bx-clear"></div>';
}

public function serviceBrowseFriends ($iProfileId, $aParams = [])
public function serviceBrowseFriends ($iProfileId = 0, $aParams = [])
{
if($this->_bIsApi)
list($iProfileId, $aParams) = [0, bx_api_get_browse_params($iProfileId)];

if(!$iProfileId)
$iProfileId = bx_get_logged_profile_id();
if(!$iProfileId)
Expand All @@ -495,8 +501,11 @@ public function serviceBrowseFriends ($iProfileId, $aParams = [])
return $this->_serviceBrowseConnections('friends', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
}

public function serviceBrowseFriendRequests ($iProfileId, $aParams = [])
public function serviceBrowseFriendRequests ($iProfileId = 0, $aParams = [])
{
if($this->_bIsApi)
list($iProfileId, $aParams) = [0, bx_api_get_browse_params($iProfileId)];

if(!$iProfileId)
$iProfileId = bx_get_logged_profile_id();
if(!$iProfileId)
Expand All @@ -519,8 +528,11 @@ public function serviceBrowseFriendRequests ($iProfileId, $aParams = [])
return $this->_serviceBrowseConnections('friend_requests', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
}

public function serviceBrowseFriendRequested ($iProfileId, $aParams = [])
public function serviceBrowseFriendRequested ($iProfileId = 0, $aParams = [])
{
if($this->_bIsApi)
list($iProfileId, $aParams) = [0, bx_api_get_browse_params($iProfileId)];

if(!$iProfileId)
$iProfileId = bx_get_logged_profile_id();
if(!$iProfileId)
Expand All @@ -543,8 +555,11 @@ public function serviceBrowseFriendRequested ($iProfileId, $aParams = [])
return $this->_serviceBrowseConnections('friend_requested', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
}

public function serviceBrowseSubscriptions ($iProfileId, $aParams = [])
public function serviceBrowseSubscriptions ($iProfileId = 0, $aParams = [])
{
if($this->_bIsApi)
list($iProfileId, $aParams) = [0, bx_api_get_browse_params($iProfileId)];

if(!$iProfileId)
$iProfileId = bx_get_logged_profile_id();
if(!$iProfileId)
Expand All @@ -567,8 +582,11 @@ public function serviceBrowseSubscriptions ($iProfileId, $aParams = [])
return $this->_serviceBrowseConnections('subscriptions', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
}

public function serviceBrowseSubscribedMe ($iProfileId, $aParams = [])
public function serviceBrowseSubscribedMe ($iProfileId = 0, $aParams = [])
{
if($this->_bIsApi)
list($iProfileId, $aParams) = [0, bx_api_get_browse_params($iProfileId)];

if(!$iProfileId)
$iProfileId = bx_get_logged_profile_id();
if(!$iProfileId)
Expand All @@ -591,8 +609,11 @@ public function serviceBrowseSubscribedMe ($iProfileId, $aParams = [])
return $this->_serviceBrowseConnections('subscribed_me', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
}

public function serviceBrowseMembers($iProfileId, $sObject, $aParams = [])
public function serviceBrowseMembers($iProfileId = 0, $sObject, $aParams = [])
{
if($this->_bIsApi)
list($iProfileId, $aParams) = [0, bx_api_get_browse_params($iProfileId)];

if(!$iProfileId)
$iProfileId = bx_get_logged_profile_id();
if(!$iProfileId)
Expand All @@ -618,8 +639,11 @@ public function serviceBrowseMembers($iProfileId, $sObject, $aParams = [])
return $this->_serviceBrowseConnections('members', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
}

public function serviceBrowseConnections ($iProfileId, $aParams = [])
public function serviceBrowseConnections ($iProfileId = 0, $aParams = [])
{
if($this->_bIsApi)
list($iProfileId, $aParams) = [0, bx_api_get_browse_params($iProfileId)];

if(!$iProfileId)
$iProfileId = bx_get_logged_profile_id();
if(!$iProfileId)
Expand Down Expand Up @@ -648,58 +672,76 @@ public function serviceBrowseConnections ($iProfileId, $aParams = [])
return $this->_serviceBrowseConnections('connections', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
}

public function serviceBrowseRecommendationsFriends ($iProfileId, $iStart = 0, $iPerPage = 0)
public function serviceBrowseRecommendationsFriends ($iProfileId = 0, $aParams = [])
{
if($this->_bIsApi)
list($iProfileId, $aParams) = [0, bx_api_get_browse_params($iProfileId)];

if(!$iProfileId)
$iProfileId = bx_get_logged_profile_id();
if(!$iProfileId)
return '';

$aParams = array_merge([
'empty_message' => false,
'start' => 0,
'per_page' => 0
], $aParams);

if(($iStartGet = bx_get('start')) !== false)
$iStart = (int)$iStartGet;
$aParams['start'] = (int)$iStartGet;

if(($iPerPageGet = bx_get('per_page')) !== false)
$iPerPage = (int)$iPerPageGet;
$aParams['per_page'] = (int)$iPerPageGet;

$oRecommendation = BxDolRecommendation::getObjectInstance('sys_friends');
if(!$oRecommendation)
return false;

if(bx_is_api()) {
$aData = $oRecommendation->getCodeAPI($iProfileId, $iStart, $iPerPage);
$aData = $oRecommendation->getCodeAPI($iProfileId, $aParams['start'], $aParams['per_page']);
$aData['request_url'] = '/api.php?r=system/browse_recommendations_friends/TemplServiceProfiles&params[]=';

return [bx_api_get_block('browse', $aData)];
}

return $oRecommendation->getCode($iProfileId, $iStart, $iPerPage);
return $oRecommendation->getCode($iProfileId, $aParams['start'], $aParams['per_page']);
}

public function serviceBrowseRecommendationsSubscriptions ($iProfileId, $iStart = 0, $iPerPage = 0)
public function serviceBrowseRecommendationsSubscriptions ($iProfileId = 0, $aParams = [])
{
if($this->_bIsApi)
list($iProfileId, $aParams) = [0, bx_api_get_browse_params($iProfileId)];

if(!$iProfileId)
$iProfileId = bx_get_logged_profile_id();
if(!$iProfileId)
return '';

$aParams = array_merge([
'empty_message' => false,
'start' => 0,
'per_page' => 0
], $aParams);

if(($iStartGet = bx_get('start')) !== false)
$iStart = (int)$iStartGet;
$aParams['start'] = (int)$iStartGet;

if(($iPerPageGet = bx_get('per_page')) !== false)
$iPerPage = (int)$iPerPageGet;
$aParams['per_page'] = (int)$iPerPageGet;

$oRecommendation = BxDolRecommendation::getObjectInstance('sys_subscriptions');
if(!$oRecommendation)
return false;

if(bx_is_api()) {
$aData = $oRecommendation->getCodeAPI($iProfileId, $iStart, $iPerPage);
$aData = $oRecommendation->getCodeAPI($iProfileId, $aParams['start'], $aParams['per_page']);
$aData['request_url'] = '/api.php?r=system/browse_recommendations_subscriptions/TemplServiceProfiles&params[]=';

return [bx_api_get_block('browse', $aData)];
}

return $oRecommendation->getCode($iProfileId, $iStart, $iPerPage);
return $oRecommendation->getCode($iProfileId, $aParams['start'], $aParams['per_page']);
}

public function serviceAccountProfileSwitcher ($iAccountId = false, $iActiveProfileId = null, $sUrlProfileAction = '', $bShowAll = 0, $sButtonTitle = '', $sProfileTemplate = '')
Expand Down

0 comments on commit d8e58b4

Please sign in to comment.