ResourceBooking::getPublicText

  1. Bitrix24 API (v. 23.675.0)
  2. calendar
  3. ResourceBooking
  4. getPublicText
  • Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/lib/userfield/resourcebooking.php
  • Класс: BitrixCalendarUserFieldResourceBooking
  • Вызов: ResourceBooking::getPublicText
static function getPublicText($userField)
{
	$resultText = '';
	$value = static::fetchFieldValue($userField["VALUE"]);

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

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

	$userIdList = array_unique($userIdList);
	$resourseIdList = array_unique($resourseIdList);

	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($resourseIdList))
	{
		$sectionList = InternalsSectionTable::getList(
			array(
				"filter" => array(
					"=ACTIVE" => 'Y',
					"!=CAL_TYPE" => ['user', 'group', 'company_calendar', 'company', 'calendar_company'],
					"ID" => $resourseIdList
				),
				"select" => array("ID", "CAL_TYPE", "NAME")
			)
		);

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

	$resListItems = [];
	if (!empty($users))
	{
		foreach($users as $user)
		{
			$resListItems[] = CCalendar::getUserName($user);
		}
	}
	if (!empty($resourceNames))
	{
		foreach($resourceNames as $resourceName)
		{
			$resListItems[] = $resourceName;
		}
	}

	if (!empty($resListItems))
	{
		$skipTime = is_array($userField['SETTINGS']) && $userField['SETTINGS']['FULL_DAY'] === 'Y';
		$fromTs = isset($value['DATE_FROM']) ? CCalendar::timestamp($value['DATE_FROM'], true, !$skipTime) : 0;
		$toTs = isset($value['DATE_TO']) ? CCalendar::timestamp($value['DATE_TO'], true, !$skipTime) : 0;

		$resultText = CCalendar::getFromToHtml($fromTs, $toTs, $skipTime, $toTs - $fromTs).': ';
		$resultText = str_replace("–", '-', $resultText);
		if(!empty($value['SERVICE_NAME']))
		{
			$resultText .= $value['SERVICE_NAME'].', ';
		}
		$resultText .= implode(', ', $resListItems);
	}
	return $resultText;
}

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