ResourceBooking::getPublicView

  1. Bitrix24 API (v. 23.675.0)
  2. calendar
  3. ResourceBooking
  4. getPublicView
  • Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/lib/userfield/resourcebooking.php
  • Класс: BitrixCalendarUserFieldResourceBooking
  • Вызов: ResourceBooking::getPublicView
static function getPublicView($userField, $additionalParams = [])
{
	$context = $additionalParams['CONTEXT'] ?? '';
	$value = static::fetchFieldValue($userField["VALUE"] ?? null);
	$skipTime = is_array($userField['SETTINGS'] ?? null) && ($userField['SETTINGS']['FULL_DAY'] ?? null) == 'Y';
	$fromTs = CCalendar::timestamp($value['DATE_FROM'] ?? null, true, !$skipTime);
	$toTs = CCalendar::timestamp($value['DATE_TO'] ?? null, true, !$skipTime);

	$users = [];
	$resources = [];
	$resourceNames = [];
	$userIdList = [];
	$resourceIdList = [];

	foreach($value['ENTRIES'] as $entry)
	{
		if ($entry['TYPE'] === 'user')
		{
			$userIdList[] = (int) $entry['RESOURCE_ID'];
		}
		else
		{
			$resourceIdList[] = (int) $entry['RESOURCE_ID'];
		}
	}

	$userIdList = array_unique($userIdList);
	$resourceIdList = array_unique($resourceIdList);

	if (!empty($userIdList))
	{
		$orm = UserTable::getList([
			'filter' => [
				'=ID' => $userIdList,
				'=ACTIVE' => 'Y'
			],
			'select' => ['ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'TITLE', 'PERSONAL_PHOTO']
		]);

		while ($user = $orm->fetch())
		{
			$user['URL'] = CCalendar::getUserUrl($user["ID"]);
			$users[] = $user;
		}
	}

	if (!empty($resourceIdList))
	{
		$sectionList = InternalsSectionTable::getList(
			array(
				"filter" => array(
					"=ACTIVE" => 'Y',
					"!=CAL_TYPE" => ['user', 'group', 'company_calendar', 'company', 'calendar_company'],
					"ID" => $resourceIdList
				),
				"select" => array("ID", "CAL_TYPE", "NAME")
			)
		);

		while ($section = $sectionList->fetch())
		{
			$resources[$section['ID']] = $section;
			$resourceNames[] = HtmlFilter::encode($section['NAME']);
		}
	}

	if ($context === 'CRM_GRID')
	{
		BitrixMainUIExtension::load([
			'ui.design-tokens',
			'ui.fonts.opensans',
		]);

		BitrixMainPageAsset::getInstance()->addCss('/bitrix/js/calendar/userfield/resourcebooking.css');
		$resListItems = [];
		if (!empty($users))
		{
			foreach($users as $user)
			{
				$resListItems[] = ''.HtmlFilter::encode(CCalendar::getUserName($user)).'';
			}
		}
		if (!empty($resourceNames))
		{
			foreach($resourceNames as $resourceName)
			{
				$resListItems[] = ''.$resourceName.'';
			}
		}

		if (!empty($resListItems))
		{
			$html = ''.CCalendar::getFromToHtml($fromTs, $toTs, $skipTime, $toTs - $fromTs).': ';
			if(!empty($value['SERVICE_NAME']))
			{
				$html .= ''.HtmlFilter::encode($value['SERVICE_NAME']).', ';
			}
			$html .= ''.implode(', ', $resListItems).'';
		}
		else
		{
			$html = ''.Loc::getMessage("USER_TYPE_RESOURCE_EMPTY").'';
		}
	}
	else
	{
		BitrixMainUIExtension::load(['uf', 'calendar.resourcebookinguserfield']);
		if (empty($users) && empty($resourceNames))
		{
			$html = Loc::getMessage("USER_TYPE_RESOURCE_EMPTY");
		}
		else
		{
			ob_start();
			?>
			
wrapDisplayResult($html); }

Добавить комментарий