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/cvetdv.ru/bitrix/modules/yandex.market/lib/component/data/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/cvetdv.ru/bitrix/modules/yandex.market/lib/component/data/editform.php
<?php

namespace Yandex\Market\Component\Data;

use Bitrix\Main;
use Yandex\Market;

class EditForm extends Market\Component\Base\EditForm
{
	public function modifyRequest(array $request, array $fields)
	{
		$result = $request;

		foreach ($fields as $fieldName => $field)
		{
			if (
				isset($request[$fieldName], $field['USER_TYPE']['BASE_TYPE'])
				&& $field['USER_TYPE']['BASE_TYPE'] === 'datetime'
			)
			{
				if (trim($request[$fieldName]) !== '')
				{
					$result[$fieldName] = new Main\Type\DateTime($request[$fieldName]);
				}
				else
				{
					$result[$fieldName] = null;
				}
			}
		}

		return $result;
	}

	public function processPostAction($action, $data)
	{
		if ($action === 'delete')
		{
			$this->processDeleteAction($data);
			return;
		}

		parent::processPostAction($action, $action);
	}

	protected function processDeleteAction($data)
	{
		global $APPLICATION;

		if (empty($data['ID'])) { throw new Main\ArgumentNullException('ID'); }

		$dataClass = $this->getDataClass();

		$deleteResult = $dataClass::delete($data['ID']);

		Market\Result\Facade::handleException($deleteResult);

		$this->setComponentParam(
			'REDIRECT_URL',
			$this->getComponentParam('LIST_URL') ?: $APPLICATION->GetCurPageParam('', [ 'postAction', 'id', 'sessid' ])
		);
	}

	public function getFields(array $select = [], array $item = null)
	{
		$dataClass = $this->getDataClass();
		$result = $this->loadTableFields($dataClass, $select, $item);
		$result = $this->applyFieldsDeprecated($result, $item);

		return $result;
	}

	protected function loadTableFields($dataClass, $select, $row)
	{
		/** @var \Yandex\Market\Reference\Storage\Table $dataClass */
		$tableFields = $dataClass::getMapDescription();
		$referenceSelectList = [];
		$result = [];

		if (empty($select)) { $select = array_keys($tableFields); }

		foreach ($select as $fieldKey)
		{
			if (isset($tableFields[$fieldKey]))
			{
				$result[$fieldKey] = $tableFields[$fieldKey];
			}
			else if ($fieldKeyDotPosition = Market\Data\TextString::getPosition($fieldKey, '.')) // reference
			{
				$fieldKeyTablePart = Market\Data\TextString::getSubstring($fieldKey, 0, $fieldKeyDotPosition);
				$fieldKeyReferencePart = Market\Data\TextString::getSubstring($fieldKey, $fieldKeyDotPosition + 1);

				if (!isset($referenceSelectList[$fieldKeyTablePart]))
				{
					$referenceSelectList[$fieldKeyTablePart] = [];
				}

				$referenceSelectList[$fieldKeyTablePart][] = $fieldKeyReferencePart;
			}
		}

		if (!empty($referenceSelectList))
		{
			/** @var \Bitrix\Main\Entity\Field[] $tableColumns */
			$tableReferenceList = $dataClass::getReference();

			foreach ($referenceSelectList as $columnKey => $referenceSelect)
			{
				if (isset($tableReferenceList[$columnKey]) && !empty($row[$columnKey]))
				{
					$rowValues = $row[$columnKey];
					$tableReference = $tableReferenceList[$columnKey];

					foreach ($rowValues as $rowValueIndex => $rowValue)
					{
						/** @var \Yandex\Market\Reference\Storage\Table $tableReferenceDataClass */
						$tableReferenceDataClass = $tableReference['TABLE'];
						$referenceFields = $this->loadTableFields($tableReferenceDataClass, $referenceSelect, $rowValue);
						$referenceLinks = $tableReferenceDataClass::getReference();

						$parent = $rowValue;

						foreach ($referenceLinks as $referenceLinkKey => $referenceLink)
						{
							if (isset($parent[$referenceLinkKey]))
							{
								unset($parent[$referenceLinkKey]);
							}
						}

						foreach ($referenceFields as $referenceFieldKey => $referenceField)
						{
							$referenceFieldInputName = $referenceField['FIELD_NAME'];

							if (preg_match('/^([^[]+)(.*)$/', $referenceFieldInputName, $matches))
							{
								$referenceFieldInputName = '[' . $matches[1] . ']' . $matches[2];
							}

							$referenceFieldInputName = $columnKey . '[' . $rowValueIndex .  ']' . $referenceFieldInputName;
							$referenceField['FIELD_NAME'] = $referenceFieldInputName;
							$referenceField['FIELD_GROUP'] = $columnKey . '.' . $referenceFieldKey;

							if (!isset($referenceField['PARENT']))
							{
								$referenceField['PARENT'] = [];
							}

							$referenceField['PARENT'][$columnKey] = $parent;

							$result[$columnKey . '_' . $rowValueIndex . '_' . $referenceFieldKey] = $referenceField;

							if (!empty($rowValue['ID']))
							{
								$result[$columnKey . '_' . $rowValueIndex . '_ID'] = [
									'USER_TYPE' => Market\Ui\UserField\Manager::getUserType('number'),
									'VALUE' => $rowValue['ID'],
									'FIELD_NAME' => $columnKey . '[' . $rowValueIndex . '][ID]',
									'HIDDEN' => 'Y',
									'FIELD_GROUP' => $columnKey . '.' . $referenceFieldKey
								];
							}
						}
					}
				}
			}
		}

		return $result;
	}

