• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/rest/externalizer.php
  • Класс: BitrixDiskRestExternalizer
  • Вызов: Externalizer::toArrayFromModel
private function toArrayFromModel(DiskInternalsModel $model)
{
	$entity = null;
	if($model instanceof DiskStorage)
	{
		$entity = new EntityStorage;
	}
	elseif($model instanceof DiskFile)
	{
		$entity = new EntityFile;
	}
	elseif($model instanceof DiskVersion)
	{
		$entity = new EntityVersion;
	}
	elseif($model instanceof DiskFolder)
	{
		$entity = new EntityFolder;
	}
	elseif($model instanceof DiskAttachedObject)
	{
		$entity = new EntityAttachedObject;
	}
	else
	{
		throw new RestException('Unknown object ' . get_class($model));
	}

	$toArray = array_intersect_key($model->toArray(), $entity->getFieldsForShow());
	foreach($entity->getFieldsForMap() as $fieldName => $modifiers)
	{
		if(!isset($toArray[$fieldName]))
		{
			continue;
		}
		$toArray[$fieldName] = call_user_func_array($modifiers['OUT'], array($toArray[$fieldName]));
	}
	unset($fieldName, $modifiers);

	if($model instanceof DiskFile)
	{
		$toArray['DOWNLOAD_URL'] = CRestUtil::getDownloadUrl(array('id' => $model->getId()), $this->restServer);
		if($model->getStorage()->getProxyType() instanceof DiskProxyTypeRestApp)
		{
			$toArray['DETAIL_URL'] = null;
			if (isModuleInstalled('bitrix24') && ($this->isImage($model) || $this->isXml($model)))
			{
				$toArray['CONTENT_URL'] = $this->getUriToContent($model);
			}
		}
		else
		{
			$toArray['DETAIL_URL'] = $this->host . $this->urlManager->getPathFileDetail($model);
		}
	}
	if($model instanceof DiskVersion)
	{
		$toArray['DOWNLOAD_URL'] = CRestUtil::getDownloadUrl(array('id' => $model->getId(), 'service' => 'version'), $this->restServer);
	}
	elseif($model instanceof DiskFolder)
	{
		if($model->getStorage()->getProxyType() instanceof DiskProxyTypeRestApp)
		{
			$toArray['DETAIL_URL'] = null;
		}
		else
		{
			$toArray['DETAIL_URL'] = $this->host . $this->urlManager->getPathInListing($model) . $model->getName();
		}
	}
	elseif($model instanceof DiskAttachedObject)
	{
		$toArray['DOWNLOAD_URL'] = $this->host . $this->urlManager->getUrlUfController(
				'download',
				array('attachedId' => $model->getId(), 'auth' => $this->restServer->getAuth())
		);
		$toArray['NAME'] = $model->getFile()->getName();
		$toArray['SIZE'] = $model->getFile()->getSize();
	}

	return $toArray;
}