0
0
mirror of https://github.com/salesagility/SuiteCRM.git synced 2024-11-24 00:29:35 +00:00
salesagility_SuiteCRM/Api/V8/JsonApi/Helper/RelationshipObjectHelper.php
2023-07-18 15:53:08 +01:00

48 lines
1.2 KiB
PHP

<?php
namespace Api\V8\JsonApi\Helper;
use Api\V8\Helper\VarDefHelper;
use Api\V8\JsonApi\Response\LinksResponse;
use Api\V8\JsonApi\Response\RelationshipResponse;
#[\AllowDynamicProperties]
class RelationshipObjectHelper
{
/**
* @var VarDefHelper
*/
protected $varDefHelper;
/**
* @param VarDefHelper $varDefHelper
*/
public function __construct(VarDefHelper $varDefHelper)
{
$this->varDefHelper = $varDefHelper;
}
/**
* @param \SugarBean $bean
* @param string $uriPath
*
* @return RelationshipResponse
*/
public function getRelationships(\SugarBean $bean, $uriPath)
{
$relationships = $this->varDefHelper->getAllRelationships($bean);
asort($relationships);
$relationshipsLinks = [];
foreach (array_unique($relationships) as $relationshipName => $module) {
$linkResponse = new LinksResponse();
$linkResponse->setRelated(
sprintf('%s/%s/%s', $uriPath, 'relationships', $relationshipName)
);
$relationshipsLinks[$module] = ['links' => $linkResponse];
}
return new RelationshipResponse($relationshipsLinks);
}
}