	protected function applyFieldsDeprecated(array $fields, $item = null)
	{
		foreach ($fields as &$field)
		{
			if (!isset($field['DEPRECATED']) || $field['DEPRECATED'] !== 'Y') { continue; }

			$value = $item !== null
				? Market\Utils\Field::getChainValue($item, $field['FIELD_NAME'], Market\Utils\Field::GLUE_BRACKET)
				: null;

			if (empty($value))
			{
				$field['HIDDEN'] = 'Y';
			}
		}
		unset($field);

		return $fields;
	}

	public function load($primary, array $select = [], $isCopy = false)
	{
		$dataClass = $this->getDataClass();
		$query = $dataClass::getByPrimary($primary);

		if ($result = $query->fetch())
		{
			if (method_exists($dataClass, 'loadExternalReference'))
			{
				$externalData = $dataClass::loadExternalReference($result['ID'], null, $isCopy);

				if (isset($externalData[$result['ID']]))
				{
					$result = array_merge(
						$result,
						$externalData[$result['ID']]
					);
				}
			}

			if ($isCopy) { unset($result['ID']); }
		}
		else
		{
			throw new Main\SystemException($this->getComponentLang('ITEM_NOT_FOUND'));
		}

		return $result;
	}

	public function validate(array $data, array $fields)
	{
		$primary = isset($data['PRIMARY']) ? $data['PRIMARY'] : null;
		$sanitizedData = array_diff_key($data, [ 'PRIMARY' => true ]);
		$dataClass = $this->getDataClass();
		$validateResult = new Main\Entity\Result();

		$dataClass::saveExtractReference($sanitizedData); // remove reference field from validation
		$dataClass::checkFields($validateResult, $primary, $sanitizedData);

		$result = new Main\Entity\Result();
		$fieldsMap = [];

		foreach ($fields as $field)
		{
			$fieldsMap[$field['FIELD_NAME']] = true;
			$fieldsMap[$field['FIELD_NAME'] . '_ID'] = true;
		}

		foreach ($validateResult->getErrors() as $error)
		{
			$fieldName = $error->getField()->getName();

			if (isset($fieldsMap[$fieldName]))
			{
				$result->addError($error);
			}
		}

		return $result;
	}

	public function add(array $data)
	{
		$dataClass = $this->getDataClass();

		return $dataClass::add($data);
	}

	public function update($primary, array $data)
	{
		$dataClass = $this->getDataClass();

		return $dataClass::update($primary, $data);
	}

	/** @return class-string<Market\Reference\Storage\Table> */
	protected function getDataClass()
	{
		$className = $this->getComponentParam('DATA_CLASS_NAME');

		Market\Reference\Assert::nonEmptyString($className, 'arParams[DATA_CLASS_NAME]');
		Market\Reference\Assert::isSubclassOf($className, Market\Reference\Storage\Table::class);

		return $className;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit