1
0
mirror of synced 2024-11-26 07:16:08 +03:00
bitrix-module/intaro.retailcrm/lib/repository/managerrepository.php
Сергей Чазов 8458360a30
Service for manager sync
* added service for manager sync
* added manager event handler in history uploading methods
* deleted logger dependence from repository
* extract config provider proxy methods from repository to service
2021-08-19 15:46:03 +03:00

68 lines
1.7 KiB
PHP

<?php
namespace Intaro\RetailCrm\Repository;
use Bitrix\Main\ORM\Objectify\EntityObject;
use Bitrix\Main\UserTable;
use RetailCrm\Component\Exception\FailedDbOperationException;
use RetailcrmConfigProvider;
use RetailcrmConstants;
/**
* Class ManagerRepository
*
* @package Intaro\RetailCrm\Repository
*/
class ManagerRepository
{
/**
* @param array $newMatches
*
* @return void
* @throws \RetailCrm\Component\Exception\FailedDbOperationException
*/
public function addManagersToMapping(array $newMatches): void
{
$usersMap = RetailcrmConfigProvider::getUsersMap();
if (is_array($usersMap)) {
$recordData = array_merge($usersMap, $newMatches);
} else {
$recordData = $newMatches;
}
if (!RetailcrmConfigProvider::setUsersMap($recordData)) {
throw new FailedDbOperationException();
}
}
/**
* @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;
}
}