• Модуль: imconnector
  • Путь к файлу: ~/bitrix/modules/imconnector/lib/connectors/base.php
  • Класс: BitrixImConnectorConnectorsBase
  • Вызов: Base::preparationUserFields
public function preparationUserFields(array $user, $userId = 0): array
{
	//The hash of the data
	$fields = [
		'UF_CONNECTOR_MD5' => md5(serialize($user))
	];

	//TODO: Hack to bypass the option of deleting the comment
	if (isset($user['name']))
	{
		//Name
		if (Library::isEmpty($user['name']))
		{
			$fields['NAME'] = '';
		}
		else
		{
			$fields['NAME'] = $user['name'];
		}
	}
	//Surname
	if (Library::isEmpty($user['last_name']))
	{
		$fields['LAST_NAME'] = '';
	}
	else
	{
		$fields['LAST_NAME'] = $user['last_name'];
	}

	if (
		Library::isEmpty($fields['NAME'])
		&& Library::isEmpty($fields['LAST_NAME'])
	)
	{
		if (Library::isEmpty($user['title']))
		{
			$fields['NAME'] = Loc::getMessage("IMCONNECTOR_GUEST_USER");
		}
		else
		{
			$fields['NAME'] = $user['title'];
		}
	}

	//The link to the profile
	if (empty($user['url']))
	{
		$fields['PERSONAL_WWW'] = '';
	}
	else
	{
		$fields['PERSONAL_WWW'] = $user['url'];
	}

	//Sex
	if (empty($user['gender']))
	{
		$fields['PERSONAL_GENDER'] = '';
	}
	else
	{
		if ($user['gender'] == 'male')
		{
			$fields['PERSONAL_GENDER'] = 'M';
		}
		elseif($user['gender'] == 'female')
		{
			$fields['PERSONAL_GENDER'] = 'F';
		}
	}
	//Personal photo
	if (
		!empty($user['picture'])
		&& is_array($user['picture'])
	)
	{
		$fields['PERSONAL_PHOTO'] = Library::downloadFile($user['picture']);

		if (
			!empty($fields['PERSONAL_PHOTO'])
			&& !empty($userId)
		)
		{
			$rowUser = UserTable::getList(
				[
					'select' => ['PERSONAL_PHOTO'],
					'filter' => ['ID' => $userId]
				]
			)->fetch();

			if (!empty($rowUser['PERSONAL_PHOTO']))
			{
				$fields['PERSONAL_PHOTO']['del'] = 'Y';
				$fields['PERSONAL_PHOTO']['old_file'] = $rowUser['PERSONAL_PHOTO'];
			}
		}
	}

	if (
		isset($user['title'])
		&& !Library::isEmpty($user['title'])
	)
	{
		$fields['TITLE'] = $user['title'];
	}

	if (
		isset($user['email'])
		&& !Library::isEmpty($user['email'])
	)
	{
		$fields['EMAIL'] = $user['email'];
	}

	if (
		isset($user['phone'])
		&& !Library::isEmpty($user['phone'])
	)
	{
		$fields['PERSONAL_MOBILE'] = $user['phone'];
	}

	return $fields;
}