403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/catalog/lib/restview/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/catalog/lib/restview/documentuserfield.php
<?php

namespace Bitrix\Catalog\RestView;

use Bitrix\Catalog\Document\StoreDocumentTableManager;
use Bitrix\Main\Result;
use Bitrix\Rest\Integration\View\Attributes;
use Bitrix\Rest\Integration\View\DataType;
use Bitrix\Rest\Integration\View\Base;

final class DocumentUserField extends Base
{
	public function getFields()
	{
		return [
			'DOCUMENT_ID' => [
				'TYPE' => DataType::TYPE_INT,
				'CANONICAL_NAME' => 'ID',
			],
			'DOCUMENT_TYPE' => [
				'TYPE' => DataType::TYPE_CHAR,
				'ATTRIBUTES' => [
					Attributes::REQUIRED,
				],
				'CANONICAL_NAME' => 'DOC_TYPE',
			],
		];
	}

	public function internalizeFieldsUpdate($fields, $fieldsInfo = []): array
	{
		$documentType = $fields['DOCUMENT_TYPE'];
		$fieldsInfo = array_merge($fieldsInfo, $this->getFields(), $this->getFieldMapForType($documentType));

		return parent::internalizeFieldsUpdate($fields, $fieldsInfo);
	}

	public function internalizeFieldsList($arguments, $fieldsInfo = []): array
	{
		$documentType = $arguments['filter']['DOCUMENT_TYPE'] ?? null;
		$allowUserFields = (is_string($documentType) && $documentType !== '');
		$fieldsInfo = array_merge(
			$fieldsInfo,
			$this->getFields(),
			$allowUserFields ? $this->getFieldMapForType($documentType) : []
		);

		return parent::internalizeFieldsList($arguments, $fieldsInfo);
	}

	protected function internalizeExtendedTypeValue($value, $info): Result
	{
		$isDynamic = in_array(Attributes::DYNAMIC, $info['ATTRIBUTES'], true);
		$isMultiple = in_array(Attributes::MULTIPLE, $info['ATTRIBUTES'], true);
		if (empty($value) && $isDynamic && $isMultiple)
		{
			$value = [''];
		}

		if (($info['USER_FIELD_TYPE'] ?? null) === 'file')
		{
			if ($isMultiple)
			{
				$internalizedValue = [];
				foreach ($value as $item)
				{
					$internalizedValue[] = $this->internalizeFileValue($item);
				}
				$value = $internalizedValue;
			}
			else
			{
				$value = $this->internalizeFileValue($value);
			}
		}

		return parent::internalizeExtendedTypeValue($value, $info);
	}

	public function externalizeFieldsGet($fields, $fieldsInfo = []): array
	{
		$documentType = $fields['DOC_TYPE'];
		$fieldsInfo = array_merge($fieldsInfo, $this->getFields(), $this->getFieldMapForType($documentType));

		return parent::externalizeFieldsGet($fields, $fieldsInfo);
	}

	public function externalizeListFields($list, $fieldsInfo = []): array
	{
		$documentType = $list[0]['DOC_TYPE'] ?? null;
		$userFields =
			$documentType !== null
				? $this->getFieldMapForType($documentType)
				: []
		;
		$fieldsInfo = array_merge($fieldsInfo, $this->getFields(), $userFields);

		return parent::externalizeListFields($list, $fieldsInfo);
	}

	private function getFieldMapForType($documentType): array
	{
		global $USER_FIELD_MANAGER;

		if (!(is_string($documentType) && $documentType !== ''))
		{
			return [];
		}

		$ufEntityId = StoreDocumentTableManager::getUfEntityIds()[$documentType] ?? '';
		if (!$ufEntityId)
		{
			return [];
		}

		$userFieldsDescriptions = $USER_FIELD_MANAGER->GetUserFields($ufEntityId, 0);

		$result = [];
		foreach ($userFieldsDescriptions as $userField)
		{
			$attributes = [Attributes::DYNAMIC];
			if ($userField['MULTIPLE'] === 'Y')
			{
				$attributes[] = Attributes::MULTIPLE;
			}
			$result['FIELD_' . $userField['ID']] = [
				'ATTRIBUTES' => $attributes,
				'CANONICAL_NAME' => $userField['FIELD_NAME'],
				'USER_FIELD_TYPE' => $userField['USER_TYPE_ID']
			];
		}

		return $result;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit