- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/lib/componenthelper.php
- Класс: BitrixSocialnetworkComponentHelper
- Вызов: ComponentHelper::getAttachmentUrlList
static function getAttachmentUrlList($valueList = [], $entityType = '', $entityId = 0, $authorId = 0, $attachmentList = []): array
{
$result = [];
if (
empty($valueList)
|| empty($attachmentList)
|| (int)$authorId <= 0
|| (int)$entityId <= 0
|| !Loader::includeModule('disk')
)
{
return $result;
}
$userFieldManager = Driver::getInstance()->getUserFieldManager();
[ $connectorClass, $moduleId ] = $userFieldManager->getConnectorDataByEntityType($entityType);
foreach($valueList as $value)
{
$attachedFileId = false;
$attachedObject = false;
[ $type, $realValue ] = FileUserType::detectType($value);
if ($type === FileUserType::TYPE_NEW_OBJECT)
{
$attachedObject = AttachedObject::load([
'=ENTITY_TYPE' => $connectorClass,
'ENTITY_ID' => $entityId,
'=MODULE_ID' => $moduleId,
'OBJECT_ID'=> $realValue
], [ 'OBJECT' ]);
if($attachedObject)
{
$attachedFileId = $attachedObject->getId();
}
}
else
{
$attachedFileId = $realValue;
}
if (
(int)$attachedFileId > 0
&& !empty($attachmentList[$attachedFileId])
)
{
if (!$attachmentList[$attachedFileId]["IS_IMAGE"])
{
$result[$value] = [
'TYPE' => 'file',
'URL' => $attachmentList[$attachedFileId]["URL"]
];
}
else
{
if (!$attachedObject)
{
$attachedObject = AttachedObject::loadById($attachedFileId, [ 'OBJECT' ]);
}
if ($attachedObject)
{
$file = $attachedObject->getFile();
$extLinks = $file->getExternalLinks([
'filter' => [
'OBJECT_ID' => $file->getId(),
'CREATED_BY' => $authorId,
'TYPE' => BitrixDiskInternalsExternalLinkTable::TYPE_MANUAL,
'IS_EXPIRED' => false,
],
'limit' => 1,
]);
if (empty($extLinks))
{
$externalLink = $file->addExternalLink([
'CREATED_BY' => $authorId,
'TYPE' => BitrixDiskInternalsExternalLinkTable::TYPE_MANUAL,
]);
}
else
{
/** @var BitrixDiskExternalLink $externalLink */
$externalLink = reset($extLinks);
}
if ($externalLink)
{
$originalFile = $file->getFile();
$result[$value] = [
'TYPE' => 'image',
'URL' => Driver::getInstance()->getUrlManager()->getUrlExternalLink(
[
'hash' => $externalLink->getHash(),
'action' => 'showFile'
],
true
),
'WIDTH' => (int)$originalFile["WIDTH"],
'HEIGHT' => (int)$originalFile["HEIGHT"]
];
}
}
}
}
}
return $result;
}