2021-08-19 15:46:03 +03:00
|
|
|
<?php
|
|
|
|
|
2024-04-29 11:44:31 +03:00
|
|
|
/**
|
|
|
|
* @category Integration
|
|
|
|
* @package Intaro\RetailCrm\Repository
|
|
|
|
* @author RetailCRM <integration@retailcrm.ru>
|
|
|
|
* @license MIT
|
|
|
|
* @link http://retailcrm.ru
|
|
|
|
* @see http://retailcrm.ru/docs
|
|
|
|
*/
|
2021-08-19 15:46:03 +03:00
|
|
|
|
|
|
|
namespace Intaro\RetailCrm\Repository;
|
|
|
|
|
|
|
|
use Bitrix\Main\ORM\Objectify\EntityObject;
|
|
|
|
use Bitrix\Main\UserTable;
|
|
|
|
use RetailcrmConfigProvider;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ManagerRepository
|
|
|
|
*
|
|
|
|
* @package Intaro\RetailCrm\Repository
|
|
|
|
*/
|
|
|
|
class ManagerRepository
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param array $newMatches
|
|
|
|
*
|
|
|
|
* @return void
|
2022-03-02 15:40:53 +03:00
|
|
|
* @throws \Bitrix\Main\ArgumentOutOfRangeException
|
2021-08-19 15:46:03 +03:00
|
|
|
*/
|
|
|
|
public function addManagersToMapping(array $newMatches): void
|
|
|
|
{
|
|
|
|
$usersMap = RetailcrmConfigProvider::getUsersMap();
|
|
|
|
|
|
|
|
if (is_array($usersMap)) {
|
|
|
|
$recordData = array_merge($usersMap, $newMatches);
|
|
|
|
} else {
|
|
|
|
$recordData = $newMatches;
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:40:53 +03:00
|
|
|
RetailcrmConfigProvider::setUsersMap($recordData);
|
2021-08-19 15:46:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $email
|
|
|
|
*
|
|
|
|
* @return int|null
|
|
|
|
* @throws \Bitrix\Main\ArgumentException
|
|
|
|
* @throws \Bitrix\Main\ObjectPropertyException
|
|
|
|
* @throws \Bitrix\Main\SystemException
|
|
|
|
*/
|
|
|
|
public function getManagerBitrixIdByEmail(string $email): ?int
|
|
|
|
{
|
|
|
|
/** @var \Bitrix\Main\ORM\Objectify\EntityObject $user */
|
|
|
|
$user = UserTable::query()
|
|
|
|
->addSelect('ID')
|
|
|
|
->where('EMAIL', $email)
|
|
|
|
->exec()
|
|
|
|
->fetchObject();
|
|
|
|
|
|
|
|
if ($user instanceof EntityObject) {
|
|
|
|
$userId = $user->get('ID');
|
|
|
|
|
|
|
|
if (is_int($userId) && $userId > 0) {
|
|
|
|
return $userId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|