%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 3.141.31.116
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64
User : www-root ( 1010)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/www-root/data/www/dev.artlot24.ru/bitrix/components/bitrix/main.field.config.detail/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/components/bitrix/main.field.config.detail//class.php
<?php

if(!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true)
{
	die();
}

use Bitrix\Main\Engine;
use Bitrix\Main\Error;
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\LanguageTable;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Application;
use Bitrix\Main\UserField\ConfigComponent;
use Bitrix\Main\UserField\Engine\SettingsArea;
use Bitrix\Main\UserFieldLangTable;
use Bitrix\Main\UserFieldTable;
use Bitrix\UI\Toolbar\Facade\Toolbar;

class MainUfDetailComponent extends ConfigComponent implements Engine\Contract\Controllerable
{
	protected const DEFAULT_USER_TYPE_ID = 'string';
	protected const DEFAULT_SORT = 100;

	protected $fieldId;
	protected $data;

	protected function init(): void
	{
		parent::init();

		if(!$this->errorCollection->isEmpty())
		{
			return;
		}

		$fieldId = (int) ($this->arParams['fieldId'] ?: Application::getInstance()->getContext()->getRequest()->get('fieldId'));
		if($fieldId > 0)
		{
			if(!$this->access->canRead($fieldId))
			{
				$this->errorCollection[] = $this->getAccessDeniedError();
				return;
			}
			$this->data = UserFieldTable::getFieldData($fieldId);
			if(!is_array($this->data))
			{
				$this->errorCollection[] = new Error(Loc::getMessage('MAIN_FIELD_CONFIG_DETAIL_FIELD_NOT_FOUND_ERROR'));
			}
		}
		else
		{
			$this->entityId = $this->arParams['entityId'] ?: Application::getInstance()->getContext()->getRequest()->get('entityId');
			if(empty($this->entityId))
			{
				$this->errorCollection[] = new Error(Loc::getMessage('MAIN_FIELD_CONFIG_DETAIL_NO_ENTITY_ID_ERROR'));
			}
		}
	}

	public function executeComponent()
	{
		$this->init();
		if(!$this->errorCollection->isEmpty())
		{
			$this->arResult['errors'] = $this->errorCollection->toArray();
			$this->includeComponentTemplate();

			return;
		}
		if(Loader::includeModule('ui'))
		{
			Toolbar::deleteFavoriteStar();
		}

		$this->arResult['field'] = $this->prepareField();
		$this->arResult['form'] = $this->prepareForm($this->arResult['field']);
		$this->arResult['types'] = $this->getUserTypes();
		$this->arResult['jsParams'] = [
			'id' => $this->arResult['field']['ID'],
			'moduleId' => $this->moduleId,
		];

		if($this->arResult['field']['ID'] > 0)
		{
			$this->arResult['title'] = Loc::getMessage('MAIN_FIELD_CONFIG_DETAIL_TITLE_EDIT');
		}
		else
		{
			$this->arResult['title'] = Loc::getMessage('MAIN_FIELD_CONFIG_DETAIL_TITLE_ADD');
		}
		$this->setTitle($this->arResult['title']);

		$this->includeComponentTemplate();
	}

	protected function prepareField(): array
	{
		if(is_array($this->data))
		{
			return $this->data;
		}

		return [
			'MANDATORY' => 'N',
			'MULTIPLE' => 'N',
			'SHOW_FILTER' => 'E',
			'SHOW_IN_LIST' => 'Y',
			'IS_SEARCHABLE' => 'Y',
			'ENTITY_ID' => $this->entityId,
			'USER_TYPE_ID' => static::DEFAULT_USER_TYPE_ID,
			'FIELD_NAME' => $this->generateFieldName(),
			'SORT' => static::DEFAULT_SORT,
			'EDIT_FORM_LABEL' => [
				Loc::getCurrentLang() => Loc::getMessage('MAIN_FIELD_CONFIG_DETAIL_DEFAULT_LABEL'),
			],
		];
	}

	protected function prepareForm(array $field): array
	{
		$form = [];
		$entity = UserFieldTable::getEntity();
		$labelsEntity = UserFieldLangTable::getEntity();

		$labelTitle = $labelsEntity->getField('EDIT_FORM_LABEL')->getTitle();
		$languages = $this->getLanguages();
		foreach($languages as $language)
		{
			$form['editFormLabel'][] = [
				'label' => $labelTitle,
				'language' => $language,
			];
		}

		$form['fieldName'] = [
			'label' => $entity->getField('FIELD_NAME')->getTitle(),
			'prefix' => $this->getFieldPrefix(),
		];
		$form['sort'] = [
			'label' => $entity->getField('SORT')->getTitle(),
		];
		$form['multiple'] = [
			'label' => $entity->getField('MULTIPLE')->getTitle(),
		];
		$form['mandatory'] = [
			'label' => $entity->getField('MANDATORY')->getTitle(),
		];
		$form['showFilter'] = [
			'label' => $entity->getField('SHOW_FILTER')->getTitle(),
		];
		$form['isSearchable'] = [
			'label' => $entity->getField('IS_SEARCHABLE')->getTitle(),
		];
		$form['userTypeId'] = [
			'label' => $entity->getField('USER_TYPE_ID')->getTitle(),
		];
		$settingsArea = new SettingsArea($field);
		$form['settings'] = [
			'label' => $entity->getField('SETTINGS')->getTitle(),
			'html' => $settingsArea->getHtml(),
		];

		return $form;
	}

	protected function getLanguages(): array
	{
		$currentLanguageId = Loc::getCurrentLang();
		$isCurrentLanguageFound = false;
		$languages = [];
		$list = LanguageTable::getList([
			'order' => ['SORT' => 'ASC'],
		])->fetchAll();
		foreach($list as $item)
		{
			$language = [
				'name' => $item['NAME'],
				'id' => $item['LID'],
			];

			if($item['LID'] === $currentLanguageId)
			{
				$language['isCurrent'] = true;
				$isCurrentLanguageFound = true;
			}

			$languages[] = $language;
		}

		if(!$isCurrentLanguageFound)
		{
			$languages[0]['isCurrent'] = true;
		}

		return $languages;
	}

	public function configureActions(): array
	{
		return [];
	}

	public function getSettingsAction(string $userTypeId): Engine\Response\HtmlContent
	{
		return new Engine\Response\HtmlContent(new SettingsArea(['USER_TYPE_ID' => $userTypeId]));
	}

	protected function generateFieldName(): string
	{
		return $this->getFieldPrefix() . time();
	}

	protected function getFieldPrefix(): string
	{
		return 'UF_' . $this->entityId . '_';
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit